diff --git a/app/static/js/services/soundfontPlayer.js b/app/static/js/services/soundfontPlayer.js
index 397fc9a..c1339cf 100644
--- a/app/static/js/services/soundfontPlayer.js
+++ b/app/static/js/services/soundfontPlayer.js
@@ -42,26 +42,41 @@
// ── SpessaSynth init ──
init: async function (audioContext) {
if (_initialized && _synthInstance) return;
- if (!window.SpessaSynthClass) {
- console.warn("[SonicSF] SpessaSynth not loaded yet. Retrying in 1s...");
- // Retry once after module script loads
+ if (!window.SpessaSynthClass || !window.__SpessaSynthCDN) {
+ console.warn("[SonicSF] SpessaSynth not loaded yet. Retrying in 2s...");
setTimeout(() => {
if (!_initialized && window.SpessaSynthClass && audioContext) {
this.init(audioContext);
}
- }, 1000);
+ }, 2000);
return;
}
try {
- _synthInstance = new window.SpessaSynthClass(audioContext.destination);
+ // Register the AudioWorklet processor from CDN
+ const procUrl = window.__SpessaSynthCDN + "spessasynth_processor.min.js";
+ await audioContext.audioWorklet.addModule(procUrl);
+ // Create WorkletSynthesizer
+ _synthInstance = new window.SpessaSynthClass(audioContext);
+ // Wait for synth to be ready (loads default soundbank)
+ await _synthInstance.isReady;
_initialized = true;
- console.log("[SonicSF] SpessaSynth initialized.");
+ console.log("[SonicSF] SpessaSynth initialized via AudioWorklet.");
// Auto-load default SF3
if (_currentSfId === null) {
this.loadSoundFont("sgm_v2.01");
}
} catch (e) {
- console.error("[SonicSF] SpessaSynth init failed:", e);
+ console.warn("[SonicSF] SpessaSynth AudioWorklet init failed:", e, "- trying WorkerSynthesizer...");
+ try {
+ const { WorkerSynthesizer } = await import(window.__SpessaSynthCDN + "index.js");
+ _synthInstance = new WorkerSynthesizer(audioContext);
+ await _synthInstance.isReady;
+ _initialized = true;
+ console.log("[SonicSF] SpessaSynth initialized via Worker.");
+ if (_currentSfId === null) this.loadSoundFont("sgm_v2.01");
+ } catch (e2) {
+ console.error("[SonicSF] SpessaSynth init failed completely:", e2);
+ }
}
},
@@ -89,11 +104,11 @@
}
}
try {
- await _synthInstance.soundFontManager.addSoundFont(buffer);
+ await _synthInstance.soundBankManager.addSoundBank(buffer, sfId);
_currentSfId = sfId;
console.log("[SonicSF] SoundFont loaded:", sfId);
} catch (e) {
- console.error("[SonicSF] Error parsing SF3:", e);
+ console.error("[SonicSF] Error parsing SF in SpessaSynth:", e);
}
},
diff --git a/app/templates/index.html b/app/templates/index.html
index ffcc05f..f5ce43e 100644
--- a/app/templates/index.html
+++ b/app/templates/index.html
@@ -11,8 +11,9 @@