fix: unload old SoundFont before loading new one
- Add _currentSfId tracking - loadSoundFont calls deleteSoundBank(oldId) before addSoundBank(newId) - Skip reload if same sfId requested - Prevents bank accumulation in SpessaSynth
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
let _synthInstance = null;
|
||||
let _initialized = false;
|
||||
let _initPromise = null;
|
||||
let _currentSfId = null;
|
||||
|
||||
const SonicSF = {
|
||||
loadedFonts: {},
|
||||
@@ -60,7 +61,12 @@
|
||||
|
||||
loadSoundFont: async function (sfId) {
|
||||
if (!_initialized || !_synthInstance) return false;
|
||||
if (_currentSfId === sfId) return true;
|
||||
try {
|
||||
// Unload previous SoundFont
|
||||
if (_currentSfId) {
|
||||
try { _synthInstance.soundBankManager.deleteSoundBank(_currentSfId); } catch (e) {}
|
||||
}
|
||||
const cache = window.SonicSFStorage;
|
||||
let buf = cache ? await cache.getBuffer(sfId) : null;
|
||||
if (!buf) {
|
||||
@@ -72,6 +78,7 @@
|
||||
}
|
||||
await _synthInstance.soundBankManager.addSoundBank(buf.slice(0), sfId);
|
||||
await _synthInstance.isReady;
|
||||
_currentSfId = sfId;
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.warn("[SonicSF] loadSoundFont failed:", e);
|
||||
|
||||
Reference in New Issue
Block a user