fix: SpessaSynth init retry + default SF3 auto-load
- getAudioContext() calls SonicSF.init on every call (not just first) - soundfontPlayer.init retries after 1s if SpessaSynth module not loaded yet - Auto-loads sgm_v2.01 SF3 on successful init - Fixes race condition: module script loads after regular scripts
This commit is contained in:
@@ -41,15 +41,25 @@
|
||||
|
||||
// ── SpessaSynth init ──
|
||||
init: async function (audioContext) {
|
||||
if (_initialized) return;
|
||||
if (_initialized && _synthInstance) return;
|
||||
if (!window.SpessaSynthClass) {
|
||||
console.warn("[SonicSF] SpessaSynth not loaded. Using oscillator fallback.");
|
||||
console.warn("[SonicSF] SpessaSynth not loaded yet. Retrying in 1s...");
|
||||
// Retry once after module script loads
|
||||
setTimeout(() => {
|
||||
if (!_initialized && window.SpessaSynthClass && audioContext) {
|
||||
this.init(audioContext);
|
||||
}
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
_synthInstance = new window.SpessaSynthClass(audioContext.destination);
|
||||
_initialized = true;
|
||||
console.log("[SonicSF] SpessaSynth initialized.");
|
||||
// Auto-load default SF3
|
||||
if (_currentSfId === null) {
|
||||
this.loadSoundFont("sgm_v2.01");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("[SonicSF] SpessaSynth init failed:", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user