Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wavefile

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wavefile - npm Package Compare versions

Comparing version 10.2.0 to 10.3.0

lib/wavefile-cue-editor.js

27

CHANGELOG.md
# CHANGELOG
## version 10.3.0 - 2020-01-20
### Features
- New resample methods: *linear* for linear interpolation and *point* for nearest point interpolation. Both methods use no LPF by default; others methods use LPF by default.
- Resample with or without LPF using any interpolation method:
```javascript
// Resample using cubic without LPF
wav.toSampleRate(44100, {method: 'cubic', LPF: false});
// Resample using cubic with LPF:
wav.toSampleRate(44100, {method: 'cubic', LPF: true});
// cubic and sinc use LPF by default
wav.toSampleRate(44100, {method: 'cubic'}); // will use LPF
```
- You can now use any Typed Array as the output for ```getSamples()```:
```javascript
// Will return the samples de-interleaved,
// packed in a array of Int32Array objects, one for each channel
samples = wav.getSamples(false, Int32Array);
// will return the samples de-interleaved,
// packed in a array of Int16Array objects, one for each channel
let samples = getSamples(false, Int16Array);
// will return the samples interleaved, packed in a Int16Array
let samples = getSamples(true, Int16Array);
```
## version 10.2.0 - 2020-01-16

@@ -4,0 +31,0 @@ Change the sample rate.

169

dist/wavefile.js

@@ -1,84 +0,85 @@

try{if(!Uint8Array.prototype.slice)Object.defineProperty(Uint8Array.prototype,"slice",{value:function(begin,end){return new Uint8Array(Array.prototype.slice.call(this,begin,end))}})}catch(err){}var aa="function"==typeof Object.create?Object.create:function(p){function m(){}m.prototype=p;return new m},F;
if("function"==typeof Object.setPrototypeOf)F=Object.setPrototypeOf;else{var N;a:{var ba={xa:!0},na={};try{na.__proto__=ba;N=na.xa;break a}catch(p){}N=!1}F=N?function(p,m){p.__proto__=m;if(p.__proto__!==m)throw new TypeError(p+" is not extensible");return p}:null}var oa=F;
function Q(p,m){p.prototype=aa(m.prototype);p.prototype.constructor=p;if(oa)oa(p,m);else for(var l in m)if("prototype"!=l)if(Object.defineProperties){var r=Object.getOwnPropertyDescriptor(m,l);r&&Object.defineProperty(p,l,r)}else p[l]=m[l]}var pa="function"==typeof Object.defineProperties?Object.defineProperty:function(p,m,l){p!=Array.prototype&&p!=Object.prototype&&(p[m]=l.value)},qa="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;
function R(p,m){if(m){for(var l=qa,r=p.split("."),v=0;v<r.length-1;v++){var n=r[v];n in l||(l[n]={});l=l[n]}r=r[r.length-1];v=l[r];n=m(v);n!=v&&null!=n&&pa(l,r,{configurable:!0,writable:!0,value:n})}}R("Object.is",function(p){return p?p:function(m,l){return m===l?0!==m||1/m===1/l:m!==m&&l!==l}});
R("Array.prototype.includes",function(p){return p?p:function(m,l){var r=this;r instanceof String&&(r=String(r));var v=r.length,n=l||0;for(0>n&&(n=Math.max(n+v,0));n<v;n++){var t=r[n];if(t===m||Object.is(t,m))return!0}return!1}});
R("String.prototype.codePointAt",function(p){return p?p:function(m){if(null==this)throw new TypeError("The 'this' value for String.prototype.codePointAt must not be null or undefined");var l=this.length;m=Number(m)||0;if(0<=m&&m<l){m|=0;var r=this.charCodeAt(m);if(55296>r||56319<r||m+1===l)return r;m=this.charCodeAt(m+1);return 56320>m||57343<m?r:1024*(r-55296)+m+9216}}});
var ra="function"==typeof Object.assign?Object.assign:function(p,m){for(var l=1;l<arguments.length;l++){var r=arguments[l];if(r)for(var v in r)Object.prototype.hasOwnProperty.call(r,v)&&(p[v]=r[v])}return p};R("Object.assign",function(p){return p||ra});var S=this;
function T(p){function m(a){a=void 0===a?null:a;var b=l.call(this)||this;a&&b.fromBuffer(a);return b}function l(){return n.apply(this,arguments)||this}function r(a,b,c){c=2*Math.PI*c/b;b=0;this.a=[];for(var d=0;d<=a;d++)0===d-a/2?this.a[d]=c:(this.a[d]=Math.sin(c*(d-a/2))/(d-a/2),this.a[d]*=.54-.46*Math.cos(2*Math.PI*d/a)),b+=this.a[d];for(c=0;c<=a;c++)this.a[c]/=b;for(a=0;a<this.a.length;a++);a=[];for(b=0;b<this.a.length-1;b++)a.push(0);this.b={L:a,O:0}}function v(a,b,c){this.F=a;this.l=(a-1)/b;
this.j=this.J;"point"===c.method?this.j=this.I:"linear"===c.method?this.j=this.H:"cubic"===c.method&&(this.j=this.G);this.s=sa;"periodic"===c.clip?(this.l=a/b,this.s=ca):"mirror"===c.clip&&(this.s=ta);this.K=1-Math.max(0,Math.min(1,c.tension||0));this.B=c.sincFilterSize||1;this.A=da(c.sincWindow||ua);"lanczos"===c.method&&(this.A=da(va(c.lanczosFilterSize)),this.sincFilterSize=c.lanczosFilterSize)}function n(){return t.apply(this,arguments)||this}function t(){var a=u.call(this)||this;a.bitDepth="0";
a.f={h:0,o:!1,D:!1,M:!1};a.F={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};return a}function u(){return w.apply(this,arguments)||this}function w(){var a=A.call(this)||this;a.W.push("RF64");a.fmt={chunkId:"",chunkSize:0,audioFormat:0,numChannels:0,sampleRate:0,byteRate:0,blockAlign:0,bitsPerSample:0,cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]};a.fact={chunkId:"",chunkSize:0,dwSampleLength:0};a.cue={chunkId:"",chunkSize:0,dwCuePoints:0,points:[]};a.smpl={chunkId:"",chunkSize:0,
dwManufacturer:0,dwProduct:0,dwSamplePeriod:0,dwMIDIUnityNote:0,dwMIDIPitchFraction:0,dwSMPTEFormat:0,dwSMPTEOffset:0,dwNumSampleLoops:0,dwSamplerData:0,loops:[]};a.bext={chunkId:"",chunkSize:0,description:"",originator:"",originatorReference:"",originationDate:"",originationTime:"",timeReference:[0,0],version:0,UMID:"",loudnessValue:0,loudnessRange:0,maxTruePeakLevel:0,maxMomentaryLoudness:0,maxShortTermLoudness:0,reserved:"",codingHistory:""};a.iXML={chunkId:"",chunkSize:0,value:""};a.ds64={chunkId:"",
chunkSize:0,riffSizeHigh:0,riffSizeLow:0,dataSizeHigh:0,dataSizeLow:0,originationTime:0,sampleCountHigh:0,sampleCountLow:0};a.data={chunkId:"",chunkSize:0,samples:new Uint8Array(0)};a.LIST=[];a.junk={chunkId:"",chunkSize:0,chunkData:[]};a._PMX={chunkId:"",chunkSize:0,value:""};a.g={h:16,o:!1,D:!1,M:!1};return a}function A(){this.container="";this.chunkSize=0;this.format="";this.V={};this.c=0;this.a={h:32,o:!1,D:!1,M:!1};this.W=["RIFF","RIFX"]}function H(a,b,c){this.a=this.c(a,b,c);this.offset=Math.ceil(a/
8)}function L(a){a=B.call(this,a)||this;a.max=Math.pow(2,a.h)/2-1;a.min=-a.max-1;return a}function B(a){this.h=a;this.b=8>a?1:Math.ceil(a/8);this.max=Math.pow(2,a)-1;this.min=0;a=8-((a-1|7)+1-a);this.f=Math.pow(2,0<a?a:8)-1}function I(a,b){this.b=a;this.c=b;this.a=(1<<a-1)-1;this.f=Math.ceil((a+b)/8);this.g=Math.pow(2,this.a+1);this.i=a+b;this.j=Math.pow(2,-(8*this.f-1-a))}function wa(a){for(var b=new Uint8Array(256),c=0;64>c;c++)b["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(c)]=
c;c=.75*a.length;"="===a[a.length-1]&&(c--,"="===a[a.length-2]&&c--);c=new ArrayBuffer(c);for(var d=new Uint8Array(c),e=0,f=0;e<a.length;e+=4){var h=b[a.charCodeAt(e)],k=b[a.charCodeAt(e+1)],q=b[a.charCodeAt(e+2)],y=b[a.charCodeAt(e+3)];d[f++]=h<<2|k>>4;d[f++]=(k&15)<<4|q>>2;d[f++]=(q&3)<<6|y&63}return c}function xa(a,b){return a=0<a?parseInt(a/b.aa*b.Z,10):parseInt(a/b.ba*b.$,10)}function ya(a,b){return parseInt(0<a?a*b.Z:a*b.$,10)}function za(a,b){return 0<a?a/b.aa:a/b.ba}function Aa(a,b){function c(d){return d}
a!=b&&(c=["32f","64"].includes(a)?ya:["32f","64"].includes(b)?za:xa);return c}function ea(a){if("32f"!=a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}function fa(a,b,c){if("8"==a)for(a=c?-128:128,c=0;c<b.length;c++)b[c]=b[c]+=a}function Ba(a){for(var b=new Uint8Array(a.length),c=[],d=0,e=0,f=0;f<a.length;f++)0==f%505&&0!=f&&(b.set(Ca(c),d),d+=256,c=[],e++),c.push(a[f]);a=a.length/2;a%2&&a++;return b.slice(0,a+512+4*e)}function Da(a,b){b=void 0===b?256:b;for(var c=
new Int16Array(2*a.length),d=[],e=0,f=0;f<a.length;f++){if(0==f%b&&0!=f){var h=d[1]<<8|d[0];C=32768<h?h-65536:h;D=d[2];J=U[D];h=[C,C];for(var k=4;k<d.length;k++){var q=d[k],y=q>>4;h.push(ha(y<<4^q));h.push(ha(y))}d=h;c.set(d,e);e+=d.length;d=[]}d.push(a[f])}return c}function Ca(a){var b=a[0];V(b);var c=[];c.push(b&255);c.push(b>>8&255);c.push(G);c.push(0);for(b=3;b<a.length;b+=2){var d=V(a[b]),e=V(a[b+1]);c.push(e<<4|d)}return c}function V(a){var b=a-E;0<=b?a=0:(a=8,b=-b);var c=U[G],d=c>>3;b>c&&(a|=
4,b-=c,d+=c);c>>=1;b>c&&(a|=2,b-=c,d+=c);c>>=1;b>c&&(a|=1,d+=c);b=a;E=b&8?E-d:E+d;-32768>E?E=-32768:32767<E&&(E=32767);G+=ia[b&7];0>G?G=0:88<G&&(G=88);return a}function ha(a){var b=0;a&4&&(b+=J);a&2&&(b+=J>>1);a&1&&(b+=J>>2);b+=J>>3;a&8&&(b=-b);C+=b;32767<C?C=32767:-32767>C&&(C=-32767);D+=ia[a];0>D?D=0:88<D&&(D=88);J=U[D];return C}function Ea(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=c;var e=a[c];e=-32768==e?-32767:e;var f=~e>>8&128;f||(e*=-1);32635<e&&(e=32635);if(256<=e){var h=
Fa[e>>8&127];e=h<<4|e>>h+3&15}else e>>=4;b[d]=e^f^85}return b}function Ga(a){for(var b=new Int16Array(a.length),c=0;c<a.length;c++){var d=c,e=a[c],f=0;e^=85;e&128&&(e&=-129,f=-1);var h=((e&240)>>4)+4;e=4!=h?1<<h|(e&15)<<h-4|1<<h-5:e<<1|1;b[d]=-8*(0===f?e:-e)}return b}function Ha(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=c,e=a[c];var f=e>>8&128;0!=f&&(e=-e);32635<e&&(e=32635);e+=132;var h=Ia[e>>7&255];b[d]=~(f|h<<4|e>>h+3&15)}return b}function Ja(a){for(var b=new Int16Array(a.length),
c=0;c<a.length;c++){var d=c,e=a[c];e=~e;var f=e>>4&7;f=Ka[f]+((e&15)<<f+3);0!=(e&128)&&(f=-f);b[d]=f}return b}function W(a,b,c,d){d=void 0===d?a.length:d;if(d%b)throw Error("Bad buffer length.");for(c=void 0===c?0:c;c<d;c+=b){var e=a,f=b,h=c;f--;for(var k=0;k<f;k++){var q=e[h+k];e[h+k]=e[h+f];e[h+f]=q;f--}}}function X(a,b,c){c=void 0===c?0:c;for(var d=0,e=a.length;d<e;d++){var f=a.codePointAt(d);if(128>f)b[c]=f,c++;else{var h=0,k=0;2047>=f?(h=1,k=192):65535>=f?(h=2,k=224):1114111>=f&&(h=3,k=240,d++);
b[c]=(f>>6*h)+k;for(c++;0<h;)b[c]=128|f>>6*(h-1)&63,c++,h--}}return c}function Y(a){var b=Math.floor(a);a-=b;return.5>a?b:.5<a?b+1:b%2?b+1:b}function K(a,b,c){c=void 0===c?a.length:c;var d=void 0===b?0:b;c=void 0===c?a.length:c;b="";for(d=void 0===d?0:d;d<c;){var e=128,f=191,h=!1,k=a[d++];if(0<=k&&127>=k)b+=String.fromCharCode(k);else{var q=0;194<=k&&223>=k?q=1:224<=k&&239>=k?(q=2,224===a[d]&&(e=160),237===a[d]&&(f=159)):240<=k&&244>=k?(q=3,240===a[d]&&(e=144),244===a[d]&&(f=143)):h=!0;k&=(1<<8-q-
1)-1;for(var y=0;y<q;y++){if(a[d]<e||a[d]>f)h=!0;k=k<<6|a[d]&63;d++}h?b+=String.fromCharCode(65533):65535>=k?b+=String.fromCharCode(k):(k-=65536,b+=String.fromCharCode((k>>10&1023)+55296,(k&1023)+56320))}}return b}function x(a){var b=[];X(a,b,0);return b}function O(a,b,c,d){d=void 0===d?0:d;b=b||{};var e=new H(b.h,b.M,b.D),f=0,h=d;try{for(var k=a.length;f<k;f++)d=e.C(c,a[f],d);b.o&&W(c,e.offset,h,d)}catch(q){ja(q,a[f],f)}return d}function M(a,b,c,d,e,f){d=void 0===d?0:d;e=void 0===e?a.length:e;f=
void 0===f?!1:f;b=b||{};var h=new H(b.h,b.M,b.D),k=h.offset,q=(e-d)%k;if(f&&(q||a.length<k))throw Error("Bad buffer length");e-=q;f=0;q=d;try{for(b.o&&W(a,k,d,e);q<e;q+=k,f++)c[f]=h.N(a,q);b.o&&W(a,k,d,e)}catch(y){ja(y,a.slice(q,q+k),q)}}function g(a,b){var c=[];O([a],b,c,0);return c}function Z(a,b,c,d,e){d=void 0===d?a.length:d;var f=[];M(a,b,f,void 0===c?0:c,d,void 0===e?!1:e);return f}function P(a,b,c){c=void 0===c?0:c;return Z(a,b,c,c+Math.ceil(b.h/8),!0)[0]}function ja(a,b,c){a.message=a.constructor.name+
" at index "+c+": "+b;throw a;}function z(a,b,c){c=void 0===c?!0:c;a=x(a);if(c)for(c=a.length;c<b;c++)a.push(0);return a}function ka(a,b){for(var c=8===b?255:Math.pow(2,b)/2-1,d=8===b?0:-c-1,e=0,f=a.length;e<f;e++)a[e]=Math.round(a[e]),a[e]>c?a[e]=c:a[e]<d&&(a[e]=d)}function ua(a){return Math.exp(-a*a)}function da(a){return function(b){return la(b)*a(b)}}function va(a){return function(b){return la(b/a)}}function la(a){return 0===a?1:Math.sin(Math.PI*a)/(Math.PI*a)}function sa(a,b){return Math.max(0,
Math.min(a,b-1))}function ca(a,b){a%=b;0>a&&(a+=b);return a}function ta(a,b){var c=2*(b-1);a=ca(a,c);a>b-1&&(a=c-a);return a}function ma(a,b,c,d){d=void 0===d?{}:d;var e=new Float64Array(a.length*((c-b)/b+1)),f=new v(a.length,e.length,{method:d.method||"cubic",tension:d.tension||0,sincFilterSize:d.sincFilterSize||32,sincWindow:d.sincWindow||void 0,lanczosFilterSize:d.lanczosFilterSize||16,clip:d.clip||"mirror"});if(c>b){var h=d.LPForder||71;d=new r(h,c,b/2);for(var k=0;k<e.length;k++)e[k]=d.c(f.j(k,
a));d=new r(h,c,b/2);for(a=e.length-1;0<=a;a--)e[a]=d.c(e[a])}else{h=d.LPForder||71;d=new r(h,b,c/2);for(k=0;k<a.length;k++)a[k]=d.c(a[k]);d=new r(h,b,c/2);for(b=a.length-1;0<=b;b--)a[b]=d.c(a[b]);for(b=0;b<e.length;b++)e[b]=f.j(b,a)}return e}var ia=[-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8],U=[7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371,408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,
1878,2066,2272,2499,2749,3024,3327,3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767],E=0,G=0,C=0,D=0,J=7,Fa=[1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7],Ia=[0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7],Ka=[0,132,396,924,1980,4092,8316,16764];
I.prototype.C=function(a,b,c){if("number"!=typeof b)throw new TypeError;Math.abs(b)>this.g-2*this.i&&(b=0>b?-Infinity:Infinity);var d=0>((b=+b)||1/b)?1:0>b?1:0;b=Math.abs(b);var e=Math.min(Math.floor(Math.log(b)/Math.LN2),1023),f=Y(b/Math.pow(2,e)*Math.pow(2,this.c));b!==b?(f=Math.pow(2,this.c-1),e=(1<<this.b)-1):0!==b&&(b>=Math.pow(2,1-this.a)?(2<=f/Math.pow(2,this.c)&&(e+=1,f=1),e>this.a?(e=(1<<this.b)-1,f=0):(e+=this.a,f=Y(f)-Math.pow(2,this.c))):(f=Y(b/Math.pow(2,1-this.a-this.c)),e=0));return this.m(a,
c,d,e,f)};I.prototype.N=function(a,b){for(var c=(1<<this.b)-1,d="",e=this.f-1;0<=e;e--){var f=a[e+b].toString(2);d+="00000000".substring(f.length)+f}e="1"==d.charAt(0)?-1:1;d=d.substring(1);f=parseInt(d.substring(0,this.b),2);d=d.substring(this.b);if(f==c)return 0!==parseInt(d,2)?NaN:Infinity*e;0===f?(f+=1,c=parseInt(d,2)):c=parseInt("1"+d,2);return e*c*this.j*Math.pow(2,f-this.a)};I.prototype.m=function(a,b,c,d,e){var f=[];f.push(c);for(c=this.b;0<c;--c)f[c]=d%2?1:0,d=Math.floor(d/2);d=f.length;
for(c=this.c;0<c;--c)f[d+c]=e%2?1:0,e=Math.floor(e/2);e=f.join("");f=this.f+b-1;for(d=b;f>=b;)a[f]=parseInt(e.substring(0,8),2),e=e.substring(8),f--,d++;return d};B.prototype.C=function(a,b,c){c=void 0===c?0:c;if(b!==b||"number"!=typeof b)throw new TypeError;this.a(b);return this.g(a,b,c)};B.prototype.N=function(a,b){var c=this.c(a,void 0===b?0:b);this.a(c);return c};B.prototype.c=function(a,b){b=void 0===b?0:b;for(var c=0,d=0;d<this.b;d++)c+=a[b+d]*Math.pow(256,d);return c};B.prototype.a=function(a){if(a>
this.max||a<this.min)throw new RangeError;};B.prototype.g=function(a,b,c){c=void 0===c?0:c;a[c]=(0>b?b+Math.pow(2,this.h):b)&255;c++;for(var d=this.b,e=2;e<d;e++)a[c]=Math.floor(b/Math.pow(2,8*(e-1)))&255,c++;8<this.h&&(a[c]=Math.floor(b/Math.pow(2,8*(this.b-1)))&this.f,c++);return c};Q(L,B);L.prototype.C=function(a,b,c){return B.prototype.C.call(this,a,b,void 0===c?0:c)};L.prototype.N=function(a,b){var c=B.prototype.c.call(this,a,void 0===b?0:b);c=this.i(c);this.a(c);return c};L.prototype.i=function(a){a>
this.max&&(a-=2*this.max+2);return a};H.prototype.N=function(a,b){return this.a.N(a,void 0===b?0:b)};H.prototype.C=function(a,b,c){return this.a.C(a,b,void 0===c?0:c)};H.prototype.c=function(a,b,c){if(b){if(!a||16!==a&&32!==a&&64!==a)throw Error("Unsupported type: float, bits: "+a);return this.b(a)}if(!a||1>a||53<a)throw Error("Unsupported type: int, bits: "+a);return c?new L(a):new B(a)};H.prototype.b=function(a){return 16===a?new I(5,11):32===a?new I(8,23):new I(11,52)};A.prototype.la=function(a){this.c=
0;this.container=this.u(a,4);if(-1===this.W.indexOf(this.container))throw Error("Not a supported format.");this.a.o="RIFX"===this.container;this.chunkSize=this.b(a);this.format=this.u(a,4);this.V={chunkId:this.container,chunkSize:this.chunkSize,format:this.format,subChunks:this.S(a)}};A.prototype.m=function(a,b){b=void 0===b?!1:b;for(var c=this.V.subChunks,d=[],e=0;e<c.length;e++)if(c[e].chunkId==a)if(b)d.push(c[e]);else return c[e];return"LIST"==a?d.length?d:null:null};A.prototype.u=function(a,b){var c=
K(a,this.c,this.c+b);this.c+=b;return c};A.prototype.b=function(a){a=P(a,this.a,this.c);this.c+=4;return a};A.prototype.S=function(a){for(var b=[],c=this.c;c<=a.length-8;)b.push(this.La(a,c)),c+=8+b[b.length-1].chunkSize,c=c%2?c+1:c;return b};A.prototype.La=function(a,b){var c={chunkId:this.ua(a,b),chunkSize:this.va(a,b)};"LIST"==c.chunkId?(c.format=K(a,b+8,b+12),this.c+=4,c.subChunks=this.S(a)):(this.c=b+8+(c.chunkSize%2?c.chunkSize+1:c.chunkSize),c.chunkData={start:b+8,end:this.c});return c};A.prototype.ua=
function(a,b){this.c+=4;return K(a,b,b+4)};A.prototype.va=function(a,b){this.c+=4;return P(a,this.a,b+4)};Q(w,A);w.prototype.fromBuffer=function(a,b){b=void 0===b?!0:b;this.R();this.la(a);this.g.o=this.a.o;if("WAVE"!=this.format)throw Error('Could not find the "WAVE" format identifier');this.Sa(a);this.Ua(a);this.Ta(a);this.Pa(a);this.ga(a);this.Qa(a);this.ea(a);this.Ra(a,b);this.Wa(a);this.Xa(a);this.fa(a)};w.prototype.R=function(){var a=new w;Object.assign(this.fmt,a.fmt);Object.assign(this.fact,
a.fact);Object.assign(this.cue,a.cue);Object.assign(this.smpl,a.smpl);Object.assign(this.bext,a.bext);Object.assign(this.iXML,a.iXML);Object.assign(this.ds64,a.ds64);Object.assign(this.data,a.data);this.LIST=[];Object.assign(this.junk,a.junk);Object.assign(this._PMX,a._PMX)};w.prototype.Ua=function(a){var b=this.m("fmt ");if(b)this.c=b.chunkData.start,this.fmt.chunkId=b.chunkId,this.fmt.chunkSize=b.chunkSize,this.fmt.audioFormat=this.i(a),this.fmt.numChannels=this.i(a),this.fmt.sampleRate=this.b(a),
this.fmt.byteRate=this.b(a),this.fmt.blockAlign=this.i(a),this.fmt.bitsPerSample=this.i(a),this.Va(a);else throw Error('Could not find the "fmt " chunk');};w.prototype.Va=function(a){16<this.fmt.chunkSize&&(this.fmt.cbSize=this.i(a),18<this.fmt.chunkSize&&(this.fmt.validBitsPerSample=this.i(a),20<this.fmt.chunkSize&&(this.fmt.dwChannelMask=this.b(a),this.fmt.subformat=[this.b(a),this.b(a),this.b(a),this.b(a)])))};w.prototype.Ta=function(a){var b=this.m("fact");b&&(this.c=b.chunkData.start,this.fact.chunkId=
b.chunkId,this.fact.chunkSize=b.chunkSize,this.fact.dwSampleLength=this.b(a))};w.prototype.Qa=function(a){var b=this.m("cue ");if(b)for(this.c=b.chunkData.start,this.cue.chunkId=b.chunkId,this.cue.chunkSize=b.chunkSize,this.cue.dwCuePoints=this.b(a),b=0;b<this.cue.dwCuePoints;b++)this.cue.points.push({dwName:this.b(a),dwPosition:this.b(a),fccChunk:this.u(a,4),dwChunkStart:this.b(a),dwBlockStart:this.b(a),dwSampleOffset:this.b(a)})};w.prototype.ea=function(a){var b=this.m("smpl");if(b)for(this.c=b.chunkData.start,
this.smpl.chunkId=b.chunkId,this.smpl.chunkSize=b.chunkSize,this.smpl.dwManufacturer=this.b(a),this.smpl.dwProduct=this.b(a),this.smpl.dwSamplePeriod=this.b(a),this.smpl.dwMIDIUnityNote=this.b(a),this.smpl.dwMIDIPitchFraction=this.b(a),this.smpl.dwSMPTEFormat=this.b(a),this.smpl.dwSMPTEOffset=this.b(a),this.smpl.dwNumSampleLoops=this.b(a),this.smpl.dwSamplerData=this.b(a),b=0;b<this.smpl.dwNumSampleLoops;b++)this.smpl.loops.push({dwName:this.b(a),dwType:this.b(a),dwStart:this.b(a),dwEnd:this.b(a),
dwFraction:this.b(a),dwPlayCount:this.b(a)})};w.prototype.Ra=function(a,b){var c=this.m("data");if(c)this.data.chunkId="data",this.data.chunkSize=c.chunkSize,b&&(this.data.samples=a.slice(c.chunkData.start,c.chunkData.end));else throw Error('Could not find the "data" chunk');};w.prototype.Pa=function(a){var b=this.m("bext");b&&(this.c=b.chunkData.start,this.bext.chunkId=b.chunkId,this.bext.chunkSize=b.chunkSize,this.bext.description=this.u(a,256),this.bext.originator=this.u(a,32),this.bext.originatorReference=
this.u(a,32),this.bext.originationDate=this.u(a,10),this.bext.originationTime=this.u(a,8),this.bext.timeReference=[this.b(a),this.b(a)],this.bext.version=this.i(a),this.bext.UMID=this.u(a,64),this.bext.loudnessValue=this.i(a),this.bext.loudnessRange=this.i(a),this.bext.maxTruePeakLevel=this.i(a),this.bext.maxMomentaryLoudness=this.i(a),this.bext.maxShortTermLoudness=this.i(a),this.bext.reserved=this.u(a,180),this.bext.codingHistory=this.u(a,this.bext.chunkSize-602))};w.prototype.ga=function(a){var b=
this.m("iXML");b&&(this.c=b.chunkData.start,this.iXML.chunkId=b.chunkId,this.iXML.chunkSize=b.chunkSize,this.iXML.value=K(a,this.c,this.c+this.iXML.chunkSize))};w.prototype.Sa=function(a){var b=this.m("ds64");if(b)this.c=b.chunkData.start,this.ds64.chunkId=b.chunkId,this.ds64.chunkSize=b.chunkSize,this.ds64.riffSizeHigh=this.b(a),this.ds64.riffSizeLow=this.b(a),this.ds64.dataSizeHigh=this.b(a),this.ds64.dataSizeLow=this.b(a),this.ds64.originationTime=this.b(a),this.ds64.sampleCountHigh=this.b(a),
this.ds64.sampleCountLow=this.b(a);else if("RF64"==this.container)throw Error('Could not find the "ds64" chunk');};w.prototype.Xa=function(a){var b=this.m("LIST",!0);if(null!==b)for(var c=0;c<b.length;c++){var d=b[c];this.LIST.push({chunkId:d.chunkId,chunkSize:d.chunkSize,format:d.format,subChunks:[]});for(var e=0;e<d.subChunks.length;e++)this.da(d.subChunks[e],d.format,a)}};w.prototype.da=function(a,b,c){"adtl"==b?-1<["labl","note","ltxt"].indexOf(a.chunkId)&&(this.c=a.chunkData.start,b={chunkId:a.chunkId,
chunkSize:a.chunkSize,dwName:this.b(c)},"ltxt"==a.chunkId?(b.dwSampleLength=this.b(c),b.dwPurposeID=this.b(c),b.dwCountry=this.i(c),b.dwLanguage=this.i(c),b.dwDialect=this.i(c),b.dwCodePage=this.i(c),b.value=""):b.value=this.U(c,this.c),this.LIST[this.LIST.length-1].subChunks.push(b)):"INFO"==b&&(this.c=a.chunkData.start,this.LIST[this.LIST.length-1].subChunks.push({chunkId:a.chunkId,chunkSize:a.chunkSize,value:this.U(c,this.c)}))};w.prototype.Wa=function(a){var b=this.m("junk");b&&(this.junk={chunkId:b.chunkId,
chunkSize:b.chunkSize,chunkData:[].slice.call(a.slice(b.chunkData.start,b.chunkData.end))})};w.prototype.fa=function(a){var b=this.m("_PMX");b&&(this.c=b.chunkData.start,this._PMX.chunkId=b.chunkId,this._PMX.chunkSize=b.chunkSize,this._PMX.value=K(a,this.c,this.c+this._PMX.chunkSize))};w.prototype.U=function(a,b){for(var c=b=void 0===b?0:b;c<a.length&&(this.c++,0!==a[c]);c++);return K(a,b,this.c-1)};w.prototype.i=function(a){a=P(a,this.g,this.c);this.c+=2;return a};Q(u,w);u.prototype.toBuffer=function(){this.g.o=
"RIFX"===this.container;this.a.o=this.g.o;for(var a=[this.Ea(),this.Aa(),this.ta(),this.Na(),this.Ca(),this.Ba(),x(this.data.chunkId),g(this.data.samples.length,this.a),this.data.samples,this.wa(),this.Ja(),this.Fa(),this.Ma()],b=0,c=0;c<a.length;c++)b+=a[c].length;c=new Uint8Array(b+12);var d=X(this.container,c,0);d=O([b+4],this.a,c,void 0===d?0:d);d=X(this.format,c,void 0===d?0:d);for(b=0;b<a.length;b++)c.set(a[b],d),d+=a[b].length;return c};u.prototype.ta=function(){var a=[];this.sa();this.bext.chunkId&&
(this.bext.chunkSize=602+this.bext.codingHistory.length,a=a.concat(x(this.bext.chunkId),g(602+this.bext.codingHistory.length,this.a),z(this.bext.description,256),z(this.bext.originator,32),z(this.bext.originatorReference,32),z(this.bext.originationDate,10),z(this.bext.originationTime,8),g(this.bext.timeReference[0],this.a),g(this.bext.timeReference[1],this.a),g(this.bext.version,this.g),z(this.bext.UMID,64),g(this.bext.loudnessValue,this.g),g(this.bext.loudnessRange,this.g),g(this.bext.maxTruePeakLevel,
this.g),g(this.bext.maxMomentaryLoudness,this.g),g(this.bext.maxShortTermLoudness,this.g),z(this.bext.reserved,180),z(this.bext.codingHistory,this.bext.codingHistory.length)));this.j(a);return a};u.prototype.sa=function(){for(var a in this.bext)if(this.bext.hasOwnProperty(a)&&this.bext[a]&&"timeReference"!=a){this.bext.chunkId="bext";break}if(this.bext.timeReference[0]||this.bext.timeReference[1])this.bext.chunkId="bext"};u.prototype.Na=function(){var a=[];if(this.iXML.chunkId){var b=x(this.iXML.value);
this.iXML.chunkSize=b.length;a=a.concat(x(this.iXML.chunkId),g(this.iXML.chunkSize,this.a),b)}this.j(a);return a};u.prototype.Aa=function(){var a=[];this.ds64.chunkId&&(a=a.concat(x(this.ds64.chunkId),g(this.ds64.chunkSize,this.a),g(this.ds64.riffSizeHigh,this.a),g(this.ds64.riffSizeLow,this.a),g(this.ds64.dataSizeHigh,this.a),g(this.ds64.dataSizeLow,this.a),g(this.ds64.originationTime,this.a),g(this.ds64.sampleCountHigh,this.a),g(this.ds64.sampleCountLow,this.a)));this.j(a);return a};u.prototype.wa=
function(){var a=[];if(this.cue.chunkId){var b=this.ya();a=a.concat(x(this.cue.chunkId),g(b.length+4,this.a),g(this.cue.dwCuePoints,this.a),b)}this.j(a);return a};u.prototype.ya=function(){for(var a=[],b=0;b<this.cue.dwCuePoints;b++)a=a.concat(g(this.cue.points[b].dwName,this.a),g(this.cue.points[b].dwPosition,this.a),x(this.cue.points[b].fccChunk),g(this.cue.points[b].dwChunkStart,this.a),g(this.cue.points[b].dwBlockStart,this.a),g(this.cue.points[b].dwSampleOffset,this.a));return a};u.prototype.Ja=
function(){var a=[];if(this.smpl.chunkId){var b=this.Ka();a=a.concat(x(this.smpl.chunkId),g(b.length+36,this.a),g(this.smpl.dwManufacturer,this.a),g(this.smpl.dwProduct,this.a),g(this.smpl.dwSamplePeriod,this.a),g(this.smpl.dwMIDIUnityNote,this.a),g(this.smpl.dwMIDIPitchFraction,this.a),g(this.smpl.dwSMPTEFormat,this.a),g(this.smpl.dwSMPTEOffset,this.a),g(this.smpl.dwNumSampleLoops,this.a),g(this.smpl.dwSamplerData,this.a),b)}this.j(a);return a};u.prototype.Ka=function(){for(var a=[],b=0;b<this.smpl.dwNumSampleLoops;b++)a=
a.concat(g(this.smpl.loops[b].dwName,this.a),g(this.smpl.loops[b].dwType,this.a),g(this.smpl.loops[b].dwStart,this.a),g(this.smpl.loops[b].dwEnd,this.a),g(this.smpl.loops[b].dwFraction,this.a),g(this.smpl.loops[b].dwPlayCount,this.a));return a};u.prototype.Ba=function(){var a=[];this.fact.chunkId&&(a=a.concat(x(this.fact.chunkId),g(this.fact.chunkSize,this.a),g(this.fact.dwSampleLength,this.a)));this.j(a);return a};u.prototype.Ca=function(){var a=[];if(this.fmt.chunkId)return a=a.concat(x(this.fmt.chunkId),
g(this.fmt.chunkSize,this.a),g(this.fmt.audioFormat,this.g),g(this.fmt.numChannels,this.g),g(this.fmt.sampleRate,this.a),g(this.fmt.byteRate,this.a),g(this.fmt.blockAlign,this.g),g(this.fmt.bitsPerSample,this.g),this.Da()),this.j(a),a;throw Error('Could not find the "fmt " chunk');};u.prototype.Da=function(){var a=[];16<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.cbSize,this.g)));18<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.validBitsPerSample,this.g)));20<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.dwChannelMask,
this.a)));24<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.subformat[0],this.a),g(this.fmt.subformat[1],this.a),g(this.fmt.subformat[2],this.a),g(this.fmt.subformat[3],this.a)));return a};u.prototype.Fa=function(){for(var a=[],b=0;b<this.LIST.length;b++){var c=this.Ha(this.LIST[b].subChunks,this.LIST[b].format);a=a.concat(x(this.LIST[b].chunkId),g(c.length+4,this.a),x(this.LIST[b].format),c)}this.j(a);return a};u.prototype.Ha=function(a,b){for(var c=[],d=0;d<a.length;d++){if("INFO"==b){var e=z(a[d].value,
a[d].value.length);c=c.concat(x(a[d].chunkId),g(e.length+1,this.a),e);c.push(0)}else"adtl"==b&&(-1<["labl","note"].indexOf(a[d].chunkId)?(e=z(a[d].value,a[d].value.length),c=c.concat(x(a[d].chunkId),g(e.length+5,this.a),g(a[d].dwName,this.a),e),c.push(0)):"ltxt"==a[d].chunkId&&(c=c.concat(this.Ia(a[d]))));this.j(c)}return c};u.prototype.Ma=function(){var a=[];if(this._PMX.chunkId){var b=x(this._PMX.value);this._PMX.chunkSize=b.length;a=a.concat(x(this._PMX.chunkId),g(this._PMX.chunkSize,this.a),b)}this.j(a);
return a};u.prototype.Ia=function(a){return x(a.chunkId).concat(g(a.value.length+20,this.a),g(a.dwName,this.a),g(a.dwSampleLength,this.a),g(a.dwPurposeID,this.a),g(a.dwCountry,this.g),g(a.dwLanguage,this.g),g(a.dwDialect,this.g),g(a.dwCodePage,this.g),z(a.value,a.value.length))};u.prototype.Ea=function(){var a=[];if(this.junk.chunkId)return a.concat(x(this.junk.chunkId),g(this.junk.chunkData.length,this.a),this.junk.chunkData);this.j(a);return a};u.prototype.j=function(a){a.length%2&&a.push(0)};Q(t,
u);t.prototype.fromScratch=function(a,b,c,d,e){e=void 0===e?{}:e;this.R();this.T(a,b,c,d,e)};t.prototype.fromBuffer=function(a,b){u.prototype.fromBuffer.call(this,a,void 0===b?!0:b);this.oa();this.X()};t.prototype.toBuffer=function(){this.Y();return u.prototype.toBuffer.call(this)};t.prototype.getSamples=function(a){a=void 0===a?!1:a;var b=new Float64Array(this.data.samples.length/(this.f.h/8));M(this.data.samples,this.f,b);if(!a&&1<this.fmt.numChannels){a=this.fmt.numChannels;for(var c=[],d=0;d<
a;d++)c[d]=new Float64Array(b.length/a);for(d=0;d<a;d++)for(var e=0,f=d;f<b.length;f+=a)c[d][e++]=b[f];b=c}return b};t.prototype.getSample=function(a){a*=this.f.h/8;if(a+this.f.h/8>this.data.samples.length)throw Error("Range error");return P(this.data.samples.slice(a,a+this.f.h/8),this.f)};t.prototype.setSample=function(a,b){a*=this.f.h/8;if(a+this.f.h/8>this.data.samples.length)throw Error("Range error");O([b],this.f,this.data.samples,void 0===a?0:a)};t.prototype.getiXML=function(){return this.iXML.value};
t.prototype.setiXML=function(a){if("string"!==typeof a)throw new TypeError("iXML value must be a string.");this.iXML.value=a;this.iXML.chunkId="iXML"};t.prototype.get_PMX=function(){return this._PMX.value};t.prototype.set_PMX=function(a){if("string"!==typeof a)throw new TypeError("_PMX value must be a string.");this._PMX.value=a;this._PMX.chunkId="_PMX"};t.prototype.T=function(a,b,c,d,e){e=void 0===e?{}:e;e.container||(e.container="RIFF");this.container=e.container;this.bitDepth=c;var f=[];if(0<d.length)if(d[0].constructor!==
Number){f=new Float64Array(d[0].length*d.length);for(var h=0,k=0,q=d[0].length;k<q;k++)for(var y=0,La=d.length;y<La;y++)f[h]=d[y][k],h++}else f=d;d=f;this.X();f=this.f.h/8;this.data.samples=new Uint8Array(d.length*f);O(d,this.f,this.data.samples);this.Oa(c,a,b,f,this.data.samples.length,e);this.data.chunkId="data";this.data.chunkSize=this.data.samples.length;this.Y()};t.prototype.Oa=function(a,b,c,d,e,f){"4"==a?this.pa(a,b,c,d,e,f):"8a"==a||"8m"==a?this.qa(a,b,c,d,e,f):-1==Object.keys(this.F).indexOf(a)||
2<b?this.ra(a,b,c,d,e,f):this.A(a,b,c,d,e,f)};t.prototype.A=function(a,b,c,d,e,f){this.container=f.container;this.chunkSize=36+e;this.format="WAVE";this.bitDepth=a;this.fmt={chunkId:"fmt ",chunkSize:16,audioFormat:this.F[a]||65534,numChannels:b,sampleRate:c,byteRate:b*d*c,blockAlign:b*d,bitsPerSample:parseInt(a,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}};t.prototype.pa=function(a,b,c,d,e,f){this.A(a,b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.byteRate=4055;this.fmt.blockAlign=
256;this.fmt.bitsPerSample=4;this.fmt.cbSize=2;this.fmt.validBitsPerSample=505;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*e}};t.prototype.ra=function(a,b,c,d,e,f){this.A(a,b,c,d,e,f);this.chunkSize=60+e;this.fmt.chunkSize=40;this.fmt.bitsPerSample=(parseInt(a,10)-1|7)+1;this.fmt.cbSize=22;this.fmt.validBitsPerSample=parseInt(a,10);a=this.fmt;c=0;1===b?c=4:2===b?c=3:4===b?c=51:6===b?c=63:8===b&&(c=1599);a.dwChannelMask=c;this.fmt.subformat=[1,1048576,2852126848,1905997824]};t.prototype.qa=
function(a,b,c,d,e,f){this.A(a,b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.cbSize=2;this.fmt.validBitsPerSample=8;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:e}};t.prototype.oa=function(){3===this.fmt.audioFormat&&32===this.fmt.bitsPerSample?this.bitDepth="32f":6===this.fmt.audioFormat?this.bitDepth="8a":7===this.fmt.audioFormat?this.bitDepth="8m":this.bitDepth=this.fmt.bitsPerSample.toString()};t.prototype.ma=function(){if(!(this.F[this.bitDepth]||8<parseInt(this.bitDepth,
10)&&54>parseInt(this.bitDepth,10)))throw Error("Invalid bit depth.");};t.prototype.X=function(){this.f={h:(parseInt(this.bitDepth,10)-1|7)+1,M:"32f"==this.bitDepth||"64"==this.bitDepth,D:"8"!=this.bitDepth,o:"RIFX"==this.container};-1<["4","8a","8m"].indexOf(this.bitDepth)&&(this.f.h=8,this.f.D=!1)};t.prototype.Y=function(){this.ma();var a=this.fmt.numChannels;if(1>a||65535<a*this.fmt.bitsPerSample/8)throw Error("Invalid number of channels.");a=this.fmt.sampleRate;if(1>a||4294967295<this.fmt.bitsPerSample/
8*this.fmt.numChannels*a)throw Error("Invalid sample rate.");};Q(n,t);n.prototype.getTag=function(a){a=this.J(a);return null!==a.w?this.LIST[a.LIST].subChunks[a.w].value:null};n.prototype.setTag=function(a,b){var c=a;if(c.constructor!==String)throw Error("Invalid tag name.");if(4>c.length)for(var d=0,e=4-c.length;d<e;d++)c+=" ";a=c;c=this.J(a);null!==c.w?(this.LIST[c.LIST].subChunks[c.w].chunkSize=b.length+1,this.LIST[c.LIST].subChunks[c.w].value=b):null!==c.LIST?this.LIST[c.LIST].subChunks.push({chunkId:a,
chunkSize:b.length+1,value:b}):(this.LIST.push({chunkId:"LIST",chunkSize:b.length+9,format:"INFO",subChunks:[]}),this.LIST[this.LIST.length-1].subChunks.push({chunkId:a,chunkSize:b.length+1,value:b}))};n.prototype.deleteTag=function(a){a=this.J(a);return null!==a.w?(this.LIST[a.LIST].subChunks.splice(a.w,1),!0):!1};n.prototype.listTags=function(){var a=this.Ga(),b={};if(null!==a)for(var c=0,d=this.LIST[a].subChunks.length;c<d;c++)b[this.LIST[a].subChunks[c].chunkId]=this.LIST[a].subChunks[c].value;
return b};n.prototype.listCuePoints=function(){for(var a=this.I(),b=0,c=a.length;b<c;b++)a[b].position=a[b].dwSampleOffset/this.fmt.sampleRate*1E3,a[b].dwSampleLength?(a[b].end=a[b].dwSampleLength/this.fmt.sampleRate*1E3,a[b].end+=a[b].position):a[b].end=null,delete a[b].value;return a};n.prototype.setCuePoint=function(a){this.cue.chunkId="cue ";a.label||(a.label="");var b=this.I();this.G();this.cue.points=[];a.dwSampleOffset=a.position*this.fmt.sampleRate/1E3;a.dwSampleLength=0;a.end&&(a.dwSampleLength=
a.end*this.fmt.sampleRate/1E3-a.dwSampleOffset);0===b.length?this.v(a,1):this.ha(b,a);this.cue.dwCuePoints=this.cue.points.length};n.prototype.deleteCuePoint=function(a){this.cue.chunkId="cue ";var b=this.I();this.G();var c=this.cue.points.length;this.cue.points=[];for(var d=0;d<c;d++)d+1!==a&&this.v(b[d],d+1);this.cue.dwCuePoints=this.cue.points.length;this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.G())};n.prototype.updateLabel=function(a,b){var c=this.H();if(null!==c)for(var d=
0,e=this.LIST[c].subChunks.length;d<e;d++)this.LIST[c].subChunks[d].dwName==a&&(this.LIST[c].subChunks[d].value=b)};n.prototype.I=function(){for(var a=[],b=0;b<this.cue.points.length;b++){var c=this.cue.points[b],d=this.za(c.dwName);d.label=d.value?d.value:"";d.dwPosition=c.dwPosition;d.fccChunk=c.fccChunk;d.dwChunkStart=c.dwChunkStart;d.dwBlockStart=c.dwBlockStart;d.dwSampleOffset=c.dwSampleOffset;a.push(d)}return a};n.prototype.za=function(a){var b=this.H(),c={};null!==b&&this.ca(c,b,a);return c};
n.prototype.ca=function(a,b,c){for(var d=0,e=this.LIST[b].subChunks.length;d<e;d++)if(this.LIST[b].subChunks[d].dwName==c){var f=this.LIST[b].subChunks[d];a.value=f.value||a.value;a.dwName=f.dwName||0;a.dwSampleLength=f.dwSampleLength||0;a.dwPurposeID=f.dwPurposeID||0;a.dwCountry=f.dwCountry||0;a.dwLanguage=f.dwLanguage||0;a.dwDialect=f.dwDialect||0;a.dwCodePage=f.dwCodePage||0}};n.prototype.Ga=function(){for(var a=null,b=0,c=this.LIST.length;b<c;b++)if("INFO"===this.LIST[b].format){a=b;break}return a};
n.prototype.H=function(){for(var a=0,b=this.LIST.length;a<b;a++)if("adtl"==this.LIST[a].format)return a;return null};n.prototype.J=function(a){for(var b={LIST:null,w:null},c=0,d=this.LIST.length;c<d;c++)if("INFO"==this.LIST[c].format){b.LIST=c;d=0;for(var e=this.LIST[c].subChunks.length;d<e;d++)if(this.LIST[c].subChunks[d].chunkId==a){b.w=d;break}break}return b};n.prototype.v=function(a,b){this.cue.points.push({dwName:b,dwPosition:a.dwPosition?a.dwPosition:0,fccChunk:a.fccChunk?a.fccChunk:"data",
dwChunkStart:a.dwChunkStart?a.dwChunkStart:0,dwBlockStart:a.dwBlockStart?a.dwBlockStart:0,dwSampleOffset:a.dwSampleOffset});this.ja(a,b)};n.prototype.ha=function(a,b){for(var c=!1,d=0;d<a.length;d++)a[d].dwSampleOffset>b.dwSampleOffset&&!c?(this.v(b,d+1),this.v(a[d],d+2),c=!0):this.v(a[d],c?d+2:d+1);c||this.v(b,this.cue.points.length+1)};n.prototype.G=function(){for(var a=0,b=this.LIST.length;a<b;a++)"adtl"==this.LIST[a].format&&this.LIST.splice(a)};n.prototype.ja=function(a,b){var c=this.H();null===
c&&(this.LIST.push({chunkId:"LIST",chunkSize:4,format:"adtl",subChunks:[]}),c=this.LIST.length-1);this.ia(c,a,b);a.dwSampleLength&&this.ka(c,a,b)};n.prototype.ia=function(a,b,c){this.LIST[a].subChunks.push({chunkId:"labl",chunkSize:4,dwName:c,value:b.label});this.LIST[a].chunkSize+=12};n.prototype.ka=function(a,b,c){this.LIST[a].subChunks.push({chunkId:"ltxt",chunkSize:20,dwName:c,dwSampleLength:b.dwSampleLength,dwPurposeID:b.dwPurposeID||0,dwCountry:b.dwCountry||0,dwLanguage:b.dwLanguage||0,dwDialect:b.dwDialect||
0,dwCodePage:b.dwCodePage||0,value:b.label});this.LIST[a].chunkSize+=28};v.prototype.I=function(a,b){return this.f(Math.round(this.l*a),b)};v.prototype.H=function(a,b){a*=this.l;var c=Math.floor(a);a-=c;return(1-a)*this.f(c,b)+a*this.f(c+1,b)};v.prototype.G=function(a,b){a*=this.l;var c=Math.floor(a),d=[this.v(c,b),this.v(c+1,b)],e=[this.f(c,b),this.f(c+1,b)];a-=c;c=a*a;var f=a*c;return(2*f-3*c+1)*e[0]+(f-2*c+a)*d[0]+(-2*f+3*c)*e[1]+(f-c)*d[1]};v.prototype.J=function(a,b){a*=this.l;var c=Math.floor(a),
d=c-this.B+1;c+=this.B;for(var e=0,f=d,h=d;d<=c?h<=c:h>=c;f=d<=c?++h:--h)e+=this.A(a-f)*this.f(f,b);return e};v.prototype.v=function(a,b){return this.K*(this.f(a+1,b)-this.f(a-1,b))/2};v.prototype.f=function(a,b){return 0<=a&&a<this.F?b[a]:b[this.s(a,this.F)]};r.prototype.c=function(a){this.b.L[this.b.O]=a;for(var b=a=0;b<this.b.L.length;b++)a+=this.a[b]*this.b.L[(this.b.O+b)%this.b.L.length];this.b.O=(this.b.O+1)%this.b.L.length;return a};Q(l,n);l.prototype.toRIFF=function(){this.l(this.fmt.numChannels,
this.fmt.sampleRate,this.bitDepth,Z(this.data.samples,this.f))};l.prototype.toRIFX=function(){this.l(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,Z(this.data.samples,this.f),{container:"RIFX"})};l.prototype.toIMAADPCM=function(){if(8E3!==this.fmt.sampleRate)throw Error("Only 8000 Hz files can be compressed as IMA-ADPCM.");if(1!==this.fmt.numChannels)throw Error("Only mono files can be compressed as IMA-ADPCM.");this.B();var a=new Int16Array(this.K());M(this.data.samples,this.f,a);this.l(this.fmt.numChannels,
this.fmt.sampleRate,"4",Ba(a),{container:this.s()})};l.prototype.fromIMAADPCM=function(a){a=void 0===a?"16":a;this.l(this.fmt.numChannels,this.fmt.sampleRate,"16",Da(this.data.samples,this.fmt.blockAlign),{container:this.s()});"16"!=a&&this.toBitDepth(a)};l.prototype.toALaw=function(){this.B();var a=new Int16Array(this.K());M(this.data.samples,this.f,a);this.l(this.fmt.numChannels,this.fmt.sampleRate,"8a",Ea(a),{container:this.s()})};l.prototype.fromALaw=function(a){a=void 0===a?"16":a;this.l(this.fmt.numChannels,
this.fmt.sampleRate,"16",Ga(this.data.samples),{container:this.s()});"16"!=a&&this.toBitDepth(a)};l.prototype.toMuLaw=function(){this.B();var a=new Int16Array(this.K());M(this.data.samples,this.f,a);this.l(this.fmt.numChannels,this.fmt.sampleRate,"8m",Ha(a),{container:this.s()})};l.prototype.fromMuLaw=function(a){a=void 0===a?"16":a;this.l(this.fmt.numChannels,this.fmt.sampleRate,"16",Ja(this.data.samples),{container:this.s()});"16"!=a&&this.toBitDepth(a)};l.prototype.toBitDepth=function(a,b){var c=
a,d=this.bitDepth;void 0===b||b||("32f"!=a&&(c=this.f.h.toString()),d=""+this.f.h);this.P();var e=this.getSamples(!0),f=new Float64Array(e.length),h=d;if(-1<["32f","64"].indexOf(h)&&-1<["32f","64"].indexOf(c))f.set(e);else{ea(h);ea(c);d=Aa(h,c);var k={ba:Math.pow(2,parseInt(h,10))/2,$:Math.pow(2,parseInt(c,10))/2,aa:Math.pow(2,parseInt(h,10))/2-1,Z:Math.pow(2,parseInt(c,10))/2-1};fa(h,e,!0);if(-1<["32f","64"].indexOf(h)){h=e.length;for(var q=0;q<h;q++)1<e[q]?e[q]=1:-1>e[q]&&(e[q]=-1)}for(h=0;h<e.length;h++)f[h]=
d(e[h],k);fa(c,f,!1)}this.l(this.fmt.numChannels,this.fmt.sampleRate,a,f,{container:this.s()})};l.prototype.toSampleRate=function(a,b){b=void 0===b?{}:b;this.na(a);var c=this.getSamples(),d=[];if(c.constructor===Float64Array)d=ma(c,this.fmt.sampleRate,a,b);else for(var e=0;e<c.length;e++)d.push(ma(c[e],this.fmt.sampleRate,a,b));if("64"!==this.bitDepth&&"32f"!==this.bitDepth)if(d[0].constructor===Number)ka(d,this.f.h);else for(c=0;c<d.length;c++)ka(d[c],this.f.h);this.l(this.fmt.numChannels,a,this.bitDepth,
d,{container:this.s()})};l.prototype.na=function(a){if(1>a||4294967295<this.fmt.bitsPerSample/8*this.fmt.numChannels*a)throw Error("Invalid sample rate.");if(-1<["4","8a","8m"].indexOf(this.bitDepth))throw Error("wavefile can't change the sample rate of compressed files.");};l.prototype.B=function(){this.P();"16"!=this.bitDepth&&this.toBitDepth("16")};l.prototype.P=function(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()};l.prototype.s=
function(){return"RF64"==this.container?"RIFF":this.container};l.prototype.l=function(a,b,c,d,e){e=void 0===e?{}:e;var f=new n;Object.assign(this.fmt,f.fmt);Object.assign(this.fact,f.fact);Object.assign(this.ds64,f.ds64);Object.assign(this.data,f.data);this.T(a,b,c,d,e)};l.prototype.K=function(){var a=this.data.samples.length/2;a%2&&a++;return a};Q(m,l);m.prototype.fromBase64=function(a){this.fromBuffer(new Uint8Array(wa(a)))};m.prototype.toBase64=function(){for(var a=this.toBuffer(),b="",c=0;c<a.length;c+=
3)b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c]>>2],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c]&3)<<4|a[c+1]>>4],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c+1]&15)<<2|a[c+2]>>6],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c+2]&63];2===a.length%3?b=b.substring(0,b.length-1)+"=":1===a.length%3&&(b=b.substring(0,b.length-2)+"==");return b};m.prototype.toDataURI=function(){return"data:audio/wav;base64,"+
this.toBase64()};m.prototype.fromDataURI=function(a){this.fromBase64(a.replace("data:audio/wav;base64,",""))};p.WaveFile=m;Object.defineProperty(p,"__esModule",{value:!0})}"object"===typeof exports&&"undefined"!==typeof module?T(exports):"function"===typeof define&&define.amd?define(["exports"],T):(S=S||self,T(S.wavefile={}));
try{if(!Uint8Array.prototype.slice)Object.defineProperty(Uint8Array.prototype,"slice",{value:function(begin,end){return new Uint8Array(Array.prototype.slice.call(this,begin,end))}})}catch(err){}var ba="function"==typeof Object.create?Object.create:function(n){function m(){}m.prototype=n;return new m},E;
if("function"==typeof Object.setPrototypeOf)E=Object.setPrototypeOf;else{var O;a:{var ca={ya:!0},oa={};try{oa.__proto__=ca;O=oa.ya;break a}catch(n){}O=!1}E=O?function(n,m){n.__proto__=m;if(n.__proto__!==m)throw new TypeError(n+" is not extensible");return n}:null}var pa=E;
function R(n,m){n.prototype=ba(m.prototype);n.prototype.constructor=n;if(pa)pa(n,m);else for(var l in m)if("prototype"!=l)if(Object.defineProperties){var q=Object.getOwnPropertyDescriptor(m,l);q&&Object.defineProperty(n,l,q)}else n[l]=m[l]}var qa="function"==typeof Object.defineProperties?Object.defineProperty:function(n,m,l){n!=Array.prototype&&n!=Object.prototype&&(n[m]=l.value)},ra="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this;
function S(n,m){if(m){for(var l=ra,q=n.split("."),v=0;v<q.length-1;v++){var r=q[v];r in l||(l[r]={});l=l[r]}q=q[q.length-1];v=l[q];r=m(v);r!=v&&null!=r&&qa(l,q,{configurable:!0,writable:!0,value:r})}}S("Object.is",function(n){return n?n:function(m,l){return m===l?0!==m||1/m===1/l:m!==m&&l!==l}});
S("Array.prototype.includes",function(n){return n?n:function(m,l){var q=this;q instanceof String&&(q=String(q));var v=q.length,r=l||0;for(0>r&&(r=Math.max(r+v,0));r<v;r++){var z=q[r];if(z===m||Object.is(z,m))return!0}return!1}});
S("String.prototype.codePointAt",function(n){return n?n:function(m){if(null==this)throw new TypeError("The 'this' value for String.prototype.codePointAt must not be null or undefined");var l=this.length;m=Number(m)||0;if(0<=m&&m<l){m|=0;var q=this.charCodeAt(m);if(55296>q||56319<q||m+1===l)return q;m=this.charCodeAt(m+1);return 56320>m||57343<m?q:1024*(q-55296)+m+9216}}});
var sa="function"==typeof Object.assign?Object.assign:function(n,m){for(var l=1;l<arguments.length;l++){var q=arguments[l];if(q)for(var v in q)Object.prototype.hasOwnProperty.call(q,v)&&(n[v]=q[v])}return n};S("Object.assign",function(n){return n||sa});var T=this;
function U(n){function m(a){a=void 0===a?null:a;var b=l.call(this)||this;a&&b.fromBuffer(a);return b}function l(){return r.apply(this,arguments)||this}function q(a,b,c){c=2*Math.PI*c/b;b=0;this.b=[];for(var d=0;d<=a;d++)0===d-a/2?this.b[d]=c:(this.b[d]=Math.sin(c*(d-a/2))/(d-a/2),this.b[d]*=.54-.46*Math.cos(2*Math.PI*d/a)),b+=this.b[d];for(c=0;c<=a;c++)this.b[c]/=b;this.a=this.c()}function v(a,b,c){this.v=a;this.j=(a-1)/b;this.L=this.H;"point"===c.method?this.L=this.G:"linear"===c.method?this.L=this.F:
"cubic"===c.method&&(this.L=this.N);this.l=ta;"periodic"===c.clip?(this.j=a/b,this.l=da):"mirror"===c.clip&&(this.l=ua);this.I=1-Math.max(0,Math.min(1,c.tension||0));this.A=c.sincFilterSize||1;this.D=va(c.sincWindow||wa)}function r(){return z.apply(this,arguments)||this}function z(){return t.apply(this,arguments)||this}function t(){var a=u.call(this)||this;a.bitDepth="0";a.f={h:0,o:!1,C:!1,K:!1};a.N={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};return a}function u(){return w.apply(this,arguments)||
this}function w(){var a=B.call(this)||this;a.X.push("RF64");a.fmt={chunkId:"",chunkSize:0,audioFormat:0,numChannels:0,sampleRate:0,byteRate:0,blockAlign:0,bitsPerSample:0,cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]};a.fact={chunkId:"",chunkSize:0,dwSampleLength:0};a.cue={chunkId:"",chunkSize:0,dwCuePoints:0,points:[]};a.smpl={chunkId:"",chunkSize:0,dwManufacturer:0,dwProduct:0,dwSamplePeriod:0,dwMIDIUnityNote:0,dwMIDIPitchFraction:0,dwSMPTEFormat:0,dwSMPTEOffset:0,dwNumSampleLoops:0,
dwSamplerData:0,loops:[]};a.bext={chunkId:"",chunkSize:0,description:"",originator:"",originatorReference:"",originationDate:"",originationTime:"",timeReference:[0,0],version:0,UMID:"",loudnessValue:0,loudnessRange:0,maxTruePeakLevel:0,maxMomentaryLoudness:0,maxShortTermLoudness:0,reserved:"",codingHistory:""};a.iXML={chunkId:"",chunkSize:0,value:""};a.ds64={chunkId:"",chunkSize:0,riffSizeHigh:0,riffSizeLow:0,dataSizeHigh:0,dataSizeLow:0,originationTime:0,sampleCountHigh:0,sampleCountLow:0};a.data=
{chunkId:"",chunkSize:0,samples:new Uint8Array(0)};a.LIST=[];a.junk={chunkId:"",chunkSize:0,chunkData:[]};a._PMX={chunkId:"",chunkSize:0,value:""};a.g={h:16,o:!1,C:!1,K:!1};return a}function B(){this.container="";this.chunkSize=0;this.format="";this.W={};this.c=0;this.a={h:32,o:!1,C:!1,K:!1};this.X=["RIFF","RIFX"]}function I(a,b,c){this.a=this.c(a,b,c);this.offset=Math.ceil(a/8)}function M(a){a=C.call(this,a)||this;a.max=Math.pow(2,a.h)/2-1;a.min=-a.max-1;return a}function C(a){this.h=a;this.b=8>
a?1:Math.ceil(a/8);this.max=Math.pow(2,a)-1;this.min=0;a=8-((a-1|7)+1-a);this.f=Math.pow(2,0<a?a:8)-1}function J(a,b){this.b=a;this.c=b;this.a=(1<<a-1)-1;this.f=Math.ceil((a+b)/8);this.g=Math.pow(2,this.a+1);this.i=a+b;this.j=Math.pow(2,-(8*this.f-1-a))}function xa(a){for(var b=new Uint8Array(256),c=0;64>c;c++)b["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(c)]=c;c=.75*a.length;"="===a[a.length-1]&&(c--,"="===a[a.length-2]&&c--);c=new ArrayBuffer(c);for(var d=new Uint8Array(c),
e=0,f=0;e<a.length;e+=4){var h=b[a.charCodeAt(e)],k=b[a.charCodeAt(e+1)],p=b[a.charCodeAt(e+2)],y=b[a.charCodeAt(e+3)];d[f++]=h<<2|k>>4;d[f++]=(k&15)<<4|p>>2;d[f++]=(p&3)<<6|y&63}return c}function ya(a,b){return a=0<a?parseInt(a/b.ba*b.$,10):parseInt(a/b.ca*b.aa,10)}function za(a,b){return parseInt(0<a?a*b.$:a*b.aa,10)}function Aa(a,b){return 0<a?a/b.ba:a/b.ca}function Ba(a,b){function c(d){return d}a!=b&&(c=["32f","64"].includes(a)?za:["32f","64"].includes(b)?Aa:ya);return c}function ea(a){if("32f"!=
a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}function fa(a,b,c){if("8"==a)for(a=c?-128:128,c=0;c<b.length;c++)b[c]=b[c]+=a}function Ca(a){for(var b=new Uint8Array(a.length),c=[],d=0,e=0,f=0;f<a.length;f++)0==f%505&&0!=f&&(b.set(Da(c),d),d+=256,c=[],e++),c.push(a[f]);a=a.length/2;a%2&&a++;return b.slice(0,a+512+4*e)}function Ea(a,b){b=void 0===b?256:b;for(var c=new Int16Array(2*a.length),d=[],e=0,f=0;f<a.length;f++){if(0==f%b&&0!=f){var h=d[1]<<8|d[0];D=
32768<h?h-65536:h;F=d[2];K=V[F];h=[D,D];for(var k=4;k<d.length;k++){var p=d[k],y=p>>4;h.push(ha(y<<4^p));h.push(ha(y))}d=h;c.set(d,e);e+=d.length;d=[]}d.push(a[f])}return c}function Da(a){var b=a[0];W(b);var c=[];c.push(b&255);c.push(b>>8&255);c.push(H);c.push(0);for(b=3;b<a.length;b+=2){var d=W(a[b]),e=W(a[b+1]);c.push(e<<4|d)}return c}function W(a){var b=a-G;0<=b?a=0:(a=8,b=-b);var c=V[H],d=c>>3;b>c&&(a|=4,b-=c,d+=c);c>>=1;b>c&&(a|=2,b-=c,d+=c);c>>=1;b>c&&(a|=1,d+=c);b=a;G=b&8?G-d:G+d;-32768>G?
G=-32768:32767<G&&(G=32767);H+=ia[b&7];0>H?H=0:88<H&&(H=88);return a}function ha(a){var b=0;a&4&&(b+=K);a&2&&(b+=K>>1);a&1&&(b+=K>>2);b+=K>>3;a&8&&(b=-b);D+=b;32767<D?D=32767:-32767>D&&(D=-32767);F+=ia[a];0>F?F=0:88<F&&(F=88);K=V[F];return D}function Fa(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=c;var e=a[c];e=-32768==e?-32767:e;var f=~e>>8&128;f||(e*=-1);32635<e&&(e=32635);if(256<=e){var h=Ga[e>>8&127];e=h<<4|e>>h+3&15}else e>>=4;b[d]=e^f^85}return b}function Ha(a){for(var b=
new Int16Array(a.length),c=0;c<a.length;c++){var d=c,e=a[c],f=0;e^=85;e&128&&(e&=-129,f=-1);var h=((e&240)>>4)+4;e=4!=h?1<<h|(e&15)<<h-4|1<<h-5:e<<1|1;b[d]=-8*(0===f?e:-e)}return b}function Ia(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=c,e=a[c];var f=e>>8&128;0!=f&&(e=-e);32635<e&&(e=32635);e+=132;var h=Ja[e>>7&255];b[d]=~(f|h<<4|e>>h+3&15)}return b}function Ka(a){for(var b=new Int16Array(a.length),c=0;c<a.length;c++){var d=c,e=a[c];e=~e;var f=e>>4&7;f=La[f]+((e&15)<<f+3);0!=
(e&128)&&(f=-f);b[d]=f}return b}function X(a,b,c,d){d=void 0===d?a.length:d;if(d%b)throw Error("Bad buffer length.");for(c=void 0===c?0:c;c<d;c+=b){var e=a,f=b,h=c;f--;for(var k=0;k<f;k++){var p=e[h+k];e[h+k]=e[h+f];e[h+f]=p;f--}}}function Y(a,b,c){c=void 0===c?0:c;for(var d=0,e=a.length;d<e;d++){var f=a.codePointAt(d);if(128>f)b[c]=f,c++;else{var h=0,k=0;2047>=f?(h=1,k=192):65535>=f?(h=2,k=224):1114111>=f&&(h=3,k=240,d++);b[c]=(f>>6*h)+k;for(c++;0<h;)b[c]=128|f>>6*(h-1)&63,c++,h--}}return c}function Z(a){var b=
Math.floor(a);a-=b;return.5>a?b:.5<a?b+1:b%2?b+1:b}function L(a,b,c){c=void 0===c?a.length:c;var d=void 0===b?0:b;c=void 0===c?a.length:c;b="";for(d=void 0===d?0:d;d<c;){var e=128,f=191,h=!1,k=a[d++];if(0<=k&&127>=k)b+=String.fromCharCode(k);else{var p=0;194<=k&&223>=k?p=1:224<=k&&239>=k?(p=2,224===a[d]&&(e=160),237===a[d]&&(f=159)):240<=k&&244>=k?(p=3,240===a[d]&&(e=144),244===a[d]&&(f=143)):h=!0;k&=(1<<8-p-1)-1;for(var y=0;y<p;y++){if(a[d]<e||a[d]>f)h=!0;k=k<<6|a[d]&63;d++}h?b+=String.fromCharCode(65533):
65535>=k?b+=String.fromCharCode(k):(k-=65536,b+=String.fromCharCode((k>>10&1023)+55296,(k&1023)+56320))}}return b}function x(a){var b=[];Y(a,b,0);return b}function P(a,b,c,d){d=void 0===d?0:d;b=b||{};var e=new I(b.h,b.K,b.C),f=0,h=d;try{for(var k=a.length;f<k;f++)d=e.B(c,a[f],d);b.o&&X(c,e.offset,h,d)}catch(p){ja(p,a[f],f)}return d}function N(a,b,c,d,e,f){d=void 0===d?0:d;e=void 0===e?a.length:e;f=void 0===f?!1:f;b=b||{};var h=new I(b.h,b.K,b.C),k=h.offset,p=(e-d)%k;if(f&&(p||a.length<k))throw Error("Bad buffer length");
e-=p;f=0;p=d;try{for(b.o&&X(a,k,d,e);p<e;p+=k,f++)c[f]=h.M(a,p);b.o&&X(a,k,d,e)}catch(y){ja(y,a.slice(p,p+k),p)}}function g(a,b){var c=[];P([a],b,c,0);return c}function aa(a,b,c,d,e){d=void 0===d?a.length:d;var f=[];N(a,b,f,void 0===c?0:c,d,void 0===e?!1:e);return f}function Q(a,b,c){c=void 0===c?0:c;return aa(a,b,c,c+Math.ceil(b.h/8),!0)[0]}function ja(a,b,c){a.message=a.constructor.name+" at index "+c+": "+b;throw a;}function A(a,b,c){c=void 0===c?!0:c;a=x(a);if(c)for(c=a.length;c<b;c++)a.push(0);
return a}function ka(a,b){for(var c=8===b?255:Math.pow(2,b)/2-1,d=8===b?0:-c-1,e=0,f=a.length;e<f;e++)a[e]=Math.round(a[e]),a[e]>c?a[e]=c:a[e]<d&&(a[e]=d)}function wa(a){return Math.exp(-a*a)}function va(a){return function(b){return(0===b?1:Math.sin(Math.PI*b)/(Math.PI*b))*a(b)}}function ta(a,b){return Math.max(0,Math.min(a,b-1))}function da(a,b){a%=b;0>a&&(a+=b);return a}function ua(a,b){var c=2*(b-1);a=da(a,c);a>b-1&&(a=c-a);return a}function la(a,b,c,d){d=void 0===d?{}:d;var e=new Float64Array(a.length*
((c-b)/b+1));d.method=d.method||"cubic";var f=new v(a.length,e.length,{method:d.method,tension:d.tension||0,sincFilterSize:d.sincFilterSize||6,sincWindow:d.sincWindow||void 0,clip:d.clip||"mirror"});void 0===d.LPF&&(d.LPF=Ma[d.method]);if(d.LPF)if(c>b){b=new q(d.LPForder||ma[d.method],c,b/2);c=0;for(d=e.length;c<d;c++)e[c]=b.filter(f.L(c,a));b.reset();for(a=e.length-1;0<=a;a--)e[a]=b.filter(e[a])}else{b=new q(d.LPForder||ma[d.method],b,c/2);c=0;for(d=a.length;c<d;c++)a[c]=b.filter(a[c]);b.reset();
for(c=a.length-1;0<=c;c--)a[c]=b.filter(a[c]);na(a,e,f)}else na(a,e,f);return e}function na(a,b,c){for(var d=0,e=b.length;d<e;d++)b[d]=c.L(d,a)}var ia=[-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8],V=[7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371,408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,1878,2066,2272,2499,2749,3024,3327,3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,11487,
12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767],G=0,H=0,D=0,F=0,K=7,Ga=[1,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7],Ja=[0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7],La=[0,132,396,924,1980,4092,8316,16764];J.prototype.B=function(a,b,c){if("number"!=typeof b)throw new TypeError;Math.abs(b)>this.g-2*this.i&&
(b=0>b?-Infinity:Infinity);var d=0>((b=+b)||1/b)?1:0>b?1:0;b=Math.abs(b);var e=Math.min(Math.floor(Math.log(b)/Math.LN2),1023),f=Z(b/Math.pow(2,e)*Math.pow(2,this.c));b!==b?(f=Math.pow(2,this.c-1),e=(1<<this.b)-1):0!==b&&(b>=Math.pow(2,1-this.a)?(2<=f/Math.pow(2,this.c)&&(e+=1,f=1),e>this.a?(e=(1<<this.b)-1,f=0):(e+=this.a,f=Z(f)-Math.pow(2,this.c))):(f=Z(b/Math.pow(2,1-this.a-this.c)),e=0));return this.m(a,c,d,e,f)};J.prototype.M=function(a,b){for(var c=(1<<this.b)-1,d="",e=this.f-1;0<=e;e--){var f=
a[e+b].toString(2);d+="00000000".substring(f.length)+f}e="1"==d.charAt(0)?-1:1;d=d.substring(1);f=parseInt(d.substring(0,this.b),2);d=d.substring(this.b);if(f==c)return 0!==parseInt(d,2)?NaN:Infinity*e;0===f?(f+=1,c=parseInt(d,2)):c=parseInt("1"+d,2);return e*c*this.j*Math.pow(2,f-this.a)};J.prototype.m=function(a,b,c,d,e){var f=[];f.push(c);for(c=this.b;0<c;--c)f[c]=d%2?1:0,d=Math.floor(d/2);d=f.length;for(c=this.c;0<c;--c)f[d+c]=e%2?1:0,e=Math.floor(e/2);e=f.join("");f=this.f+b-1;for(d=b;f>=b;)a[f]=
parseInt(e.substring(0,8),2),e=e.substring(8),f--,d++;return d};C.prototype.B=function(a,b,c){c=void 0===c?0:c;if(b!==b||"number"!=typeof b)throw new TypeError;this.a(b);return this.g(a,b,c)};C.prototype.M=function(a,b){var c=this.c(a,void 0===b?0:b);this.a(c);return c};C.prototype.c=function(a,b){b=void 0===b?0:b;for(var c=0,d=0;d<this.b;d++)c+=a[b+d]*Math.pow(256,d);return c};C.prototype.a=function(a){if(a>this.max||a<this.min)throw new RangeError;};C.prototype.g=function(a,b,c){c=void 0===c?0:
c;a[c]=(0>b?b+Math.pow(2,this.h):b)&255;c++;for(var d=this.b,e=2;e<d;e++)a[c]=Math.floor(b/Math.pow(2,8*(e-1)))&255,c++;8<this.h&&(a[c]=Math.floor(b/Math.pow(2,8*(this.b-1)))&this.f,c++);return c};R(M,C);M.prototype.B=function(a,b,c){return C.prototype.B.call(this,a,b,void 0===c?0:c)};M.prototype.M=function(a,b){var c=C.prototype.c.call(this,a,void 0===b?0:b);c=this.i(c);this.a(c);return c};M.prototype.i=function(a){a>this.max&&(a-=2*this.max+2);return a};I.prototype.M=function(a,b){return this.a.M(a,
void 0===b?0:b)};I.prototype.B=function(a,b,c){return this.a.B(a,b,void 0===c?0:c)};I.prototype.c=function(a,b,c){if(b){if(!a||16!==a&&32!==a&&64!==a)throw Error("Unsupported type: float, bits: "+a);return this.b(a)}if(!a||1>a||53<a)throw Error("Unsupported type: int, bits: "+a);return c?new M(a):new C(a)};I.prototype.b=function(a){return 16===a?new J(5,11):32===a?new J(8,23):new J(11,52)};B.prototype.ma=function(a){this.c=0;this.container=this.s(a,4);if(-1===this.X.indexOf(this.container))throw Error("Not a supported format.");
this.a.o="RIFX"===this.container;this.chunkSize=this.b(a);this.format=this.s(a,4);this.W={chunkId:this.container,chunkSize:this.chunkSize,format:this.format,subChunks:this.T(a)}};B.prototype.m=function(a,b){b=void 0===b?!1:b;for(var c=this.W.subChunks,d=[],e=0;e<c.length;e++)if(c[e].chunkId==a)if(b)d.push(c[e]);else return c[e];return"LIST"==a?d.length?d:null:null};B.prototype.s=function(a,b){var c=L(a,this.c,this.c+b);this.c+=b;return c};B.prototype.b=function(a){a=Q(a,this.a,this.c);this.c+=4;return a};
B.prototype.T=function(a){for(var b=[],c=this.c;c<=a.length-8;)b.push(this.Ma(a,c)),c+=8+b[b.length-1].chunkSize,c=c%2?c+1:c;return b};B.prototype.Ma=function(a,b){var c={chunkId:this.va(a,b),chunkSize:this.wa(a,b)};"LIST"==c.chunkId?(c.format=L(a,b+8,b+12),this.c+=4,c.subChunks=this.T(a)):(this.c=b+8+(c.chunkSize%2?c.chunkSize+1:c.chunkSize),c.chunkData={start:b+8,end:this.c});return c};B.prototype.va=function(a,b){this.c+=4;return L(a,b,b+4)};B.prototype.wa=function(a,b){this.c+=4;return Q(a,this.a,
b+4)};R(w,B);w.prototype.fromBuffer=function(a,b){b=void 0===b?!0:b;this.S();this.ma(a);this.g.o=this.a.o;if("WAVE"!=this.format)throw Error('Could not find the "WAVE" format identifier');this.Ta(a);this.Va(a);this.Ua(a);this.Qa(a);this.ha(a);this.Ra(a);this.fa(a);this.Sa(a,b);this.Xa(a);this.Ya(a);this.ga(a)};w.prototype.S=function(){var a=new w;Object.assign(this.fmt,a.fmt);Object.assign(this.fact,a.fact);Object.assign(this.cue,a.cue);Object.assign(this.smpl,a.smpl);Object.assign(this.bext,a.bext);
Object.assign(this.iXML,a.iXML);Object.assign(this.ds64,a.ds64);Object.assign(this.data,a.data);this.LIST=[];Object.assign(this.junk,a.junk);Object.assign(this._PMX,a._PMX)};w.prototype.Va=function(a){var b=this.m("fmt ");if(b)this.c=b.chunkData.start,this.fmt.chunkId=b.chunkId,this.fmt.chunkSize=b.chunkSize,this.fmt.audioFormat=this.i(a),this.fmt.numChannels=this.i(a),this.fmt.sampleRate=this.b(a),this.fmt.byteRate=this.b(a),this.fmt.blockAlign=this.i(a),this.fmt.bitsPerSample=this.i(a),this.Wa(a);
else throw Error('Could not find the "fmt " chunk');};w.prototype.Wa=function(a){16<this.fmt.chunkSize&&(this.fmt.cbSize=this.i(a),18<this.fmt.chunkSize&&(this.fmt.validBitsPerSample=this.i(a),20<this.fmt.chunkSize&&(this.fmt.dwChannelMask=this.b(a),this.fmt.subformat=[this.b(a),this.b(a),this.b(a),this.b(a)])))};w.prototype.Ua=function(a){var b=this.m("fact");b&&(this.c=b.chunkData.start,this.fact.chunkId=b.chunkId,this.fact.chunkSize=b.chunkSize,this.fact.dwSampleLength=this.b(a))};w.prototype.Ra=
function(a){var b=this.m("cue ");if(b)for(this.c=b.chunkData.start,this.cue.chunkId=b.chunkId,this.cue.chunkSize=b.chunkSize,this.cue.dwCuePoints=this.b(a),b=0;b<this.cue.dwCuePoints;b++)this.cue.points.push({dwName:this.b(a),dwPosition:this.b(a),fccChunk:this.s(a,4),dwChunkStart:this.b(a),dwBlockStart:this.b(a),dwSampleOffset:this.b(a)})};w.prototype.fa=function(a){var b=this.m("smpl");if(b)for(this.c=b.chunkData.start,this.smpl.chunkId=b.chunkId,this.smpl.chunkSize=b.chunkSize,this.smpl.dwManufacturer=
this.b(a),this.smpl.dwProduct=this.b(a),this.smpl.dwSamplePeriod=this.b(a),this.smpl.dwMIDIUnityNote=this.b(a),this.smpl.dwMIDIPitchFraction=this.b(a),this.smpl.dwSMPTEFormat=this.b(a),this.smpl.dwSMPTEOffset=this.b(a),this.smpl.dwNumSampleLoops=this.b(a),this.smpl.dwSamplerData=this.b(a),b=0;b<this.smpl.dwNumSampleLoops;b++)this.smpl.loops.push({dwName:this.b(a),dwType:this.b(a),dwStart:this.b(a),dwEnd:this.b(a),dwFraction:this.b(a),dwPlayCount:this.b(a)})};w.prototype.Sa=function(a,b){var c=this.m("data");
if(c)this.data.chunkId="data",this.data.chunkSize=c.chunkSize,b&&(this.data.samples=a.slice(c.chunkData.start,c.chunkData.end));else throw Error('Could not find the "data" chunk');};w.prototype.Qa=function(a){var b=this.m("bext");b&&(this.c=b.chunkData.start,this.bext.chunkId=b.chunkId,this.bext.chunkSize=b.chunkSize,this.bext.description=this.s(a,256),this.bext.originator=this.s(a,32),this.bext.originatorReference=this.s(a,32),this.bext.originationDate=this.s(a,10),this.bext.originationTime=this.s(a,
8),this.bext.timeReference=[this.b(a),this.b(a)],this.bext.version=this.i(a),this.bext.UMID=this.s(a,64),this.bext.loudnessValue=this.i(a),this.bext.loudnessRange=this.i(a),this.bext.maxTruePeakLevel=this.i(a),this.bext.maxMomentaryLoudness=this.i(a),this.bext.maxShortTermLoudness=this.i(a),this.bext.reserved=this.s(a,180),this.bext.codingHistory=this.s(a,this.bext.chunkSize-602))};w.prototype.ha=function(a){var b=this.m("iXML");b&&(this.c=b.chunkData.start,this.iXML.chunkId=b.chunkId,this.iXML.chunkSize=
b.chunkSize,this.iXML.value=L(a,this.c,this.c+this.iXML.chunkSize))};w.prototype.Ta=function(a){var b=this.m("ds64");if(b)this.c=b.chunkData.start,this.ds64.chunkId=b.chunkId,this.ds64.chunkSize=b.chunkSize,this.ds64.riffSizeHigh=this.b(a),this.ds64.riffSizeLow=this.b(a),this.ds64.dataSizeHigh=this.b(a),this.ds64.dataSizeLow=this.b(a),this.ds64.originationTime=this.b(a),this.ds64.sampleCountHigh=this.b(a),this.ds64.sampleCountLow=this.b(a);else if("RF64"==this.container)throw Error('Could not find the "ds64" chunk');
};w.prototype.Ya=function(a){var b=this.m("LIST",!0);if(null!==b)for(var c=0;c<b.length;c++){var d=b[c];this.LIST.push({chunkId:d.chunkId,chunkSize:d.chunkSize,format:d.format,subChunks:[]});for(var e=0;e<d.subChunks.length;e++)this.ea(d.subChunks[e],d.format,a)}};w.prototype.ea=function(a,b,c){"adtl"==b?-1<["labl","note","ltxt"].indexOf(a.chunkId)&&(this.c=a.chunkData.start,b={chunkId:a.chunkId,chunkSize:a.chunkSize,dwName:this.b(c)},"ltxt"==a.chunkId?(b.dwSampleLength=this.b(c),b.dwPurposeID=this.b(c),
b.dwCountry=this.i(c),b.dwLanguage=this.i(c),b.dwDialect=this.i(c),b.dwCodePage=this.i(c),b.value=""):b.value=this.V(c,this.c),this.LIST[this.LIST.length-1].subChunks.push(b)):"INFO"==b&&(this.c=a.chunkData.start,this.LIST[this.LIST.length-1].subChunks.push({chunkId:a.chunkId,chunkSize:a.chunkSize,value:this.V(c,this.c)}))};w.prototype.Xa=function(a){var b=this.m("junk");b&&(this.junk={chunkId:b.chunkId,chunkSize:b.chunkSize,chunkData:[].slice.call(a.slice(b.chunkData.start,b.chunkData.end))})};w.prototype.ga=
function(a){var b=this.m("_PMX");b&&(this.c=b.chunkData.start,this._PMX.chunkId=b.chunkId,this._PMX.chunkSize=b.chunkSize,this._PMX.value=L(a,this.c,this.c+this._PMX.chunkSize))};w.prototype.V=function(a,b){for(var c=b=void 0===b?0:b;c<a.length&&(this.c++,0!==a[c]);c++);return L(a,b,this.c-1)};w.prototype.i=function(a){a=Q(a,this.g,this.c);this.c+=2;return a};R(u,w);u.prototype.toBuffer=function(){this.g.o="RIFX"===this.container;this.a.o=this.g.o;for(var a=[this.Fa(),this.Ba(),this.ua(),this.Oa(),
this.Da(),this.Ca(),x(this.data.chunkId),g(this.data.samples.length,this.a),this.data.samples,this.xa(),this.Ka(),this.Ga(),this.Na()],b=0,c=0;c<a.length;c++)b+=a[c].length;c=new Uint8Array(b+12);var d=Y(this.container,c,0);d=P([b+4],this.a,c,void 0===d?0:d);d=Y(this.format,c,void 0===d?0:d);for(b=0;b<a.length;b++)c.set(a[b],d),d+=a[b].length;return c};u.prototype.ua=function(){var a=[];this.ta();this.bext.chunkId&&(this.bext.chunkSize=602+this.bext.codingHistory.length,a=a.concat(x(this.bext.chunkId),
g(602+this.bext.codingHistory.length,this.a),A(this.bext.description,256),A(this.bext.originator,32),A(this.bext.originatorReference,32),A(this.bext.originationDate,10),A(this.bext.originationTime,8),g(this.bext.timeReference[0],this.a),g(this.bext.timeReference[1],this.a),g(this.bext.version,this.g),A(this.bext.UMID,64),g(this.bext.loudnessValue,this.g),g(this.bext.loudnessRange,this.g),g(this.bext.maxTruePeakLevel,this.g),g(this.bext.maxMomentaryLoudness,this.g),g(this.bext.maxShortTermLoudness,
this.g),A(this.bext.reserved,180),A(this.bext.codingHistory,this.bext.codingHistory.length)));this.j(a);return a};u.prototype.ta=function(){for(var a in this.bext)if(this.bext.hasOwnProperty(a)&&this.bext[a]&&"timeReference"!=a){this.bext.chunkId="bext";break}if(this.bext.timeReference[0]||this.bext.timeReference[1])this.bext.chunkId="bext"};u.prototype.Oa=function(){var a=[];if(this.iXML.chunkId){var b=x(this.iXML.value);this.iXML.chunkSize=b.length;a=a.concat(x(this.iXML.chunkId),g(this.iXML.chunkSize,
this.a),b)}this.j(a);return a};u.prototype.Ba=function(){var a=[];this.ds64.chunkId&&(a=a.concat(x(this.ds64.chunkId),g(this.ds64.chunkSize,this.a),g(this.ds64.riffSizeHigh,this.a),g(this.ds64.riffSizeLow,this.a),g(this.ds64.dataSizeHigh,this.a),g(this.ds64.dataSizeLow,this.a),g(this.ds64.originationTime,this.a),g(this.ds64.sampleCountHigh,this.a),g(this.ds64.sampleCountLow,this.a)));this.j(a);return a};u.prototype.xa=function(){var a=[];if(this.cue.chunkId){var b=this.za();a=a.concat(x(this.cue.chunkId),
g(b.length+4,this.a),g(this.cue.dwCuePoints,this.a),b)}this.j(a);return a};u.prototype.za=function(){for(var a=[],b=0;b<this.cue.dwCuePoints;b++)a=a.concat(g(this.cue.points[b].dwName,this.a),g(this.cue.points[b].dwPosition,this.a),x(this.cue.points[b].fccChunk),g(this.cue.points[b].dwChunkStart,this.a),g(this.cue.points[b].dwBlockStart,this.a),g(this.cue.points[b].dwSampleOffset,this.a));return a};u.prototype.Ka=function(){var a=[];if(this.smpl.chunkId){var b=this.La();a=a.concat(x(this.smpl.chunkId),
g(b.length+36,this.a),g(this.smpl.dwManufacturer,this.a),g(this.smpl.dwProduct,this.a),g(this.smpl.dwSamplePeriod,this.a),g(this.smpl.dwMIDIUnityNote,this.a),g(this.smpl.dwMIDIPitchFraction,this.a),g(this.smpl.dwSMPTEFormat,this.a),g(this.smpl.dwSMPTEOffset,this.a),g(this.smpl.dwNumSampleLoops,this.a),g(this.smpl.dwSamplerData,this.a),b)}this.j(a);return a};u.prototype.La=function(){for(var a=[],b=0;b<this.smpl.dwNumSampleLoops;b++)a=a.concat(g(this.smpl.loops[b].dwName,this.a),g(this.smpl.loops[b].dwType,
this.a),g(this.smpl.loops[b].dwStart,this.a),g(this.smpl.loops[b].dwEnd,this.a),g(this.smpl.loops[b].dwFraction,this.a),g(this.smpl.loops[b].dwPlayCount,this.a));return a};u.prototype.Ca=function(){var a=[];this.fact.chunkId&&(a=a.concat(x(this.fact.chunkId),g(this.fact.chunkSize,this.a),g(this.fact.dwSampleLength,this.a)));this.j(a);return a};u.prototype.Da=function(){var a=[];if(this.fmt.chunkId)return a=a.concat(x(this.fmt.chunkId),g(this.fmt.chunkSize,this.a),g(this.fmt.audioFormat,this.g),g(this.fmt.numChannels,
this.g),g(this.fmt.sampleRate,this.a),g(this.fmt.byteRate,this.a),g(this.fmt.blockAlign,this.g),g(this.fmt.bitsPerSample,this.g),this.Ea()),this.j(a),a;throw Error('Could not find the "fmt " chunk');};u.prototype.Ea=function(){var a=[];16<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.cbSize,this.g)));18<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.validBitsPerSample,this.g)));20<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.dwChannelMask,this.a)));24<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.subformat[0],
this.a),g(this.fmt.subformat[1],this.a),g(this.fmt.subformat[2],this.a),g(this.fmt.subformat[3],this.a)));return a};u.prototype.Ga=function(){for(var a=[],b=0;b<this.LIST.length;b++){var c=this.Ia(this.LIST[b].subChunks,this.LIST[b].format);a=a.concat(x(this.LIST[b].chunkId),g(c.length+4,this.a),x(this.LIST[b].format),c)}this.j(a);return a};u.prototype.Ia=function(a,b){for(var c=[],d=0;d<a.length;d++){if("INFO"==b){var e=A(a[d].value,a[d].value.length);c=c.concat(x(a[d].chunkId),g(e.length+1,this.a),
e);c.push(0)}else"adtl"==b&&(-1<["labl","note"].indexOf(a[d].chunkId)?(e=A(a[d].value,a[d].value.length),c=c.concat(x(a[d].chunkId),g(e.length+5,this.a),g(a[d].dwName,this.a),e),c.push(0)):"ltxt"==a[d].chunkId&&(c=c.concat(this.Ja(a[d]))));this.j(c)}return c};u.prototype.Na=function(){var a=[];if(this._PMX.chunkId){var b=x(this._PMX.value);this._PMX.chunkSize=b.length;a=a.concat(x(this._PMX.chunkId),g(this._PMX.chunkSize,this.a),b)}this.j(a);return a};u.prototype.Ja=function(a){return x(a.chunkId).concat(g(a.value.length+
20,this.a),g(a.dwName,this.a),g(a.dwSampleLength,this.a),g(a.dwPurposeID,this.a),g(a.dwCountry,this.g),g(a.dwLanguage,this.g),g(a.dwDialect,this.g),g(a.dwCodePage,this.g),A(a.value,a.value.length))};u.prototype.Fa=function(){var a=[];if(this.junk.chunkId)return a.concat(x(this.junk.chunkId),g(this.junk.chunkData.length,this.a),this.junk.chunkData);this.j(a);return a};u.prototype.j=function(a){a.length%2&&a.push(0)};R(t,u);t.prototype.fromScratch=function(a,b,c,d,e){e=void 0===e?{}:e;this.S();this.U(a,
b,c,d,e)};t.prototype.fromBuffer=function(a,b){u.prototype.fromBuffer.call(this,a,void 0===b?!0:b);this.pa();this.Y()};t.prototype.toBuffer=function(){this.Z();return u.prototype.toBuffer.call(this)};t.prototype.getSamples=function(a,b){a=void 0===a?!1:a;b=void 0===b?Float64Array:b;var c=new b(this.data.samples.length/(this.f.h/8));N(this.data.samples,this.f,c);if(!a&&1<this.fmt.numChannels){var d=this.fmt.numChannels,e=b;e=void 0===e?Float64Array:e;for(var f=[],h=0;h<d;h++)f[h]=new e(c.length/d);
for(e=0;e<d;e++){h=0;for(var k=e;k<c.length;k+=d)f[e][h++]=c[k]}c=f}return c};t.prototype.getSample=function(a){a*=this.f.h/8;if(a+this.f.h/8>this.data.samples.length)throw Error("Range error");return Q(this.data.samples.slice(a,a+this.f.h/8),this.f)};t.prototype.setSample=function(a,b){a*=this.f.h/8;if(a+this.f.h/8>this.data.samples.length)throw Error("Range error");P([b],this.f,this.data.samples,void 0===a?0:a)};t.prototype.getiXML=function(){return this.iXML.value};t.prototype.setiXML=function(a){if("string"!==
typeof a)throw new TypeError("iXML value must be a string.");this.iXML.value=a;this.iXML.chunkId="iXML"};t.prototype.get_PMX=function(){return this._PMX.value};t.prototype.set_PMX=function(a){if("string"!==typeof a)throw new TypeError("_PMX value must be a string.");this._PMX.value=a;this._PMX.chunkId="_PMX"};t.prototype.U=function(a,b,c,d,e){e=void 0===e?{}:e;e.container||(e.container="RIFF");this.container=e.container;this.bitDepth=c;var f=[];if(0<d.length)if(d[0].constructor!==Number){f=new Float64Array(d[0].length*
d.length);for(var h=0,k=0,p=d[0].length;k<p;k++)for(var y=0,Na=d.length;y<Na;y++)f[h]=d[y][k],h++}else f=d;d=f;this.Y();f=this.f.h/8;this.data.samples=new Uint8Array(d.length*f);P(d,this.f,this.data.samples);this.Pa(c,a,b,f,this.data.samples.length,e);this.data.chunkId="data";this.data.chunkSize=this.data.samples.length;this.Z()};t.prototype.Pa=function(a,b,c,d,e,f){"4"==a?this.qa(a,b,c,d,e,f):"8a"==a||"8m"==a?this.ra(a,b,c,d,e,f):-1==Object.keys(this.N).indexOf(a)||2<b?this.sa(a,b,c,d,e,f):this.A(a,
b,c,d,e,f)};t.prototype.A=function(a,b,c,d,e,f){this.container=f.container;this.chunkSize=36+e;this.format="WAVE";this.bitDepth=a;this.fmt={chunkId:"fmt ",chunkSize:16,audioFormat:this.N[a]||65534,numChannels:b,sampleRate:c,byteRate:b*d*c,blockAlign:b*d,bitsPerSample:parseInt(a,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}};t.prototype.qa=function(a,b,c,d,e,f){this.A(a,b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.byteRate=4055;this.fmt.blockAlign=256;this.fmt.bitsPerSample=
4;this.fmt.cbSize=2;this.fmt.validBitsPerSample=505;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*e}};t.prototype.sa=function(a,b,c,d,e,f){this.A(a,b,c,d,e,f);this.chunkSize=60+e;this.fmt.chunkSize=40;this.fmt.bitsPerSample=(parseInt(a,10)-1|7)+1;this.fmt.cbSize=22;this.fmt.validBitsPerSample=parseInt(a,10);a=this.fmt;c=0;1===b?c=4:2===b?c=3:4===b?c=51:6===b?c=63:8===b&&(c=1599);a.dwChannelMask=c;this.fmt.subformat=[1,1048576,2852126848,1905997824]};t.prototype.ra=function(a,b,c,d,e,f){this.A(a,
b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.cbSize=2;this.fmt.validBitsPerSample=8;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:e}};t.prototype.pa=function(){3===this.fmt.audioFormat&&32===this.fmt.bitsPerSample?this.bitDepth="32f":6===this.fmt.audioFormat?this.bitDepth="8a":7===this.fmt.audioFormat?this.bitDepth="8m":this.bitDepth=this.fmt.bitsPerSample.toString()};t.prototype.na=function(){if(!(this.N[this.bitDepth]||8<parseInt(this.bitDepth,10)&&54>parseInt(this.bitDepth,
10)))throw Error("Invalid bit depth.");};t.prototype.Y=function(){this.f={h:(parseInt(this.bitDepth,10)-1|7)+1,K:"32f"==this.bitDepth||"64"==this.bitDepth,C:"8"!=this.bitDepth,o:"RIFX"==this.container};-1<["4","8a","8m"].indexOf(this.bitDepth)&&(this.f.h=8,this.f.C=!1)};t.prototype.Z=function(){this.na();var a=this.fmt.numChannels;if(1>a||65535<a*this.fmt.bitsPerSample/8)throw Error("Invalid number of channels.");a=this.fmt.sampleRate;if(1>a||4294967295<this.fmt.bitsPerSample/8*this.fmt.numChannels*
a)throw Error("Invalid sample rate.");};R(z,t);z.prototype.getTag=function(a){a=this.I(a);return null!==a.w?this.LIST[a.LIST].subChunks[a.w].value:null};z.prototype.setTag=function(a,b){var c=a;if(c.constructor!==String)throw Error("Invalid tag name.");if(4>c.length)for(var d=0,e=4-c.length;d<e;d++)c+=" ";a=c;c=this.I(a);null!==c.w?(this.LIST[c.LIST].subChunks[c.w].chunkSize=b.length+1,this.LIST[c.LIST].subChunks[c.w].value=b):null!==c.LIST?this.LIST[c.LIST].subChunks.push({chunkId:a,chunkSize:b.length+
1,value:b}):(this.LIST.push({chunkId:"LIST",chunkSize:b.length+9,format:"INFO",subChunks:[]}),this.LIST[this.LIST.length-1].subChunks.push({chunkId:a,chunkSize:b.length+1,value:b}))};z.prototype.deleteTag=function(a){a=this.I(a);return null!==a.w?(this.LIST[a.LIST].subChunks.splice(a.w,1),!0):!1};z.prototype.listTags=function(){var a=this.Ha(),b={};if(null!==a)for(var c=0,d=this.LIST[a].subChunks.length;c<d;c++)b[this.LIST[a].subChunks[c].chunkId]=this.LIST[a].subChunks[c].value;return b};z.prototype.Ha=
function(){for(var a=null,b=0,c=this.LIST.length;b<c;b++)if("INFO"===this.LIST[b].format){a=b;break}return a};z.prototype.I=function(a){for(var b={LIST:null,w:null},c=0,d=this.LIST.length;c<d;c++)if("INFO"==this.LIST[c].format){b.LIST=c;d=0;for(var e=this.LIST[c].subChunks.length;d<e;d++)if(this.LIST[c].subChunks[d].chunkId==a){b.w=d;break}break}return b};R(r,z);r.prototype.listCuePoints=function(){for(var a=this.H(),b=0,c=a.length;b<c;b++)a[b].position=a[b].dwSampleOffset/this.fmt.sampleRate*1E3,
a[b].dwSampleLength?(a[b].end=a[b].dwSampleLength/this.fmt.sampleRate*1E3,a[b].end+=a[b].position):a[b].end=null,delete a[b].value;return a};r.prototype.setCuePoint=function(a){this.cue.chunkId="cue ";a.label||(a.label="");var b=this.H();this.F();this.cue.points=[];a.dwSampleOffset=a.position*this.fmt.sampleRate/1E3;a.dwSampleLength=0;a.end&&(a.dwSampleLength=a.end*this.fmt.sampleRate/1E3-a.dwSampleOffset);0===b.length?this.v(a,1):this.ia(b,a);this.cue.dwCuePoints=this.cue.points.length};r.prototype.deleteCuePoint=
function(a){this.cue.chunkId="cue ";var b=this.H();this.F();var c=this.cue.points.length;this.cue.points=[];for(var d=0;d<c;d++)d+1!==a&&this.v(b[d],d+1);this.cue.dwCuePoints=this.cue.points.length;this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.F())};r.prototype.updateLabel=function(a,b){var c=this.G();if(null!==c)for(var d=0,e=this.LIST[c].subChunks.length;d<e;d++)this.LIST[c].subChunks[d].dwName==a&&(this.LIST[c].subChunks[d].value=b)};r.prototype.H=function(){for(var a=
[],b=0;b<this.cue.points.length;b++){var c=this.cue.points[b],d=this.Aa(c.dwName);d.label=d.value?d.value:"";d.dwPosition=c.dwPosition;d.fccChunk=c.fccChunk;d.dwChunkStart=c.dwChunkStart;d.dwBlockStart=c.dwBlockStart;d.dwSampleOffset=c.dwSampleOffset;a.push(d)}return a};r.prototype.Aa=function(a){var b=this.G(),c={};null!==b&&this.da(c,b,a);return c};r.prototype.da=function(a,b,c){for(var d=0,e=this.LIST[b].subChunks.length;d<e;d++)if(this.LIST[b].subChunks[d].dwName==c){var f=this.LIST[b].subChunks[d];
a.value=f.value||a.value;a.dwName=f.dwName||0;a.dwSampleLength=f.dwSampleLength||0;a.dwPurposeID=f.dwPurposeID||0;a.dwCountry=f.dwCountry||0;a.dwLanguage=f.dwLanguage||0;a.dwDialect=f.dwDialect||0;a.dwCodePage=f.dwCodePage||0}};r.prototype.G=function(){for(var a=0,b=this.LIST.length;a<b;a++)if("adtl"==this.LIST[a].format)return a;return null};r.prototype.v=function(a,b){this.cue.points.push({dwName:b,dwPosition:a.dwPosition?a.dwPosition:0,fccChunk:a.fccChunk?a.fccChunk:"data",dwChunkStart:a.dwChunkStart?
a.dwChunkStart:0,dwBlockStart:a.dwBlockStart?a.dwBlockStart:0,dwSampleOffset:a.dwSampleOffset});this.ka(a,b)};r.prototype.ia=function(a,b){for(var c=!1,d=0;d<a.length;d++)a[d].dwSampleOffset>b.dwSampleOffset&&!c?(this.v(b,d+1),this.v(a[d],d+2),c=!0):this.v(a[d],c?d+2:d+1);c||this.v(b,this.cue.points.length+1)};r.prototype.F=function(){for(var a=0,b=this.LIST.length;a<b;a++)"adtl"==this.LIST[a].format&&this.LIST.splice(a)};r.prototype.ka=function(a,b){var c=this.G();null===c&&(this.LIST.push({chunkId:"LIST",
chunkSize:4,format:"adtl",subChunks:[]}),c=this.LIST.length-1);this.ja(c,a,b);a.dwSampleLength&&this.la(c,a,b)};r.prototype.ja=function(a,b,c){this.LIST[a].subChunks.push({chunkId:"labl",chunkSize:4,dwName:c,value:b.label});this.LIST[a].chunkSize+=12};r.prototype.la=function(a,b,c){this.LIST[a].subChunks.push({chunkId:"ltxt",chunkSize:20,dwName:c,dwSampleLength:b.dwSampleLength,dwPurposeID:b.dwPurposeID||0,dwCountry:b.dwCountry||0,dwLanguage:b.dwLanguage||0,dwDialect:b.dwDialect||0,dwCodePage:b.dwCodePage||
0,value:b.label});this.LIST[a].chunkSize+=28};v.prototype.G=function(a,b){return this.f(Math.round(this.j*a),b)};v.prototype.F=function(a,b){a*=this.j;var c=Math.floor(a);a-=c;return(1-a)*this.f(c,b)+a*this.f(c+1,b)};v.prototype.N=function(a,b){a*=this.j;var c=Math.floor(a),d=[this.u(c,b),this.u(c+1,b)],e=[this.f(c,b),this.f(c+1,b)];a-=c;c=a*a;var f=a*c;return(2*f-3*c+1)*e[0]+(f-2*c+a)*d[0]+(-2*f+3*c)*e[1]+(f-c)*d[1]};v.prototype.H=function(a,b){a*=this.j;var c=Math.floor(a),d=c-this.A+1;c+=this.A;
for(var e=0,f=d,h=d;d<=c?h<=c:h>=c;f=d<=c?++h:--h)e+=this.D(a-f)*this.f(f,b);return e};v.prototype.u=function(a,b){return this.I*(this.f(a+1,b)-this.f(a-1,b))/2};v.prototype.f=function(a,b){return 0<=a&&a<this.v?b[a]:b[this.l(a,this.v)]};q.prototype.filter=function(a){this.a.J[this.a.O]=a;for(var b=a=0,c=this.a.J.length;b<c;b++)a+=this.b[b]*this.a.J[(this.a.O+b)%this.a.J.length];this.a.O=(this.a.O+1)%this.a.J.length;return a};q.prototype.reset=function(){this.a=this.c()};q.prototype.c=function(){for(var a=
[],b=0;b<this.b.length-1;b++)a.push(0);return{J:a,O:0}};var Ma={point:!1,linear:!1,cubic:!0,sinc:!0},ma={point:71,linear:71,cubic:71,sinc:71};R(l,r);l.prototype.toRIFF=function(){this.l(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,aa(this.data.samples,this.f))};l.prototype.toRIFX=function(){this.l(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,aa(this.data.samples,this.f),{container:"RIFX"})};l.prototype.toIMAADPCM=function(){if(8E3!==this.fmt.sampleRate)throw Error("Only 8000 Hz files can be compressed as IMA-ADPCM.");
if(1!==this.fmt.numChannels)throw Error("Only mono files can be compressed as IMA-ADPCM.");this.D();var a=new Int16Array(this.P());N(this.data.samples,this.f,a);this.l(this.fmt.numChannels,this.fmt.sampleRate,"4",Ca(a),{container:this.u()})};l.prototype.fromIMAADPCM=function(a){a=void 0===a?"16":a;this.l(this.fmt.numChannels,this.fmt.sampleRate,"16",Ea(this.data.samples,this.fmt.blockAlign),{container:this.u()});"16"!=a&&this.toBitDepth(a)};l.prototype.toALaw=function(){this.D();var a=new Int16Array(this.P());
N(this.data.samples,this.f,a);this.l(this.fmt.numChannels,this.fmt.sampleRate,"8a",Fa(a),{container:this.u()})};l.prototype.fromALaw=function(a){a=void 0===a?"16":a;this.l(this.fmt.numChannels,this.fmt.sampleRate,"16",Ha(this.data.samples),{container:this.u()});"16"!=a&&this.toBitDepth(a)};l.prototype.toMuLaw=function(){this.D();var a=new Int16Array(this.P());N(this.data.samples,this.f,a);this.l(this.fmt.numChannels,this.fmt.sampleRate,"8m",Ia(a),{container:this.u()})};l.prototype.fromMuLaw=function(a){a=
void 0===a?"16":a;this.l(this.fmt.numChannels,this.fmt.sampleRate,"16",Ka(this.data.samples),{container:this.u()});"16"!=a&&this.toBitDepth(a)};l.prototype.toBitDepth=function(a,b){var c=a,d=this.bitDepth;void 0===b||b||("32f"!=a&&(c=this.f.h.toString()),d=""+this.f.h);this.R();var e=this.getSamples(!0),f=new Float64Array(e.length),h=d;if(-1<["32f","64"].indexOf(h)&&-1<["32f","64"].indexOf(c))f.set(e);else{ea(h);ea(c);d=Ba(h,c);var k={ca:Math.pow(2,parseInt(h,10))/2,aa:Math.pow(2,parseInt(c,10))/
2,ba:Math.pow(2,parseInt(h,10))/2-1,$:Math.pow(2,parseInt(c,10))/2-1};fa(h,e,!0);if(-1<["32f","64"].indexOf(h)){h=e.length;for(var p=0;p<h;p++)1<e[p]?e[p]=1:-1>e[p]&&(e[p]=-1)}for(h=0;h<e.length;h++)f[h]=d(e[h],k);fa(c,f,!1)}this.l(this.fmt.numChannels,this.fmt.sampleRate,a,f,{container:this.u()})};l.prototype.toSampleRate=function(a,b){b=void 0===b?{}:b;this.oa(a);var c=this.getSamples(),d=[];if(c.constructor===Float64Array)d=la(c,this.fmt.sampleRate,a,b);else for(var e=0;e<c.length;e++)d.push(la(c[e],
this.fmt.sampleRate,a,b));if("64"!==this.bitDepth&&"32f"!==this.bitDepth)if(d[0].constructor===Number)ka(d,this.f.h);else for(c=0;c<d.length;c++)ka(d[c],this.f.h);this.l(this.fmt.numChannels,a,this.bitDepth,d,{container:this.u()})};l.prototype.oa=function(a){if(1>a||4294967295<this.fmt.bitsPerSample/8*this.fmt.numChannels*a)throw Error("Invalid sample rate.");if(-1<["4","8a","8m"].indexOf(this.bitDepth))throw Error("wavefile can't change the sample rate of compressed files.");};l.prototype.D=function(){this.R();
"16"!=this.bitDepth&&this.toBitDepth("16")};l.prototype.R=function(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()};l.prototype.u=function(){return"RF64"==this.container?"RIFF":this.container};l.prototype.l=function(a,b,c,d,e){e=void 0===e?{}:e;var f=new r;Object.assign(this.fmt,f.fmt);Object.assign(this.fact,f.fact);Object.assign(this.ds64,f.ds64);Object.assign(this.data,f.data);this.U(a,b,c,d,e)};l.prototype.P=function(){var a=this.data.samples.length/
2;a%2&&a++;return a};R(m,l);m.prototype.fromBase64=function(a){this.fromBuffer(new Uint8Array(xa(a)))};m.prototype.toBase64=function(){for(var a=this.toBuffer(),b="",c=0;c<a.length;c+=3)b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c]>>2],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c]&3)<<4|a[c+1]>>4],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c+1]&15)<<2|a[c+2]>>6],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c+
2]&63];2===a.length%3?b=b.substring(0,b.length-1)+"=":1===a.length%3&&(b=b.substring(0,b.length-2)+"==");return b};m.prototype.toDataURI=function(){return"data:audio/wav;base64,"+this.toBase64()};m.prototype.fromDataURI=function(a){this.fromBase64(a.replace("data:audio/wav;base64,",""))};n.WaveFile=m;Object.defineProperty(n,"__esModule",{value:!0})}
"object"===typeof exports&&"undefined"!==typeof module?U(exports):"function"===typeof define&&define.amd?define(["exports"],U):(T=T||self,U(T.wavefile={}));

@@ -323,5 +323,9 @@ /*

* false to return the samples de-interleaved. Defaults to false.
* @param {?Function=} OutputObject The Typed Array object to write the
* samples. Assumes Float64Array by default.
* @return {!Float64Array|Array<Float64Array>} the samples.
*/
WaveFile.prototype.getSamples = function(interleaved=false) {};
WaveFile.prototype.getSamples = function(
interleaved=false,
OutputObject=Float64Array) {};

@@ -441,3 +445,4 @@ /**

sincWindow: function(x){},
LPForder: 1}) {};
LPForder: 1,
LPF: true}) {};

@@ -444,0 +449,0 @@ /**

@@ -109,5 +109,7 @@ // Type definitions for wavefile 10.2

* false to return the samples de-interleaved. Defaults to false.
* @param {?Function=} OutputObject The Typed Array object to write the
* samples. Assumes Float64Array by default.
* @return {!Float64Array|Array<Float64Array>} the samples.
*/
getSamples(interleaved?:boolean): Float64Array;
getSamples(interleaved?:boolean, OutputObject?: Function): Float64Array;

@@ -114,0 +116,0 @@ /**

@@ -59,9 +59,11 @@ /*

* @param {number} numChannels The number of channels to split the samples.
* @param {?Function=} OutputObject The Typed Array object to write the
* samples. Assumes Float64Array by default.
* @return {!Array|!TypedArray}
*/
export function deInterleave(samples, numChannels) {
export function deInterleave(samples, numChannels, OutputObject=Float64Array) {
/** @type {!Array|!TypedArray} */
let finalSamples = [];
for (let i = 0; i < numChannels; i++) {
finalSamples[i] = new Float64Array(samples.length / numChannels);
finalSamples[i] = new OutputObject(samples.length / numChannels);
}

@@ -68,0 +70,0 @@ for (let i = 0; i < numChannels; i ++) {

@@ -60,17 +60,3 @@ /*

}
let b = [];
for (let i = 0; i < this.filters.length; i++) {
b[i] = {
re: this.filters[i],
im: 0
};
}
let r = [];
for (let i = 0; i < this.filters.length - 1; i++) {
r.push(0);
}
this.z = {
buf: r,
pointer: 0
};
this.z = this.initZ_();
}

@@ -85,3 +71,3 @@

let out = 0;
for (let i = 0; i < this.z.buf.length; i++) {
for (let i = 0, len = this.z.buf.length; i < len; i++) {
out += (

@@ -93,2 +79,24 @@ this.filters[i] * this.z.buf[(this.z.pointer + i) % this.z.buf.length]);

}
/**
* Reset the filter.
*/
reset() {
this.z = this.initZ_();
}
/**
* Return the default value for z.
* @private
*/
initZ_() {
let r = [];
for (let i = 0; i < this.filters.length - 1; i++) {
r.push(0);
}
return {
buf: r,
pointer: 0
};
}
}

@@ -33,2 +33,16 @@ /*

const DEFAULT_LPF_USE = {
'point': false,
'linear': false,
'cubic': true,
'sinc': true
};
const DEFAULT_LPF_ORDER = {
'point': 71,
'linear': 71,
'cubic': 71,
'sinc': 71
};
/**

@@ -42,4 +56,3 @@ * Change the sample rate of the samples to a new sample rate.

*/
export function resample(
samples, oldSampleRate, sampleRate, details={}) {
export function resample(samples, oldSampleRate, sampleRate, details={}) {
// Make the new sample container

@@ -49,2 +62,3 @@ let rate = ((sampleRate - oldSampleRate) / oldSampleRate) + 1;

// Create the interpolator
details.method = details.method || 'cubic';
let interpolator = new Interpolator(

@@ -54,19 +68,33 @@ samples.length,

{
method: details.method || 'cubic',
method: details.method,
tension: details.tension || 0,
sincFilterSize: details.sincFilterSize || 32,
sincFilterSize: details.sincFilterSize || 6,
sincWindow: details.sincWindow || undefined,
lanczosFilterSize: details.lanczosFilterSize || 16,
clip: details.clip || 'mirror'
});
// Upsampling
if (sampleRate > oldSampleRate) {
upsample_(
samples, newSamples, interpolator,
sampleRate, oldSampleRate, details.LPForder || 71);
// Downsampling
// Resample + LPF
if (details.LPF === undefined) {
details.LPF = DEFAULT_LPF_USE[details.method];
}
if (details.LPF) {
// Upsampling
if (sampleRate > oldSampleRate) {
let filter = new FIRLPF(
details.LPForder || DEFAULT_LPF_ORDER[details.method],
sampleRate,
(oldSampleRate / 2));
upsample_(
samples, newSamples, interpolator, filter);
// Downsampling
} else {
let filter = new FIRLPF(
details.LPForder || DEFAULT_LPF_ORDER[details.method],
oldSampleRate,
sampleRate / 2);
downsample_(
samples, newSamples, interpolator, filter);
}
// Resample, no LPF
} else {
downsample_(
samples, newSamples, interpolator,
sampleRate, oldSampleRate, details.LPForder || 71);
resample_(samples, newSamples, interpolator);
}

@@ -77,47 +105,50 @@ return newSamples;

/**
* Upsample.
* Resample.
* @param {!Array|!TypedArray} samples The original samples.
* @param {!Float64Array} newSamples The container for the new samples.
* @param {Object} interpolator The interpolator.
* @param {number} sampleRate The target sample rate.
* @param {number} oldSampleRate The original sample rate.
* @param {number} LPForder The LPF order.
* @return {!Float64Array}
* @private
*/
function upsample_(
samples, newSamples, interpolator, sampleRate, oldSampleRate, LPForder) {
function resample_(samples, newSamples, interpolator) {
// Resample
for (let i = 0, len = newSamples.length; i < len; i++) {
newSamples[i] = interpolator.interpolate(i, samples);
}
}
/**
* Upsample with LPF.
* @param {!Array|!TypedArray} samples The original samples.
* @param {!Float64Array} newSamples The container for the new samples.
* @param {Object} interpolator The interpolator.
* @param {Object} filter The LPF object.
* @private
*/
function upsample_(samples, newSamples, interpolator, filter) {
// Resample and filter
let filter = new FIRLPF(LPForder, sampleRate, (oldSampleRate / 2));
for (let i=0; i< newSamples.length; i++) {
for (let i = 0, len = newSamples.length; i < len; i++) {
newSamples[i] = filter.filter(interpolator.interpolate(i, samples));
}
// Reverse filter
filter = new FIRLPF(LPForder, sampleRate, (oldSampleRate / 2));
filter.reset();
for (let i = newSamples.length - 1; i >= 0; i--) {
newSamples[i] = filter.filter(newSamples[i]);
}
return newSamples;
}
/**
* Downsample.
* Downsample with LPF.
* @param {!Array|!TypedArray} samples The original samples.
* @param {!Float64Array} newSamples The container for the new samples.
* @param {Object} interpolator The interpolator.
* @param {number} sampleRate The target sample rate.
* @param {number} oldSampleRate The original sample rate.
* @param {number} LPForder The LPF order.
* @return {!Float64Array}
* @param {Object} filter The LPF object.
* @private
*/
function downsample_(
samples, newSamples, interpolator, sampleRate, oldSampleRate, LPForder) {
function downsample_(samples, newSamples, interpolator, filter) {
// Filter
let filter = new FIRLPF(LPForder, oldSampleRate, sampleRate / 2);
for (let i = 0; i < samples.length; i++) {
for (let i = 0, len = samples.length; i < len; i++) {
samples[i] = filter.filter(samples[i]);
}
// Reverse filter
filter = new FIRLPF(LPForder, oldSampleRate, sampleRate / 2);
filter.reset();
for (let i = samples.length - 1; i >= 0; i--) {

@@ -127,6 +158,3 @@ samples[i] = filter.filter(samples[i]);

// Resample
for (let i=0; i< newSamples.length; i++) {
newSamples[i] = interpolator.interpolate(i, samples);
}
return newSamples;
resample_(samples, newSamples, interpolator);
}

@@ -94,6 +94,2 @@ /*

this.kernel_ = sincKernel_(details.sincWindow || gaussianWindow_);
if (details.method === 'lanczos') {
this.kernel_ = sincKernel_(lanczosWindow_(details.lanczosFilterSize));
this.sincFilterSize = details.lanczosFilterSize;
}
}

@@ -211,11 +207,2 @@

/**
* @param {number} size The filter size.
* @return {Function}
* @private
*/
function lanczosWindow_(size) {
return function(x) { return sinc_(x / size); };
}
/**
* @param {number} x The sinc signal.

@@ -222,0 +209,0 @@ * @return {number}

@@ -34,3 +34,3 @@ /*

import { unpackArray, unpackArrayTo } from 'byte-data';
import { WaveFileMetaEditor } from './wavefile-meta-editor';
import { WaveFileCueEditor } from './wavefile-cue-editor';
import { truncateIntSamples } from './parsers/truncate-samples';

@@ -42,6 +42,6 @@ import { validateSampleRate } from './validators/validate-sample-rate';

* A class to convert wav files to other types of wav files.
* @extends WaveFileMetaEditor
* @extends WaveFileCueEditor
* @ignore
*/
export class WaveFileConverter extends WaveFileMetaEditor {
export class WaveFileConverter extends WaveFileCueEditor {

@@ -334,3 +334,3 @@ /**

fromExisting_(numChannels, sampleRate, bitDepthCode, samples, options={}) {
let tmpWav = new WaveFileMetaEditor();
let tmpWav = new WaveFileCueEditor();
Object.assign(this.fmt, tmpWav.fmt);

@@ -337,0 +337,0 @@ Object.assign(this.fact, tmpWav.fact);

@@ -127,5 +127,7 @@ /*

* false to return the samples de-interleaved. Defaults to false.
* @param {?Function=} OutputObject The Typed Array object to write the
* samples. Assumes Float64Array by default.
* @return {!Array|!TypedArray} the samples.
*/
getSamples(interleaved=false) {
getSamples(interleaved=false, OutputObject=Float64Array) {
/**

@@ -136,3 +138,3 @@ * A Float64Array created with a size to match the

*/
let samples = new Float64Array(
let samples = new OutputObject(
this.data.samples.length / (this.dataType.bits / 8));

@@ -142,3 +144,3 @@ // Unpack all the samples

if (!interleaved && this.fmt.numChannels > 1) {
return deInterleave(samples, this.fmt.numChannels);
return deInterleave(samples, this.fmt.numChannels, OutputObject);
}

@@ -145,0 +147,0 @@ return samples;

{
"name": "wavefile",
"version": "10.2.0",
"version": "10.3.0",
"description": "Create, read and write wav files according to the specs.",

@@ -72,4 +72,7 @@ "homepage": "https://github.com/rochars/wavefile",

"test": "nyc ./node_modules/mocha/bin/_mocha test/resampler test/dist test/src test/wavefile-parser test/lib --recursive -R dot --timeout=1600000",
"test-sr": "nyc ./node_modules/mocha/bin/_mocha test/resampler-full -R dot --timeout=1600000",
"test-sr-sinc": "nyc ./node_modules/mocha/bin/_mocha test/resampler-full/sinc.js -R dot --timeout=1600000",
"test-sr": "node ./node_modules/mocha/bin/_mocha test/resampler-full -R dot --timeout=1600000",
"test-sr-point": "node ./node_modules/mocha/bin/_mocha test/resampler-full/point.js -R dot --timeout=1600000",
"test-sr-linear": "node ./node_modules/mocha/bin/_mocha test/resampler-full/linear.js -R dot --timeout=1600000",
"test-sr-cubic": "node ./node_modules/mocha/bin/_mocha test/resampler-full/cubic.js -R dot --timeout=1600000",
"test-sr-sinc": "node ./node_modules/mocha/bin/_mocha test/resampler-full/sinc.js test/resampler-full/sinc-no-LPF.js -R dot --timeout=1600000",
"test-umd": "node ./node_modules/mocha/bin/_mocha test/resampler test/dist test/src --umd --recursive -R dot --timeout=240000",

@@ -76,0 +79,0 @@ "test-tsc": "tsc ./test/TypeScript/index.ts && node -r esm ./test/TypeScript/index.js",

@@ -388,3 +388,3 @@ # wavefile

### Change the sample rate
You can change the sample rate of the audio with the **toSampleRate()** method. By default, **cubic interpolation** is used to resample the data. You can use **cubic** and **sinc**.
You can change the sample rate of the audio with the **toSampleRate()** method. By default, **cubic interpolation** is used to resample the data. You can choose between **cubic**, **sinc**, **point** and **linear**.
```javascript

@@ -394,3 +394,3 @@ // Load a wav file with 16kHz audio

// Change the bit depth to 44.1kHz
// Change the sample rate to 44.1kHz
// using the default configuration

@@ -407,6 +407,21 @@ wav.toSampleRate(44100);

```javascript
// Change the bit depth to 44.1kHz using sinc
// Change the sample rate to 44.1kHz using sinc
wav.toSampleRate(44100, {method: "sinc"});
```
#### Resampling methods
- **point**: Nearest point interpolation, lowest quality, no LPF by default, fastest
- **linear**: Linear interpolation, low quality, no LPF by default, fast
- **cubic**: Cubic interpolation, use LPF by default **(default method)**
- **sinc**: Windowed sinc interpolation, use LPF by default, slowest
You can turn the LPF on and off for any resampling method:
```javascript
// Will use 'sinc' method with no LPF
wav.toSampleRate(44100, {method: "sinc", LPF: false});
// Will use 'linear' method with LPF
wav.toSampleRate(44100, {method: "linear", LPF: true});
```
#### Changing the sample rate of ADPCM, mu-Law or A-Law

@@ -481,2 +496,15 @@ You need to convert compressed files to standard PCM before resampling:

You can use any typed array as the output of *getSamples()*:
```javascript
// Will return the samples de-interleaved,
// packed in a array of Int32Array objects, one for each channel
samples = wav.getSamples(false, Int32Array);
// will return the samples de-interleaved,
// packed in a array of Int16Array objects, one for each channel
let samples = getSamples(false, Int16Array);
// will return the samples interleaved, packed in a Int16Array
let samples = getSamples(true, Int16Array);
```
To get and set samples in a WaveFile instance you should use WaveFile.getSample(index) and WaveFile.setSample(index, sample). The 'index' is the index of the sample in the sample array, not the index of the bytes in data.samples.

@@ -760,5 +788,7 @@

* false to return the samples de-interleaved. Defaults to false.
* @param {?Function=} OutputObject The Typed Array object to write the
* samples. Assumes Float64Array by default.
* @return {!Float64Array|Array<Float64Array>} the samples.
*/
WaveFile.getSamples(interleaved=false) {};
WaveFile.getSamples(interleaved=false, OutputObject=Float64Array) {};

@@ -765,0 +795,0 @@ /**

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc