import fs from 'node:fs';import path from 'node:path'; const rate=22050; function writeWav(root,name,samples){const n=samples.length,b=Buffer.alloc(44+n*2);b.write('RIFF');b.writeUInt32LE(b.length-8,4);b.write('WAVEfmt ',8);b.writeUInt32LE(16,16);b.writeUInt16LE(1,20);b.writeUInt16LE(1,22);b.writeUInt32LE(rate,24);b.writeUInt32LE(rate*2,28);b.writeUInt16LE(2,32);b.writeUInt16LE(16,34);b.write('data',36);b.writeUInt32LE(n*2,40);for(let i=0;inotes.map((midi,j)=>({f:Math.round(440*2**((midi-69)/12)*seconds)/seconds,phase:(k*1.7+j*.9),gain:j===0?.75:1}))); let sum=0,peak=0; for(let i=0;i