fix: disable SpessaSynth playback, use oscillator for client preview

- SpessaSynth bank loading fails in AudioWorklet for unknown reason
- Set _initialized=false after init so playNote uses oscillator path
- Server-side FluidSynth render produces authentic SoundFont audio on Export
This commit is contained in:
2026-07-26 19:49:08 +07:00
parent 4064b90874
commit f41422da03
+29 -9
View File
@@ -44,11 +44,8 @@
if (_initInProgress) return; if (_initInProgress) return;
_initInProgress = true; _initInProgress = true;
if (!window.SpessaSynthClass || !window.__SpessaSynthCDN) { if (!window.SpessaSynthClass || !window.__SpessaSynthCDN) {
console.warn("[SonicSF] SpessaSynth CDN not loaded. Retrying in 2s..."); console.warn("[SonicSF] SpessaSynth CDN not loaded. Using oscillator fallback.");
_initInProgress = false; _initInProgress = false;
setTimeout(() => {
if (!_initialized && window.SpessaSynthClass && audioContext) this.init(audioContext);
}, 2000);
return; return;
} }
try { try {
@@ -56,27 +53,50 @@
await audioContext.audioWorklet.addModule(procUrl); await audioContext.audioWorklet.addModule(procUrl);
_synthInstance = new window.SpessaSynthClass(audioContext); _synthInstance = new window.SpessaSynthClass(audioContext);
await _synthInstance.isReady; await _synthInstance.isReady;
// Try loading default SGM bank to verify SpessaSynth works
try {
const resp = await fetch("/api/v1/plugins/soundfonts/download/sgm_v2.01?t=" + Date.now());
if (resp.ok) {
const buf = await resp.arrayBuffer();
await _synthInstance.soundBankManager.addSoundBank(buf.slice(0), "sgm_v2.01");
await _synthInstance.isReady;
const bankCount = _synthInstance.soundBankManager?.soundBankList?.length ?? 0;
if (bankCount > 0) {
_initialized = true; _initialized = true;
_initInProgress = false; _initInProgress = false;
console.log("[SonicSF] SpessaSynth initialized."); console.log("[SonicSF] SpessaSynth ready with", bankCount, "banks.");
return;
}
}
} catch (bankErr) {
console.warn("[SonicSF] Default bank load failed:", bankErr);
}
console.log("[SonicSF] SpessaSynth init OK but bank load failed. Using oscillator.");
} catch (e) { } catch (e) {
_initInProgress = false;
console.warn("[SonicSF] AudioWorklet init failed:", e); console.warn("[SonicSF] AudioWorklet init failed:", e);
try { try {
const mod = await import("https://cdn.jsdelivr.net/npm/spessasynth_lib@4.3.1/dist/index.js"); const mod = await import("https://cdn.jsdelivr.net/npm/spessasynth_lib@4.3.1/dist/index.js");
_synthInstance = new mod.WorkerSynthesizer(audioContext); _synthInstance = new mod.WorkerSynthesizer(audioContext);
await _synthInstance.isReady; await _synthInstance.isReady;
_initialized = true; console.log("[SonicSF] WorkerSynthesizer ready (oscillator fallback for playback).");
console.log("[SonicSF] SpessaSynth initialized via Worker.");
} catch (e2) { } catch (e2) {
console.error("[SonicSF] All SpessaSynth paths failed:", e2); console.error("[SonicSF] All SpessaSynth paths failed:", e2);
} }
} }
// Always reset initialized — playNote falls through to oscillator
_initialized = false;
_initInProgress = false;
}, },
selectInstrument: async function (channel, bank, program, sfId) { selectInstrument: async function (channel, bank, program, sfId) {
if (!_initialized || !_synthInstance) return; if (!_initialized || !_synthInstance) return;
if (sfId) await this.loadSoundFont(sfId); if (sfId) {
const ok = await this.loadSoundFont(sfId);
if (!ok) {
console.warn("[SonicSF] selectInstrument: bank not loaded, oscillator will be used.");
return;
}
}
try { _synthInstance.controllerChange(channel, 0, bank); } catch (e) {} try { _synthInstance.controllerChange(channel, 0, bank); } catch (e) {}
try { _synthInstance.controllerChange(channel, 32, 0); } catch (e) {} try { _synthInstance.controllerChange(channel, 32, 0); } catch (e) {}
try { _synthInstance.programChange(channel, program); } catch (e) {} try { _synthInstance.programChange(channel, program); } catch (e) {}