fix: SpessaSynth CDN URL + AudioWorklet init flow
- Fix CDN URL: spessasynth_lib@4.3.1/dist/index.js (was @latest with wrong path) - Use WorkletSynthesizer instead of Synthesizer (correct class name) - Add audioWorklet.addModule() for processor CDN URL - Await synth.isReady before use - Use soundBankManager.addSoundBank() (correct API) - Fallback to WorkerSynthesizer if AudioWorklet fails
This commit is contained in:
@@ -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);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user