From 28be934a1927c85eadf42df4849f609918a26eb0 Mon Sep 17 00:00:00 2001 From: 3dtours Date: Sun, 26 Jul 2026 20:47:15 +0700 Subject: [PATCH] fix: schedule SpessaSynth noteOn by startTime via setTimeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: timeline play passes exactAudioTime as 4th param which SpessaSynth interprets as enableReverh (boolean). All notes at T=0. Fix: compute delay = startTime - ctx.currentTime, use setTimeout to call noteOn(channel, pitch, vel) at correct future time. Never pass startTime to noteOn() — SpessaSynth doesn't support it. --- app/static/js/services/soundfontPlayer.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js index c3c60a6..07d181e 100644 --- a/app/static/js/services/soundfontPlayer.js +++ b/app/static/js/services/soundfontPlayer.js @@ -159,13 +159,18 @@ } if (channel === undefined) channel = 0; const durSec = durationMs / 1000; - try { - _synthInstance.noteOn(channel, midiPitch, midiVel); - setTimeout(() => { try { _synthInstance.noteOff(channel, midiPitch); } catch (e) {} }, durSec * 1000); - } catch (e) { - console.warn("[SonicSF] SpessaSynth noteOn error, oscillator fallback:", e); - this._playNoteOsc(note, velocity, durationMs, startTime, program, null, channel, synthEngine); - } + const now = ctx.currentTime; + const delay = (typeof startTime === 'number' && startTime > now) ? (startTime - now) : 0; + const doNote = () => { + try { + _synthInstance.noteOn(channel, midiPitch, midiVel); + setTimeout(() => { try { _synthInstance.noteOff(channel, midiPitch); } catch (e) {} }, durSec * 1000); + } catch (e) { + console.warn("[SonicSF] SpessaSynth noteOn error:", e); + this._playNoteOsc(note, velocity, durationMs, startTime, program, null, channel, synthEngine); + } + }; + if (delay > 0) setTimeout(doNote, delay * 1000); else doNote(); }, _playNoteOsc: function (note, velocity, durationMs, startTime, program, destinationNode, channel, synthEngine) {