var g=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports);var m=g((D,s)=>{"use strict";var d={1:"lpcm",3:"lpcm"};function p(r,t){t=t||{},global.Buffer&&r instanceof global.Buffer&&(r=Uint8Array.from(r).buffer);var n=new DataView(r),e=U(n);if(e.string(4)!=="RIFF")throw new TypeError("Invalid WAV file");if(e.uint32(),e.string(4)!=="WAVE")throw new TypeError("Invalid WAV file");var u=null,a=null;do{var o=e.string(4),i=e.uint32();switch(o){case"fmt ":if(u=h(e,i),u instanceof Error)throw u;break;case"data":if(a=b(e,i,u,t),a instanceof Error)throw a;break;default:e.skip(i);break}}while(a===null);return a}function x(r,t){return new Promise(function(n){n(p(r,t))})}function h(r,t){var n=r.uint16();if(!d.hasOwnProperty(n))return new TypeError("Unsupported format in WAV file: 0x"+n.toString(16));var e={formatId:n,floatingPoint:n===3,numberOfChannels:r.uint16(),sampleRate:r.uint32(),byteRate:r.uint32(),blockSize:r.uint16(),bitDepth:r.uint16()};return r.skip(t-16),e}function b(r,t,n,e){t=Math.min(t,r.remain());for(var u=Math.floor(t/n.blockSize),a=n.numberOfChannels,o=n.sampleRate,i=new Array(a),f=0;f<a;f++)i[f]=new Float32Array(u);var c=y(r,i,u,n,e);return c instanceof Error?c:{numberOfChannels:a,length:u,sampleRate:o,channelData:i}}function y(r,t,n,e,u){var a=e.bitDepth,o=e.floatingPoint?"f":u.symmetric?"s":"",i="pcm"+a+o;if(!r[i])return new TypeError("Not supported bit depth: "+e.bitDepth);for(var f=r[i].bind(r),c=e.numberOfChannels,v=0;v<n;v++)for(var l=0;l<c;l++)t[l][v]=f();return null}function U(r){var t=0;return{remain:function(){return r.byteLength-t},skip:function(n){t+=n},uint8:function(){var n=r.getUint8(t,!0);return t+=1,n},int16:function(){var n=r.getInt16(t,!0);return t+=2,n},uint16:function(){var n=r.getUint16(t,!0);return t+=2,n},uint32:function(){var n=r.getUint32(t,!0);return t+=4,n},string:function(n){for(var e="",u=0;u<n;u++)e+=String.fromCharCode(this.uint8());return e},pcm8:function(){var n=r.getUint8(t)-128;return t+=1,n<0?n/128:n/127},pcm8s:function(){var n=r.getUint8(t)-127.5;return t+=1,n/127.5},pcm16:function(){var n=r.getInt16(t,!0);return t+=2,n<0?n/32768:n/32767},pcm16s:function(){var n=r.getInt16(t,!0);return t+=2,n/32768},pcm24:function(){var n=r.getUint8(t+0),e=r.getUint8(t+1),u=r.getUint8(t+2),a=n+(e<<8)+(u<<16),o=a>8388608?a-16777216:a;return t+=3,o<0?o/8388608:o/8388607},pcm24s:function(){var n=r.getUint8(t+0),e=r.getUint8(t+1),u=r.getUint8(t+2),a=n+(e<<8)+(u<<16),o=a>8388608?a-16777216:a;return t+=3,o/8388608},pcm32:function(){var n=r.getInt32(t,!0);return t+=4,n<0?n/2147483648:n/2147483647},pcm32s:function(){var n=r.getInt32(t,!0);return t+=4,n/2147483648},pcm32f:function(){var n=r.getFloat32(t,!0);return t+=4,n},pcm64f:function(){var n=r.getFloat64(t,!0);return t+=8,n}}}s.exports.decode=x;s.exports.decode.sync=p});var I=m();module.exports=I;
