// Render notes of a preset from an SF2 with spessasynth_core, dry (effects off), mono — used for // the reference comparison (GeneralUser GS "Acoustic Bass", program 32, by default) in the app's // worker and in scripts/render_reference.ts. import { SoundBankLoader, SpessaSynthProcessor } from "spessasynth_core"; export async function renderReference(sf2: ArrayBuffer | Uint8Array, program: number, notes: [number, number][], hold: number, len: number, fs = 44100, bank = 0): Promise { const buf = sf2 instanceof Uint8Array ? (sf2.buffer.slice(sf2.byteOffset, sf2.byteOffset + sf2.byteLength) as ArrayBuffer) : sf2; const out: Float32Array[] = []; for (const [note, vel] of notes) { const synth = new SpessaSynthProcessor(fs, { effectsEnabled: false } as never); synth.soundBankManager.addSoundBank(SoundBankLoader.fromArrayBuffer(buf.slice(0)), "main"); await (synth as unknown as { ready: Promise }).ready; if (bank) synth.controllerChange(0, 0 as never, bank); synth.programChange(0, program); const n = Math.round(len * fs); const L = new Float32Array(n), R = new Float32Array(n); const block = 128, off = Math.round(hold * fs); synth.noteOn(0, note, vel); let released = false; for (let s = 0; s < n; s += block) { if (!released && s + block > off) { synth.noteOff(0, note); released = true; } synth.process(L, R, s, Math.min(block, n - s)); } const m = new Float32Array(n); for (let i = 0; i < n; i++) m[i] = 0.5 * (L[i] + R[i]); out.push(m); } return out; }