const {execFileSync}=require('node:child_process'); const ff=process.env.FFMPEG || 'ffmpeg'; const normal='0.25*sin(2*PI*1000*t)'; const input=sign=>'aevalsrc='+normal+'|'+sign+'('+normal+'):s=48000:d=2:c=stereo'; const results={}; for(const [name,sign] of [['inverted','-'],['corrected','']]){ for(const [channel,filter] of [['left','pan=mono|c0=c0'],['right','pan=mono|c0=c1'],['mono','pan=mono|c0=0.5*c0+0.5*c1']]){ const pcm=execFileSync(ff,['-v','error','-f','lavfi','-i',input(''),'-f','lavfi','-i',input(sign),'-filter_complex','[0:a][1:a]concat=n=2:v=0:a=1,'+filter,'-f','s16le','-'],{maxBuffer:2000000}); results[name]??={}; results[name][channel]=[0,1].map(segment=>{ const samples=48000*2; let peak=0,nonzero=0; for(let i=segment*samples;i<(segment+1)*samples;i++){ const value=Math.abs(pcm.readInt16LE(i*2)); peak=Math.max(peak,value); if(value)nonzero++; } return {samples,peak,nonzero}; }); } } console.log(JSON.stringify(results,null,2));