/** * Minimal float32 WAV encoder (format tag 3, IEEE float, mono). The * header is exactly 44 bytes with no extra chunks, which the offline * evaluation harness relies on: numbl has no audioread, so tools/load_wav.m * reads the rate at byte 24 and the samples from byte 44. Real MATLAB, * Python soundfile, and audio editors read these files normally. */ export function wavFloat32(samples: Float32Array, sr: number): Uint8Array { const dataLen = samples.length * 4; const buf = new ArrayBuffer(44 + dataLen); const v = new DataView(buf); const ascii = (off: number, s: string) => { for (let i = 0; i < s.length; i++) v.setUint8(off + i, s.charCodeAt(i)); }; ascii(0, 'RIFF'); v.setUint32(4, 36 + dataLen, true); ascii(8, 'WAVE'); ascii(12, 'fmt '); v.setUint32(16, 16, true); // fmt chunk size v.setUint16(20, 3, true); // IEEE float v.setUint16(22, 1, true); // mono v.setUint32(24, sr, true); v.setUint32(28, sr * 4, true); // byte rate v.setUint16(32, 4, true); // block align v.setUint16(34, 32, true); // bits per sample ascii(36, 'data'); v.setUint32(40, dataLen, true); new Float32Array(buf, 44).set(samples); return new Uint8Array(buf); }