fix: schedule SpessaSynth noteOn by startTime via setTimeout
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.
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user