import fs from 'node:fs';import path from 'node:path'; export function buildAudio(root){ const out=path.join(root,'audio');fs.mkdirSync(out,{recursive:true}); const cues={ui:[[659,.055,0],[784,.06,.025]],hint:[[523,.09,0],[659,.10,.055],[784,.13,.11]],correct:[[659,.11,0]],error:[[330,.09,0],[247,.09,.045]],undo:[[440,.065,0]],restart:[[523,.08,0],[392,.09,.06]],complete:[[261.6256,.96,0,.8],[329.6276,.68,0,.62],[392,.62,0,.48],[523.251,.5,0,.16]],checkpoint:[[523,.14,0]]}; for(let n=1;n<=36;n++){const f=523*Math.pow(2,(n-1)/12);cues['move-'+n]=[[f,.09,0]];cues['checkpoint-'+n]=[[f,.14,0]];} for(const [name,tones]of Object.entries(cues)){ const rate=22050,length=Math.ceil((Math.max(...tones.map(([,d,t])=>d+t))+.02)*rate),b=Buffer.alloc(44+length*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(length*2,40); for(let i=0;i=d)continue; const move=name.startsWith('move-'),node=name.startsWith('checkpoint'),attenuation=1/(1+Math.pow(f/2300,1.35)); const gain=(name==='complete'?.20:node?.38:move?.28:.23)*attenuation*weight; const tau=name==='complete'?.11:node?.032:move?.022:.025; const env=(1-Math.exp(-u/(node?.0015:.003)))*Math.exp(-u/tau)*Math.min(1,(d-u)/.008); sample+=(Math.sin(2*Math.PI*f*u)+.10*Math.exp(-u/.012)*Math.sin(4*Math.PI*f*u))*gain*env; }b.writeInt16LE(Math.round(Math.max(-1,Math.min(1,sample))*32767),44+i*2);}fs.writeFileSync(path.join(out,name+'.wav'),b); } }