Comparing version 8.4.1 to 8.4.2
@@ -16,41 +16,41 @@ #!/usr/bin/env node | ||
const help = " Usage:\n" + | ||
"\n" + | ||
" wavefile path/to/input.wav [...options] path/to/output.wav\n" + | ||
"\n" + | ||
" Available options:\n" + | ||
"\n" + | ||
" --bitdepth Ex: wavefile input.wav --bitdepth=32f output.wav\n" + | ||
" Change the bit depth.\n" + | ||
" The input file is not affected.\n" + | ||
" Possible values: 8, 16, 24, 32, 32f, 64\n" + | ||
"\n" + | ||
" --compress Ex: wavefile input.wav --compress=adpcm output.wav\n" + | ||
" Apply compression to the file.\n" + | ||
" The input file is not affected.\n" + | ||
" Possible values: adpcm, alaw, mulaw\n" + | ||
"\n" + | ||
" --tag Ex: wavefile input.wav --tag=ICRD\n" + | ||
" Print the value of tag if the tag exists.\n" + | ||
"\n" + | ||
" --list-tags Ex: wavefile input.wav --list-tags\n" + | ||
" Print all tags of the file.\n" + | ||
"\n" + | ||
" --list-cue Ex: wavefile input.wav --list-cue\n" + | ||
" Print all the cue points of the file.\n" + | ||
"\n" + | ||
" --bits Ex: wavefile input.wav --bits\n" + | ||
" Print the bit depth of the file.\n" + | ||
"\n" + | ||
" --rate Ex: wavefile input.wav --rate\n" + | ||
" Print the sample rate of the file.\n" + | ||
"\n" + | ||
" --help Ex: --help\n" + | ||
" Show this help page.\n" + | ||
"\n"; | ||
"\n" + | ||
" wavefile path/to/input.wav [...options] path/to/output.wav\n" + | ||
"\n" + | ||
" Available options:\n" + | ||
"\n" + | ||
" --bitdepth Ex: wavefile input.wav --bitdepth=32f output.wav\n" + | ||
" Change the bit depth.\n" + | ||
" The input file is not affected.\n" + | ||
" Possible values: 8, 16, 24, 32, 32f, 64\n" + | ||
"\n" + | ||
" --compress Ex: wavefile input.wav --compress=adpcm output.wav\n" + | ||
" Apply compression to the file.\n" + | ||
" The input file is not affected.\n" + | ||
" Possible values: adpcm, alaw, mulaw\n" + | ||
"\n" + | ||
" --tag Ex: wavefile input.wav --tag=ICRD\n" + | ||
" Print the value of tag if the tag exists.\n" + | ||
"\n" + | ||
" --list-tags Ex: wavefile input.wav --list-tags\n" + | ||
" Print all tags of the file.\n" + | ||
"\n" + | ||
" --list-cue Ex: wavefile input.wav --list-cue\n" + | ||
" Print all the cue points of the file.\n" + | ||
"\n" + | ||
" --bits Ex: wavefile input.wav --bits\n" + | ||
" Print the bit depth of the file.\n" + | ||
"\n" + | ||
" --rate Ex: wavefile input.wav --rate\n" + | ||
" Print the sample rate of the file.\n" + | ||
"\n" + | ||
" --help Ex: --help\n" + | ||
" Show this help page.\n" + | ||
"\n"; | ||
// Help | ||
if (process.argv[2] == '-h' || process.argv[2] == '--help' || process.argv.length < 4) { | ||
console.log(presentation); | ||
console.log(help); | ||
process.exit(); | ||
console.log(presentation); | ||
console.log(help); | ||
process.exit(); | ||
} | ||
@@ -71,7 +71,7 @@ | ||
for (let arg=2; arg<process.argv.length; arg++) { | ||
if (process.argv[arg].slice(0, 1) == '-') { | ||
commands.push(process.argv[arg]); | ||
} else { | ||
files.push(process.argv[arg]); | ||
} | ||
if (process.argv[arg].slice(0, 1) == '-') { | ||
commands.push(process.argv[arg]); | ||
} else { | ||
files.push(process.argv[arg]); | ||
} | ||
} | ||
@@ -88,48 +88,48 @@ | ||
for (let command in commands) { | ||
// --bitdepth | ||
let splitCommand = commands[command].split("="); | ||
if (splitCommand[0] == '--bitdepth') { | ||
wav.toBitDepth(splitCommand[1]); | ||
shouldWrite = true; | ||
// --compress | ||
} else if (splitCommand[0] == '--compress') { | ||
if (splitCommand[1] == 'adpcm') { | ||
wav.toIMAADPCM(); | ||
shouldWrite = true; | ||
} else if (splitCommand[1] == 'alaw') { | ||
wav.toALaw(); | ||
shouldWrite = true; | ||
} else if (splitCommand[1] == 'mulaw') { | ||
wav.toMuLaw(); | ||
shouldWrite = true; | ||
} | ||
// --tag | ||
}else if (splitCommand[0] == '--tag') { | ||
console.log(wav.getTag(splitCommand[1])); | ||
// --list-tag | ||
}else if (splitCommand[0] == '--list-tags') { | ||
tags = wav.listTags(); | ||
for (var tag in tags) { | ||
if (tags.hasOwnProperty(tag)) { | ||
console.log(tag + ': ' + tags[tag]); | ||
} | ||
} | ||
// --list-cue | ||
}else if (splitCommand[0] == '--list-cue') { | ||
console.log(wav.listCuePoints()); | ||
// --bits | ||
}else if (splitCommand[0] == '--bits') { | ||
if (wav.fmt.validBitsPerSample) { | ||
console.log(wav.fmt.validBitsPerSample); | ||
} else { | ||
console.log(wav.fmt.bitPerSample); | ||
} | ||
// --rate | ||
}else if (splitCommand[0] == '--rate') { | ||
console.log(wav.fmt.sampleRate); | ||
// error | ||
} else { | ||
console.log('ERROR: Bad option. Run wavefile -h to check the available options.'); | ||
process.exit(); | ||
} | ||
// --bitdepth | ||
let splitCommand = commands[command].split("="); | ||
if (splitCommand[0] == '--bitdepth') { | ||
wav.toBitDepth(splitCommand[1]); | ||
shouldWrite = true; | ||
// --compress | ||
} else if (splitCommand[0] == '--compress') { | ||
if (splitCommand[1] == 'adpcm') { | ||
wav.toIMAADPCM(); | ||
shouldWrite = true; | ||
} else if (splitCommand[1] == 'alaw') { | ||
wav.toALaw(); | ||
shouldWrite = true; | ||
} else if (splitCommand[1] == 'mulaw') { | ||
wav.toMuLaw(); | ||
shouldWrite = true; | ||
} | ||
// --tag | ||
} else if (splitCommand[0] == '--tag') { | ||
console.log(wav.getTag(splitCommand[1])); | ||
// --list-tag | ||
} else if (splitCommand[0] == '--list-tags') { | ||
tags = wav.listTags(); | ||
for (var tag in tags) { | ||
if (tags.hasOwnProperty(tag)) { | ||
console.log(tag + ': ' + tags[tag]); | ||
} | ||
} | ||
// --list-cue | ||
} else if (splitCommand[0] == '--list-cue') { | ||
console.log(wav.listCuePoints()); | ||
// --bits | ||
} else if (splitCommand[0] == '--bits') { | ||
if (wav.fmt.validBitsPerSample) { | ||
console.log(wav.fmt.validBitsPerSample); | ||
} else { | ||
console.log(wav.fmt.bitPerSample); | ||
} | ||
// --rate | ||
} else if (splitCommand[0] == '--rate') { | ||
console.log(wav.fmt.sampleRate); | ||
// error | ||
} else { | ||
console.log('ERROR: Bad option. Run wavefile -h to check the available options.'); | ||
process.exit(); | ||
} | ||
} | ||
@@ -139,7 +139,7 @@ | ||
if (shouldWrite) { | ||
if (files.length) { | ||
for (let file in files) { | ||
fs.writeFileSync(files[file], wav.toBuffer()); | ||
} | ||
} | ||
if (files.length) { | ||
for (let file in files) { | ||
fs.writeFileSync(files[file], wav.toBuffer()); | ||
} | ||
} | ||
} |
# CHANGELOG | ||
## version 8.4.2 (2018-08-06) | ||
- Use ArrayBufferView to represent TypedArray in index.d.ts | ||
- Use WaveFile.prototype in externs/wavefile.js | ||
## version 8.4.1 (2018-08-06) | ||
@@ -4,0 +8,0 @@ - Update dependencies. |
@@ -1,1 +0,64 @@ | ||
var WaveFile=function(){"use strict";const t=new Float32Array(1);function e(t,e,h,u){r(e),r(h);let o=function(t,e){let r=function(t){return t};t!=e&&(r=["32f","64"].includes(t)?["32f","64"].includes(e)?a:i:["32f","64"].includes(e)?s:n);return r}(e,h),l={oldMin:Math.pow(2,parseInt(e,10))/2,newMin:Math.pow(2,parseInt(h,10))/2,oldMax:Math.pow(2,parseInt(e,10))/2-1,newMax:Math.pow(2,parseInt(h,10))/2-1};const c=t.length;if("8"==e)for(let e=0;e<c;e++)u[e]=t[e]-=128;for(let e=0;e<c;e++)u[e]=o(t[e],l);if("8"==h)for(let t=0;t<c;t++)u[t]=u[t]+=128}function n(t,e){return t=t>0?parseInt(t/e.oldMax*e.newMax,10):parseInt(t/e.oldMin*e.newMin,10)}function i(t,e){return parseInt(t>0?t*e.newMax:t*e.newMin,10)}function s(t,e){return t>0?t/e.oldMax:t/e.oldMin}function a(e){return t[0]=e,t[0]}function r(t){if("32f"!=t&&"64"!=t&&(parseInt(t,10)<"8"||parseInt(t,10)>"53"))throw new Error("Invalid bit depth.")}const h=[-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];let o=0,l=0,c=0,d=0,f=7;function m(t){let e=function(t){k(t);let e=[];return e.push(255&t),e.push(t>>8&255),e.push(l),e.push(0),e}(t[0]);for(let n=3;n<t.length;n+=2){let i=k(t[n]),s=k(t[n+1]);e.push(s<<4|i)}for(;e.length<256;)e.push(0);return e}function p(t){c=b(t[1]<<8|t[0]),d=t[2],f=u[d];let e=[c,b(t[3]<<8|t[2])];for(let n=4;n<t.length;n++){let i=t[n],s=i>>4,a=s<<4^i;e.push(S(a)),e.push(S(s))}return e}function b(t){return t>32768?t-65536:t}function k(t){let e=t-o,n=0;e>=0?n=0:(n=8,e=-e);let i=u[l],s=i>>3;return e>i&&(n|=4,e-=i,s+=i),e>(i>>=1)&&(n|=2,e-=i,s+=i),e>(i>>=1)&&(n|=1,s+=i),function(t,e){8&t?o-=e:o+=e;o<-32768?o=-32768:o>32767&&(o=32767);(l+=h[7&t])<0?l=0:l>88&&(l=88)}(n,s),n}function S(t){let e=0;return 4&t&&(e+=f),2&t&&(e+=f>>1),1&t&&(e+=f>>2),e+=f>>3,8&t&&(e=-e),(c+=e)>32767?c=32767:c<-32767&&(c=-32767),function(t){(d+=h[t])<0?d=0:d>88&&(d=88);f=u[d]}(t),c}const g=[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];function w(t){let e,n=~(t=-32768==t?-32767:t)>>8&128;if(n||(t*=-1),t>32635&&(t=32635),t>=256){let n=g[t>>8&127];e=n<<4|t>>n+3&15}else e=t>>4;return 85^e^n}function I(t){let e=0;128&(t^=85)&&(t&=-129,e=-1);let n=4+((240&t)>>4),i=0;return i=4!=n?1<<n|(15&t)<<n-4|1<<n-5:t<<1|1,8*(i=0===e?i:-i)*-1}const _=132,C=32635,T=[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],L=[0,132,396,924,1980,4092,8316,16764];function x(t){let e,n,i,s;return 0!=(e=t>>8&128)&&(t=-t),t>C&&(t=C),s=~(e|(n=T[(t+=_)>>7&255])<<4|(i=t>>n+3&15))}function z(t){let e,n,i,s;return e=128&(t=~t),i=15&t,s=L[n=t>>4&7]+(i<<n+3),0!=e&&(s=-s),s}const y="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",P=new Uint8Array(256);for(let t=0;t<y.length;t++)P[y.charCodeAt(t)]=t;const M=function(t,e,n){const i=new Uint8Array(t,e,n),s=i.length;let a="";for(let t=0;t<s;t+=3)a+=y[i[t]>>2],a+=y[(3&i[t])<<4|i[t+1]>>4],a+=y[(15&i[t+1])<<2|i[t+2]>>6],a+=y[63&i[t+2]];return s%3==2?a=a.substring(0,a.length-1)+"=":s%3==1&&(a=a.substring(0,a.length-2)+"=="),a},D=function(t){const e=t.length;let n,i,s,a,r=.75*t.length,h=0;"="===t[t.length-1]&&(r--,"="===t[t.length-2]&&r--);const u=new ArrayBuffer(r),o=new Uint8Array(u);for(let r=0;r<e;r+=4)n=P[t.charCodeAt(r)],i=P[t.charCodeAt(r+1)],s=P[t.charCodeAt(r+2)],a=P[t.charCodeAt(r+3)],o[h++]=n<<2|i>>4,o[h++]=(15&i)<<4|s>>2,o[h++]=(3&s)<<6|63&a;return u};function A(t,e,n){e--;for(let i=0;i<e;i++){let s=t[n+i];t[n+i]=t[n+e],t[n+e]=s,e--}}function v(t,e,n=0){for(let i=0,s=t.length;i<s;i++){let s=t.codePointAt(i);if(s<128)e[n]=s,n++;else{let t=0,a=0;for(s<=2047?(t=1,a=192):s<=65535?(t=2,a=224):s<=1114111&&(t=3,a=240,i++),e[n]=(s>>6*t)+a,n++;t>0;)e[n]=128|s>>6*(t-1)&63,n++,t--}}return n}const F="Unsupported type";function R(t){B(t),t==t&&t!==1/0&&t!==-1/0||E("integer")}function B(t){null==t&&E(),t.constructor!=Number&&t.constructor!=Boolean&&E()}function E(t="valid number"){throw new Error("Argument is not a "+t)}class N{constructor(t,e){this.ebits=t,this.fbits=e,this.bias=(1<<t-1)-1,this.numBytes=Math.ceil((t+e)/8),this.biasP2=Math.pow(2,this.bias+1),this.ebitsFbits=t+e,this.fbias=Math.pow(2,-(8*this.numBytes-1-t))}pack(t,e,n){Math.abs(e)>this.biasP2-2*this.ebitsFbits&&(e=e<0?-1/0:1/0);let i=((e=+e)||1/e)<0?1:e<0?1:0;e=Math.abs(e);let s=Math.min(Math.floor(Math.log(e)/Math.LN2),1023),a=this.roundToEven(e/Math.pow(2,s)*Math.pow(2,this.fbits));return e!=e?(a=Math.pow(2,this.fbits-1),s=(1<<this.ebits)-1):0!==e&&(e>=Math.pow(2,1-this.bias)?(a/Math.pow(2,this.fbits)>=2&&(s+=1,a=1),s>this.bias?(s=(1<<this.ebits)-1,a=0):(s+=this.bias,a=this.roundToEven(a)-Math.pow(2,this.fbits))):(a=this.roundToEven(e/Math.pow(2,1-this.bias-this.fbits)),s=0)),this.packFloatBits_(t,n,i,s,a)}unpack(t,e){let n,i=(1<<this.ebits)-1,s="";for(let n=this.numBytes-1;n>=0;n--){let i=t[n+e].toString(2);s+="00000000".substring(i.length)+i}let a="1"==s.charAt(0)?-1:1;s=s.substring(1);let r=parseInt(s.substring(0,this.ebits),2);return s=s.substring(this.ebits),r==i?0!==parseInt(s,2)?NaN:a*(1/0):(0===r?(r+=1,n=parseInt(s,2)):n=parseInt("1"+s,2),a*n*this.fbias*Math.pow(2,r-this.bias))}packFloatBits_(t,e,n,i,s){let a=[];a.push(n);for(let t=this.ebits;t>0;t-=1)a[t]=i%2?1:0,i=Math.floor(i/2);let r=a.length;for(let t=this.fbits;t>0;t-=1)a[r+t]=s%2?1:0,s=Math.floor(s/2);let h=a.join(""),u=this.numBytes+e-1,o=e;for(;u>=e;)t[u]=parseInt(h.substring(0,8),2),h=h.substring(8),u--,o++;return o}roundToEven(t){var e=Math.floor(t),n=t-e;return n<.5?e:n>.5?e+1:e%2?e+1:e}}class U{constructor(t){this.bits=t,this.bytes=t<8?1:Math.ceil(t/8),this.max=Math.pow(2,t)-1,this.min=0;let e=8-(1+(t-1|7)-t);this.lastByteMask_=Math.pow(2,e>0?e:8)-1}pack(t,e,n=0){if(e!=e)throw new Error("NaN");this.overflow(e),t[n]=255&(e<0?e+Math.pow(2,this.bits):e),n++;let i=this.bytes;for(let s=2;s<i;s++)t[n]=255&Math.floor(e/Math.pow(2,8*(s-1))),n++;return this.bits>8&&(t[n]=Math.floor(e/Math.pow(2,8*(this.bytes-1)))&this.lastByteMask_,n++),n}unpack(t,e=0){let n=this.unpackUnsafe(t,e);return this.overflow(n),n}unpackUnsafe(t,e){let n=0;for(let i=0;i<this.bytes;i++)n+=t[e+i]*Math.pow(256,i);return n}overflow(t){if(t>this.max||t<this.min)throw new Error("Overflow")}}class O extends U{constructor(t){super(t),this.max=Math.pow(2,this.bits)/2-1,this.min=-this.max-1}pack(t,e,n=0){return super.pack(t,e,n)}unpack(t,e=0){let n=super.unpackUnsafe(t,e);return n=this.sign_(n),this.overflow(n),n}sign_(t){return t>this.max&&(t-=2*this.max+2),t}}class H{constructor(t,e,n){this.parser=null,e?(!function(t){if(!t||16!==t&&32!==t&&64!==t)throw new Error(F+": float, bits: "+t)}(t),this.parser=this.getFPParser_(t)):(!function(t){if(!t||t<1||t>53)throw new Error(F+": int, bits: "+t)}(t),this.parser=n?new O(t):new U(t),this.parser.bytes=8===this.parser.bytes?4:this.parser.bytes)}unpack(t,e=0){return this.parser.unpack(t,e)}pack(t,e,n=0){return this.parser.pack(t,e,n)}getFPParser_(t){return 16===t?new N(5,11):32===t?new N(8,23):new N(11,52)}}function j(t,e=0,n=t.length){return function(t,e=0,n=t.length){let i="";for(let s=e;s<n;){let e=128,n=191,a=!1,r=t[s++];if(r>=0&&r<=127)i+=String.fromCharCode(r);else{let h=0;r>=194&&r<=223?h=1:r>=224&&r<=239?(h=2,224===t[s]&&(e=160),237===t[s]&&(n=159)):r>=240&&r<=244?(h=3,240===t[s]&&(e=144),244===t[s]&&(n=143)):a=!0,r&=(1<<8-h-1)-1;for(let i=0;i<h;i++)(t[s]<e||t[s]>n)&&(a=!0),r=r<<6|63&t[s],s++;a?i+=String.fromCharCode(65533):r<=65535?i+=String.fromCharCode(r):(r-=65536,i+=String.fromCharCode(55296+(r>>10&1023),56320+(1023&r)))}}return i}(t,e,n)}function G(t){let e=[];return v(t,e,0),e}function X(t,e,n=0){return v(t,e,n)}function V(t,e){let n=[];return W(t,e,n),n}function W(t,e,n,i=0){return Z([t],e,n,i)}function Z(t,e,n,i=0){let s=new H((e=e||{}).bits,e.fp,e.signed),a=Y(e.bits),r=e.fp?B:R,h=0;try{for(let u=t.length;h<u;h++){r(t[h]);let u=i+a;for(;i<u;)i=s.pack(n,t[h],i);Q(e.be,n,a,i-a,i)}}catch(t){throw new Error(t.message+" at input index "+h)}return i}function q(t,e,n=0){return J(t,e,n,n+Y(e.bits),!0)[0]}function J(t,e,n=0,i=t.length,s=!1){let a=[];return K(t,e,a,n,i,s),a}function K(t,e,n,i=0,s=t.length,a=!1){let r=new H((e=e||{}).bits,e.fp,e.signed),h=Y(e.bits),u=(s-i)%h;if(a&&(u||t.length<h))throw new Error("Bad buffer length");s-=u;let o=0;try{Q(e.be,t,h,i,s);for(let e=i;e<s;e+=h,o++)n[o]=r.unpack(t,e);Q(e.be,t,h,i,s)}catch(t){throw new Error(t.message+" at output index "+o)}}function Q(t,e,n,i,s){t&&function(t,e,n=0,i=t.length){if(i%e)throw new Error("Bad buffer length.");for(let s=n;s<i;s+=e)A(t,e,s)}(e,n,i,s)}function Y(t){return t<8?1:Math.ceil(t/8)}var $={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};function tt(t,e,n,i,s,a){let r={};return r="4"==t?function(t,e,n,i,s,a){let r=et(t,e,n,i,s,a);return r.chunkSize=40+s,r.fmt.chunkSize=20,r.fmt.byteRate=4055,r.fmt.blockAlign=256,r.fmt.bitsPerSample=4,r.fmt.cbSize=2,r.fmt.validBitsPerSample=505,r.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*s},r}(t,e,n,i,s,a):"8a"==t||"8m"==t?function(t,e,n,i,s,a){let r=et(t,e,n,i,s,a);return r.chunkSize=40+s,r.fmt.chunkSize=20,r.fmt.cbSize=2,r.fmt.validBitsPerSample=8,r.fact={chunkId:"fact",chunkSize:4,dwSampleLength:s},r}(t,e,n,i,s,a):-1==Object.keys($).indexOf(t)||e>2?function(t,e,n,i,s,a){let r=et(t,e,n,i,s,a);return r.chunkSize=60+s,r.fmt.chunkSize=40,r.fmt.bitsPerSample=1+(parseInt(t,10)-1|7),r.fmt.cbSize=22,r.fmt.validBitsPerSample=parseInt(t,10),r.fmt.dwChannelMask=function(t){let e=0;return 1===t?e=4:2===t?e=3:4===t?e=51:6===t?e=63:8===t&&(e=1599),e}(e),r.fmt.subformat=[1,1048576,2852126848,1905997824],r}(t,e,n,i,s,a):et(t,e,n,i,s,a)}function et(t,e,n,i,s,a){return{container:a.container,chunkSize:36+s,format:"WAVE",bitDepth:t,fmt:{chunkId:"fmt ",chunkSize:16,audioFormat:$[t]||65534,numChannels:e,sampleRate:n,byteRate:e*i*n,blockAlign:e*i,bitsPerSample:parseInt(t,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}}}function nt(t){!function(t){if(!$[t.bitDepth]){if(parseInt(t.bitDepth,10)>8&&parseInt(t.bitDepth,10)<54)return!0;throw new Error("Invalid bit depth.")}}(t),function(t){let e=t.fmt.numChannels*t.fmt.bitsPerSample/8;if(t.fmt.numChannels<1||e>65535)throw new Error("Invalid number of channels.")}(t),function(t){let e=t.fmt.numChannels*(t.fmt.bitsPerSample/8)*t.fmt.sampleRate;if(t.fmt.sampleRate<1||e>4294967295)throw new Error("Invalid sample rate.")}(t)}class it{constructor(){this.head_=0}writeString_(t,e,n=!0){let i=G(t);if(n)for(let t=i.length;t<e;t++)i.push(0);return i}readZSTR_(t,e=0){let n="";for(let i=e;i<t.length&&(this.head_++,0!==t[i]);i++)n+=j(t,i,i+1);return n}readString_(t,e){let n="";return n=j(t,this.head_,this.head_+e),this.head_+=e,n}read_(t,e){let n=e.bits/8,i=q(t,e,this.head_);return this.head_+=n,i}}let st=new it;function at(t){let e={bits:32,be:!1},n={bits:16,be:!1};n.be="RIFX"===t.container,e.be=n.be;let i=[function(t,e){let n=[];if(t.junk.chunkId)return n.concat(G(t.junk.chunkId),V(t.junk.chunkData.length,e),t.junk.chunkData);return n}(t,e),function(t,e){let n=[];t.ds64.chunkId&&(n=n.concat(G(t.ds64.chunkId),V(t.ds64.chunkSize,e),V(t.ds64.riffSizeHigh,e),V(t.ds64.riffSizeLow,e),V(t.ds64.dataSizeHigh,e),V(t.ds64.dataSizeLow,e),V(t.ds64.originationTime,e),V(t.ds64.sampleCountHigh,e),V(t.ds64.sampleCountLow,e)));return n}(t,e),function(t,e,n){let i=[];(function(t){for(var e in t.bext)if(t.bext.hasOwnProperty(e)&&t.bext[e]&&"timeReference"!=e){t.bext.chunkId="bext";break}(t.bext.timeReference[0]||t.bext.timeReference[1])&&(t.bext.chunkId="bext")})(t),t.bext.chunkId&&(t.bext.chunkSize=602+t.bext.codingHistory.length,i=i.concat(G(t.bext.chunkId),V(602+t.bext.codingHistory.length,e),st.writeString_(t.bext.description,256),st.writeString_(t.bext.originator,32),st.writeString_(t.bext.originatorReference,32),st.writeString_(t.bext.originationDate,10),st.writeString_(t.bext.originationTime,8),V(t.bext.timeReference[0],e),V(t.bext.timeReference[1],e),V(t.bext.version,n),st.writeString_(t.bext.UMID,64),V(t.bext.loudnessValue,n),V(t.bext.loudnessRange,n),V(t.bext.maxTruePeakLevel,n),V(t.bext.maxMomentaryLoudness,n),V(t.bext.maxShortTermLoudness,n),st.writeString_(t.bext.reserved,180),st.writeString_(t.bext.codingHistory,t.bext.codingHistory.length)));return i}(t,e,n),function(t,e,n){let i=[];if(t.fmt.chunkId)return i.concat(G(t.fmt.chunkId),V(t.fmt.chunkSize,e),V(t.fmt.audioFormat,n),V(t.fmt.numChannels,n),V(t.fmt.sampleRate,e),V(t.fmt.byteRate,e),V(t.fmt.blockAlign,n),V(t.fmt.bitsPerSample,n),function(t,e,n){let i=[];t.fmt.chunkSize>16&&(i=i.concat(V(t.fmt.cbSize,n)));t.fmt.chunkSize>18&&(i=i.concat(V(t.fmt.validBitsPerSample,n)));t.fmt.chunkSize>20&&(i=i.concat(V(t.fmt.dwChannelMask,e)));t.fmt.chunkSize>24&&(i=i.concat(V(t.fmt.subformat[0],e),V(t.fmt.subformat[1],e),V(t.fmt.subformat[2],e),V(t.fmt.subformat[3],e)));return i}(t,e,n));throw Error('Could not find the "fmt " chunk')}(t,e,n),function(t,e){let n=[];t.fact.chunkId&&(n=n.concat(G(t.fact.chunkId),V(t.fact.chunkSize,e),V(t.fact.dwSampleLength,e)));return n}(t,e),G(t.data.chunkId),V(t.data.samples.length,e),t.data.samples,function(t,e){let n=[];if(t.cue.chunkId){let i=function(t,e){let n=[];for(let i=0;i<t.cue.dwCuePoints;i++)n=n.concat(V(t.cue.points[i].dwName,e),V(t.cue.points[i].dwPosition,e),G(t.cue.points[i].fccChunk),V(t.cue.points[i].dwChunkStart,e),V(t.cue.points[i].dwBlockStart,e),V(t.cue.points[i].dwSampleOffset,e));return n}(t,e);n=n.concat(G(t.cue.chunkId),V(i.length+4,e),V(t.cue.dwCuePoints,e),i)}return n}(t,e),function(t,e){let n=[];if(t.smpl.chunkId){let i=function(t,e){let n=[];for(let i=0;i<t.smpl.dwNumSampleLoops;i++)n=n.concat(V(t.smpl.loops[i].dwName,e),V(t.smpl.loops[i].dwType,e),V(t.smpl.loops[i].dwStart,e),V(t.smpl.loops[i].dwEnd,e),V(t.smpl.loops[i].dwFraction,e),V(t.smpl.loops[i].dwPlayCount,e));return n}(t,e);n=n.concat(G(t.smpl.chunkId),V(i.length+36,e),V(t.smpl.dwManufacturer,e),V(t.smpl.dwProduct,e),V(t.smpl.dwSamplePeriod,e),V(t.smpl.dwMIDIUnityNote,e),V(t.smpl.dwMIDIPitchFraction,e),V(t.smpl.dwSMPTEFormat,e),V(t.smpl.dwSMPTEOffset,e),V(t.smpl.dwNumSampleLoops,e),V(t.smpl.dwSamplerData,e),i)}return n}(t,e),function(t,e,n){let i=[];for(let s=0;s<t.LIST.length;s++){let a=rt(t.LIST[s].subChunks,t.LIST[s].format,t,e,n);i=i.concat(G(t.LIST[s].chunkId),V(a.length+4,e),G(t.LIST[s].format),a)}return i}(t,e,n)],s=0;for(let t=0;t<i.length;t++)s+=i[t].length;let a=new Uint8Array(s+12),r=0;r=W(s+4,e,a,r=X(t.container,a,r)),r=X(t.format,a,r);for(let t=0;t<i.length;t++)a.set(i[t],r),r+=i[t].length;return a}function rt(t,e,n,i,s){let a=[];for(let r=0;r<t.length;r++)"INFO"==e?(a=a.concat(G(t[r].chunkId),V(t[r].value.length+1,i),st.writeString_(t[r].value,t[r].value.length))).push(0):"adtl"==e&&(["labl","note"].indexOf(t[r].chunkId)>-1?(a=a.concat(G(t[r].chunkId),V(t[r].value.length+4+1,i),V(t[r].dwName,i),st.writeString_(t[r].value,t[r].value.length))).push(0):"ltxt"==t[r].chunkId&&(a=a.concat(ht(t[r],n,i,s)))),a.length%2&&a.push(0);return a}function ht(t,e,n,i){return[].concat(G(t.chunkId),V(t.value.length+20,n),V(t.dwName,n),V(t.dwSampleLength,n),V(t.dwPurposeID,n),V(t.dwCountry,i),V(t.dwLanguage,i),V(t.dwDialect,i),V(t.dwCodePage,i),st.writeString_(t.value,t.value.length))}const ut={bits:32};let ot=0;function lt(t){ot=0;let e=mt(t,0);ut.be="RIFX"==e;let n=j(t,8,12);return ot+=4,{chunkId:e,chunkSize:pt(t,0),format:n,subChunks:dt(t)}}function ct(t,e,n=!1){let i=[];for(let s=0;s<t.length;s++)if(t[s].chunkId==e){if(!n)return t[s];i.push(t[s])}return"LIST"==e&&i.length?i:null}function dt(t){let e=[],n=ot;for(;n<=t.length-8;)e.push(ft(t,n)),n=(n+=8+e[e.length-1].chunkSize)%2?n+1:n;return e}function ft(t,e){let n={chunkId:mt(t,e),chunkSize:pt(t,e)};if("LIST"==n.chunkId)n.format=j(t,e+8,e+12),ot+=4,n.subChunks=dt(t);else{let t=n.chunkSize%2?n.chunkSize+1:n.chunkSize;ot=e+8+t,n.chunkData={start:e+8,end:ot}}return n}function mt(t,e){return ot+=4,j(t,e,e+4)}function pt(t,e){return ot+=4,q(t,ut,e+4)}let bt=new it;function kt(t,e,n){bt.head_=0;let i={bits:32,be:!1},s={bits:16,be:!1};!function(t,e,n,i){if(bt.head_=0,e.container=bt.readString_(t,4),-1===["RIFF","RIFX","RF64"].indexOf(e.container))throw Error("Not a supported format.");if(i.be="RIFX"===e.container,n.be=i.be,e.chunkSize=bt.read_(t,n),e.format=bt.readString_(t,4),"WAVE"!=e.format)throw Error('Could not find the "WAVE" format identifier')}(t,n,i,s);let a=lt(t);!function(t,e,n,i){let s=ct(e,"ds64");if(s)bt.head_=s.chunkData.start,n.ds64.chunkId=s.chunkId,n.ds64.chunkSize=s.chunkSize,n.ds64.riffSizeHigh=bt.read_(t,i),n.ds64.riffSizeLow=bt.read_(t,i),n.ds64.dataSizeHigh=bt.read_(t,i),n.ds64.dataSizeLow=bt.read_(t,i),n.ds64.originationTime=bt.read_(t,i),n.ds64.sampleCountHigh=bt.read_(t,i),n.ds64.sampleCountLow=bt.read_(t,i);else if("RF64"==n.container)throw Error('Could not find the "ds64" chunk')}(t,a.subChunks,n,i),function(t,e,n,i,s){let a=ct(e,"fmt ");if(!a)throw Error('Could not find the "fmt " chunk');bt.head_=a.chunkData.start,n.fmt.chunkId=a.chunkId,n.fmt.chunkSize=a.chunkSize,n.fmt.audioFormat=bt.read_(t,s),n.fmt.numChannels=bt.read_(t,s),n.fmt.sampleRate=bt.read_(t,i),n.fmt.byteRate=bt.read_(t,i),n.fmt.blockAlign=bt.read_(t,s),n.fmt.bitsPerSample=bt.read_(t,s),function(t,e,n,i){e.fmt.chunkSize>16&&(e.fmt.cbSize=bt.read_(t,i),e.fmt.chunkSize>18&&(e.fmt.validBitsPerSample=bt.read_(t,i),e.fmt.chunkSize>20&&(e.fmt.dwChannelMask=bt.read_(t,n),e.fmt.subformat=[bt.read_(t,n),bt.read_(t,n),bt.read_(t,n),bt.read_(t,n)])))}(t,n,i,s)}(t,a.subChunks,n,i,s),function(t,e,n,i){let s=ct(e,"fact");s&&(bt.head_=s.chunkData.start,n.fact.chunkId=s.chunkId,n.fact.chunkSize=s.chunkSize,n.fact.dwSampleLength=bt.read_(t,i))}(t,a.subChunks,n,i),function(t,e,n,i,s){let a=ct(e,"bext");a&&(bt.head_=a.chunkData.start,n.bext.chunkId=a.chunkId,n.bext.chunkSize=a.chunkSize,n.bext.description=bt.readString_(t,256),n.bext.originator=bt.readString_(t,32),n.bext.originatorReference=bt.readString_(t,32),n.bext.originationDate=bt.readString_(t,10),n.bext.originationTime=bt.readString_(t,8),n.bext.timeReference=[bt.read_(t,i),bt.read_(t,i)],n.bext.version=bt.read_(t,s),n.bext.UMID=bt.readString_(t,64),n.bext.loudnessValue=bt.read_(t,s),n.bext.loudnessRange=bt.read_(t,s),n.bext.maxTruePeakLevel=bt.read_(t,s),n.bext.maxMomentaryLoudness=bt.read_(t,s),n.bext.maxShortTermLoudness=bt.read_(t,s),n.bext.reserved=bt.readString_(t,180),n.bext.codingHistory=bt.readString_(t,n.bext.chunkSize-602))}(t,a.subChunks,n,i,s),function(t,e,n,i){let s=ct(e,"cue ");if(s){bt.head_=s.chunkData.start,n.cue.chunkId=s.chunkId,n.cue.chunkSize=s.chunkSize,n.cue.dwCuePoints=bt.read_(t,i);for(let e=0;e<n.cue.dwCuePoints;e++)n.cue.points.push({dwName:bt.read_(t,i),dwPosition:bt.read_(t,i),fccChunk:bt.readString_(t,4),dwChunkStart:bt.read_(t,i),dwBlockStart:bt.read_(t,i),dwSampleOffset:bt.read_(t,i)})}}(t,a.subChunks,n,i),function(t,e,n,i){let s=ct(e,"smpl");if(s){bt.head_=s.chunkData.start,n.smpl.chunkId=s.chunkId,n.smpl.chunkSize=s.chunkSize,n.smpl.dwManufacturer=bt.read_(t,i),n.smpl.dwProduct=bt.read_(t,i),n.smpl.dwSamplePeriod=bt.read_(t,i),n.smpl.dwMIDIUnityNote=bt.read_(t,i),n.smpl.dwMIDIPitchFraction=bt.read_(t,i),n.smpl.dwSMPTEFormat=bt.read_(t,i),n.smpl.dwSMPTEOffset=bt.read_(t,i),n.smpl.dwNumSampleLoops=bt.read_(t,i),n.smpl.dwSamplerData=bt.read_(t,i);for(let e=0;e<n.smpl.dwNumSampleLoops;e++)n.smpl.loops.push({dwName:bt.read_(t,i),dwType:bt.read_(t,i),dwStart:bt.read_(t,i),dwEnd:bt.read_(t,i),dwFraction:bt.read_(t,i),dwPlayCount:bt.read_(t,i)})}}(t,a.subChunks,n,i),function(t,e,n,i){let s=ct(e,"data");if(!s)throw Error('Could not find the "data" chunk');i.data.chunkId="data",i.data.chunkSize=s.chunkSize,n&&(i.data.samples=t.slice(s.chunkData.start,s.chunkData.end))}(t,a.subChunks,e,n),function(t,e,n){let i=ct(e,"junk");i&&(n.junk={chunkId:i.chunkId,chunkSize:i.chunkSize,chunkData:[].slice.call(t.slice(i.chunkData.start,i.chunkData.end))})}(t,a.subChunks,n),function(t,e,n,i,s){let a=ct(e,"LIST",!0);if(null===a)return;for(let e=0;e<a.length;e++){let r=a[e];n.LIST.push({chunkId:r.chunkId,chunkSize:r.chunkSize,format:r.format,subChunks:[]});for(let e=0;e<r.subChunks.length;e++)St(r.subChunks[e],r.format,t,n,i,s)}}(t,a.subChunks,n,i,s)}function St(t,e,n,i,s,a){if("adtl"==e){if(["labl","note","ltxt"].indexOf(t.chunkId)>-1){bt.head_=t.chunkData.start;let e={chunkId:t.chunkId,chunkSize:t.chunkSize,dwName:bt.read_(n,s)};"ltxt"==t.chunkId&&(e.dwSampleLength=bt.read_(n,s),e.dwPurposeID=bt.read_(n,s),e.dwCountry=bt.read_(n,a),e.dwLanguage=bt.read_(n,a),e.dwDialect=bt.read_(n,a),e.dwCodePage=bt.read_(n,a)),e.value=bt.readZSTR_(n,bt.head_),i.LIST[i.LIST.length-1].subChunks.push(e)}}else"INFO"==e&&(bt.head_=t.chunkData.start,i.LIST[i.LIST.length-1].subChunks.push({chunkId:t.chunkId,chunkSize:t.chunkSize,value:bt.readZSTR_(n,bt.head_)}))}class gt{constructor(){this.container="",this.chunkSize=0,this.format="",this.fmt={chunkId:"",chunkSize:0,audioFormat:0,numChannels:0,sampleRate:0,byteRate:0,blockAlign:0,bitsPerSample:0,cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]},this.fact={chunkId:"",chunkSize:0,dwSampleLength:0},this.cue={chunkId:"",chunkSize:0,dwCuePoints:0,points:[]},this.smpl={chunkId:"",chunkSize:0,dwManufacturer:0,dwProduct:0,dwSamplePeriod:0,dwMIDIUnityNote:0,dwMIDIPitchFraction:0,dwSMPTEFormat:0,dwSMPTEOffset:0,dwNumSampleLoops:0,dwSamplerData:0,loops:[]},this.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:""},this.ds64={chunkId:"",chunkSize:0,riffSizeHigh:0,riffSizeLow:0,dataSizeHigh:0,dataSizeLow:0,originationTime:0,sampleCountHigh:0,sampleCountLow:0},this.data={chunkId:"",chunkSize:0,samples:new Uint8Array(0)},this.LIST=[],this.junk={chunkId:"",chunkSize:0,chunkData:[]}}}return class extends gt{constructor(t=null){super(),this.bitDepth="0",this.dataType={},t&&this.fromBuffer(t)}getSample(t){if((t*=this.dataType.bits/8)+this.dataType.bits/8>this.data.samples.length)throw new Error("Range error");return q(this.data.samples.slice(t,t+this.dataType.bits/8),this.dataType)}setSample(t,e){if((t*=this.dataType.bits/8)+this.dataType.bits/8>this.data.samples.length)throw new Error("Range error");W(e,this.dataType,this.data.samples,t)}fromScratch(t,e,n,i,s={}){s.container||(s.container="RIFF"),this.container=s.container,this.bitDepth=n,i=this.interleave_(i),this.updateDataType_();let a=this.dataType.bits/8;this.data.samples=new Uint8Array(i.length*a),Z(i,this.dataType,this.data.samples);let r=tt(n,t,e,a,this.data.samples.length,s);this.clearHeader_(),this.chunkSize=r.chunkSize,this.format=r.format,this.fmt=r.fmt,r.fact&&(this.fact=r.fact),this.data.chunkId="data",this.data.chunkSize=this.data.samples.length,nt(this)}fromBuffer(t,e=!0){this.clearHeader_(),kt(t,e,this),this.bitDepthFromFmt_(),this.updateDataType_()}toBuffer(){return nt(this),at(this)}fromBase64(t){this.fromBuffer(new Uint8Array(D(t)))}toBase64(){let t=this.toBuffer();return M(t,0,t.length)}toDataURI(){return"data:audio/wav;base64,"+this.toBase64()}fromDataURI(t){this.fromBase64(t.replace("data:audio/wav;base64,",""))}toRIFF(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,J(this.data.samples,this.dataType))}toRIFX(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,J(this.data.samples,this.dataType),{container:"RIFX"})}toBitDepth(t,n=!0){let i=t,s=this.bitDepth;n||("32f"!=t&&(i=this.dataType.bits.toString()),s=this.dataType.bits),this.assureUncompressed_();let a=this.data.samples.length/(this.dataType.bits/8),r=new Float64Array(a+1),h=new Float64Array(a+1);K(this.data.samples,this.dataType,r),"32f"!=s&&"64"!=s||this.truncateSamples_(r),e(r,s,i,h),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,t,h,{container:this.correctContainer_()})}toIMAADPCM(){if(8e3!==this.fmt.sampleRate)throw new Error("Only 8000 Hz files can be compressed as IMA-ADPCM.");if(1!==this.fmt.numChannels)throw new Error("Only mono files can be compressed as IMA-ADPCM.");{this.assure16Bit_();let t=new Int16Array(this.data.samples.length/2);K(this.data.samples,this.dataType,t),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"4",function(t){let e=new Uint8Array(t.length/2+512),n=[],i=0;for(let s=0;s<t.length;s++)s%505==0&&0!=s&&(e.set(m(n),i),i+=256,n=[]),n.push(t[s]);return e}(t),{container:this.correctContainer_()})}}fromIMAADPCM(t="16"){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(t,e=256){let n=new Int16Array(2*t.length),i=[],s=0;for(let a=0;a<t.length;a++)a%e==0&&0!=a&&(n.set(p(i),s),s+=2*e,i=[]),i.push(t[a]);return n}(this.data.samples,this.fmt.blockAlign),{container:this.correctContainer_()}),"16"!=t&&this.toBitDepth(t)}toALaw(){this.assure16Bit_();let t=new Int16Array(this.data.samples.length/2);K(this.data.samples,this.dataType,t),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8a",function(t){let e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=w(t[n]);return e}(t),{container:this.correctContainer_()})}fromALaw(t="16"){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(t){let e=new Int16Array(t.length);for(let n=0;n<t.length;n++)e[n]=I(t[n]);return e}(this.data.samples),{container:this.correctContainer_()}),"16"!=t&&this.toBitDepth(t)}toMuLaw(){this.assure16Bit_();let t=new Int16Array(this.data.samples.length/2);K(this.data.samples,this.dataType,t),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8m",function(t){let e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=x(t[n]);return e}(t),{container:this.correctContainer_()})}fromMuLaw(t="16"){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(t){let e=new Int16Array(t.length);for(let n=0;n<t.length;n++)e[n]=z(t[n]);return e}(this.data.samples),{container:this.correctContainer_()}),"16"!=t&&this.toBitDepth(t)}setTag(t,e){t=this.fixTagName_(t);let n=this.getTagIndex_(t);null!==n.TAG?(this.LIST[n.LIST].subChunks[n.TAG].chunkSize=e.length+1,this.LIST[n.LIST].subChunks[n.TAG].value=e):null!==n.LIST?this.LIST[n.LIST].subChunks.push({chunkId:t,chunkSize:e.length+1,value:e}):(this.LIST.push({chunkId:"LIST",chunkSize:8+e.length+1,format:"INFO",subChunks:[]}),this.LIST[this.LIST.length-1].subChunks.push({chunkId:t,chunkSize:e.length+1,value:e}))}getTag(t){let e=this.getTagIndex_(t);return null!==e.TAG?this.LIST[e.LIST].subChunks[e.TAG].value:null}listTags(){let t=this.getLISTINFOIndex_(),e={};if(null!==t)for(let n=0,i=this.LIST[t].subChunks.length;n<i;n++)e[this.LIST[t].subChunks[n].chunkId]=this.LIST[t].subChunks[n].value;return e}deleteTag(t){let e=this.getTagIndex_(t);return null!==e.TAG&&(this.LIST[e.LIST].subChunks.splice(e.TAG,1),!0)}setCuePoint(t,e=""){this.cue.chunkId="cue ",t=t*this.fmt.sampleRate/1e3;let n=this.getCuePoints_();this.clearLISTadtl_();let i=this.cue.points.length;this.cue.points=[];let s=!1;if(0===i)this.setCuePoint_(t,1,e);else{for(let a=0;a<i;a++)n[a].dwPosition>t&&!s?(this.setCuePoint_(t,a+1,e),this.setCuePoint_(n[a].dwPosition,a+2,n[a].label),s=!0):this.setCuePoint_(n[a].dwPosition,a+1,n[a].label);s||this.setCuePoint_(t,this.cue.points.length+1,e)}this.cue.dwCuePoints=this.cue.points.length}deleteCuePoint(t){this.cue.chunkId="cue ";let e=this.getCuePoints_();this.clearLISTadtl_();let n=this.cue.points.length;this.cue.points=[];for(let i=0;i<n;i++)i+1!==t&&this.setCuePoint_(e[i].dwPosition,i+1,e[i].label);this.cue.dwCuePoints=this.cue.points.length,this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.clearLISTadtl_())}listCuePoints(){let t=this.getCuePoints_();for(let e=0,n=t.length;e<n;e++)t[e].milliseconds=t[e].dwPosition/this.fmt.sampleRate*1e3;return t}updateLabel(t,e){let n=this.getAdtlChunk_();if(null!==n)for(let i=0,s=this.LIST[n].subChunks.length;i<s;i++)this.LIST[n].subChunks[i].dwName==t&&(this.LIST[n].subChunks[i].value=e)}bitDepthFromFmt_(){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()}setCuePoint_(t,e,n){this.cue.points.push({dwName:e,dwPosition:t,fccChunk:"data",dwChunkStart:0,dwBlockStart:0,dwSampleOffset:t}),this.setLabl_(e,n)}getCuePoints_(){let t=[];for(let e=0,n=this.cue.points.length;e<n;e++)t.push({dwPosition:this.cue.points[e].dwPosition,label:this.getLabelForCuePoint_(this.cue.points[e].dwName)});return t}getLabelForCuePoint_(t){let e=this.getAdtlChunk_();if(null!==e)for(let n=0,i=this.LIST[e].subChunks.length;n<i;n++)if(this.LIST[e].subChunks[n].dwName==t)return this.LIST[e].subChunks[n].value;return""}clearLISTadtl_(){for(let t=0,e=this.LIST.length;t<e;t++)"adtl"==this.LIST[t].format&&this.LIST.splice(t)}setLabl_(t,e){let n=this.getAdtlChunk_();null===n&&(this.LIST.push({chunkId:"LIST",chunkSize:4,format:"adtl",subChunks:[]}),n=this.LIST.length-1),this.setLabelText_(null===n?0:n,t,e)}setLabelText_(t,e,n){this.LIST[t].subChunks.push({chunkId:"labl",chunkSize:n.length,dwName:e,value:n}),this.LIST[t].chunkSize+=n.length+4+4+4+1}getAdtlChunk_(){for(let t=0,e=this.LIST.length;t<e;t++)if("adtl"==this.LIST[t].format)return t;return null}getLISTINFOIndex_(){let t=null;for(let e=0,n=this.LIST.length;e<n;e++)if("INFO"===this.LIST[e].format){t=e;break}return t}getTagIndex_(t){let e={LIST:null,TAG:null};for(let n=0,i=this.LIST.length;n<i;n++)if("INFO"==this.LIST[n].format){e.LIST=n;for(let i=0,s=this.LIST[n].subChunks.length;i<s;i++)if(this.LIST[n].subChunks[i].chunkId==t){e.TAG=i;break}break}return e}fixTagName_(t){if(t.constructor!==String)throw new Error("Invalid tag name.");if(t.length<4)for(let e=0,n=4-t.length;e<n;e++)t+=" ";return t}clearHeader_(){this.fmt.cbSize=0,this.fmt.validBitsPerSample=0,this.fact.chunkId="",this.ds64.chunkId=""}assure16Bit_(){this.assureUncompressed_(),"16"!=this.bitDepth&&this.toBitDepth("16")}assureUncompressed_(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()}interleave_(t){if(t.length>0&&t[0].constructor===Array){let e=[];for(let n=0,i=t[0].length;n<i;n++)for(let i=0,s=t.length;i<s;i++)e.push(t[i][n]);t=e}return t}updateDataType_(){this.dataType={bits:1+(parseInt(this.bitDepth,10)-1|7),fp:"32f"==this.bitDepth||"64"==this.bitDepth,signed:"8"!=this.bitDepth,be:"RIFX"==this.container},["4","8a","8m"].indexOf(this.bitDepth)>-1&&(this.dataType.bits=8,this.dataType.signed=!1)}correctContainer_(){return"RF64"==this.container?"RIFF":this.container}truncateSamples_(t){for(let e=0,n=t.length;e<n;e++)t[e]>1?t[e]=1:t[e]<-1&&(t[e]=-1)}}}();window.WaveFile=WaveFile; | ||
var na="function"==typeof Object.create?Object.create:function(e){function m(){}m.prototype=e;return new m},N;if("function"==typeof Object.setPrototypeOf)N=Object.setPrototypeOf;else{var O;a:{var oa={K:!0},P={};try{P.__proto__=oa;O=P.K;break a}catch(e){}O=!1}N=O?function(e,m){e.__proto__=m;if(e.__proto__!==m)throw new TypeError(e+" is not extensible");return e}:null}var X=N; | ||
function Y(e,m){e.prototype=na(m.prototype);e.prototype.constructor=e;if(X)X(e,m);else for(var l in m)if("prototype"!=l)if(Object.defineProperties){var n=Object.getOwnPropertyDescriptor(m,l);n&&Object.defineProperty(e,l,n)}else e[l]=m[l];e.O=m.prototype}var pa="function"==typeof Object.defineProperties?Object.defineProperty:function(e,m,l){e!=Array.prototype&&e!=Object.prototype&&(e[m]=l.value)},qa="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this; | ||
function Z(e,m){if(m){var l=qa;e=e.split(".");for(var n=0;n<e.length-1;n++){var p=e[n];p in l||(l[p]={});l=l[p]}e=e[e.length-1];n=l[e];m=m(n);m!=n&&null!=m&&pa(l,e,{configurable:!0,writable:!0,value:m})}}Z("Object.is",function(e){return e?e:function(e,l){return e===l?0!==e||1/e===1/l:e!==e&&l!==l}}); | ||
Z("Array.prototype.includes",function(e){return e?e:function(e,l){var m=this;m instanceof String&&(m=String(m));var p=m.length;l=l||0;for(0>l&&(l=Math.max(l+p,0));l<p;l++){var u=m[l];if(u===e||Object.is(u,e))return!0}return!1}}); | ||
Z("String.prototype.codePointAt",function(e){return e?e:function(e){if(null==this)throw new TypeError("The 'this' value for String.prototype.codePointAt must not be null or undefined");var l=this.length;e=Number(e)||0;if(0<=e&&e<l){e|=0;var m=this.charCodeAt(e);if(55296>m||56319<m||e+1===l)return m;e=this.charCodeAt(e+1);return 56320>e||57343<e?m:1024*(m-55296)+e+9216}}}); | ||
var Na=function(){function e(a){a=void 0===a?null:a;var b=m.call(this)||this;b.bitDepth="0";b.dataType={};a&&b.fromBuffer(a);return b}function m(){this.container="";this.chunkSize=0;this.format="";this.fmt={chunkId:"",chunkSize:0,audioFormat:0,numChannels:0,sampleRate:0,byteRate:0,blockAlign:0,bitsPerSample:0,cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]};this.fact={chunkId:"",chunkSize:0,dwSampleLength:0};this.cue={chunkId:"",chunkSize:0,dwCuePoints:0,points:[]};this.smpl={chunkId:"", | ||
chunkSize:0,dwManufacturer:0,dwProduct:0,dwSamplePeriod:0,dwMIDIUnityNote:0,dwMIDIPitchFraction:0,dwSMPTEFormat:0,dwSMPTEOffset:0,dwNumSampleLoops:0,dwSamplerData:0,loops:[]};this.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:""};this.ds64={chunkId:"",chunkSize:0,riffSizeHigh:0, | ||
riffSizeLow:0,dataSizeHigh:0,dataSizeLow:0,originationTime:0,sampleCountHigh:0,sampleCountLow:0};this.data={chunkId:"",chunkSize:0,samples:new Uint8Array(0)};this.LIST=[];this.junk={chunkId:"",chunkSize:0,chunkData:[]}}function l(){this.b=0}function n(a,b,c){if(b){if(!a||16!==a&&32!==a&&64!==a)throw Error("Unsupported type: float, bits: "+a);a=this.g(a)}else{if(!a||1>a||53<a)throw Error("Unsupported type: int, bits: "+a);a=c?new p(a):new u(a)}this.a=a}function p(a){a=u.call(this,a)||this;a.max=Math.pow(2, | ||
a.f)/2-1;a.min=-a.max-1;return a}function u(a){this.f=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.j=Math.pow(2,0<a?a:8)-1}function E(a,b){this.b=a;this.c=b;this.a=(1<<a-1)-1;this.j=Math.ceil((a+b)/8);this.o=Math.pow(2,this.a+1);this.s=a+b;this.u=Math.pow(2,-(8*this.j-1-a))}function ra(a){var b=a.length,c=.75*a.length,d=0;"\x3d"===a[a.length-1]&&(c--,"\x3d"===a[a.length-2]&&c--);for(var g=new ArrayBuffer(c),f=new Uint8Array(g),e=0;e<b;e+=4){c=H[a.charCodeAt(e)]; | ||
var h=H[a.charCodeAt(e+1)];var k=H[a.charCodeAt(e+2)];var l=H[a.charCodeAt(e+3)];f[d++]=c<<2|h>>4;f[d++]=(h&15)<<4|k>>2;f[d++]=(k&3)<<6|l&63}return g}function ta(a,b){return a=0<a?parseInt(a/b.D*b.B,10):parseInt(a/b.F*b.C,10)}function ua(a,b){return parseInt(0<a?a*b.B:a*b.C,10)}function va(a,b){return 0<a?a/b.D:a/b.F}function wa(a){aa[0]=a;return aa[0]}function xa(a,b){function c(a){return a}a!=b&&(["32f","64"].includes(a)?["32f","64"].includes(b)?c=wa:c=ua:c=["32f","64"].includes(b)?va:ta);return c} | ||
function ba(a){if("32f"!=a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}function ya(a){for(var b=new Uint8Array(a.length/2+512),c=[],d=0,g=0;g<a.length;g++)0==g%505&&0!=g&&(b.set(za(c),d),d+=256,c=[]),c.push(a[g]);return b}function Aa(a,b){b=void 0===b?256:b;for(var c=new Int16Array(2*a.length),d=[],g=0,f=0;f<a.length;f++)0==f%b&&0!=f&&(c.set(Ba(d),g),g+=2*b,d=[]),d.push(a[f]);return c}function za(a){var b=a[0];Q(b);var c=[];c.push(b&255);c.push(b>>8&255); | ||
c.push(F);c.push(0);for(b=3;b<a.length;b+=2){var d=Q(a[b]),g=Q(a[b+1]);c.push(g<<4|d)}for(;256>c.length;)c.push(0);return c}function Ba(a){A=ca(a[1]<<8|a[0]);B=a[2];G=R[B];for(var b=[A,ca(a[3]<<8|a[2])],c=4;c<a.length;c++){var d=a[c],g=d>>4;b.push(da(g<<4^d));b.push(da(g))}return b}function ca(a){return 32768<a?a-65536:a}function Q(a){var b=a-C;0<=b?a=0:(a=8,b=-b);var c=R[F],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;C=b&8?C-d:C+d;-32768>C?C=-32768:32767<C&& | ||
(C=32767);F+=ea[b&7];0>F?F=0:88<F&&(F=88);return a}function da(a){var b=0;a&4&&(b+=G);a&2&&(b+=G>>1);a&1&&(b+=G>>2);b+=G>>3;a&8&&(b=-b);A+=b;32767<A?A=32767:-32767>A&&(A=-32767);B+=ea[a];0>B?B=0:88<B&&(B=88);G=R[B];return A}function Ca(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=a[c];d=-32768==d?-32767:d;var g=~d>>8&128;g||(d*=-1);32635<d&&(d=32635);if(256<=d){var f=Da[d>>8&127];d=f<<4|d>>f+3&15}else d>>=4;b[c]=d^g^85}return b}function Ea(a){for(var b=new Int16Array(a.length), | ||
c=0;c<a.length;c++){var d=a[c],g=0;d^=85;d&128&&(d&=-129,g=-1);var f=((d&240)>>4)+4;d=4!=f?1<<f|(d&15)<<f-4|1<<f-5:d<<1|1;b[c]=-8*(0===g?d:-d)}return b}function Fa(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=a[c];var g=d>>8&128;0!=g&&(d=-d);32635<d&&(d=32635);d+=132;var f=Ga[d>>7&255];b[c]=~(g|f<<4|d>>f+3&15)}return b}function Ha(a){for(var b=new Int16Array(a.length),c=0;c<a.length;c++){var d=a[c];d=~d;var g=d>>4&7;g=Ia[g]+((d&15)<<g+3);0!=(d&128)&&(g=-g);b[c]=g}return b}function S(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 g=a,f=b,e=c;f--;for(var h=0;h<f;h++){var k=g[e+h];g[e+h]=g[e+f];g[e+f]=k;f--}}}function T(a,b,c){c=void 0===c?0:c;for(var d=0,g=a.length;d<g;d++){var f=a.codePointAt(d);if(128>f)b[c]=f,c++;else{var e=0,h=0;2047>=f?(e=1,h=192):65535>=f?(e=2,h=224):1114111>=f&&(e=3,h=240,d++);b[c]=(f>>6*e)+h;for(c++;0<e;)b[c]=128|f>>6*(e-1)&63,c++,e--}}return c}function J(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 g=128,f=191,e=!1,h=a[d++];if(0<=h&&127>=h)b+=String.fromCharCode(h);else{var k=0;194<=h&&223>=h?k=1:224<=h&&239>=h?(k=2,224===a[d]&&(g=160),237===a[d]&&(f=159)):240<=h&&244>=h?(k=3,240===a[d]&&(g=144),244===a[d]&&(f=143)):e=!0;h&=(1<<8-k-1)-1;for(var l=0;l<k;l++){if(a[d]<g||a[d]>f)e=!0;h=h<<6|a[d]&63;d++}e?b+=String.fromCharCode(65533):65535>=h?b+=String.fromCharCode(h):(h-=65536,b+=String.fromCharCode((h>>10&1023)+55296,(h&1023)+56320))}}return b} | ||
function q(a){var b=[];T(a,b,0);return b}function k(a,b){var c=[];K([a],b,c,0);return c}function K(a,b,c,d){d=void 0===d?0:d;b=b||{};var g=new n(b.f,b.v,b.A),f=Math.ceil(b.f/8),e=0;try{for(var h=a.length;e<h;e++){var k=a[e];if(void 0===k||null===k)throw Error("Argument is not a valid number");if(k.constructor!=Number&&k.constructor!=Boolean)throw Error("Argument is not a valid number");for(var l=d+f;d<l;)d=g.b(c,a[e],d);b.h&&S(c,f,d-f,d)}}catch(Ja){a=a[e];if(b.v||Infinity!==a&&-Infinity!==a&&a=== | ||
a)throw Error(Ja.message+" at input index "+e);throw Error("Argument is not a integer at input index "+e);}return d}function U(a,b,c){c=void 0===c?0:c;return V(a,b,c,c+Math.ceil(b.f/8),!0)[0]}function V(a,b,c,d,g){d=void 0===d?a.length:d;var f=[];I(a,b,f,void 0===c?0:c,d,void 0===g?!1:g);return f}function I(a,b,c,d,g,f){d=void 0===d?0:d;g=void 0===g?a.length:g;f=void 0===f?!1:f;b=b||{};var e=new n(b.f,b.v,b.A),h=Math.ceil(b.f/8),k=(g-d)%h;if(f&&(k||a.length<h))throw Error("Bad buffer length");g-= | ||
k;f=0;try{b.h&&S(a,h,d,g);for(k=d;k<g;k+=h,f++)c[f]=e.c(a,k);b.h&&S(a,h,d,g)}catch(sa){throw Error(sa.message+" at output index "+f);}}function L(a,b,c,d,g,f){return{container:f.container,chunkSize:36+g,format:"WAVE",bitDepth:a,fmt:{chunkId:"fmt ",chunkSize:16,audioFormat:W[a]||65534,numChannels:b,sampleRate:c,byteRate:b*d*c,blockAlign:b*d,bitsPerSample:parseInt(a,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}}}function fa(a){if(!W[a.bitDepth]){if(8<parseInt(a.bitDepth,10)&&54>parseInt(a.bitDepth, | ||
10))return!0;throw Error("Invalid bit depth.");}return!0}function ha(a){var b=a.fmt.numChannels*a.fmt.bitsPerSample/8;if(1>a.fmt.numChannels||65535<b)throw Error("Invalid number of channels.");return!0}function ia(a){var b=a.fmt.bitsPerSample/8*a.fmt.numChannels*a.fmt.sampleRate;if(1>a.fmt.sampleRate||4294967295<b)throw Error("Invalid sample rate.");return!0}function Ka(a,b,c){var d=[];16<a.fmt.chunkSize&&(d=d.concat(k(a.fmt.cbSize,c)));18<a.fmt.chunkSize&&(d=d.concat(k(a.fmt.validBitsPerSample,c))); | ||
20<a.fmt.chunkSize&&(d=d.concat(k(a.fmt.dwChannelMask,b)));24<a.fmt.chunkSize&&(d=d.concat(k(a.fmt.subformat[0],b),k(a.fmt.subformat[1],b),k(a.fmt.subformat[2],b),k(a.fmt.subformat[3],b)));return d}function La(a,b,c,d){return[].concat(q(a.chunkId),k(a.value.length+20,c),k(a.dwName,c),k(a.dwSampleLength,c),k(a.dwPurposeID,c),k(a.dwCountry,d),k(a.dwLanguage,d),k(a.dwDialect,d),k(a.dwCodePage,d),y.g(a.value,a.value.length))}function w(a,b,c){c=void 0===c?!1:c;for(var d=[],g=0;g<a.length;g++)if(a[g].chunkId== | ||
b)if(c)d.push(a[g]);else return a[g];return"LIST"==b?d.length?d:null:null}function ja(a){for(var b=[],c=D;c<=a.length-8;)b.push(Ma(a,c)),c+=8+b[b.length-1].chunkSize,c=c%2?c+1:c;return b}function Ma(a,b){var c={chunkId:ka(a,b),chunkSize:la(a,b)};"LIST"==c.chunkId?(c.format=J(a,b+8,b+12),D+=4,c.subChunks=ja(a)):(D=b+8+(c.chunkSize%2?c.chunkSize+1:c.chunkSize),c.chunkData={start:b+8,end:D});return c}function ka(a,b){D+=4;return J(a,b,b+4)}function la(a,b){D+=4;return U(a,ma,b+4)}for(var aa=new Float32Array(1), | ||
ea=[-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8],R=[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],C=0,F=0,A=0,B=0,G=7,Da=[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],Ga=[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],Ia=[0,132,396,924,1980,4092,8316,16764],H=new Uint8Array(256),M=0;64>M;M++)H["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(M)]=M;E.prototype.g=function(a,b,c){Math.abs(b)>this.o-2*this.s&&(b=0>b?-Infinity:Infinity);var d=0>((b=+b)||1/b)?1:0>b?1:0;b=Math.abs(b); | ||
var g=Math.min(Math.floor(Math.log(b)/Math.LN2),1023),f=this.l(b/Math.pow(2,g)*Math.pow(2,this.c));b!==b?(f=Math.pow(2,this.c-1),g=(1<<this.b)-1):0!==b&&(b>=Math.pow(2,1-this.a)?(2<=f/Math.pow(2,this.c)&&(g+=1,f=1),g>this.a?(g=(1<<this.b)-1,f=0):(g+=this.a,f=this.l(f)-Math.pow(2,this.c))):(f=this.l(b/Math.pow(2,1-this.a-this.c)),g=0));return this.w(a,c,d,g,f)};E.prototype.i=function(a,b){for(var c=(1<<this.b)-1,d="",g=this.j-1;0<=g;g--){var f=a[g+b].toString(2);d+="00000000".substring(f.length)+f}a= | ||
"1"==d.charAt(0)?-1:1;d=d.substring(1);b=parseInt(d.substring(0,this.b),2);d=d.substring(this.b);if(b==c)return 0!==parseInt(d,2)?NaN:Infinity*a;0===b?(b+=1,c=parseInt(d,2)):c=parseInt("1"+d,2);return a*c*this.u*Math.pow(2,b-this.a)};E.prototype.w=function(a,b,c,d,g){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]=g%2?1:0,g=Math.floor(g/2);g=f.join("");f=this.j+b-1;for(d=b;f>=b;)a[f]=parseInt(g.substring(0,8),2),g=g.substring(8),f--,d++; | ||
return d};E.prototype.l=function(a){var b=Math.floor(a);a-=b;return.5>a?b:.5<a?b+1:b%2?b+1:b};u.prototype.g=function(a,b,c){c=void 0===c?0:c;if(b!==b)throw Error("NaN");this.a(b);a[c]=(0>b?b+Math.pow(2,this.f):b)&255;c++;for(var d=this.b,g=2;g<d;g++)a[c]=Math.floor(b/Math.pow(2,8*(g-1)))&255,c++;8<this.f&&(a[c]=Math.floor(b/Math.pow(2,8*(this.b-1)))&this.j,c++);return c};u.prototype.i=function(a,b){a=this.c(a,void 0===b?0:b);this.a(a);return a};u.prototype.c=function(a,b){for(var c=0,d=0;d<this.b;d++)c+= | ||
a[b+d]*Math.pow(256,d);return c};u.prototype.a=function(a){if(a>this.max||a<this.min)throw Error("Overflow");};Y(p,u);p.prototype.g=function(a,b,c){return u.prototype.g.call(this,a,b,void 0===c?0:c)};p.prototype.i=function(a,b){a=u.prototype.c.call(this,a,void 0===b?0:b);a=this.l(a);this.a(a);return a};p.prototype.l=function(a){a>this.max&&(a-=2*this.max+2);return a};n.prototype.c=function(a,b){return this.a.i(a,void 0===b?0:b)};n.prototype.b=function(a,b,c){return this.a.g(a,b,void 0===c?0:c)};n.prototype.g= | ||
function(a){return 16===a?new E(5,11):32===a?new E(8,23):new E(11,52)};var W={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};l.prototype.g=function(a,b){var c=void 0===c?!0:c;a=q(a);if(c)for(c=a.length;c<b;c++)a.push(0);return a};l.prototype.i=function(a,b){var c="";for(b=void 0===b?0:b;b<a.length;b++){this.b++;if(0===a[b])break;c+=J(a,b,b+1)}return c};l.prototype.c=function(a,b){a=J(a,this.b,this.b+b);this.b+=b;return a};l.prototype.a=function(a,b){var c=b.f/8;a=U(a,b,this.b);this.b+=c;return a}; | ||
var y=new l,ma={f:32},D=0,h=new l;Y(e,m);e.prototype.getSample=function(a){a*=this.dataType.f/8;if(a+this.dataType.f/8>this.data.samples.length)throw Error("Range error");return U(this.data.samples.slice(a,a+this.dataType.f/8),this.dataType)};e.prototype.setSample=function(a,b){a*=this.dataType.f/8;if(a+this.dataType.f/8>this.data.samples.length)throw Error("Range error");K([b],this.dataType,this.data.samples,void 0===a?0:a)};e.prototype.fromScratch=function(a,b,c,d,g){g=void 0===g?{}:g;g.container|| | ||
(g.container="RIFF");this.container=g.container;this.bitDepth=c;d=this.G(d);this.u();var f=this.dataType.f/8;this.data.samples=new Uint8Array(d.length*f);K(d,this.dataType,this.data.samples);d=this.data.samples.length;"4"==c?(a=L(c,a,b,f,d,g),a.chunkSize=40+d,a.fmt.chunkSize=20,a.fmt.byteRate=4055,a.fmt.blockAlign=256,a.fmt.bitsPerSample=4,a.fmt.cbSize=2,a.fmt.validBitsPerSample=505,a.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*d}):"8a"==c||"8m"==c?(a=L(c,a,b,f,d,g),a.chunkSize=40+d,a.fmt.chunkSize= | ||
20,a.fmt.cbSize=2,a.fmt.validBitsPerSample=8,a.fact={chunkId:"fact",chunkSize:4,dwSampleLength:d}):-1==Object.keys(W).indexOf(c)||2<a?(b=L(c,a,b,f,d,g),b.chunkSize=60+d,b.fmt.chunkSize=40,b.fmt.bitsPerSample=(parseInt(c,10)-1|7)+1,b.fmt.cbSize=22,b.fmt.validBitsPerSample=parseInt(c,10),d=0,1===a?d=4:2===a?d=3:4===a?d=51:6===a?d=63:8===a&&(d=1599),b.fmt.dwChannelMask=d,b.fmt.subformat=[1,1048576,2852126848,1905997824],a=b):a=L(c,a,b,f,d,g);this.s();this.chunkSize=a.chunkSize;this.format=a.format;this.fmt= | ||
a.fmt;a.fact&&(this.fact=a.fact);this.data.chunkId="data";this.data.chunkSize=this.data.samples.length;fa(this);ha(this);ia(this)};e.prototype.fromBuffer=function(a,b){b=void 0===b?!0:b;this.s();var c=b;b={f:32,h:!1};var d={f:16,h:!1};h.b=0;this.container=h.c(a,4);if(-1===["RIFF","RIFX","RF64"].indexOf(this.container))throw Error("Not a supported format.");d.h="RIFX"===this.container;b.h=d.h;this.chunkSize=h.a(a,b);this.format=h.c(a,4);if("WAVE"!=this.format)throw Error('Could not find the "WAVE" format identifier'); | ||
D=0;var g=ka(a,0);ma.h="RIFX"==g;D+=4;la(a,0);g=ja(a);var f=w(g,"ds64");if(f)h.b=f.chunkData.start,this.ds64.chunkId=f.chunkId,this.ds64.chunkSize=f.chunkSize,this.ds64.riffSizeHigh=h.a(a,b),this.ds64.riffSizeLow=h.a(a,b),this.ds64.dataSizeHigh=h.a(a,b),this.ds64.dataSizeLow=h.a(a,b),this.ds64.originationTime=h.a(a,b),this.ds64.sampleCountHigh=h.a(a,b),this.ds64.sampleCountLow=h.a(a,b);else if("RF64"==this.container)throw Error('Could not find the "ds64" chunk');if(f=w(g,"fmt "))h.b=f.chunkData.start, | ||
this.fmt.chunkId=f.chunkId,this.fmt.chunkSize=f.chunkSize,this.fmt.audioFormat=h.a(a,d),this.fmt.numChannels=h.a(a,d),this.fmt.sampleRate=h.a(a,b),this.fmt.byteRate=h.a(a,b),this.fmt.blockAlign=h.a(a,d),this.fmt.bitsPerSample=h.a(a,d),16<this.fmt.chunkSize&&(this.fmt.cbSize=h.a(a,d),18<this.fmt.chunkSize&&(this.fmt.validBitsPerSample=h.a(a,d),20<this.fmt.chunkSize&&(this.fmt.dwChannelMask=h.a(a,b),this.fmt.subformat=[h.a(a,b),h.a(a,b),h.a(a,b),h.a(a,b)])));else throw Error('Could not find the "fmt " chunk'); | ||
if(f=w(g,"fact"))h.b=f.chunkData.start,this.fact.chunkId=f.chunkId,this.fact.chunkSize=f.chunkSize,this.fact.dwSampleLength=h.a(a,b);if(f=w(g,"bext"))h.b=f.chunkData.start,this.bext.chunkId=f.chunkId,this.bext.chunkSize=f.chunkSize,this.bext.description=h.c(a,256),this.bext.originator=h.c(a,32),this.bext.originatorReference=h.c(a,32),this.bext.originationDate=h.c(a,10),this.bext.originationTime=h.c(a,8),this.bext.timeReference=[h.a(a,b),h.a(a,b)],this.bext.version=h.a(a,d),this.bext.UMID=h.c(a,64), | ||
this.bext.loudnessValue=h.a(a,d),this.bext.loudnessRange=h.a(a,d),this.bext.maxTruePeakLevel=h.a(a,d),this.bext.maxMomentaryLoudness=h.a(a,d),this.bext.maxShortTermLoudness=h.a(a,d),this.bext.reserved=h.c(a,180),this.bext.codingHistory=h.c(a,this.bext.chunkSize-602);if(f=w(g,"cue "))for(h.b=f.chunkData.start,this.cue.chunkId=f.chunkId,this.cue.chunkSize=f.chunkSize,this.cue.dwCuePoints=h.a(a,b),f=0;f<this.cue.dwCuePoints;f++)this.cue.points.push({dwName:h.a(a,b),dwPosition:h.a(a,b),fccChunk:h.c(a, | ||
4),dwChunkStart:h.a(a,b),dwBlockStart:h.a(a,b),dwSampleOffset:h.a(a,b)});if(f=w(g,"smpl"))for(h.b=f.chunkData.start,this.smpl.chunkId=f.chunkId,this.smpl.chunkSize=f.chunkSize,this.smpl.dwManufacturer=h.a(a,b),this.smpl.dwProduct=h.a(a,b),this.smpl.dwSamplePeriod=h.a(a,b),this.smpl.dwMIDIUnityNote=h.a(a,b),this.smpl.dwMIDIPitchFraction=h.a(a,b),this.smpl.dwSMPTEFormat=h.a(a,b),this.smpl.dwSMPTEOffset=h.a(a,b),this.smpl.dwNumSampleLoops=h.a(a,b),this.smpl.dwSamplerData=h.a(a,b),f=0;f<this.smpl.dwNumSampleLoops;f++)this.smpl.loops.push({dwName:h.a(a, | ||
b),dwType:h.a(a,b),dwStart:h.a(a,b),dwEnd:h.a(a,b),dwFraction:h.a(a,b),dwPlayCount:h.a(a,b)});if(f=w(g,"data"))this.data.chunkId="data",this.data.chunkSize=f.chunkSize,c&&(this.data.samples=a.slice(f.chunkData.start,f.chunkData.end));else throw Error('Could not find the "data" chunk');if(c=w(g,"junk"))this.junk={chunkId:c.chunkId,chunkSize:c.chunkSize,chunkData:[].slice.call(a.slice(c.chunkData.start,c.chunkData.end))};g=w(g,"LIST",!0);if(null!==g)for(c=0;c<g.length;c++){f=g[c];this.LIST.push({chunkId:f.chunkId, | ||
chunkSize:f.chunkSize,format:f.format,subChunks:[]});for(var e=0;e<f.subChunks.length;e++){var k=f.subChunks[e],l=f.format,m=a,n=b,q=d;"adtl"==l?-1<["labl","note","ltxt"].indexOf(k.chunkId)&&(h.b=k.chunkData.start,l={chunkId:k.chunkId,chunkSize:k.chunkSize,dwName:h.a(m,n)},"ltxt"==k.chunkId&&(l.dwSampleLength=h.a(m,n),l.dwPurposeID=h.a(m,n),l.dwCountry=h.a(m,q),l.dwLanguage=h.a(m,q),l.dwDialect=h.a(m,q),l.dwCodePage=h.a(m,q)),l.value=h.i(m,h.b),this.LIST[this.LIST.length-1].subChunks.push(l)):"INFO"== | ||
l&&(h.b=k.chunkData.start,this.LIST[this.LIST.length-1].subChunks.push({chunkId:k.chunkId,chunkSize:k.chunkSize,value:h.i(m,h.b)}))}}this.w();this.u()};e.prototype.toBuffer=function(){fa(this);ha(this);ia(this);var a={f:32,h:!1},b={f:16,h:!1};b.h="RIFX"===this.container;a.h=b.h;var c=[];c=this.junk.chunkId?c.concat(q(this.junk.chunkId),k(this.junk.chunkData.length,a),this.junk.chunkData):c;var d=[];this.ds64.chunkId&&(d=d.concat(q(this.ds64.chunkId),k(this.ds64.chunkSize,a),k(this.ds64.riffSizeHigh, | ||
a),k(this.ds64.riffSizeLow,a),k(this.ds64.dataSizeHigh,a),k(this.ds64.dataSizeLow,a),k(this.ds64.originationTime,a),k(this.ds64.sampleCountHigh,a),k(this.ds64.sampleCountLow,a)));var g=[];for(f in this.bext)if(this.bext.hasOwnProperty(f)&&this.bext[f]&&"timeReference"!=f){this.bext.chunkId="bext";break}if(this.bext.timeReference[0]||this.bext.timeReference[1])this.bext.chunkId="bext";this.bext.chunkId&&(this.bext.chunkSize=602+this.bext.codingHistory.length,g=g.concat(q(this.bext.chunkId),k(602+this.bext.codingHistory.length, | ||
a),y.g(this.bext.description,256),y.g(this.bext.originator,32),y.g(this.bext.originatorReference,32),y.g(this.bext.originationDate,10),y.g(this.bext.originationTime,8),k(this.bext.timeReference[0],a),k(this.bext.timeReference[1],a),k(this.bext.version,b),y.g(this.bext.UMID,64),k(this.bext.loudnessValue,b),k(this.bext.loudnessRange,b),k(this.bext.maxTruePeakLevel,b),k(this.bext.maxMomentaryLoudness,b),k(this.bext.maxShortTermLoudness,b),y.g(this.bext.reserved,180),y.g(this.bext.codingHistory,this.bext.codingHistory.length))); | ||
var f=g;g=[];if(this.fmt.chunkId)g=g.concat(q(this.fmt.chunkId),k(this.fmt.chunkSize,a),k(this.fmt.audioFormat,b),k(this.fmt.numChannels,b),k(this.fmt.sampleRate,a),k(this.fmt.byteRate,a),k(this.fmt.blockAlign,b),k(this.fmt.bitsPerSample,b),Ka(this,a,b));else throw Error('Could not find the "fmt " chunk');var e=[];this.fact.chunkId&&(e=e.concat(q(this.fact.chunkId),k(this.fact.chunkSize,a),k(this.fact.dwSampleLength,a)));var h=q(this.data.chunkId),l=k(this.data.samples.length,a),m=this.data.samples; | ||
var n=[];if(this.cue.chunkId){var p=[];for(var r=0;r<this.cue.dwCuePoints;r++)p=p.concat(k(this.cue.points[r].dwName,a),k(this.cue.points[r].dwPosition,a),q(this.cue.points[r].fccChunk),k(this.cue.points[r].dwChunkStart,a),k(this.cue.points[r].dwBlockStart,a),k(this.cue.points[r].dwSampleOffset,a));n=n.concat(q(this.cue.chunkId),k(p.length+4,a),k(this.cue.dwCuePoints,a),p)}p=[];if(this.smpl.chunkId){r=[];for(var v=0;v<this.smpl.dwNumSampleLoops;v++)r=r.concat(k(this.smpl.loops[v].dwName,a),k(this.smpl.loops[v].dwType, | ||
a),k(this.smpl.loops[v].dwStart,a),k(this.smpl.loops[v].dwEnd,a),k(this.smpl.loops[v].dwFraction,a),k(this.smpl.loops[v].dwPlayCount,a));p=p.concat(q(this.smpl.chunkId),k(r.length+36,a),k(this.smpl.dwManufacturer,a),k(this.smpl.dwProduct,a),k(this.smpl.dwSamplePeriod,a),k(this.smpl.dwMIDIUnityNote,a),k(this.smpl.dwMIDIPitchFraction,a),k(this.smpl.dwSMPTEFormat,a),k(this.smpl.dwSMPTEOffset,a),k(this.smpl.dwNumSampleLoops,a),k(this.smpl.dwSamplerData,a),r)}r=[];for(v=0;v<this.LIST.length;v++){var t= | ||
this.LIST[v].subChunks;for(var u=this.LIST[v].format,w=a,A=b,z=[],x=0;x<t.length;x++)"INFO"==u?(z=z.concat(q(t[x].chunkId),k(t[x].value.length+1,w),y.g(t[x].value,t[x].value.length)),z.push(0)):"adtl"==u&&(-1<["labl","note"].indexOf(t[x].chunkId)?(z=z.concat(q(t[x].chunkId),k(t[x].value.length+4+1,w),k(t[x].dwName,w),y.g(t[x].value,t[x].value.length)),z.push(0)):"ltxt"==t[x].chunkId&&(z=z.concat(La(t[x],this,w,A)))),z.length%2&&z.push(0);t=z;r=r.concat(q(this.LIST[v].chunkId),k(t.length+4,a),q(this.LIST[v].format), | ||
t)}b=[c,d,f,g,e,h,l,m,n,p,r];for(d=c=0;d<b.length;d++)c+=b[d].length;d=new Uint8Array(c+12);f=T(this.container,d,0);f=K([c+4],a,d,void 0===f?0:f);f=T(this.format,d,void 0===f?0:f);for(a=0;a<b.length;a++)d.set(b[a],f),f+=b[a].length;return d};e.prototype.fromBase64=function(a){this.fromBuffer(new Uint8Array(ra(a)))};e.prototype.toBase64=function(){var a=this.toBuffer();a=new Uint8Array(a,0,a.length);for(var b=a.length,c="",d=0;d<b;d+=3)c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[d]>> | ||
2],c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[d]&3)<<4|a[d+1]>>4],c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[d+1]&15)<<2|a[d+2]>>6],c+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[d+2]&63];2===b%3?c=c.substring(0,c.length-1)+"\x3d":1===b%3&&(c=c.substring(0,c.length-2)+"\x3d\x3d");return c};e.prototype.toDataURI=function(){return"data:audio/wav;base64,"+this.toBase64()};e.prototype.fromDataURI=function(a){this.fromBase64(a.replace("data:audio/wav;base64,", | ||
""))};e.prototype.toRIFF=function(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,V(this.data.samples,this.dataType))};e.prototype.toRIFX=function(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,V(this.data.samples,this.dataType),{container:"RIFX"})};e.prototype.toBitDepth=function(a,b){var c=a,d=this.bitDepth;void 0===b||b||("32f"!=a&&(c=this.dataType.f.toString()),d=this.dataType.f);this.o();var e=this.data.samples.length/(this.dataType.f/8);b= | ||
new Float64Array(e+1);e=new Float64Array(e+1);I(this.data.samples,this.dataType,b);"32f"!=d&&"64"!=d||this.J(b);var f=d;d=c;ba(f);ba(d);var h=xa(f,d),k={F:Math.pow(2,parseInt(f,10))/2,C:Math.pow(2,parseInt(d,10))/2,D:Math.pow(2,parseInt(f,10))/2-1,B:Math.pow(2,parseInt(d,10))/2-1};c=b.length;if("8"==f)for(f=0;f<c;f++)e[f]=b[f]-=128;for(f=0;f<c;f++)e[f]=h(b[f],k);if("8"==d)for(b=0;b<c;b++)e[b]=e[b]+=128;this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,a,e,{container:this.a()})};e.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.c();var a=new Int16Array(this.data.samples.length/2);I(this.data.samples,this.dataType,a);this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"4",ya(a),{container:this.a()})};e.prototype.fromIMAADPCM=function(a){a=void 0===a?"16":a;this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16", | ||
Aa(this.data.samples,this.fmt.blockAlign),{container:this.a()});"16"!=a&&this.toBitDepth(a)};e.prototype.toALaw=function(){this.c();var a=new Int16Array(this.data.samples.length/2);I(this.data.samples,this.dataType,a);this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8a",Ca(a),{container:this.a()})};e.prototype.fromALaw=function(a){a=void 0===a?"16":a;this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",Ea(this.data.samples),{container:this.a()});"16"!=a&&this.toBitDepth(a)};e.prototype.toMuLaw= | ||
function(){this.c();var a=new Int16Array(this.data.samples.length/2);I(this.data.samples,this.dataType,a);this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8m",Fa(a),{container:this.a()})};e.prototype.fromMuLaw=function(a){a=void 0===a?"16":a;this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",Ha(this.data.samples),{container:this.a()});"16"!=a&&this.toBitDepth(a)};e.prototype.setTag=function(a,b){a=this.L(a);var c=this.l(a);null!==c.m?(this.LIST[c.LIST].subChunks[c.m].chunkSize= | ||
b.length+1,this.LIST[c.LIST].subChunks[c.m].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}))};e.prototype.getTag=function(a){a=this.l(a);return null!==a.m?this.LIST[a.LIST].subChunks[a.m].value:null};e.prototype.listTags=function(){var a=this.M(),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};e.prototype.deleteTag=function(a){a=this.l(a);return null!==a.m?(this.LIST[a.LIST].subChunks.splice(a.m,1),!0):!1};e.prototype.setCuePoint=function(a,b){b=void 0===b?"":b;this.cue.chunkId="cue ";a=a*this.fmt.sampleRate/1E3;var c=this.j();this.g();var d=this.cue.points.length;this.cue.points=[];var e=!1;if(0===d)this.b(a,1,b);else{for(var f=0;f<d;f++)c[f].dwPosition>a&&!e?(this.b(a,f+1,b),this.b(c[f].dwPosition,f+ | ||
2,c[f].label),e=!0):this.b(c[f].dwPosition,f+1,c[f].label);e||this.b(a,this.cue.points.length+1,b)}this.cue.dwCuePoints=this.cue.points.length};e.prototype.deleteCuePoint=function(a){this.cue.chunkId="cue ";var b=this.j();this.g();var c=this.cue.points.length;this.cue.points=[];for(var d=0;d<c;d++)d+1!==a&&this.b(b[d].dwPosition,d+1,b[d].label);this.cue.dwCuePoints=this.cue.points.length;this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.g())};e.prototype.listCuePoints=function(){for(var a= | ||
this.j(),b=0,c=a.length;b<c;b++)a[b].milliseconds=a[b].dwPosition/this.fmt.sampleRate*1E3;return a};e.prototype.updateLabel=function(a,b){var c=this.i();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)};e.prototype.w=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()}; | ||
e.prototype.b=function(a,b,c){this.cue.points.push({dwName:b,dwPosition:a,fccChunk:"data",dwChunkStart:0,dwBlockStart:0,dwSampleOffset:a});this.I(b,c)};e.prototype.j=function(){for(var a=[],b=0,c=this.cue.points.length;b<c;b++)a.push({dwPosition:this.cue.points[b].dwPosition,label:this.N(this.cue.points[b].dwName)});return a};e.prototype.N=function(a){var b=this.i();if(null!==b)for(var c=0,d=this.LIST[b].subChunks.length;c<d;c++)if(this.LIST[b].subChunks[c].dwName==a)return this.LIST[b].subChunks[c].value; | ||
return""};e.prototype.g=function(){for(var a=0,b=this.LIST.length;a<b;a++)"adtl"==this.LIST[a].format&&this.LIST.splice(a)};e.prototype.I=function(a,b){var c=this.i();null===c&&(this.LIST.push({chunkId:"LIST",chunkSize:4,format:"adtl",subChunks:[]}),c=this.LIST.length-1);this.H(null===c?0:c,a,b)};e.prototype.H=function(a,b,c){this.LIST[a].subChunks.push({chunkId:"labl",chunkSize:c.length,dwName:b,value:c});this.LIST[a].chunkSize+=c.length+13};e.prototype.i=function(){for(var a=0,b=this.LIST.length;a< | ||
b;a++)if("adtl"==this.LIST[a].format)return a;return null};e.prototype.M=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};e.prototype.l=function(a){for(var b={LIST:null,m: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.m=d;break}break}return b};e.prototype.L=function(a){if(a.constructor!==String)throw Error("Invalid tag name."); | ||
if(4>a.length)for(var b=0,c=4-a.length;b<c;b++)a+=" ";return a};e.prototype.s=function(){this.fmt.cbSize=0;this.fmt.validBitsPerSample=0;this.fact.chunkId="";this.ds64.chunkId=""};e.prototype.c=function(){this.o();"16"!=this.bitDepth&&this.toBitDepth("16")};e.prototype.o=function(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()};e.prototype.G=function(a){if(0<a.length&&a[0].constructor===Array){for(var b=[],c=0,d=a[0].length;c<d;c++)for(var e= | ||
0,f=a.length;e<f;e++)b.push(a[e][c]);a=b}return a};e.prototype.u=function(){this.dataType={f:(parseInt(this.bitDepth,10)-1|7)+1,v:"32f"==this.bitDepth||"64"==this.bitDepth,A:"8"!=this.bitDepth,h:"RIFX"==this.container};-1<["4","8a","8m"].indexOf(this.bitDepth)&&(this.dataType.f=8,this.dataType.A=!1)};e.prototype.a=function(){return"RF64"==this.container?"RIFF":this.container};e.prototype.J=function(a){for(var b=0,c=a.length;b<c;b++)1<a[b]?a[b]=1:-1>a[b]&&(a[b]=-1)};return e}();window.WaveFile=Na; |
@@ -1,1 +0,1 @@ | ||
Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(searchElement,fromIndex){if(null==this)throw new TypeError('"this" is null or not defined');var o=Object(this),len=o.length>>>0;if(0===len)return!1;var x,y,n=0|fromIndex,k=Math.max(n>=0?n:len-Math.abs(n),0);for(;k<len;){if((x=o[k])===(y=searchElement)||"number"==typeof x&&"number"==typeof y&&isNaN(x)&&isNaN(y))return!0;k++}return!1}}),String.prototype.codePointAt||function(){"use strict";var defineProperty=function(){try{var object={},$defineProperty=Object.defineProperty,result=$defineProperty(object,object,object)&&$defineProperty}catch(error){}return result}(),codePointAt=function(position){if(null==this)throw TypeError();var string=String(this),size=string.length,index=position?Number(position):0;if(index!=index&&(index=0),!(index<0||index>=size)){var second,first=string.charCodeAt(index);return first>=55296&&first<=56319&&size>index+1&&(second=string.charCodeAt(index+1))>=56320&&second<=57343?1024*(first-55296)+second-56320+65536:first}};defineProperty?defineProperty(String.prototype,"codePointAt",{value:codePointAt,configurable:!0,writable:!0}):String.prototype.codePointAt=codePointAt}(),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:Array.prototype.slice}),function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.WaveFile=factory()}(this,function(){"use strict";var f64f32_=new Float32Array(1);function bitDepth(input,original,target,output){validateBitDepth_(original),validateBitDepth_(target);var toFunction=function(original,target){var func=function(x){return x};original!=target&&(func=["32f","64"].includes(original)?["32f","64"].includes(target)?floatToFloat_:floatToInt_:["32f","64"].includes(target)?intToFloat_:intToInt_);return func}(original,target),options={oldMin:Math.pow(2,parseInt(original,10))/2,newMin:Math.pow(2,parseInt(target,10))/2,oldMax:Math.pow(2,parseInt(original,10))/2-1,newMax:Math.pow(2,parseInt(target,10))/2-1},len=input.length;if("8"==original)for(var i=0;i<len;i++)output[i]=input[i]-=128;for(var _i=0;_i<len;_i++)output[_i]=toFunction(input[_i],options);if("8"==target)for(var _i2=0;_i2<len;_i2++)output[_i2]=output[_i2]+=128}function intToInt_(sample,args){return sample=sample>0?parseInt(sample/args.oldMax*args.newMax,10):parseInt(sample/args.oldMin*args.newMin,10)}function floatToInt_(sample,args){return parseInt(sample>0?sample*args.newMax:sample*args.newMin,10)}function intToFloat_(sample,args){return sample>0?sample/args.oldMax:sample/args.oldMin}function floatToFloat_(sample){return f64f32_[0]=sample,f64f32_[0]}function validateBitDepth_(bitDepth){if("32f"!=bitDepth&&"64"!=bitDepth&&(parseInt(bitDepth,10)<"8"||parseInt(bitDepth,10)>"53"))throw new Error("Invalid bit depth.")}var INDEX_TABLE=[-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8],STEP_TABLE=[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],encoderPredicted_=0,encoderIndex_=0,decoderPredicted_=0,decoderIndex_=0,decoderStep_=7;function encodeBlock(block){for(var adpcmSamples=function(sample){encodeSample_(sample);var adpcmSamples=[];return adpcmSamples.push(255&sample),adpcmSamples.push(sample>>8&255),adpcmSamples.push(encoderIndex_),adpcmSamples.push(0),adpcmSamples}(block[0]),i=3;i<block.length;i+=2){var sample2=encodeSample_(block[i]),sample=encodeSample_(block[i+1]);adpcmSamples.push(sample<<4|sample2)}for(;adpcmSamples.length<256;)adpcmSamples.push(0);return adpcmSamples}function decodeBlock(block){decoderPredicted_=sign_(block[1]<<8|block[0]),decoderIndex_=block[2],decoderStep_=STEP_TABLE[decoderIndex_];for(var result=[decoderPredicted_,sign_(block[3]<<8|block[2])],i=4;i<block.length;i++){var original_sample=block[i],second_sample=original_sample>>4,first_sample=second_sample<<4^original_sample;result.push(decodeSample_(first_sample)),result.push(decodeSample_(second_sample))}return result}function sign_(num){return num>32768?num-65536:num}function encodeSample_(sample){var delta=sample-encoderPredicted_,value=0;delta>=0?value=0:(value=8,delta=-delta);var step=STEP_TABLE[encoderIndex_],diff=step>>3;return delta>step&&(value|=4,delta-=step,diff+=step),delta>(step>>=1)&&(value|=2,delta-=step,diff+=step),delta>(step>>=1)&&(value|=1,diff+=step),function(value,diff){8&value?encoderPredicted_-=diff:encoderPredicted_+=diff;encoderPredicted_<-32768?encoderPredicted_=-32768:encoderPredicted_>32767&&(encoderPredicted_=32767);(encoderIndex_+=INDEX_TABLE[7&value])<0?encoderIndex_=0:encoderIndex_>88&&(encoderIndex_=88)}(value,diff),value}function decodeSample_(nibble){var difference=0;return 4&nibble&&(difference+=decoderStep_),2&nibble&&(difference+=decoderStep_>>1),1&nibble&&(difference+=decoderStep_>>2),difference+=decoderStep_>>3,8&nibble&&(difference=-difference),(decoderPredicted_+=difference)>32767?decoderPredicted_=32767:decoderPredicted_<-32767&&(decoderPredicted_=-32767),function(nibble){(decoderIndex_+=INDEX_TABLE[nibble])<0?decoderIndex_=0:decoderIndex_>88&&(decoderIndex_=88);decoderStep_=STEP_TABLE[decoderIndex_]}(nibble),decoderPredicted_}var LOG_TABLE=[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];function encodeSample(sample){var compandedValue=void 0,sign=~(sample=-32768==sample?-32767:sample)>>8&128;if(sign||(sample*=-1),sample>32635&&(sample=32635),sample>=256){var exponent=LOG_TABLE[sample>>8&127];compandedValue=exponent<<4|sample>>exponent+3&15}else compandedValue=sample>>4;return 85^compandedValue^sign}function decodeSample(aLawSample){var sign=0;128&(aLawSample^=85)&&(aLawSample&=-129,sign=-1);var position=4+((240&aLawSample)>>4),decoded=0;return decoded=4!=position?1<<position|(15&aLawSample)<<position-4|1<<position-5:aLawSample<<1|1,8*(decoded=0===sign?decoded:-decoded)*-1}var BIAS=132,CLIP=32635,encodeTable=[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],decodeTable=[0,132,396,924,1980,4092,8316,16764];for(var chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",lookup=new Uint8Array(256),i=0;i<chars.length;i++)lookup[chars.charCodeAt(i)]=i;function swap(bytes,offset,index){offset--;for(var x=0;x<offset;x++){var theByte=bytes[index+x];bytes[index+x]=bytes[index+offset],bytes[index+offset]=theByte,offset--}}function pack(str,buffer){for(var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=0,len=str.length;i<len;i++){var codePoint=str.codePointAt(i);if(codePoint<128)buffer[index]=codePoint,index++;else{var count=0,offset=0;for(codePoint<=2047?(count=1,offset=192):codePoint<=65535?(count=2,offset=224):codePoint<=1114111&&(count=3,offset=240,i++),buffer[index]=(codePoint>>6*count)+offset,index++;count>0;)buffer[index]=128|codePoint>>6*(count-1)&63,index++,count--}}return index}var TYPE_ERR="Unsupported type";function validateIsInt(value){validateIsNumber(value),value==value&&value!==1/0&&value!==-1/0||throwValueErr_("integer")}function validateIsNumber(value){null==value&&throwValueErr_(),value.constructor!=Number&&value.constructor!=Boolean&&throwValueErr_()}function throwValueErr_(){var theType=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"valid number";throw new Error("Argument is not a "+theType)}var classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")},createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}(),get=function get(object,property,receiver){null===object&&(object=Function.prototype);var desc=Object.getOwnPropertyDescriptor(object,property);if(void 0===desc){var parent=Object.getPrototypeOf(object);return null===parent?void 0:get(parent,property,receiver)}if("value"in desc)return desc.value;var getter=desc.get;return void 0!==getter?getter.call(receiver):void 0},inherits=function(subClass,superClass){if("function"!=typeof superClass&&null!==superClass)throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)},possibleConstructorReturn=function(self,call){if(!self)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!call||"object"!=typeof call&&"function"!=typeof call?self:call},IEEE754Buffer=function(){function IEEE754Buffer(ebits,fbits){classCallCheck(this,IEEE754Buffer),this.ebits=ebits,this.fbits=fbits,this.bias=(1<<ebits-1)-1,this.numBytes=Math.ceil((ebits+fbits)/8),this.biasP2=Math.pow(2,this.bias+1),this.ebitsFbits=ebits+fbits,this.fbias=Math.pow(2,-(8*this.numBytes-1-ebits))}return createClass(IEEE754Buffer,[{key:"pack",value:function(buffer,num,index){Math.abs(num)>this.biasP2-2*this.ebitsFbits&&(num=num<0?-1/0:1/0);var sign=((num=+num)||1/num)<0?1:num<0?1:0;num=Math.abs(num);var exp=Math.min(Math.floor(Math.log(num)/Math.LN2),1023),fraction=this.roundToEven(num/Math.pow(2,exp)*Math.pow(2,this.fbits));return num!=num?(fraction=Math.pow(2,this.fbits-1),exp=(1<<this.ebits)-1):0!==num&&(num>=Math.pow(2,1-this.bias)?(fraction/Math.pow(2,this.fbits)>=2&&(exp+=1,fraction=1),exp>this.bias?(exp=(1<<this.ebits)-1,fraction=0):(exp+=this.bias,fraction=this.roundToEven(fraction)-Math.pow(2,this.fbits))):(fraction=this.roundToEven(num/Math.pow(2,1-this.bias-this.fbits)),exp=0)),this.packFloatBits_(buffer,index,sign,exp,fraction)}},{key:"unpack",value:function(buffer,index){for(var eMax=(1<<this.ebits)-1,significand=void 0,leftBits="",i=this.numBytes-1;i>=0;i--){var t=buffer[i+index].toString(2);leftBits+="00000000".substring(t.length)+t}var sign="1"==leftBits.charAt(0)?-1:1;leftBits=leftBits.substring(1);var exponent=parseInt(leftBits.substring(0,this.ebits),2);return leftBits=leftBits.substring(this.ebits),exponent==eMax?0!==parseInt(leftBits,2)?NaN:sign*(1/0):(0===exponent?(exponent+=1,significand=parseInt(leftBits,2)):significand=parseInt("1"+leftBits,2),sign*significand*this.fbias*Math.pow(2,exponent-this.bias))}},{key:"packFloatBits_",value:function(buffer,index,sign,exp,fraction){var bits=[];bits.push(sign);for(var i=this.ebits;i>0;i-=1)bits[i]=exp%2?1:0,exp=Math.floor(exp/2);for(var len=bits.length,_i=this.fbits;_i>0;_i-=1)bits[len+_i]=fraction%2?1:0,fraction=Math.floor(fraction/2);for(var str=bits.join(""),numBytes=this.numBytes+index-1,k=index;numBytes>=index;)buffer[numBytes]=parseInt(str.substring(0,8),2),str=str.substring(8),numBytes--,k++;return k}},{key:"roundToEven",value:function(n){var w=Math.floor(n),f=n-w;return f<.5?w:f>.5?w+1:w%2?w+1:w}}]),IEEE754Buffer}(),UintBuffer=function(){function UintBuffer(bits){classCallCheck(this,UintBuffer),this.bits=bits,this.bytes=bits<8?1:Math.ceil(bits/8),this.max=Math.pow(2,bits)-1,this.min=0;var r=8-(1+(bits-1|7)-bits);this.lastByteMask_=Math.pow(2,r>0?r:8)-1}return createClass(UintBuffer,[{key:"pack",value:function(buffer,num){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(num!=num)throw new Error("NaN");this.overflow(num),buffer[index]=255&(num<0?num+Math.pow(2,this.bits):num),index++;for(var len=this.bytes,i=2;i<len;i++)buffer[index]=255&Math.floor(num/Math.pow(2,8*(i-1))),index++;return this.bits>8&&(buffer[index]=Math.floor(num/Math.pow(2,8*(this.bytes-1)))&this.lastByteMask_,index++),index}},{key:"unpack",value:function(buffer){var index=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,num=this.unpackUnsafe(buffer,index);return this.overflow(num),num}},{key:"unpackUnsafe",value:function(buffer,index){for(var num=0,x=0;x<this.bytes;x++)num+=buffer[index+x]*Math.pow(256,x);return num}},{key:"overflow",value:function(num){if(num>this.max||num<this.min)throw new Error("Overflow")}}]),UintBuffer}(),TwosComplementBuffer=function(_UintBuffer){function TwosComplementBuffer(bits){classCallCheck(this,TwosComplementBuffer);var _this=possibleConstructorReturn(this,(TwosComplementBuffer.__proto__||Object.getPrototypeOf(TwosComplementBuffer)).call(this,bits));return _this.max=Math.pow(2,_this.bits)/2-1,_this.min=-_this.max-1,_this}return inherits(TwosComplementBuffer,UintBuffer),createClass(TwosComplementBuffer,[{key:"pack",value:function(buffer,num){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return get(TwosComplementBuffer.prototype.__proto__||Object.getPrototypeOf(TwosComplementBuffer.prototype),"pack",this).call(this,buffer,num,index)}},{key:"unpack",value:function(buffer){var index=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,num=get(TwosComplementBuffer.prototype.__proto__||Object.getPrototypeOf(TwosComplementBuffer.prototype),"unpackUnsafe",this).call(this,buffer,index);return num=this.sign_(num),this.overflow(num),num}},{key:"sign_",value:function(num){return num>this.max&&(num-=2*this.max+2),num}}]),TwosComplementBuffer}(),NumberBuffer=function(){function NumberBuffer(bits,fp,signed){classCallCheck(this,NumberBuffer),this.parser=null,fp?(!function(bits){if(!bits||16!==bits&&32!==bits&&64!==bits)throw new Error(TYPE_ERR+": float, bits: "+bits)}(bits),this.parser=this.getFPParser_(bits)):(!function(bits){if(!bits||bits<1||bits>53)throw new Error(TYPE_ERR+": int, bits: "+bits)}(bits),this.parser=signed?new TwosComplementBuffer(bits):new UintBuffer(bits),this.parser.bytes=8===this.parser.bytes?4:this.parser.bytes)}return createClass(NumberBuffer,[{key:"unpack",value:function(buffer){var index=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.parser.unpack(buffer,index)}},{key:"pack",value:function(buffer,num){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return this.parser.pack(buffer,num,index)}},{key:"getFPParser_",value:function(bits){return 16===bits?new IEEE754Buffer(5,11):32===bits?new IEEE754Buffer(8,23):new IEEE754Buffer(11,52)}}]),NumberBuffer}();function unpackString(buffer){return function(buffer){for(var start=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,end=arguments.length>2&&void 0!==arguments[2]?arguments[2]:buffer.length,str="",index=start;index<end;){var lowerBoundary=128,upperBoundary=191,replace=!1,charCode=buffer[index++];if(charCode>=0&&charCode<=127)str+=String.fromCharCode(charCode);else{var count=0;charCode>=194&&charCode<=223?count=1:charCode>=224&&charCode<=239?(count=2,224===buffer[index]&&(lowerBoundary=160),237===buffer[index]&&(upperBoundary=159)):charCode>=240&&charCode<=244?(count=3,240===buffer[index]&&(lowerBoundary=144),244===buffer[index]&&(upperBoundary=143)):replace=!0,charCode&=(1<<8-count-1)-1;for(var i=0;i<count;i++)(buffer[index]<lowerBoundary||buffer[index]>upperBoundary)&&(replace=!0),charCode=charCode<<6|63&buffer[index],index++;replace?str+=String.fromCharCode(65533):charCode<=65535?str+=String.fromCharCode(charCode):(charCode-=65536,str+=String.fromCharCode(55296+(charCode>>10&1023),56320+(1023&charCode)))}}return str}(buffer,arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,arguments.length>2&&void 0!==arguments[2]?arguments[2]:buffer.length)}function packString(str){var buffer=[];return pack(str,buffer,0),buffer}function packStringTo(str,buffer){return pack(str,buffer,arguments.length>2&&void 0!==arguments[2]?arguments[2]:0)}function pack$1(value,theType){var output=[];return packTo(value,theType,output),output}function packTo(value,theType,buffer){return packArrayTo([value],theType,buffer,arguments.length>3&&void 0!==arguments[3]?arguments[3]:0)}function packArrayTo(values,theType,buffer){var index=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,packer=new NumberBuffer((theType=theType||{}).bits,theType.fp,theType.signed),offset=offset_(theType.bits),validateInput=theType.fp?validateIsNumber:validateIsInt,i=0;try{for(var valuesLen=values.length;i<valuesLen;i++){validateInput(values[i]);for(var len=index+offset;index<len;)index=packer.pack(buffer,values[i],index);swap_(theType.be,buffer,offset,index-offset,index)}}catch(e){throw new Error(e.message+" at input index "+i)}return index}function unpack$1(buffer,theType){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return unpackArray(buffer,theType,index,index+offset_(theType.bits),!0)[0]}function unpackArray(buffer,theType){var output=[];return unpackArrayTo(buffer,theType,output,arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,arguments.length>3&&void 0!==arguments[3]?arguments[3]:buffer.length,arguments.length>4&&void 0!==arguments[4]&&arguments[4]),output}function unpackArrayTo(buffer,theType,output){var start=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,end=arguments.length>4&&void 0!==arguments[4]?arguments[4]:buffer.length,safe=arguments.length>5&&void 0!==arguments[5]&&arguments[5],packer=new NumberBuffer((theType=theType||{}).bits,theType.fp,theType.signed),offset=offset_(theType.bits),extra=(end-start)%offset;if(safe&&(extra||buffer.length<offset))throw new Error("Bad buffer length");end-=extra;var i=0;try{swap_(theType.be,buffer,offset,start,end);for(var j=start;j<end;j+=offset,i++)output[i]=packer.unpack(buffer,j);swap_(theType.be,buffer,offset,start,end)}catch(e){throw new Error(e.message+" at output index "+i)}}function swap_(flip,buffer,offset,start,end){flip&&function(bytes,offset){var start=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,end=arguments.length>3&&void 0!==arguments[3]?arguments[3]:bytes.length;if(end%offset)throw new Error("Bad buffer length.");for(var index=start;index<end;index+=offset)swap(bytes,offset,index)}(buffer,offset,start,end)}function offset_(bits){return bits<8?1:Math.ceil(bits/8)}var WAV_AUDIO_FORMATS={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};function makeWavHeader(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){return"4"==bitDepthCode?function(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){var header=createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options);return header.chunkSize=40+samplesLength,header.fmt.chunkSize=20,header.fmt.byteRate=4055,header.fmt.blockAlign=256,header.fmt.bitsPerSample=4,header.fmt.cbSize=2,header.fmt.validBitsPerSample=505,header.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*samplesLength},header}(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options):"8a"==bitDepthCode||"8m"==bitDepthCode?function(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){var header=createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options);return header.chunkSize=40+samplesLength,header.fmt.chunkSize=20,header.fmt.cbSize=2,header.fmt.validBitsPerSample=8,header.fact={chunkId:"fact",chunkSize:4,dwSampleLength:samplesLength},header}(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options):-1==Object.keys(WAV_AUDIO_FORMATS).indexOf(bitDepthCode)||numChannels>2?function(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){var header=createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options);return header.chunkSize=60+samplesLength,header.fmt.chunkSize=40,header.fmt.bitsPerSample=1+(parseInt(bitDepthCode,10)-1|7),header.fmt.cbSize=22,header.fmt.validBitsPerSample=parseInt(bitDepthCode,10),header.fmt.dwChannelMask=function(numChannels){var dwChannelMask=0;return 1===numChannels?dwChannelMask=4:2===numChannels?dwChannelMask=3:4===numChannels?dwChannelMask=51:6===numChannels?dwChannelMask=63:8===numChannels&&(dwChannelMask=1599),dwChannelMask}(numChannels),header.fmt.subformat=[1,1048576,2852126848,1905997824],header}(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options):createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options)}function createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){return{container:options.container,chunkSize:36+samplesLength,format:"WAVE",bitDepth:bitDepthCode,fmt:{chunkId:"fmt ",chunkSize:16,audioFormat:WAV_AUDIO_FORMATS[bitDepthCode]||65534,numChannels:numChannels,sampleRate:sampleRate,byteRate:numChannels*numBytes*sampleRate,blockAlign:numChannels*numBytes,bitsPerSample:parseInt(bitDepthCode,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}}}function validateWavHeader_(header){!function(header){if(!WAV_AUDIO_FORMATS[header.bitDepth]){if(parseInt(header.bitDepth,10)>8&&parseInt(header.bitDepth,10)<54)return!0;throw new Error("Invalid bit depth.")}}(header),function(header){var blockAlign=header.fmt.numChannels*header.fmt.bitsPerSample/8;if(header.fmt.numChannels<1||blockAlign>65535)throw new Error("Invalid number of channels.")}(header),function(header){var byteRate=header.fmt.numChannels*(header.fmt.bitsPerSample/8)*header.fmt.sampleRate;if(header.fmt.sampleRate<1||byteRate>4294967295)throw new Error("Invalid sample rate.")}(header)}var BufferIO=function(){function BufferIO(){classCallCheck(this,BufferIO),this.head_=0}return createClass(BufferIO,[{key:"writeString_",value:function(str,maxSize){var push=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],bytes=packString(str);if(push)for(var i=bytes.length;i<maxSize;i++)bytes.push(0);return bytes}},{key:"readZSTR_",value:function(bytes){for(var str="",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;i<bytes.length&&(this.head_++,0!==bytes[i]);i++)str+=unpackString(bytes,i,i+1);return str}},{key:"readString_",value:function(bytes,maxSize){var str;return str=unpackString(bytes,this.head_,this.head_+maxSize),this.head_+=maxSize,str}},{key:"read_",value:function(bytes,bdType){var size=bdType.bits/8,value=unpack$1(bytes,bdType,this.head_);return this.head_+=size,value}}]),BufferIO}(),io=new BufferIO;function writeWavBuffer(wav){var uInt32_={bits:32,be:!1},uInt16_={bits:16,be:!1};uInt16_.be="RIFX"===wav.container,uInt32_.be=uInt16_.be;for(var fileBody=[function(wav,uInt32_){var bytes=[];if(wav.junk.chunkId)return bytes.concat(packString(wav.junk.chunkId),pack$1(wav.junk.chunkData.length,uInt32_),wav.junk.chunkData);return bytes}(wav,uInt32_),function(wav,uInt32_){var bytes=[];wav.ds64.chunkId&&(bytes=bytes.concat(packString(wav.ds64.chunkId),pack$1(wav.ds64.chunkSize,uInt32_),pack$1(wav.ds64.riffSizeHigh,uInt32_),pack$1(wav.ds64.riffSizeLow,uInt32_),pack$1(wav.ds64.dataSizeHigh,uInt32_),pack$1(wav.ds64.dataSizeLow,uInt32_),pack$1(wav.ds64.originationTime,uInt32_),pack$1(wav.ds64.sampleCountHigh,uInt32_),pack$1(wav.ds64.sampleCountLow,uInt32_)));return bytes}(wav,uInt32_),function(wav,uInt32_,uInt16_){var bytes=[];(function(wav){for(var prop in wav.bext)if(wav.bext.hasOwnProperty(prop)&&wav.bext[prop]&&"timeReference"!=prop){wav.bext.chunkId="bext";break}(wav.bext.timeReference[0]||wav.bext.timeReference[1])&&(wav.bext.chunkId="bext")})(wav),wav.bext.chunkId&&(wav.bext.chunkSize=602+wav.bext.codingHistory.length,bytes=bytes.concat(packString(wav.bext.chunkId),pack$1(602+wav.bext.codingHistory.length,uInt32_),io.writeString_(wav.bext.description,256),io.writeString_(wav.bext.originator,32),io.writeString_(wav.bext.originatorReference,32),io.writeString_(wav.bext.originationDate,10),io.writeString_(wav.bext.originationTime,8),pack$1(wav.bext.timeReference[0],uInt32_),pack$1(wav.bext.timeReference[1],uInt32_),pack$1(wav.bext.version,uInt16_),io.writeString_(wav.bext.UMID,64),pack$1(wav.bext.loudnessValue,uInt16_),pack$1(wav.bext.loudnessRange,uInt16_),pack$1(wav.bext.maxTruePeakLevel,uInt16_),pack$1(wav.bext.maxMomentaryLoudness,uInt16_),pack$1(wav.bext.maxShortTermLoudness,uInt16_),io.writeString_(wav.bext.reserved,180),io.writeString_(wav.bext.codingHistory,wav.bext.codingHistory.length)));return bytes}(wav,uInt32_,uInt16_),function(wav,uInt32_,uInt16_){if(wav.fmt.chunkId)return[].concat(packString(wav.fmt.chunkId),pack$1(wav.fmt.chunkSize,uInt32_),pack$1(wav.fmt.audioFormat,uInt16_),pack$1(wav.fmt.numChannels,uInt16_),pack$1(wav.fmt.sampleRate,uInt32_),pack$1(wav.fmt.byteRate,uInt32_),pack$1(wav.fmt.blockAlign,uInt16_),pack$1(wav.fmt.bitsPerSample,uInt16_),function(wav,uInt32_,uInt16_){var extension=[];wav.fmt.chunkSize>16&&(extension=extension.concat(pack$1(wav.fmt.cbSize,uInt16_)));wav.fmt.chunkSize>18&&(extension=extension.concat(pack$1(wav.fmt.validBitsPerSample,uInt16_)));wav.fmt.chunkSize>20&&(extension=extension.concat(pack$1(wav.fmt.dwChannelMask,uInt32_)));wav.fmt.chunkSize>24&&(extension=extension.concat(pack$1(wav.fmt.subformat[0],uInt32_),pack$1(wav.fmt.subformat[1],uInt32_),pack$1(wav.fmt.subformat[2],uInt32_),pack$1(wav.fmt.subformat[3],uInt32_)));return extension}(wav,uInt32_,uInt16_));throw Error('Could not find the "fmt " chunk')}(wav,uInt32_,uInt16_),function(wav,uInt32_){var bytes=[];wav.fact.chunkId&&(bytes=bytes.concat(packString(wav.fact.chunkId),pack$1(wav.fact.chunkSize,uInt32_),pack$1(wav.fact.dwSampleLength,uInt32_)));return bytes}(wav,uInt32_),packString(wav.data.chunkId),pack$1(wav.data.samples.length,uInt32_),wav.data.samples,function(wav,uInt32_){var bytes=[];if(wav.cue.chunkId){var cuePointsBytes=function(wav,uInt32_){for(var points=[],i=0;i<wav.cue.dwCuePoints;i++)points=points.concat(pack$1(wav.cue.points[i].dwName,uInt32_),pack$1(wav.cue.points[i].dwPosition,uInt32_),packString(wav.cue.points[i].fccChunk),pack$1(wav.cue.points[i].dwChunkStart,uInt32_),pack$1(wav.cue.points[i].dwBlockStart,uInt32_),pack$1(wav.cue.points[i].dwSampleOffset,uInt32_));return points}(wav,uInt32_);bytes=bytes.concat(packString(wav.cue.chunkId),pack$1(cuePointsBytes.length+4,uInt32_),pack$1(wav.cue.dwCuePoints,uInt32_),cuePointsBytes)}return bytes}(wav,uInt32_),function(wav,uInt32_){var bytes=[];if(wav.smpl.chunkId){var smplLoopsBytes=function(wav,uInt32_){for(var loops=[],i=0;i<wav.smpl.dwNumSampleLoops;i++)loops=loops.concat(pack$1(wav.smpl.loops[i].dwName,uInt32_),pack$1(wav.smpl.loops[i].dwType,uInt32_),pack$1(wav.smpl.loops[i].dwStart,uInt32_),pack$1(wav.smpl.loops[i].dwEnd,uInt32_),pack$1(wav.smpl.loops[i].dwFraction,uInt32_),pack$1(wav.smpl.loops[i].dwPlayCount,uInt32_));return loops}(wav,uInt32_);bytes=bytes.concat(packString(wav.smpl.chunkId),pack$1(smplLoopsBytes.length+36,uInt32_),pack$1(wav.smpl.dwManufacturer,uInt32_),pack$1(wav.smpl.dwProduct,uInt32_),pack$1(wav.smpl.dwSamplePeriod,uInt32_),pack$1(wav.smpl.dwMIDIUnityNote,uInt32_),pack$1(wav.smpl.dwMIDIPitchFraction,uInt32_),pack$1(wav.smpl.dwSMPTEFormat,uInt32_),pack$1(wav.smpl.dwSMPTEOffset,uInt32_),pack$1(wav.smpl.dwNumSampleLoops,uInt32_),pack$1(wav.smpl.dwSamplerData,uInt32_),smplLoopsBytes)}return bytes}(wav,uInt32_),function(wav,uInt32_,uInt16_){for(var bytes=[],i=0;i<wav.LIST.length;i++){var subChunksBytes=getLISTSubChunksBytes_(wav.LIST[i].subChunks,wav.LIST[i].format,wav,uInt32_,uInt16_);bytes=bytes.concat(packString(wav.LIST[i].chunkId),pack$1(subChunksBytes.length+4,uInt32_),packString(wav.LIST[i].format),subChunksBytes)}return bytes}(wav,uInt32_,uInt16_)],fileBodyLength=0,i=0;i<fileBody.length;i++)fileBodyLength+=fileBody[i].length;var file=new Uint8Array(fileBodyLength+12),index=0;index=packTo(fileBodyLength+4,uInt32_,file,index=packStringTo(wav.container,file,index)),index=packStringTo(wav.format,file,index);for(var _i=0;_i<fileBody.length;_i++)file.set(fileBody[_i],index),index+=fileBody[_i].length;return file}function getLISTSubChunksBytes_(subChunks,format,wav,uInt32_,uInt16_){for(var bytes=[],i=0;i<subChunks.length;i++)"INFO"==format?(bytes=bytes.concat(packString(subChunks[i].chunkId),pack$1(subChunks[i].value.length+1,uInt32_),io.writeString_(subChunks[i].value,subChunks[i].value.length))).push(0):"adtl"==format&&(["labl","note"].indexOf(subChunks[i].chunkId)>-1?(bytes=bytes.concat(packString(subChunks[i].chunkId),pack$1(subChunks[i].value.length+4+1,uInt32_),pack$1(subChunks[i].dwName,uInt32_),io.writeString_(subChunks[i].value,subChunks[i].value.length))).push(0):"ltxt"==subChunks[i].chunkId&&(bytes=bytes.concat(getLtxtChunkBytes_(subChunks[i],wav,uInt32_,uInt16_)))),bytes.length%2&&bytes.push(0);return bytes}function getLtxtChunkBytes_(ltxt,wav,uInt32_,uInt16_){return[].concat(packString(ltxt.chunkId),pack$1(ltxt.value.length+20,uInt32_),pack$1(ltxt.dwName,uInt32_),pack$1(ltxt.dwSampleLength,uInt32_),pack$1(ltxt.dwPurposeID,uInt32_),pack$1(ltxt.dwCountry,uInt16_),pack$1(ltxt.dwLanguage,uInt16_),pack$1(ltxt.dwDialect,uInt16_),pack$1(ltxt.dwCodePage,uInt16_),io.writeString_(ltxt.value,ltxt.value.length))}var uInt32_={bits:32},head_=0;function riffChunks(buffer){head_=0;var chunkId=getChunkId_(buffer,0);uInt32_.be="RIFX"==chunkId;var format=unpackString(buffer,8,12);return head_+=4,{chunkId:chunkId,chunkSize:getChunkSize_(buffer,0),format:format,subChunks:getSubChunksIndex_(buffer)}}function findChunk(chunks,chunkId){for(var multiple=arguments.length>2&&void 0!==arguments[2]&&arguments[2],chunk=[],i=0;i<chunks.length;i++)if(chunks[i].chunkId==chunkId){if(!multiple)return chunks[i];chunk.push(chunks[i])}return"LIST"==chunkId&&chunk.length?chunk:null}function getSubChunksIndex_(buffer){for(var chunks=[],i=head_;i<=buffer.length-8;)chunks.push(getSubChunkIndex_(buffer,i)),i=(i+=8+chunks[chunks.length-1].chunkSize)%2?i+1:i;return chunks}function getSubChunkIndex_(buffer,index){var chunk={chunkId:getChunkId_(buffer,index),chunkSize:getChunkSize_(buffer,index)};if("LIST"==chunk.chunkId)chunk.format=unpackString(buffer,index+8,index+12),head_+=4,chunk.subChunks=getSubChunksIndex_(buffer);else{var realChunkSize=chunk.chunkSize%2?chunk.chunkSize+1:chunk.chunkSize;head_=index+8+realChunkSize,chunk.chunkData={start:index+8,end:head_}}return chunk}function getChunkId_(buffer,index){return head_+=4,unpackString(buffer,index,index+4)}function getChunkSize_(buffer,index){return head_+=4,unpack$1(buffer,uInt32_,index+4)}var io$1=new BufferIO;function readWavBuffer(buffer,samples,wav){io$1.head_=0;var uInt32_={bits:32,be:!1},uInt16_={bits:16,be:!1};!function(bytes,wav,uInt32_,uInt16_){if(io$1.head_=0,wav.container=io$1.readString_(bytes,4),-1===["RIFF","RIFX","RF64"].indexOf(wav.container))throw Error("Not a supported format.");if(uInt16_.be="RIFX"===wav.container,uInt32_.be=uInt16_.be,wav.chunkSize=io$1.read_(bytes,uInt32_),wav.format=io$1.readString_(bytes,4),"WAVE"!=wav.format)throw Error('Could not find the "WAVE" format identifier')}(buffer,wav,uInt32_,uInt16_);var chunk=riffChunks(buffer);!function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"ds64");if(chunk)io$1.head_=chunk.chunkData.start,wav.ds64.chunkId=chunk.chunkId,wav.ds64.chunkSize=chunk.chunkSize,wav.ds64.riffSizeHigh=io$1.read_(buffer,uInt32_),wav.ds64.riffSizeLow=io$1.read_(buffer,uInt32_),wav.ds64.dataSizeHigh=io$1.read_(buffer,uInt32_),wav.ds64.dataSizeLow=io$1.read_(buffer,uInt32_),wav.ds64.originationTime=io$1.read_(buffer,uInt32_),wav.ds64.sampleCountHigh=io$1.read_(buffer,uInt32_),wav.ds64.sampleCountLow=io$1.read_(buffer,uInt32_);else if("RF64"==wav.container)throw Error('Could not find the "ds64" chunk')}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,wav,uInt32_,uInt16_){var chunk=findChunk(signature,"fmt ");if(!chunk)throw Error('Could not find the "fmt " chunk');io$1.head_=chunk.chunkData.start,wav.fmt.chunkId=chunk.chunkId,wav.fmt.chunkSize=chunk.chunkSize,wav.fmt.audioFormat=io$1.read_(buffer,uInt16_),wav.fmt.numChannels=io$1.read_(buffer,uInt16_),wav.fmt.sampleRate=io$1.read_(buffer,uInt32_),wav.fmt.byteRate=io$1.read_(buffer,uInt32_),wav.fmt.blockAlign=io$1.read_(buffer,uInt16_),wav.fmt.bitsPerSample=io$1.read_(buffer,uInt16_),function(buffer,wav,uInt32_,uInt16_){wav.fmt.chunkSize>16&&(wav.fmt.cbSize=io$1.read_(buffer,uInt16_),wav.fmt.chunkSize>18&&(wav.fmt.validBitsPerSample=io$1.read_(buffer,uInt16_),wav.fmt.chunkSize>20&&(wav.fmt.dwChannelMask=io$1.read_(buffer,uInt32_),wav.fmt.subformat=[io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_)])))}(buffer,wav,uInt32_,uInt16_)}(buffer,chunk.subChunks,wav,uInt32_,uInt16_),function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"fact");chunk&&(io$1.head_=chunk.chunkData.start,wav.fact.chunkId=chunk.chunkId,wav.fact.chunkSize=chunk.chunkSize,wav.fact.dwSampleLength=io$1.read_(buffer,uInt32_))}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,wav,uInt32_,uInt16_){var chunk=findChunk(signature,"bext");chunk&&(io$1.head_=chunk.chunkData.start,wav.bext.chunkId=chunk.chunkId,wav.bext.chunkSize=chunk.chunkSize,wav.bext.description=io$1.readString_(buffer,256),wav.bext.originator=io$1.readString_(buffer,32),wav.bext.originatorReference=io$1.readString_(buffer,32),wav.bext.originationDate=io$1.readString_(buffer,10),wav.bext.originationTime=io$1.readString_(buffer,8),wav.bext.timeReference=[io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_)],wav.bext.version=io$1.read_(buffer,uInt16_),wav.bext.UMID=io$1.readString_(buffer,64),wav.bext.loudnessValue=io$1.read_(buffer,uInt16_),wav.bext.loudnessRange=io$1.read_(buffer,uInt16_),wav.bext.maxTruePeakLevel=io$1.read_(buffer,uInt16_),wav.bext.maxMomentaryLoudness=io$1.read_(buffer,uInt16_),wav.bext.maxShortTermLoudness=io$1.read_(buffer,uInt16_),wav.bext.reserved=io$1.readString_(buffer,180),wav.bext.codingHistory=io$1.readString_(buffer,wav.bext.chunkSize-602))}(buffer,chunk.subChunks,wav,uInt32_,uInt16_),function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"cue ");if(chunk){io$1.head_=chunk.chunkData.start,wav.cue.chunkId=chunk.chunkId,wav.cue.chunkSize=chunk.chunkSize,wav.cue.dwCuePoints=io$1.read_(buffer,uInt32_);for(var i=0;i<wav.cue.dwCuePoints;i++)wav.cue.points.push({dwName:io$1.read_(buffer,uInt32_),dwPosition:io$1.read_(buffer,uInt32_),fccChunk:io$1.readString_(buffer,4),dwChunkStart:io$1.read_(buffer,uInt32_),dwBlockStart:io$1.read_(buffer,uInt32_),dwSampleOffset:io$1.read_(buffer,uInt32_)})}}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"smpl");if(chunk){io$1.head_=chunk.chunkData.start,wav.smpl.chunkId=chunk.chunkId,wav.smpl.chunkSize=chunk.chunkSize,wav.smpl.dwManufacturer=io$1.read_(buffer,uInt32_),wav.smpl.dwProduct=io$1.read_(buffer,uInt32_),wav.smpl.dwSamplePeriod=io$1.read_(buffer,uInt32_),wav.smpl.dwMIDIUnityNote=io$1.read_(buffer,uInt32_),wav.smpl.dwMIDIPitchFraction=io$1.read_(buffer,uInt32_),wav.smpl.dwSMPTEFormat=io$1.read_(buffer,uInt32_),wav.smpl.dwSMPTEOffset=io$1.read_(buffer,uInt32_),wav.smpl.dwNumSampleLoops=io$1.read_(buffer,uInt32_),wav.smpl.dwSamplerData=io$1.read_(buffer,uInt32_);for(var i=0;i<wav.smpl.dwNumSampleLoops;i++)wav.smpl.loops.push({dwName:io$1.read_(buffer,uInt32_),dwType:io$1.read_(buffer,uInt32_),dwStart:io$1.read_(buffer,uInt32_),dwEnd:io$1.read_(buffer,uInt32_),dwFraction:io$1.read_(buffer,uInt32_),dwPlayCount:io$1.read_(buffer,uInt32_)})}}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,samples,wav){var chunk=findChunk(signature,"data");if(!chunk)throw Error('Could not find the "data" chunk');wav.data.chunkId="data",wav.data.chunkSize=chunk.chunkSize,samples&&(wav.data.samples=buffer.slice(chunk.chunkData.start,chunk.chunkData.end))}(buffer,chunk.subChunks,samples,wav),function(buffer,signature,wav){var chunk=findChunk(signature,"junk");chunk&&(wav.junk={chunkId:chunk.chunkId,chunkSize:chunk.chunkSize,chunkData:[].slice.call(buffer.slice(chunk.chunkData.start,chunk.chunkData.end))})}(buffer,chunk.subChunks,wav),function(buffer,signature,wav,uInt32_,uInt16_){var listChunks=findChunk(signature,"LIST",!0);if(null===listChunks)return;for(var j=0;j<listChunks.length;j++){var subChunk=listChunks[j];wav.LIST.push({chunkId:subChunk.chunkId,chunkSize:subChunk.chunkSize,format:subChunk.format,subChunks:[]});for(var x=0;x<subChunk.subChunks.length;x++)readLISTSubChunks_(subChunk.subChunks[x],subChunk.format,buffer,wav,uInt32_,uInt16_)}}(buffer,chunk.subChunks,wav,uInt32_,uInt16_)}function readLISTSubChunks_(subChunk,format,buffer,wav,uInt32_,uInt16_){if("adtl"==format){if(["labl","note","ltxt"].indexOf(subChunk.chunkId)>-1){io$1.head_=subChunk.chunkData.start;var item={chunkId:subChunk.chunkId,chunkSize:subChunk.chunkSize,dwName:io$1.read_(buffer,uInt32_)};"ltxt"==subChunk.chunkId&&(item.dwSampleLength=io$1.read_(buffer,uInt32_),item.dwPurposeID=io$1.read_(buffer,uInt32_),item.dwCountry=io$1.read_(buffer,uInt16_),item.dwLanguage=io$1.read_(buffer,uInt16_),item.dwDialect=io$1.read_(buffer,uInt16_),item.dwCodePage=io$1.read_(buffer,uInt16_)),item.value=io$1.readZSTR_(buffer,io$1.head_),wav.LIST[wav.LIST.length-1].subChunks.push(item)}}else"INFO"==format&&(io$1.head_=subChunk.chunkData.start,wav.LIST[wav.LIST.length-1].subChunks.push({chunkId:subChunk.chunkId,chunkSize:subChunk.chunkSize,value:io$1.readZSTR_(buffer,io$1.head_)}))}var WavBuffer=function WavBuffer(){classCallCheck(this,WavBuffer),this.container="",this.chunkSize=0,this.format="",this.fmt={chunkId:"",chunkSize:0,audioFormat:0,numChannels:0,sampleRate:0,byteRate:0,blockAlign:0,bitsPerSample:0,cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]},this.fact={chunkId:"",chunkSize:0,dwSampleLength:0},this.cue={chunkId:"",chunkSize:0,dwCuePoints:0,points:[]},this.smpl={chunkId:"",chunkSize:0,dwManufacturer:0,dwProduct:0,dwSamplePeriod:0,dwMIDIUnityNote:0,dwMIDIPitchFraction:0,dwSMPTEFormat:0,dwSMPTEOffset:0,dwNumSampleLoops:0,dwSamplerData:0,loops:[]},this.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:""},this.ds64={chunkId:"",chunkSize:0,riffSizeHigh:0,riffSizeLow:0,dataSizeHigh:0,dataSizeLow:0,originationTime:0,sampleCountHigh:0,sampleCountLow:0},this.data={chunkId:"",chunkSize:0,samples:new Uint8Array(0)},this.LIST=[],this.junk={chunkId:"",chunkSize:0,chunkData:[]}};return function(_WavBuffer){function WaveFile(){var bytes=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;classCallCheck(this,WaveFile);var _this=possibleConstructorReturn(this,(WaveFile.__proto__||Object.getPrototypeOf(WaveFile)).call(this));return _this.bitDepth="0",_this.dataType={},bytes&&_this.fromBuffer(bytes),_this}return inherits(WaveFile,WavBuffer),createClass(WaveFile,[{key:"getSample",value:function(index){if((index*=this.dataType.bits/8)+this.dataType.bits/8>this.data.samples.length)throw new Error("Range error");return unpack$1(this.data.samples.slice(index,index+this.dataType.bits/8),this.dataType)}},{key:"setSample",value:function(index,sample){if((index*=this.dataType.bits/8)+this.dataType.bits/8>this.data.samples.length)throw new Error("Range error");packTo(sample,this.dataType,this.data.samples,index)}},{key:"fromScratch",value:function(numChannels,sampleRate,bitDepthCode,samples){var options=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};options.container||(options.container="RIFF"),this.container=options.container,this.bitDepth=bitDepthCode,samples=this.interleave_(samples),this.updateDataType_();var numBytes=this.dataType.bits/8;this.data.samples=new Uint8Array(samples.length*numBytes),packArrayTo(samples,this.dataType,this.data.samples);var header=makeWavHeader(bitDepthCode,numChannels,sampleRate,numBytes,this.data.samples.length,options);this.clearHeader_(),this.chunkSize=header.chunkSize,this.format=header.format,this.fmt=header.fmt,header.fact&&(this.fact=header.fact),this.data.chunkId="data",this.data.chunkSize=this.data.samples.length,validateWavHeader_(this)}},{key:"fromBuffer",value:function(bytes){var samples=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];this.clearHeader_(),readWavBuffer(bytes,samples,this),this.bitDepthFromFmt_(),this.updateDataType_()}},{key:"toBuffer",value:function(){return validateWavHeader_(this),writeWavBuffer(this)}},{key:"fromBase64",value:function(base64String){this.fromBuffer(new Uint8Array(function(base64){var len=base64.length,bufferLength=.75*base64.length,p=0,encoded1=void 0,encoded2=void 0,encoded3=void 0,encoded4=void 0;"="===base64[base64.length-1]&&(bufferLength--,"="===base64[base64.length-2]&&bufferLength--);for(var arraybuffer=new ArrayBuffer(bufferLength),bytes=new Uint8Array(arraybuffer),_i2=0;_i2<len;_i2+=4)encoded1=lookup[base64.charCodeAt(_i2)],encoded2=lookup[base64.charCodeAt(_i2+1)],encoded3=lookup[base64.charCodeAt(_i2+2)],encoded4=lookup[base64.charCodeAt(_i2+3)],bytes[p++]=encoded1<<2|encoded2>>4,bytes[p++]=(15&encoded2)<<4|encoded3>>2,bytes[p++]=(3&encoded3)<<6|63&encoded4;return arraybuffer}(base64String)))}},{key:"toBase64",value:function(){var buffer=this.toBuffer();return function(arraybuffer,byteOffset,length){for(var bytes=new Uint8Array(arraybuffer,byteOffset,length),len=bytes.length,base64="",_i=0;_i<len;_i+=3)base64+=chars[bytes[_i]>>2],base64+=chars[(3&bytes[_i])<<4|bytes[_i+1]>>4],base64+=chars[(15&bytes[_i+1])<<2|bytes[_i+2]>>6],base64+=chars[63&bytes[_i+2]];return len%3==2?base64=base64.substring(0,base64.length-1)+"=":len%3==1&&(base64=base64.substring(0,base64.length-2)+"=="),base64}(buffer,0,buffer.length)}},{key:"toDataURI",value:function(){return"data:audio/wav;base64,"+this.toBase64()}},{key:"fromDataURI",value:function(dataURI){this.fromBase64(dataURI.replace("data:audio/wav;base64,",""))}},{key:"toRIFF",value:function(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,unpackArray(this.data.samples,this.dataType))}},{key:"toRIFX",value:function(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,unpackArray(this.data.samples,this.dataType),{container:"RIFX"})}},{key:"toBitDepth",value:function(newBitDepth){var changeResolution=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],toBitDepth=newBitDepth,thisBitDepth=this.bitDepth;changeResolution||("32f"!=newBitDepth&&(toBitDepth=this.dataType.bits.toString()),thisBitDepth=this.dataType.bits),this.assureUncompressed_();var sampleCount=this.data.samples.length/(this.dataType.bits/8),typedSamplesInput=new Float64Array(sampleCount+1),typedSamplesOutput=new Float64Array(sampleCount+1);unpackArrayTo(this.data.samples,this.dataType,typedSamplesInput),"32f"!=thisBitDepth&&"64"!=thisBitDepth||this.truncateSamples_(typedSamplesInput),bitDepth(typedSamplesInput,thisBitDepth,toBitDepth,typedSamplesOutput),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,newBitDepth,typedSamplesOutput,{container:this.correctContainer_()})}},{key:"toIMAADPCM",value:function(){if(8e3!==this.fmt.sampleRate)throw new Error("Only 8000 Hz files can be compressed as IMA-ADPCM.");if(1!==this.fmt.numChannels)throw new Error("Only mono files can be compressed as IMA-ADPCM.");this.assure16Bit_();var output=new Int16Array(this.data.samples.length/2);unpackArrayTo(this.data.samples,this.dataType,output),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"4",function(samples){for(var adpcmSamples=new Uint8Array(samples.length/2+512),block=[],fileIndex=0,i=0;i<samples.length;i++)i%505==0&&0!=i&&(adpcmSamples.set(encodeBlock(block),fileIndex),fileIndex+=256,block=[]),block.push(samples[i]);return adpcmSamples}(output),{container:this.correctContainer_()})}},{key:"fromIMAADPCM",value:function(){var bitDepthCode=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"16";this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(adpcmSamples){for(var blockAlign=arguments.length>1&&void 0!==arguments[1]?arguments[1]:256,samples=new Int16Array(2*adpcmSamples.length),block=[],fileIndex=0,i=0;i<adpcmSamples.length;i++)i%blockAlign==0&&0!=i&&(samples.set(decodeBlock(block),fileIndex),fileIndex+=2*blockAlign,block=[]),block.push(adpcmSamples[i]);return samples}(this.data.samples,this.fmt.blockAlign),{container:this.correctContainer_()}),"16"!=bitDepthCode&&this.toBitDepth(bitDepthCode)}},{key:"toALaw",value:function(){this.assure16Bit_();var output=new Int16Array(this.data.samples.length/2);unpackArrayTo(this.data.samples,this.dataType,output),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8a",function(samples){for(var aLawSamples=new Uint8Array(samples.length),i=0;i<samples.length;i++)aLawSamples[i]=encodeSample(samples[i]);return aLawSamples}(output),{container:this.correctContainer_()})}},{key:"fromALaw",value:function(){var bitDepthCode=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"16";this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(samples){for(var pcmSamples=new Int16Array(samples.length),i=0;i<samples.length;i++)pcmSamples[i]=decodeSample(samples[i]);return pcmSamples}(this.data.samples),{container:this.correctContainer_()}),"16"!=bitDepthCode&&this.toBitDepth(bitDepthCode)}},{key:"toMuLaw",value:function(){this.assure16Bit_();var output=new Int16Array(this.data.samples.length/2);unpackArrayTo(this.data.samples,this.dataType,output),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8m",function(samples){for(var sample,sign,exponent,muLawSamples=new Uint8Array(samples.length),i=0;i<samples.length;i++)muLawSamples[i]=(sample=samples[i],sign=void 0,exponent=void 0,0!=(sign=sample>>8&128)&&(sample=-sample),sample>CLIP&&(sample=CLIP),~(sign|(exponent=encodeTable[(sample+=BIAS)>>7&255])<<4|sample>>exponent+3&15));return muLawSamples}(output),{container:this.correctContainer_()})}},{key:"fromMuLaw",value:function(){var bitDepthCode=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"16";this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(samples){for(var muLawSample,sign,exponent,mantissa,sample,pcmSamples=new Int16Array(samples.length),i=0;i<samples.length;i++)pcmSamples[i]=(muLawSample=samples[i],sign=void 0,exponent=void 0,mantissa=void 0,sample=void 0,sample=void 0,sign=128&(muLawSample=~muLawSample),mantissa=15&muLawSample,sample=decodeTable[exponent=muLawSample>>4&7]+(mantissa<<exponent+3),0!=sign&&(sample=-sample),sample);return pcmSamples}(this.data.samples),{container:this.correctContainer_()}),"16"!=bitDepthCode&&this.toBitDepth(bitDepthCode)}},{key:"setTag",value:function(tag,value){tag=this.fixTagName_(tag);var index=this.getTagIndex_(tag);null!==index.TAG?(this.LIST[index.LIST].subChunks[index.TAG].chunkSize=value.length+1,this.LIST[index.LIST].subChunks[index.TAG].value=value):null!==index.LIST?this.LIST[index.LIST].subChunks.push({chunkId:tag,chunkSize:value.length+1,value:value}):(this.LIST.push({chunkId:"LIST",chunkSize:8+value.length+1,format:"INFO",subChunks:[]}),this.LIST[this.LIST.length-1].subChunks.push({chunkId:tag,chunkSize:value.length+1,value:value}))}},{key:"getTag",value:function(tag){var index=this.getTagIndex_(tag);return null!==index.TAG?this.LIST[index.LIST].subChunks[index.TAG].value:null}},{key:"listTags",value:function(){var index=this.getLISTINFOIndex_(),tags={};if(null!==index)for(var i=0,len=this.LIST[index].subChunks.length;i<len;i++)tags[this.LIST[index].subChunks[i].chunkId]=this.LIST[index].subChunks[i].value;return tags}},{key:"deleteTag",value:function(tag){var index=this.getTagIndex_(tag);return null!==index.TAG&&(this.LIST[index.LIST].subChunks.splice(index.TAG,1),!0)}},{key:"setCuePoint",value:function(position){var labl=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";this.cue.chunkId="cue ",position=position*this.fmt.sampleRate/1e3;var existingPoints=this.getCuePoints_();this.clearLISTadtl_();var len=this.cue.points.length;this.cue.points=[];var hasSet=!1;if(0===len)this.setCuePoint_(position,1,labl);else{for(var i=0;i<len;i++)existingPoints[i].dwPosition>position&&!hasSet?(this.setCuePoint_(position,i+1,labl),this.setCuePoint_(existingPoints[i].dwPosition,i+2,existingPoints[i].label),hasSet=!0):this.setCuePoint_(existingPoints[i].dwPosition,i+1,existingPoints[i].label);hasSet||this.setCuePoint_(position,this.cue.points.length+1,labl)}this.cue.dwCuePoints=this.cue.points.length}},{key:"deleteCuePoint",value:function(index){this.cue.chunkId="cue ";var existingPoints=this.getCuePoints_();this.clearLISTadtl_();var len=this.cue.points.length;this.cue.points=[];for(var i=0;i<len;i++)i+1!==index&&this.setCuePoint_(existingPoints[i].dwPosition,i+1,existingPoints[i].label);this.cue.dwCuePoints=this.cue.points.length,this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.clearLISTadtl_())}},{key:"listCuePoints",value:function(){for(var points=this.getCuePoints_(),i=0,len=points.length;i<len;i++)points[i].milliseconds=points[i].dwPosition/this.fmt.sampleRate*1e3;return points}},{key:"updateLabel",value:function(pointIndex,label){var cIndex=this.getAdtlChunk_();if(null!==cIndex)for(var i=0,len=this.LIST[cIndex].subChunks.length;i<len;i++)this.LIST[cIndex].subChunks[i].dwName==pointIndex&&(this.LIST[cIndex].subChunks[i].value=label)}},{key:"bitDepthFromFmt_",value: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()}},{key:"setCuePoint_",value:function(position,dwName,label){this.cue.points.push({dwName:dwName,dwPosition:position,fccChunk:"data",dwChunkStart:0,dwBlockStart:0,dwSampleOffset:position}),this.setLabl_(dwName,label)}},{key:"getCuePoints_",value:function(){for(var points=[],i=0,len=this.cue.points.length;i<len;i++)points.push({dwPosition:this.cue.points[i].dwPosition,label:this.getLabelForCuePoint_(this.cue.points[i].dwName)});return points}},{key:"getLabelForCuePoint_",value:function(pointDwName){var cIndex=this.getAdtlChunk_();if(null!==cIndex)for(var i=0,len=this.LIST[cIndex].subChunks.length;i<len;i++)if(this.LIST[cIndex].subChunks[i].dwName==pointDwName)return this.LIST[cIndex].subChunks[i].value;return""}},{key:"clearLISTadtl_",value:function(){for(var i=0,len=this.LIST.length;i<len;i++)"adtl"==this.LIST[i].format&&this.LIST.splice(i)}},{key:"setLabl_",value:function(dwName,label){var adtlIndex=this.getAdtlChunk_();null===adtlIndex&&(this.LIST.push({chunkId:"LIST",chunkSize:4,format:"adtl",subChunks:[]}),adtlIndex=this.LIST.length-1),this.setLabelText_(null===adtlIndex?0:adtlIndex,dwName,label)}},{key:"setLabelText_",value:function(adtlIndex,dwName,label){this.LIST[adtlIndex].subChunks.push({chunkId:"labl",chunkSize:label.length,dwName:dwName,value:label}),this.LIST[adtlIndex].chunkSize+=label.length+4+4+4+1}},{key:"getAdtlChunk_",value:function(){for(var i=0,len=this.LIST.length;i<len;i++)if("adtl"==this.LIST[i].format)return i;return null}},{key:"getLISTINFOIndex_",value:function(){for(var index=null,i=0,len=this.LIST.length;i<len;i++)if("INFO"===this.LIST[i].format){index=i;break}return index}},{key:"getTagIndex_",value:function(tag){for(var index={LIST:null,TAG:null},i=0,len=this.LIST.length;i<len;i++)if("INFO"==this.LIST[i].format){index.LIST=i;for(var j=0,subLen=this.LIST[i].subChunks.length;j<subLen;j++)if(this.LIST[i].subChunks[j].chunkId==tag){index.TAG=j;break}break}return index}},{key:"fixTagName_",value:function(tag){if(tag.constructor!==String)throw new Error("Invalid tag name.");if(tag.length<4)for(var i=0,len=4-tag.length;i<len;i++)tag+=" ";return tag}},{key:"clearHeader_",value:function(){this.fmt.cbSize=0,this.fmt.validBitsPerSample=0,this.fact.chunkId="",this.ds64.chunkId=""}},{key:"assure16Bit_",value:function(){this.assureUncompressed_(),"16"!=this.bitDepth&&this.toBitDepth("16")}},{key:"assureUncompressed_",value:function(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()}},{key:"interleave_",value:function(samples){if(samples.length>0&&samples[0].constructor===Array){for(var finalSamples=[],i=0,len=samples[0].length;i<len;i++)for(var j=0,subLen=samples.length;j<subLen;j++)finalSamples.push(samples[j][i]);samples=finalSamples}return samples}},{key:"updateDataType_",value:function(){this.dataType={bits:1+(parseInt(this.bitDepth,10)-1|7),fp:"32f"==this.bitDepth||"64"==this.bitDepth,signed:"8"!=this.bitDepth,be:"RIFX"==this.container},["4","8a","8m"].indexOf(this.bitDepth)>-1&&(this.dataType.bits=8,this.dataType.signed=!1)}},{key:"correctContainer_",value:function(){return"RF64"==this.container?"RIFF":this.container}},{key:"truncateSamples_",value:function(samples){for(var i=0,len=samples.length;i<len;i++)samples[i]>1?samples[i]=1:samples[i]<-1&&(samples[i]=-1)}}]),WaveFile}()}); | ||
Array.prototype.includes||Object.defineProperty(Array.prototype,"includes",{value:function(searchElement,fromIndex){if(null==this)throw new TypeError('"this" is null or not defined');var o=Object(this),len=o.length>>>0;if(0===len)return!1;var x,y,n=0|fromIndex,k=Math.max(n>=0?n:len-Math.abs(n),0);for(;k<len;){if((x=o[k])===(y=searchElement)||"number"==typeof x&&"number"==typeof y&&isNaN(x)&&isNaN(y))return!0;k++}return!1}}),String.prototype.codePointAt||function(){"use strict";var defineProperty=function(){try{var object={},$defineProperty=Object.defineProperty,result=$defineProperty(object,object,object)&&$defineProperty}catch(error){}return result}(),codePointAt=function(position){if(null==this)throw TypeError();var string=String(this),size=string.length,index=position?Number(position):0;if(index!=index&&(index=0),!(index<0||index>=size)){var second,first=string.charCodeAt(index);return first>=55296&&first<=56319&&size>index+1&&(second=string.charCodeAt(index+1))>=56320&&second<=57343?1024*(first-55296)+second-56320+65536:first}};defineProperty?defineProperty(String.prototype,"codePointAt",{value:codePointAt,configurable:!0,writable:!0}):String.prototype.codePointAt=codePointAt}(),Uint8Array.prototype.slice||Object.defineProperty(Uint8Array.prototype,"slice",{value:Array.prototype.slice}),function(global,factory){"object"==typeof exports&&"undefined"!=typeof module?module.exports=factory():"function"==typeof define&&define.amd?define(factory):global.WaveFile=factory()}(this,function(){"use strict";var f64f32_=new Float32Array(1);function bitDepth(input,original,target,output){validateBitDepth_(original),validateBitDepth_(target);var toFunction=function(original,target){var func=function(x){return x};original!=target&&(func=["32f","64"].includes(original)?["32f","64"].includes(target)?floatToFloat_:floatToInt_:["32f","64"].includes(target)?intToFloat_:intToInt_);return func}(original,target),options={oldMin:Math.pow(2,parseInt(original,10))/2,newMin:Math.pow(2,parseInt(target,10))/2,oldMax:Math.pow(2,parseInt(original,10))/2-1,newMax:Math.pow(2,parseInt(target,10))/2-1},len=input.length;if("8"==original)for(var i=0;i<len;i++)output[i]=input[i]-=128;for(var _i=0;_i<len;_i++)output[_i]=toFunction(input[_i],options);if("8"==target)for(var _i2=0;_i2<len;_i2++)output[_i2]=output[_i2]+=128}function intToInt_(sample,args){return sample=sample>0?parseInt(sample/args.oldMax*args.newMax,10):parseInt(sample/args.oldMin*args.newMin,10)}function floatToInt_(sample,args){return parseInt(sample>0?sample*args.newMax:sample*args.newMin,10)}function intToFloat_(sample,args){return sample>0?sample/args.oldMax:sample/args.oldMin}function floatToFloat_(sample){return f64f32_[0]=sample,f64f32_[0]}function validateBitDepth_(bitDepth){if("32f"!=bitDepth&&"64"!=bitDepth&&(parseInt(bitDepth,10)<"8"||parseInt(bitDepth,10)>"53"))throw new Error("Invalid bit depth.")}var INDEX_TABLE=[-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8],STEP_TABLE=[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],encoderPredicted_=0,encoderIndex_=0,decoderPredicted_=0,decoderIndex_=0,decoderStep_=7;function encodeBlock(block){for(var adpcmSamples=function(sample){encodeSample_(sample);var adpcmSamples=[];return adpcmSamples.push(255&sample),adpcmSamples.push(sample>>8&255),adpcmSamples.push(encoderIndex_),adpcmSamples.push(0),adpcmSamples}(block[0]),i=3;i<block.length;i+=2){var sample2=encodeSample_(block[i]),sample=encodeSample_(block[i+1]);adpcmSamples.push(sample<<4|sample2)}for(;adpcmSamples.length<256;)adpcmSamples.push(0);return adpcmSamples}function decodeBlock(block){decoderPredicted_=sign_(block[1]<<8|block[0]),decoderIndex_=block[2],decoderStep_=STEP_TABLE[decoderIndex_];for(var result=[decoderPredicted_,sign_(block[3]<<8|block[2])],i=4;i<block.length;i++){var original_sample=block[i],second_sample=original_sample>>4,first_sample=second_sample<<4^original_sample;result.push(decodeSample_(first_sample)),result.push(decodeSample_(second_sample))}return result}function sign_(num){return num>32768?num-65536:num}function encodeSample_(sample){var delta=sample-encoderPredicted_,value=0;delta>=0?value=0:(value=8,delta=-delta);var step=STEP_TABLE[encoderIndex_],diff=step>>3;return delta>step&&(value|=4,delta-=step,diff+=step),delta>(step>>=1)&&(value|=2,delta-=step,diff+=step),delta>(step>>=1)&&(value|=1,diff+=step),function(value,diff){8&value?encoderPredicted_-=diff:encoderPredicted_+=diff;encoderPredicted_<-32768?encoderPredicted_=-32768:encoderPredicted_>32767&&(encoderPredicted_=32767);(encoderIndex_+=INDEX_TABLE[7&value])<0?encoderIndex_=0:encoderIndex_>88&&(encoderIndex_=88)}(value,diff),value}function decodeSample_(nibble){var difference=0;return 4&nibble&&(difference+=decoderStep_),2&nibble&&(difference+=decoderStep_>>1),1&nibble&&(difference+=decoderStep_>>2),difference+=decoderStep_>>3,8&nibble&&(difference=-difference),(decoderPredicted_+=difference)>32767?decoderPredicted_=32767:decoderPredicted_<-32767&&(decoderPredicted_=-32767),function(nibble){(decoderIndex_+=INDEX_TABLE[nibble])<0?decoderIndex_=0:decoderIndex_>88&&(decoderIndex_=88);decoderStep_=STEP_TABLE[decoderIndex_]}(nibble),decoderPredicted_}var LOG_TABLE=[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];function encodeSample(sample){var compandedValue=void 0,sign=~(sample=-32768==sample?-32767:sample)>>8&128;if(sign||(sample*=-1),sample>32635&&(sample=32635),sample>=256){var exponent=LOG_TABLE[sample>>8&127];compandedValue=exponent<<4|sample>>exponent+3&15}else compandedValue=sample>>4;return 85^compandedValue^sign}function decodeSample(aLawSample){var sign=0;128&(aLawSample^=85)&&(aLawSample&=-129,sign=-1);var position=4+((240&aLawSample)>>4),decoded=0;return decoded=4!=position?1<<position|(15&aLawSample)<<position-4|1<<position-5:aLawSample<<1|1,8*(decoded=0===sign?decoded:-decoded)*-1}var BIAS=132,CLIP=32635,encodeTable=[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],decodeTable=[0,132,396,924,1980,4092,8316,16764];for(var chars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",lookup=new Uint8Array(256),i=0;i<chars.length;i++)lookup[chars.charCodeAt(i)]=i;function swap(bytes,offset,index){offset--;for(var x=0;x<offset;x++){var theByte=bytes[index+x];bytes[index+x]=bytes[index+offset],bytes[index+offset]=theByte,offset--}}function pack(str,buffer){for(var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,i=0,len=str.length;i<len;i++){var codePoint=str.codePointAt(i);if(codePoint<128)buffer[index]=codePoint,index++;else{var count=0,offset=0;for(codePoint<=2047?(count=1,offset=192):codePoint<=65535?(count=2,offset=224):codePoint<=1114111&&(count=3,offset=240,i++),buffer[index]=(codePoint>>6*count)+offset,index++;count>0;)buffer[index]=128|codePoint>>6*(count-1)&63,index++,count--}}return index}var TYPE_ERR="Unsupported type",TYPE_NAN="Argument is not a valid number";function validateIsNumber(value){if(null==value)throw new Error(TYPE_NAN);if(value.constructor!=Number&&value.constructor!=Boolean)throw new Error(TYPE_NAN)}var classCallCheck=function(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")},createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}(),get=function get(object,property,receiver){null===object&&(object=Function.prototype);var desc=Object.getOwnPropertyDescriptor(object,property);if(void 0===desc){var parent=Object.getPrototypeOf(object);return null===parent?void 0:get(parent,property,receiver)}if("value"in desc)return desc.value;var getter=desc.get;return void 0!==getter?getter.call(receiver):void 0},inherits=function(subClass,superClass){if("function"!=typeof superClass&&null!==superClass)throw new TypeError("Super expression must either be null or a function, not "+typeof superClass);subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,enumerable:!1,writable:!0,configurable:!0}}),superClass&&(Object.setPrototypeOf?Object.setPrototypeOf(subClass,superClass):subClass.__proto__=superClass)},possibleConstructorReturn=function(self,call){if(!self)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!call||"object"!=typeof call&&"function"!=typeof call?self:call},IEEE754Buffer=function(){function IEEE754Buffer(ebits,fbits){classCallCheck(this,IEEE754Buffer),this.ebits=ebits,this.fbits=fbits,this.bias=(1<<ebits-1)-1,this.numBytes=Math.ceil((ebits+fbits)/8),this.biasP2=Math.pow(2,this.bias+1),this.ebitsFbits=ebits+fbits,this.fbias=Math.pow(2,-(8*this.numBytes-1-ebits))}return createClass(IEEE754Buffer,[{key:"pack",value:function(buffer,num,index){Math.abs(num)>this.biasP2-2*this.ebitsFbits&&(num=num<0?-1/0:1/0);var sign=((num=+num)||1/num)<0?1:num<0?1:0;num=Math.abs(num);var exp=Math.min(Math.floor(Math.log(num)/Math.LN2),1023),fraction=this.roundToEven(num/Math.pow(2,exp)*Math.pow(2,this.fbits));return num!=num?(fraction=Math.pow(2,this.fbits-1),exp=(1<<this.ebits)-1):0!==num&&(num>=Math.pow(2,1-this.bias)?(fraction/Math.pow(2,this.fbits)>=2&&(exp+=1,fraction=1),exp>this.bias?(exp=(1<<this.ebits)-1,fraction=0):(exp+=this.bias,fraction=this.roundToEven(fraction)-Math.pow(2,this.fbits))):(fraction=this.roundToEven(num/Math.pow(2,1-this.bias-this.fbits)),exp=0)),this.packFloatBits_(buffer,index,sign,exp,fraction)}},{key:"unpack",value:function(buffer,index){for(var eMax=(1<<this.ebits)-1,significand=void 0,leftBits="",i=this.numBytes-1;i>=0;i--){var t=buffer[i+index].toString(2);leftBits+="00000000".substring(t.length)+t}var sign="1"==leftBits.charAt(0)?-1:1;leftBits=leftBits.substring(1);var exponent=parseInt(leftBits.substring(0,this.ebits),2);return leftBits=leftBits.substring(this.ebits),exponent==eMax?0!==parseInt(leftBits,2)?NaN:sign*(1/0):(0===exponent?(exponent+=1,significand=parseInt(leftBits,2)):significand=parseInt("1"+leftBits,2),sign*significand*this.fbias*Math.pow(2,exponent-this.bias))}},{key:"packFloatBits_",value:function(buffer,index,sign,exp,fraction){var bits=[];bits.push(sign);for(var i=this.ebits;i>0;i-=1)bits[i]=exp%2?1:0,exp=Math.floor(exp/2);for(var len=bits.length,_i=this.fbits;_i>0;_i-=1)bits[len+_i]=fraction%2?1:0,fraction=Math.floor(fraction/2);for(var str=bits.join(""),numBytes=this.numBytes+index-1,k=index;numBytes>=index;)buffer[numBytes]=parseInt(str.substring(0,8),2),str=str.substring(8),numBytes--,k++;return k}},{key:"roundToEven",value:function(n){var w=Math.floor(n),f=n-w;return f<.5?w:f>.5?w+1:w%2?w+1:w}}]),IEEE754Buffer}(),UintBuffer=function(){function UintBuffer(bits){classCallCheck(this,UintBuffer),this.bits=bits,this.bytes=bits<8?1:Math.ceil(bits/8),this.max=Math.pow(2,bits)-1,this.min=0;var r=8-(1+(bits-1|7)-bits);this.lastByteMask_=Math.pow(2,r>0?r:8)-1}return createClass(UintBuffer,[{key:"pack",value:function(buffer,num){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if(num!=num)throw new Error("NaN");this.overflow(num),buffer[index]=255&(num<0?num+Math.pow(2,this.bits):num),index++;for(var len=this.bytes,i=2;i<len;i++)buffer[index]=255&Math.floor(num/Math.pow(2,8*(i-1))),index++;return this.bits>8&&(buffer[index]=Math.floor(num/Math.pow(2,8*(this.bytes-1)))&this.lastByteMask_,index++),index}},{key:"unpack",value:function(buffer){var index=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,num=this.unpackUnsafe(buffer,index);return this.overflow(num),num}},{key:"unpackUnsafe",value:function(buffer,index){for(var num=0,x=0;x<this.bytes;x++)num+=buffer[index+x]*Math.pow(256,x);return num}},{key:"overflow",value:function(num){if(num>this.max||num<this.min)throw new Error("Overflow")}}]),UintBuffer}(),TwosComplementBuffer=function(_UintBuffer){function TwosComplementBuffer(bits){classCallCheck(this,TwosComplementBuffer);var _this=possibleConstructorReturn(this,(TwosComplementBuffer.__proto__||Object.getPrototypeOf(TwosComplementBuffer)).call(this,bits));return _this.max=Math.pow(2,_this.bits)/2-1,_this.min=-_this.max-1,_this}return inherits(TwosComplementBuffer,UintBuffer),createClass(TwosComplementBuffer,[{key:"pack",value:function(buffer,num){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return get(TwosComplementBuffer.prototype.__proto__||Object.getPrototypeOf(TwosComplementBuffer.prototype),"pack",this).call(this,buffer,num,index)}},{key:"unpack",value:function(buffer){var index=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,num=get(TwosComplementBuffer.prototype.__proto__||Object.getPrototypeOf(TwosComplementBuffer.prototype),"unpackUnsafe",this).call(this,buffer,index);return num=this.sign_(num),this.overflow(num),num}},{key:"sign_",value:function(num){return num>this.max&&(num-=2*this.max+2),num}}]),TwosComplementBuffer}(),NumberBuffer=function(){function NumberBuffer(bits,fp,signed){classCallCheck(this,NumberBuffer);var parser=void 0;fp?(!function(bits){if(!bits||16!==bits&&32!==bits&&64!==bits)throw new Error(TYPE_ERR+": float, bits: "+bits)}(bits),parser=this.getFPParser_(bits)):(!function(bits){if(!bits||bits<1||bits>53)throw new Error(TYPE_ERR+": int, bits: "+bits)}(bits),parser=signed?new TwosComplementBuffer(bits):new UintBuffer(bits)),this.parser=parser}return createClass(NumberBuffer,[{key:"unpack",value:function(buffer){var index=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return this.parser.unpack(buffer,index)}},{key:"pack",value:function(buffer,num){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return this.parser.pack(buffer,num,index)}},{key:"getFPParser_",value:function(bits){return 16===bits?new IEEE754Buffer(5,11):32===bits?new IEEE754Buffer(8,23):new IEEE754Buffer(11,52)}}]),NumberBuffer}();function unpackString(buffer){return function(buffer){for(var start=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,end=arguments.length>2&&void 0!==arguments[2]?arguments[2]:buffer.length,str="",index=start;index<end;){var lowerBoundary=128,upperBoundary=191,replace=!1,charCode=buffer[index++];if(charCode>=0&&charCode<=127)str+=String.fromCharCode(charCode);else{var count=0;charCode>=194&&charCode<=223?count=1:charCode>=224&&charCode<=239?(count=2,224===buffer[index]&&(lowerBoundary=160),237===buffer[index]&&(upperBoundary=159)):charCode>=240&&charCode<=244?(count=3,240===buffer[index]&&(lowerBoundary=144),244===buffer[index]&&(upperBoundary=143)):replace=!0,charCode&=(1<<8-count-1)-1;for(var i=0;i<count;i++)(buffer[index]<lowerBoundary||buffer[index]>upperBoundary)&&(replace=!0),charCode=charCode<<6|63&buffer[index],index++;replace?str+=String.fromCharCode(65533):charCode<=65535?str+=String.fromCharCode(charCode):(charCode-=65536,str+=String.fromCharCode(55296+(charCode>>10&1023),56320+(1023&charCode)))}}return str}(buffer,arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,arguments.length>2&&void 0!==arguments[2]?arguments[2]:buffer.length)}function packString(str){var buffer=[];return pack(str,buffer,0),buffer}function packStringTo(str,buffer){return pack(str,buffer,arguments.length>2&&void 0!==arguments[2]?arguments[2]:0)}function pack$1(value,theType){var output=[];return packTo(value,theType,output),output}function packTo(value,theType,buffer){return packArrayTo([value],theType,buffer,arguments.length>3&&void 0!==arguments[3]?arguments[3]:0)}function packArrayTo(values,theType,buffer){var index=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,packer=new NumberBuffer((theType=theType||{}).bits,theType.fp,theType.signed),offset=Math.ceil(theType.bits/8),i=0;try{for(var valuesLen=values.length;i<valuesLen;i++){validateIsNumber(values[i]);for(var len=index+offset;index<len;)index=packer.pack(buffer,values[i],index);swap_(theType.be,buffer,offset,index-offset,index)}}catch(e){var value=values[i];throw theType.fp||value!==1/0&&value!==-1/0&&value==value?new Error(e.message+" at input index "+i):new Error("Argument is not a integer at input index "+i)}return index}function unpack$1(buffer,theType){var index=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return unpackArray(buffer,theType,index,index+Math.ceil(theType.bits/8),!0)[0]}function unpackArray(buffer,theType){var output=[];return unpackArrayTo(buffer,theType,output,arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,arguments.length>3&&void 0!==arguments[3]?arguments[3]:buffer.length,arguments.length>4&&void 0!==arguments[4]&&arguments[4]),output}function unpackArrayTo(buffer,theType,output){var start=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,end=arguments.length>4&&void 0!==arguments[4]?arguments[4]:buffer.length,safe=arguments.length>5&&void 0!==arguments[5]&&arguments[5],packer=new NumberBuffer((theType=theType||{}).bits,theType.fp,theType.signed),offset=Math.ceil(theType.bits/8),extra=(end-start)%offset;if(safe&&(extra||buffer.length<offset))throw new Error("Bad buffer length");end-=extra;var i=0;try{swap_(theType.be,buffer,offset,start,end);for(var j=start;j<end;j+=offset,i++)output[i]=packer.unpack(buffer,j);swap_(theType.be,buffer,offset,start,end)}catch(e){throw new Error(e.message+" at output index "+i)}}function swap_(flip,buffer,offset,start,end){flip&&function(bytes,offset){var start=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0,end=arguments.length>3&&void 0!==arguments[3]?arguments[3]:bytes.length;if(end%offset)throw new Error("Bad buffer length.");for(var index=start;index<end;index+=offset)swap(bytes,offset,index)}(buffer,offset,start,end)}var WAV_AUDIO_FORMATS={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};function makeWavHeader(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){return"4"==bitDepthCode?function(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){var header=createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options);return header.chunkSize=40+samplesLength,header.fmt.chunkSize=20,header.fmt.byteRate=4055,header.fmt.blockAlign=256,header.fmt.bitsPerSample=4,header.fmt.cbSize=2,header.fmt.validBitsPerSample=505,header.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*samplesLength},header}(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options):"8a"==bitDepthCode||"8m"==bitDepthCode?function(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){var header=createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options);return header.chunkSize=40+samplesLength,header.fmt.chunkSize=20,header.fmt.cbSize=2,header.fmt.validBitsPerSample=8,header.fact={chunkId:"fact",chunkSize:4,dwSampleLength:samplesLength},header}(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options):-1==Object.keys(WAV_AUDIO_FORMATS).indexOf(bitDepthCode)||numChannels>2?function(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){var header=createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options);return header.chunkSize=60+samplesLength,header.fmt.chunkSize=40,header.fmt.bitsPerSample=1+(parseInt(bitDepthCode,10)-1|7),header.fmt.cbSize=22,header.fmt.validBitsPerSample=parseInt(bitDepthCode,10),header.fmt.dwChannelMask=function(numChannels){var dwChannelMask=0;return 1===numChannels?dwChannelMask=4:2===numChannels?dwChannelMask=3:4===numChannels?dwChannelMask=51:6===numChannels?dwChannelMask=63:8===numChannels&&(dwChannelMask=1599),dwChannelMask}(numChannels),header.fmt.subformat=[1,1048576,2852126848,1905997824],header}(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options):createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options)}function createPCMHeader_(bitDepthCode,numChannels,sampleRate,numBytes,samplesLength,options){return{container:options.container,chunkSize:36+samplesLength,format:"WAVE",bitDepth:bitDepthCode,fmt:{chunkId:"fmt ",chunkSize:16,audioFormat:WAV_AUDIO_FORMATS[bitDepthCode]||65534,numChannels:numChannels,sampleRate:sampleRate,byteRate:numChannels*numBytes*sampleRate,blockAlign:numChannels*numBytes,bitsPerSample:parseInt(bitDepthCode,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}}}function validateWavHeader_(header){!function(header){if(!WAV_AUDIO_FORMATS[header.bitDepth]){if(parseInt(header.bitDepth,10)>8&&parseInt(header.bitDepth,10)<54)return!0;throw new Error("Invalid bit depth.")}}(header),function(header){var blockAlign=header.fmt.numChannels*header.fmt.bitsPerSample/8;if(header.fmt.numChannels<1||blockAlign>65535)throw new Error("Invalid number of channels.")}(header),function(header){var byteRate=header.fmt.numChannels*(header.fmt.bitsPerSample/8)*header.fmt.sampleRate;if(header.fmt.sampleRate<1||byteRate>4294967295)throw new Error("Invalid sample rate.")}(header)}var BufferIO=function(){function BufferIO(){classCallCheck(this,BufferIO),this.head_=0}return createClass(BufferIO,[{key:"writeString_",value:function(str,maxSize){var push=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],bytes=packString(str);if(push)for(var i=bytes.length;i<maxSize;i++)bytes.push(0);return bytes}},{key:"readZSTR_",value:function(bytes){for(var str="",i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;i<bytes.length&&(this.head_++,0!==bytes[i]);i++)str+=unpackString(bytes,i,i+1);return str}},{key:"readString_",value:function(bytes,maxSize){var str;return str=unpackString(bytes,this.head_,this.head_+maxSize),this.head_+=maxSize,str}},{key:"read_",value:function(bytes,bdType){var size=bdType.bits/8,value=unpack$1(bytes,bdType,this.head_);return this.head_+=size,value}}]),BufferIO}(),io=new BufferIO;function writeWavBuffer(wav){var uInt32_={bits:32,be:!1},uInt16_={bits:16,be:!1};uInt16_.be="RIFX"===wav.container,uInt32_.be=uInt16_.be;for(var fileBody=[function(wav,uInt32_){var bytes=[];if(wav.junk.chunkId)return bytes.concat(packString(wav.junk.chunkId),pack$1(wav.junk.chunkData.length,uInt32_),wav.junk.chunkData);return bytes}(wav,uInt32_),function(wav,uInt32_){var bytes=[];wav.ds64.chunkId&&(bytes=bytes.concat(packString(wav.ds64.chunkId),pack$1(wav.ds64.chunkSize,uInt32_),pack$1(wav.ds64.riffSizeHigh,uInt32_),pack$1(wav.ds64.riffSizeLow,uInt32_),pack$1(wav.ds64.dataSizeHigh,uInt32_),pack$1(wav.ds64.dataSizeLow,uInt32_),pack$1(wav.ds64.originationTime,uInt32_),pack$1(wav.ds64.sampleCountHigh,uInt32_),pack$1(wav.ds64.sampleCountLow,uInt32_)));return bytes}(wav,uInt32_),function(wav,uInt32_,uInt16_){var bytes=[];(function(wav){for(var prop in wav.bext)if(wav.bext.hasOwnProperty(prop)&&wav.bext[prop]&&"timeReference"!=prop){wav.bext.chunkId="bext";break}(wav.bext.timeReference[0]||wav.bext.timeReference[1])&&(wav.bext.chunkId="bext")})(wav),wav.bext.chunkId&&(wav.bext.chunkSize=602+wav.bext.codingHistory.length,bytes=bytes.concat(packString(wav.bext.chunkId),pack$1(602+wav.bext.codingHistory.length,uInt32_),io.writeString_(wav.bext.description,256),io.writeString_(wav.bext.originator,32),io.writeString_(wav.bext.originatorReference,32),io.writeString_(wav.bext.originationDate,10),io.writeString_(wav.bext.originationTime,8),pack$1(wav.bext.timeReference[0],uInt32_),pack$1(wav.bext.timeReference[1],uInt32_),pack$1(wav.bext.version,uInt16_),io.writeString_(wav.bext.UMID,64),pack$1(wav.bext.loudnessValue,uInt16_),pack$1(wav.bext.loudnessRange,uInt16_),pack$1(wav.bext.maxTruePeakLevel,uInt16_),pack$1(wav.bext.maxMomentaryLoudness,uInt16_),pack$1(wav.bext.maxShortTermLoudness,uInt16_),io.writeString_(wav.bext.reserved,180),io.writeString_(wav.bext.codingHistory,wav.bext.codingHistory.length)));return bytes}(wav,uInt32_,uInt16_),function(wav,uInt32_,uInt16_){if(wav.fmt.chunkId)return[].concat(packString(wav.fmt.chunkId),pack$1(wav.fmt.chunkSize,uInt32_),pack$1(wav.fmt.audioFormat,uInt16_),pack$1(wav.fmt.numChannels,uInt16_),pack$1(wav.fmt.sampleRate,uInt32_),pack$1(wav.fmt.byteRate,uInt32_),pack$1(wav.fmt.blockAlign,uInt16_),pack$1(wav.fmt.bitsPerSample,uInt16_),function(wav,uInt32_,uInt16_){var extension=[];wav.fmt.chunkSize>16&&(extension=extension.concat(pack$1(wav.fmt.cbSize,uInt16_)));wav.fmt.chunkSize>18&&(extension=extension.concat(pack$1(wav.fmt.validBitsPerSample,uInt16_)));wav.fmt.chunkSize>20&&(extension=extension.concat(pack$1(wav.fmt.dwChannelMask,uInt32_)));wav.fmt.chunkSize>24&&(extension=extension.concat(pack$1(wav.fmt.subformat[0],uInt32_),pack$1(wav.fmt.subformat[1],uInt32_),pack$1(wav.fmt.subformat[2],uInt32_),pack$1(wav.fmt.subformat[3],uInt32_)));return extension}(wav,uInt32_,uInt16_));throw Error('Could not find the "fmt " chunk')}(wav,uInt32_,uInt16_),function(wav,uInt32_){var bytes=[];wav.fact.chunkId&&(bytes=bytes.concat(packString(wav.fact.chunkId),pack$1(wav.fact.chunkSize,uInt32_),pack$1(wav.fact.dwSampleLength,uInt32_)));return bytes}(wav,uInt32_),packString(wav.data.chunkId),pack$1(wav.data.samples.length,uInt32_),wav.data.samples,function(wav,uInt32_){var bytes=[];if(wav.cue.chunkId){var cuePointsBytes=function(wav,uInt32_){for(var points=[],i=0;i<wav.cue.dwCuePoints;i++)points=points.concat(pack$1(wav.cue.points[i].dwName,uInt32_),pack$1(wav.cue.points[i].dwPosition,uInt32_),packString(wav.cue.points[i].fccChunk),pack$1(wav.cue.points[i].dwChunkStart,uInt32_),pack$1(wav.cue.points[i].dwBlockStart,uInt32_),pack$1(wav.cue.points[i].dwSampleOffset,uInt32_));return points}(wav,uInt32_);bytes=bytes.concat(packString(wav.cue.chunkId),pack$1(cuePointsBytes.length+4,uInt32_),pack$1(wav.cue.dwCuePoints,uInt32_),cuePointsBytes)}return bytes}(wav,uInt32_),function(wav,uInt32_){var bytes=[];if(wav.smpl.chunkId){var smplLoopsBytes=function(wav,uInt32_){for(var loops=[],i=0;i<wav.smpl.dwNumSampleLoops;i++)loops=loops.concat(pack$1(wav.smpl.loops[i].dwName,uInt32_),pack$1(wav.smpl.loops[i].dwType,uInt32_),pack$1(wav.smpl.loops[i].dwStart,uInt32_),pack$1(wav.smpl.loops[i].dwEnd,uInt32_),pack$1(wav.smpl.loops[i].dwFraction,uInt32_),pack$1(wav.smpl.loops[i].dwPlayCount,uInt32_));return loops}(wav,uInt32_);bytes=bytes.concat(packString(wav.smpl.chunkId),pack$1(smplLoopsBytes.length+36,uInt32_),pack$1(wav.smpl.dwManufacturer,uInt32_),pack$1(wav.smpl.dwProduct,uInt32_),pack$1(wav.smpl.dwSamplePeriod,uInt32_),pack$1(wav.smpl.dwMIDIUnityNote,uInt32_),pack$1(wav.smpl.dwMIDIPitchFraction,uInt32_),pack$1(wav.smpl.dwSMPTEFormat,uInt32_),pack$1(wav.smpl.dwSMPTEOffset,uInt32_),pack$1(wav.smpl.dwNumSampleLoops,uInt32_),pack$1(wav.smpl.dwSamplerData,uInt32_),smplLoopsBytes)}return bytes}(wav,uInt32_),function(wav,uInt32_,uInt16_){for(var bytes=[],i=0;i<wav.LIST.length;i++){var subChunksBytes=getLISTSubChunksBytes_(wav.LIST[i].subChunks,wav.LIST[i].format,wav,uInt32_,uInt16_);bytes=bytes.concat(packString(wav.LIST[i].chunkId),pack$1(subChunksBytes.length+4,uInt32_),packString(wav.LIST[i].format),subChunksBytes)}return bytes}(wav,uInt32_,uInt16_)],fileBodyLength=0,i=0;i<fileBody.length;i++)fileBodyLength+=fileBody[i].length;var file=new Uint8Array(fileBodyLength+12),index=0;index=packTo(fileBodyLength+4,uInt32_,file,index=packStringTo(wav.container,file,index)),index=packStringTo(wav.format,file,index);for(var _i=0;_i<fileBody.length;_i++)file.set(fileBody[_i],index),index+=fileBody[_i].length;return file}function getLISTSubChunksBytes_(subChunks,format,wav,uInt32_,uInt16_){for(var bytes=[],i=0;i<subChunks.length;i++)"INFO"==format?(bytes=bytes.concat(packString(subChunks[i].chunkId),pack$1(subChunks[i].value.length+1,uInt32_),io.writeString_(subChunks[i].value,subChunks[i].value.length))).push(0):"adtl"==format&&(["labl","note"].indexOf(subChunks[i].chunkId)>-1?(bytes=bytes.concat(packString(subChunks[i].chunkId),pack$1(subChunks[i].value.length+4+1,uInt32_),pack$1(subChunks[i].dwName,uInt32_),io.writeString_(subChunks[i].value,subChunks[i].value.length))).push(0):"ltxt"==subChunks[i].chunkId&&(bytes=bytes.concat(getLtxtChunkBytes_(subChunks[i],wav,uInt32_,uInt16_)))),bytes.length%2&&bytes.push(0);return bytes}function getLtxtChunkBytes_(ltxt,wav,uInt32_,uInt16_){return[].concat(packString(ltxt.chunkId),pack$1(ltxt.value.length+20,uInt32_),pack$1(ltxt.dwName,uInt32_),pack$1(ltxt.dwSampleLength,uInt32_),pack$1(ltxt.dwPurposeID,uInt32_),pack$1(ltxt.dwCountry,uInt16_),pack$1(ltxt.dwLanguage,uInt16_),pack$1(ltxt.dwDialect,uInt16_),pack$1(ltxt.dwCodePage,uInt16_),io.writeString_(ltxt.value,ltxt.value.length))}var uInt32_={bits:32},head_=0;function riffChunks(buffer){head_=0;var chunkId=getChunkId_(buffer,0);uInt32_.be="RIFX"==chunkId;var format=unpackString(buffer,8,12);return head_+=4,{chunkId:chunkId,chunkSize:getChunkSize_(buffer,0),format:format,subChunks:getSubChunksIndex_(buffer)}}function findChunk(chunks,chunkId){for(var multiple=arguments.length>2&&void 0!==arguments[2]&&arguments[2],chunk=[],i=0;i<chunks.length;i++)if(chunks[i].chunkId==chunkId){if(!multiple)return chunks[i];chunk.push(chunks[i])}return"LIST"==chunkId&&chunk.length?chunk:null}function getSubChunksIndex_(buffer){for(var chunks=[],i=head_;i<=buffer.length-8;)chunks.push(getSubChunkIndex_(buffer,i)),i=(i+=8+chunks[chunks.length-1].chunkSize)%2?i+1:i;return chunks}function getSubChunkIndex_(buffer,index){var chunk={chunkId:getChunkId_(buffer,index),chunkSize:getChunkSize_(buffer,index)};if("LIST"==chunk.chunkId)chunk.format=unpackString(buffer,index+8,index+12),head_+=4,chunk.subChunks=getSubChunksIndex_(buffer);else{var realChunkSize=chunk.chunkSize%2?chunk.chunkSize+1:chunk.chunkSize;head_=index+8+realChunkSize,chunk.chunkData={start:index+8,end:head_}}return chunk}function getChunkId_(buffer,index){return head_+=4,unpackString(buffer,index,index+4)}function getChunkSize_(buffer,index){return head_+=4,unpack$1(buffer,uInt32_,index+4)}var io$1=new BufferIO;function readWavBuffer(buffer,samples,wav){io$1.head_=0;var uInt32_={bits:32,be:!1},uInt16_={bits:16,be:!1};!function(bytes,wav,uInt32_,uInt16_){if(io$1.head_=0,wav.container=io$1.readString_(bytes,4),-1===["RIFF","RIFX","RF64"].indexOf(wav.container))throw Error("Not a supported format.");if(uInt16_.be="RIFX"===wav.container,uInt32_.be=uInt16_.be,wav.chunkSize=io$1.read_(bytes,uInt32_),wav.format=io$1.readString_(bytes,4),"WAVE"!=wav.format)throw Error('Could not find the "WAVE" format identifier')}(buffer,wav,uInt32_,uInt16_);var chunk=riffChunks(buffer);!function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"ds64");if(chunk)io$1.head_=chunk.chunkData.start,wav.ds64.chunkId=chunk.chunkId,wav.ds64.chunkSize=chunk.chunkSize,wav.ds64.riffSizeHigh=io$1.read_(buffer,uInt32_),wav.ds64.riffSizeLow=io$1.read_(buffer,uInt32_),wav.ds64.dataSizeHigh=io$1.read_(buffer,uInt32_),wav.ds64.dataSizeLow=io$1.read_(buffer,uInt32_),wav.ds64.originationTime=io$1.read_(buffer,uInt32_),wav.ds64.sampleCountHigh=io$1.read_(buffer,uInt32_),wav.ds64.sampleCountLow=io$1.read_(buffer,uInt32_);else if("RF64"==wav.container)throw Error('Could not find the "ds64" chunk')}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,wav,uInt32_,uInt16_){var chunk=findChunk(signature,"fmt ");if(!chunk)throw Error('Could not find the "fmt " chunk');io$1.head_=chunk.chunkData.start,wav.fmt.chunkId=chunk.chunkId,wav.fmt.chunkSize=chunk.chunkSize,wav.fmt.audioFormat=io$1.read_(buffer,uInt16_),wav.fmt.numChannels=io$1.read_(buffer,uInt16_),wav.fmt.sampleRate=io$1.read_(buffer,uInt32_),wav.fmt.byteRate=io$1.read_(buffer,uInt32_),wav.fmt.blockAlign=io$1.read_(buffer,uInt16_),wav.fmt.bitsPerSample=io$1.read_(buffer,uInt16_),function(buffer,wav,uInt32_,uInt16_){wav.fmt.chunkSize>16&&(wav.fmt.cbSize=io$1.read_(buffer,uInt16_),wav.fmt.chunkSize>18&&(wav.fmt.validBitsPerSample=io$1.read_(buffer,uInt16_),wav.fmt.chunkSize>20&&(wav.fmt.dwChannelMask=io$1.read_(buffer,uInt32_),wav.fmt.subformat=[io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_)])))}(buffer,wav,uInt32_,uInt16_)}(buffer,chunk.subChunks,wav,uInt32_,uInt16_),function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"fact");chunk&&(io$1.head_=chunk.chunkData.start,wav.fact.chunkId=chunk.chunkId,wav.fact.chunkSize=chunk.chunkSize,wav.fact.dwSampleLength=io$1.read_(buffer,uInt32_))}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,wav,uInt32_,uInt16_){var chunk=findChunk(signature,"bext");chunk&&(io$1.head_=chunk.chunkData.start,wav.bext.chunkId=chunk.chunkId,wav.bext.chunkSize=chunk.chunkSize,wav.bext.description=io$1.readString_(buffer,256),wav.bext.originator=io$1.readString_(buffer,32),wav.bext.originatorReference=io$1.readString_(buffer,32),wav.bext.originationDate=io$1.readString_(buffer,10),wav.bext.originationTime=io$1.readString_(buffer,8),wav.bext.timeReference=[io$1.read_(buffer,uInt32_),io$1.read_(buffer,uInt32_)],wav.bext.version=io$1.read_(buffer,uInt16_),wav.bext.UMID=io$1.readString_(buffer,64),wav.bext.loudnessValue=io$1.read_(buffer,uInt16_),wav.bext.loudnessRange=io$1.read_(buffer,uInt16_),wav.bext.maxTruePeakLevel=io$1.read_(buffer,uInt16_),wav.bext.maxMomentaryLoudness=io$1.read_(buffer,uInt16_),wav.bext.maxShortTermLoudness=io$1.read_(buffer,uInt16_),wav.bext.reserved=io$1.readString_(buffer,180),wav.bext.codingHistory=io$1.readString_(buffer,wav.bext.chunkSize-602))}(buffer,chunk.subChunks,wav,uInt32_,uInt16_),function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"cue ");if(chunk){io$1.head_=chunk.chunkData.start,wav.cue.chunkId=chunk.chunkId,wav.cue.chunkSize=chunk.chunkSize,wav.cue.dwCuePoints=io$1.read_(buffer,uInt32_);for(var i=0;i<wav.cue.dwCuePoints;i++)wav.cue.points.push({dwName:io$1.read_(buffer,uInt32_),dwPosition:io$1.read_(buffer,uInt32_),fccChunk:io$1.readString_(buffer,4),dwChunkStart:io$1.read_(buffer,uInt32_),dwBlockStart:io$1.read_(buffer,uInt32_),dwSampleOffset:io$1.read_(buffer,uInt32_)})}}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,wav,uInt32_){var chunk=findChunk(signature,"smpl");if(chunk){io$1.head_=chunk.chunkData.start,wav.smpl.chunkId=chunk.chunkId,wav.smpl.chunkSize=chunk.chunkSize,wav.smpl.dwManufacturer=io$1.read_(buffer,uInt32_),wav.smpl.dwProduct=io$1.read_(buffer,uInt32_),wav.smpl.dwSamplePeriod=io$1.read_(buffer,uInt32_),wav.smpl.dwMIDIUnityNote=io$1.read_(buffer,uInt32_),wav.smpl.dwMIDIPitchFraction=io$1.read_(buffer,uInt32_),wav.smpl.dwSMPTEFormat=io$1.read_(buffer,uInt32_),wav.smpl.dwSMPTEOffset=io$1.read_(buffer,uInt32_),wav.smpl.dwNumSampleLoops=io$1.read_(buffer,uInt32_),wav.smpl.dwSamplerData=io$1.read_(buffer,uInt32_);for(var i=0;i<wav.smpl.dwNumSampleLoops;i++)wav.smpl.loops.push({dwName:io$1.read_(buffer,uInt32_),dwType:io$1.read_(buffer,uInt32_),dwStart:io$1.read_(buffer,uInt32_),dwEnd:io$1.read_(buffer,uInt32_),dwFraction:io$1.read_(buffer,uInt32_),dwPlayCount:io$1.read_(buffer,uInt32_)})}}(buffer,chunk.subChunks,wav,uInt32_),function(buffer,signature,samples,wav){var chunk=findChunk(signature,"data");if(!chunk)throw Error('Could not find the "data" chunk');wav.data.chunkId="data",wav.data.chunkSize=chunk.chunkSize,samples&&(wav.data.samples=buffer.slice(chunk.chunkData.start,chunk.chunkData.end))}(buffer,chunk.subChunks,samples,wav),function(buffer,signature,wav){var chunk=findChunk(signature,"junk");chunk&&(wav.junk={chunkId:chunk.chunkId,chunkSize:chunk.chunkSize,chunkData:[].slice.call(buffer.slice(chunk.chunkData.start,chunk.chunkData.end))})}(buffer,chunk.subChunks,wav),function(buffer,signature,wav,uInt32_,uInt16_){var listChunks=findChunk(signature,"LIST",!0);if(null===listChunks)return;for(var j=0;j<listChunks.length;j++){var subChunk=listChunks[j];wav.LIST.push({chunkId:subChunk.chunkId,chunkSize:subChunk.chunkSize,format:subChunk.format,subChunks:[]});for(var x=0;x<subChunk.subChunks.length;x++)readLISTSubChunks_(subChunk.subChunks[x],subChunk.format,buffer,wav,uInt32_,uInt16_)}}(buffer,chunk.subChunks,wav,uInt32_,uInt16_)}function readLISTSubChunks_(subChunk,format,buffer,wav,uInt32_,uInt16_){if("adtl"==format){if(["labl","note","ltxt"].indexOf(subChunk.chunkId)>-1){io$1.head_=subChunk.chunkData.start;var item={chunkId:subChunk.chunkId,chunkSize:subChunk.chunkSize,dwName:io$1.read_(buffer,uInt32_)};"ltxt"==subChunk.chunkId&&(item.dwSampleLength=io$1.read_(buffer,uInt32_),item.dwPurposeID=io$1.read_(buffer,uInt32_),item.dwCountry=io$1.read_(buffer,uInt16_),item.dwLanguage=io$1.read_(buffer,uInt16_),item.dwDialect=io$1.read_(buffer,uInt16_),item.dwCodePage=io$1.read_(buffer,uInt16_)),item.value=io$1.readZSTR_(buffer,io$1.head_),wav.LIST[wav.LIST.length-1].subChunks.push(item)}}else"INFO"==format&&(io$1.head_=subChunk.chunkData.start,wav.LIST[wav.LIST.length-1].subChunks.push({chunkId:subChunk.chunkId,chunkSize:subChunk.chunkSize,value:io$1.readZSTR_(buffer,io$1.head_)}))}var WavBuffer=function WavBuffer(){classCallCheck(this,WavBuffer),this.container="",this.chunkSize=0,this.format="",this.fmt={chunkId:"",chunkSize:0,audioFormat:0,numChannels:0,sampleRate:0,byteRate:0,blockAlign:0,bitsPerSample:0,cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]},this.fact={chunkId:"",chunkSize:0,dwSampleLength:0},this.cue={chunkId:"",chunkSize:0,dwCuePoints:0,points:[]},this.smpl={chunkId:"",chunkSize:0,dwManufacturer:0,dwProduct:0,dwSamplePeriod:0,dwMIDIUnityNote:0,dwMIDIPitchFraction:0,dwSMPTEFormat:0,dwSMPTEOffset:0,dwNumSampleLoops:0,dwSamplerData:0,loops:[]},this.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:""},this.ds64={chunkId:"",chunkSize:0,riffSizeHigh:0,riffSizeLow:0,dataSizeHigh:0,dataSizeLow:0,originationTime:0,sampleCountHigh:0,sampleCountLow:0},this.data={chunkId:"",chunkSize:0,samples:new Uint8Array(0)},this.LIST=[],this.junk={chunkId:"",chunkSize:0,chunkData:[]}};return function(_WavBuffer){function WaveFile(){var bytes=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;classCallCheck(this,WaveFile);var _this=possibleConstructorReturn(this,(WaveFile.__proto__||Object.getPrototypeOf(WaveFile)).call(this));return _this.bitDepth="0",_this.dataType={},bytes&&_this.fromBuffer(bytes),_this}return inherits(WaveFile,WavBuffer),createClass(WaveFile,[{key:"getSample",value:function(index){if((index*=this.dataType.bits/8)+this.dataType.bits/8>this.data.samples.length)throw new Error("Range error");return unpack$1(this.data.samples.slice(index,index+this.dataType.bits/8),this.dataType)}},{key:"setSample",value:function(index,sample){if((index*=this.dataType.bits/8)+this.dataType.bits/8>this.data.samples.length)throw new Error("Range error");packTo(sample,this.dataType,this.data.samples,index)}},{key:"fromScratch",value:function(numChannels,sampleRate,bitDepthCode,samples){var options=arguments.length>4&&void 0!==arguments[4]?arguments[4]:{};options.container||(options.container="RIFF"),this.container=options.container,this.bitDepth=bitDepthCode,samples=this.interleave_(samples),this.updateDataType_();var numBytes=this.dataType.bits/8;this.data.samples=new Uint8Array(samples.length*numBytes),packArrayTo(samples,this.dataType,this.data.samples);var header=makeWavHeader(bitDepthCode,numChannels,sampleRate,numBytes,this.data.samples.length,options);this.clearHeader_(),this.chunkSize=header.chunkSize,this.format=header.format,this.fmt=header.fmt,header.fact&&(this.fact=header.fact),this.data.chunkId="data",this.data.chunkSize=this.data.samples.length,validateWavHeader_(this)}},{key:"fromBuffer",value:function(bytes){var samples=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];this.clearHeader_(),readWavBuffer(bytes,samples,this),this.bitDepthFromFmt_(),this.updateDataType_()}},{key:"toBuffer",value:function(){return validateWavHeader_(this),writeWavBuffer(this)}},{key:"fromBase64",value:function(base64String){this.fromBuffer(new Uint8Array(function(base64){var len=base64.length,bufferLength=.75*base64.length,p=0,encoded1=void 0,encoded2=void 0,encoded3=void 0,encoded4=void 0;"="===base64[base64.length-1]&&(bufferLength--,"="===base64[base64.length-2]&&bufferLength--);for(var arraybuffer=new ArrayBuffer(bufferLength),bytes=new Uint8Array(arraybuffer),_i2=0;_i2<len;_i2+=4)encoded1=lookup[base64.charCodeAt(_i2)],encoded2=lookup[base64.charCodeAt(_i2+1)],encoded3=lookup[base64.charCodeAt(_i2+2)],encoded4=lookup[base64.charCodeAt(_i2+3)],bytes[p++]=encoded1<<2|encoded2>>4,bytes[p++]=(15&encoded2)<<4|encoded3>>2,bytes[p++]=(3&encoded3)<<6|63&encoded4;return arraybuffer}(base64String)))}},{key:"toBase64",value:function(){var buffer=this.toBuffer();return function(arraybuffer,byteOffset,length){for(var bytes=new Uint8Array(arraybuffer,byteOffset,length),len=bytes.length,base64="",_i=0;_i<len;_i+=3)base64+=chars[bytes[_i]>>2],base64+=chars[(3&bytes[_i])<<4|bytes[_i+1]>>4],base64+=chars[(15&bytes[_i+1])<<2|bytes[_i+2]>>6],base64+=chars[63&bytes[_i+2]];return len%3==2?base64=base64.substring(0,base64.length-1)+"=":len%3==1&&(base64=base64.substring(0,base64.length-2)+"=="),base64}(buffer,0,buffer.length)}},{key:"toDataURI",value:function(){return"data:audio/wav;base64,"+this.toBase64()}},{key:"fromDataURI",value:function(dataURI){this.fromBase64(dataURI.replace("data:audio/wav;base64,",""))}},{key:"toRIFF",value:function(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,unpackArray(this.data.samples,this.dataType))}},{key:"toRIFX",value:function(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,unpackArray(this.data.samples,this.dataType),{container:"RIFX"})}},{key:"toBitDepth",value:function(newBitDepth){var changeResolution=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],toBitDepth=newBitDepth,thisBitDepth=this.bitDepth;changeResolution||("32f"!=newBitDepth&&(toBitDepth=this.dataType.bits.toString()),thisBitDepth=this.dataType.bits),this.assureUncompressed_();var sampleCount=this.data.samples.length/(this.dataType.bits/8),typedSamplesInput=new Float64Array(sampleCount+1),typedSamplesOutput=new Float64Array(sampleCount+1);unpackArrayTo(this.data.samples,this.dataType,typedSamplesInput),"32f"!=thisBitDepth&&"64"!=thisBitDepth||this.truncateSamples_(typedSamplesInput),bitDepth(typedSamplesInput,thisBitDepth,toBitDepth,typedSamplesOutput),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,newBitDepth,typedSamplesOutput,{container:this.correctContainer_()})}},{key:"toIMAADPCM",value:function(){if(8e3!==this.fmt.sampleRate)throw new Error("Only 8000 Hz files can be compressed as IMA-ADPCM.");if(1!==this.fmt.numChannels)throw new Error("Only mono files can be compressed as IMA-ADPCM.");this.assure16Bit_();var output=new Int16Array(this.data.samples.length/2);unpackArrayTo(this.data.samples,this.dataType,output),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"4",function(samples){for(var adpcmSamples=new Uint8Array(samples.length/2+512),block=[],fileIndex=0,i=0;i<samples.length;i++)i%505==0&&0!=i&&(adpcmSamples.set(encodeBlock(block),fileIndex),fileIndex+=256,block=[]),block.push(samples[i]);return adpcmSamples}(output),{container:this.correctContainer_()})}},{key:"fromIMAADPCM",value:function(){var bitDepthCode=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"16";this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(adpcmSamples){for(var blockAlign=arguments.length>1&&void 0!==arguments[1]?arguments[1]:256,samples=new Int16Array(2*adpcmSamples.length),block=[],fileIndex=0,i=0;i<adpcmSamples.length;i++)i%blockAlign==0&&0!=i&&(samples.set(decodeBlock(block),fileIndex),fileIndex+=2*blockAlign,block=[]),block.push(adpcmSamples[i]);return samples}(this.data.samples,this.fmt.blockAlign),{container:this.correctContainer_()}),"16"!=bitDepthCode&&this.toBitDepth(bitDepthCode)}},{key:"toALaw",value:function(){this.assure16Bit_();var output=new Int16Array(this.data.samples.length/2);unpackArrayTo(this.data.samples,this.dataType,output),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8a",function(samples){for(var aLawSamples=new Uint8Array(samples.length),i=0;i<samples.length;i++)aLawSamples[i]=encodeSample(samples[i]);return aLawSamples}(output),{container:this.correctContainer_()})}},{key:"fromALaw",value:function(){var bitDepthCode=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"16";this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(samples){for(var pcmSamples=new Int16Array(samples.length),i=0;i<samples.length;i++)pcmSamples[i]=decodeSample(samples[i]);return pcmSamples}(this.data.samples),{container:this.correctContainer_()}),"16"!=bitDepthCode&&this.toBitDepth(bitDepthCode)}},{key:"toMuLaw",value:function(){this.assure16Bit_();var output=new Int16Array(this.data.samples.length/2);unpackArrayTo(this.data.samples,this.dataType,output),this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8m",function(samples){for(var sample,sign,exponent,muLawSamples=new Uint8Array(samples.length),i=0;i<samples.length;i++)muLawSamples[i]=(sample=samples[i],sign=void 0,exponent=void 0,0!=(sign=sample>>8&128)&&(sample=-sample),sample>CLIP&&(sample=CLIP),~(sign|(exponent=encodeTable[(sample+=BIAS)>>7&255])<<4|sample>>exponent+3&15));return muLawSamples}(output),{container:this.correctContainer_()})}},{key:"fromMuLaw",value:function(){var bitDepthCode=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"16";this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",function(samples){for(var muLawSample,sign,exponent,mantissa,sample,pcmSamples=new Int16Array(samples.length),i=0;i<samples.length;i++)pcmSamples[i]=(muLawSample=samples[i],sign=void 0,exponent=void 0,mantissa=void 0,sample=void 0,sample=void 0,sign=128&(muLawSample=~muLawSample),mantissa=15&muLawSample,sample=decodeTable[exponent=muLawSample>>4&7]+(mantissa<<exponent+3),0!=sign&&(sample=-sample),sample);return pcmSamples}(this.data.samples),{container:this.correctContainer_()}),"16"!=bitDepthCode&&this.toBitDepth(bitDepthCode)}},{key:"setTag",value:function(tag,value){tag=this.fixTagName_(tag);var index=this.getTagIndex_(tag);null!==index.TAG?(this.LIST[index.LIST].subChunks[index.TAG].chunkSize=value.length+1,this.LIST[index.LIST].subChunks[index.TAG].value=value):null!==index.LIST?this.LIST[index.LIST].subChunks.push({chunkId:tag,chunkSize:value.length+1,value:value}):(this.LIST.push({chunkId:"LIST",chunkSize:8+value.length+1,format:"INFO",subChunks:[]}),this.LIST[this.LIST.length-1].subChunks.push({chunkId:tag,chunkSize:value.length+1,value:value}))}},{key:"getTag",value:function(tag){var index=this.getTagIndex_(tag);return null!==index.TAG?this.LIST[index.LIST].subChunks[index.TAG].value:null}},{key:"listTags",value:function(){var index=this.getLISTINFOIndex_(),tags={};if(null!==index)for(var i=0,len=this.LIST[index].subChunks.length;i<len;i++)tags[this.LIST[index].subChunks[i].chunkId]=this.LIST[index].subChunks[i].value;return tags}},{key:"deleteTag",value:function(tag){var index=this.getTagIndex_(tag);return null!==index.TAG&&(this.LIST[index.LIST].subChunks.splice(index.TAG,1),!0)}},{key:"setCuePoint",value:function(position){var labl=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";this.cue.chunkId="cue ",position=position*this.fmt.sampleRate/1e3;var existingPoints=this.getCuePoints_();this.clearLISTadtl_();var len=this.cue.points.length;this.cue.points=[];var hasSet=!1;if(0===len)this.setCuePoint_(position,1,labl);else{for(var i=0;i<len;i++)existingPoints[i].dwPosition>position&&!hasSet?(this.setCuePoint_(position,i+1,labl),this.setCuePoint_(existingPoints[i].dwPosition,i+2,existingPoints[i].label),hasSet=!0):this.setCuePoint_(existingPoints[i].dwPosition,i+1,existingPoints[i].label);hasSet||this.setCuePoint_(position,this.cue.points.length+1,labl)}this.cue.dwCuePoints=this.cue.points.length}},{key:"deleteCuePoint",value:function(index){this.cue.chunkId="cue ";var existingPoints=this.getCuePoints_();this.clearLISTadtl_();var len=this.cue.points.length;this.cue.points=[];for(var i=0;i<len;i++)i+1!==index&&this.setCuePoint_(existingPoints[i].dwPosition,i+1,existingPoints[i].label);this.cue.dwCuePoints=this.cue.points.length,this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.clearLISTadtl_())}},{key:"listCuePoints",value:function(){for(var points=this.getCuePoints_(),i=0,len=points.length;i<len;i++)points[i].milliseconds=points[i].dwPosition/this.fmt.sampleRate*1e3;return points}},{key:"updateLabel",value:function(pointIndex,label){var cIndex=this.getAdtlChunk_();if(null!==cIndex)for(var i=0,len=this.LIST[cIndex].subChunks.length;i<len;i++)this.LIST[cIndex].subChunks[i].dwName==pointIndex&&(this.LIST[cIndex].subChunks[i].value=label)}},{key:"bitDepthFromFmt_",value: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()}},{key:"setCuePoint_",value:function(position,dwName,label){this.cue.points.push({dwName:dwName,dwPosition:position,fccChunk:"data",dwChunkStart:0,dwBlockStart:0,dwSampleOffset:position}),this.setLabl_(dwName,label)}},{key:"getCuePoints_",value:function(){for(var points=[],i=0,len=this.cue.points.length;i<len;i++)points.push({dwPosition:this.cue.points[i].dwPosition,label:this.getLabelForCuePoint_(this.cue.points[i].dwName)});return points}},{key:"getLabelForCuePoint_",value:function(pointDwName){var cIndex=this.getAdtlChunk_();if(null!==cIndex)for(var i=0,len=this.LIST[cIndex].subChunks.length;i<len;i++)if(this.LIST[cIndex].subChunks[i].dwName==pointDwName)return this.LIST[cIndex].subChunks[i].value;return""}},{key:"clearLISTadtl_",value:function(){for(var i=0,len=this.LIST.length;i<len;i++)"adtl"==this.LIST[i].format&&this.LIST.splice(i)}},{key:"setLabl_",value:function(dwName,label){var adtlIndex=this.getAdtlChunk_();null===adtlIndex&&(this.LIST.push({chunkId:"LIST",chunkSize:4,format:"adtl",subChunks:[]}),adtlIndex=this.LIST.length-1),this.setLabelText_(null===adtlIndex?0:adtlIndex,dwName,label)}},{key:"setLabelText_",value:function(adtlIndex,dwName,label){this.LIST[adtlIndex].subChunks.push({chunkId:"labl",chunkSize:label.length,dwName:dwName,value:label}),this.LIST[adtlIndex].chunkSize+=label.length+4+4+4+1}},{key:"getAdtlChunk_",value:function(){for(var i=0,len=this.LIST.length;i<len;i++)if("adtl"==this.LIST[i].format)return i;return null}},{key:"getLISTINFOIndex_",value:function(){for(var index=null,i=0,len=this.LIST.length;i<len;i++)if("INFO"===this.LIST[i].format){index=i;break}return index}},{key:"getTagIndex_",value:function(tag){for(var index={LIST:null,TAG:null},i=0,len=this.LIST.length;i<len;i++)if("INFO"==this.LIST[i].format){index.LIST=i;for(var j=0,subLen=this.LIST[i].subChunks.length;j<subLen;j++)if(this.LIST[i].subChunks[j].chunkId==tag){index.TAG=j;break}break}return index}},{key:"fixTagName_",value:function(tag){if(tag.constructor!==String)throw new Error("Invalid tag name.");if(tag.length<4)for(var i=0,len=4-tag.length;i<len;i++)tag+=" ";return tag}},{key:"clearHeader_",value:function(){this.fmt.cbSize=0,this.fmt.validBitsPerSample=0,this.fact.chunkId="",this.ds64.chunkId=""}},{key:"assure16Bit_",value:function(){this.assureUncompressed_(),"16"!=this.bitDepth&&this.toBitDepth("16")}},{key:"assureUncompressed_",value:function(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()}},{key:"interleave_",value:function(samples){if(samples.length>0&&samples[0].constructor===Array){for(var finalSamples=[],i=0,len=samples[0].length;i<len;i++)for(var j=0,subLen=samples.length;j<subLen;j++)finalSamples.push(samples[j][i]);samples=finalSamples}return samples}},{key:"updateDataType_",value:function(){this.dataType={bits:1+(parseInt(this.bitDepth,10)-1|7),fp:"32f"==this.bitDepth||"64"==this.bitDepth,signed:"8"!=this.bitDepth,be:"RIFX"==this.container},["4","8a","8m"].indexOf(this.bitDepth)>-1&&(this.dataType.bits=8,this.dataType.signed=!1)}},{key:"correctContainer_",value:function(){return"RF64"==this.container?"RIFF":this.container}},{key:"truncateSamples_",value:function(samples){for(var i=0,len=samples.length;i<len;i++)samples[i]>1?samples[i]=1:samples[i]<-1&&(samples[i]=-1)}}]),WaveFile}()}); |
@@ -0,4 +1,27 @@ | ||
/* | ||
* Copyright (c) 2017-2018 Rafael da Silva Rocha. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining | ||
* a copy of this software and associated documentation files (the | ||
* "Software"), to deal in the Software without restriction, including | ||
* without limitation the rights to use, copy, modify, merge, publish, | ||
* distribute, sublicense, and/or sell copies of the Software, and to | ||
* permit persons to whom the Software is furnished to do so, subject to | ||
* the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
/** | ||
* @fileoverview Externs for wavefile 9.0 | ||
* | ||
* @fileoverview Externs for wavefile 8.4 | ||
* @see https://github.com/rochars/wavefile | ||
@@ -16,7 +39,7 @@ * @externs | ||
*/ | ||
WaveFile.container = ''; | ||
WaveFile.prototype.container = ''; | ||
/** | ||
* @type {number} | ||
*/ | ||
WaveFile.chunkSize = 0; | ||
WaveFile.prototype.chunkSize = 0; | ||
/** | ||
@@ -27,3 +50,3 @@ * The format. | ||
*/ | ||
WaveFile.format = ''; | ||
WaveFile.prototype.format = ''; | ||
/** | ||
@@ -33,3 +56,3 @@ * The data of the fmt chunk. | ||
*/ | ||
WaveFile.fmt = { | ||
WaveFile.prototype.fmt = { | ||
/** @type {string} */ | ||
@@ -67,3 +90,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.fact = { | ||
WaveFile.prototype.fact = { | ||
/** @type {string} */ | ||
@@ -80,3 +103,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.cue = { | ||
WaveFile.prototype.cue = { | ||
/** @type {string} */ | ||
@@ -103,3 +126,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.smpl = { | ||
WaveFile.prototype.smpl = { | ||
/** @type {string} */ | ||
@@ -143,3 +166,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.bext = { | ||
WaveFile.prototype.bext = { | ||
/** @type {string} */ | ||
@@ -188,3 +211,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.ds64 = { | ||
WaveFile.prototype.ds64 = { | ||
/** @type {string} */ | ||
@@ -213,3 +236,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.data = { | ||
WaveFile.prototype.data = { | ||
/** @type {string} */ | ||
@@ -226,3 +249,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.LIST = [ | ||
WaveFile.prototype.LIST = [ | ||
{ | ||
@@ -265,3 +288,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.junk = { | ||
WaveFile.prototype.junk = { | ||
/** @type {string} */ | ||
@@ -278,3 +301,3 @@ chunkId: '', | ||
*/ | ||
WaveFile.bitDepth = ''; | ||
WaveFile.prototype.bitDepth = ''; | ||
@@ -287,3 +310,3 @@ /** | ||
*/ | ||
WaveFile.getSample = function(index) {}; | ||
WaveFile.prototype.getSample = function(index) {}; | ||
@@ -296,3 +319,3 @@ /** | ||
*/ | ||
WaveFile.setSample = function(index, sample) {}; | ||
WaveFile.prototype.setSample = function(index, sample) {}; | ||
@@ -315,4 +338,5 @@ /** | ||
*/ | ||
WaveFile.fromScratch = function( | ||
numChannels, sampleRate, bitDepthCode, samples, options={container:'RIFF'}) {}; | ||
WaveFile.prototype.fromScratch = function( | ||
numChannels, sampleRate, bitDepthCode, samples, options={ | ||
container:'RIFF'}) {}; | ||
@@ -327,3 +351,3 @@ /** | ||
*/ | ||
WaveFile.fromBuffer = function(bytes, samples=true) {}; | ||
WaveFile.prototype.fromBuffer = function(bytes, samples=true) {}; | ||
@@ -336,3 +360,3 @@ /** | ||
*/ | ||
WaveFile.toBuffer = function() {}; | ||
WaveFile.prototype.toBuffer = function() {}; | ||
@@ -344,3 +368,3 @@ /** | ||
*/ | ||
WaveFile.fromBase64 = function(base64String) {}; | ||
WaveFile.prototype.fromBase64 = function(base64String) {}; | ||
@@ -352,3 +376,3 @@ /** | ||
*/ | ||
WaveFile.toBase64 = function() {}; | ||
WaveFile.prototype.toBase64 = function() {}; | ||
@@ -361,3 +385,3 @@ /** | ||
*/ | ||
WaveFile.toDataURI = function() {}; | ||
WaveFile.prototype.toDataURI = function() {}; | ||
@@ -369,3 +393,3 @@ /** | ||
*/ | ||
WaveFile.fromDataURI = function(dataURI) {}; | ||
WaveFile.prototype.fromDataURI = function(dataURI) {}; | ||
@@ -375,3 +399,3 @@ /** | ||
*/ | ||
WaveFile.toRIFF = function() {}; | ||
WaveFile.prototype.toRIFF = function() {}; | ||
@@ -381,3 +405,3 @@ /** | ||
*/ | ||
WaveFile.toRIFX = function() {}; | ||
WaveFile.prototype.toRIFX = function() {}; | ||
@@ -392,3 +416,3 @@ /** | ||
*/ | ||
WaveFile.toBitDepth = function(newBitDepth, changeResolution=true) {}; | ||
WaveFile.prototype.toBitDepth = function(newBitDepth, changeResolution=true) {}; | ||
@@ -400,3 +424,3 @@ /** | ||
*/ | ||
WaveFile.toIMAADPCM = function() {}; | ||
WaveFile.prototype.toIMAADPCM = function() {}; | ||
@@ -409,3 +433,3 @@ /** | ||
*/ | ||
WaveFile.fromIMAADPCM = function(bitDepthCode='16') {}; | ||
WaveFile.prototype.fromIMAADPCM = function(bitDepthCode='16') {}; | ||
@@ -415,3 +439,3 @@ /** | ||
*/ | ||
WaveFile.toALaw = function() {}; | ||
WaveFile.prototype.toALaw = function() {}; | ||
@@ -424,3 +448,3 @@ /** | ||
*/ | ||
WaveFile.fromALaw = function(bitDepthCode='16') {}; | ||
WaveFile.prototype.fromALaw = function(bitDepthCode='16') {}; | ||
@@ -430,3 +454,3 @@ /** | ||
*/ | ||
WaveFile.toMuLaw = function() {}; | ||
WaveFile.prototype.toMuLaw = function() {}; | ||
@@ -439,3 +463,3 @@ /** | ||
*/ | ||
WaveFile.fromMuLaw = function(bitDepthCode='16') {}; | ||
WaveFile.prototype.fromMuLaw = function(bitDepthCode='16') {}; | ||
@@ -449,3 +473,3 @@ /** | ||
*/ | ||
WaveFile.setTag = function(tag, value) {}; | ||
WaveFile.prototype.setTag = function(tag, value) {}; | ||
@@ -457,3 +481,3 @@ /** | ||
*/ | ||
WaveFile.getTag = function(tag) {}; | ||
WaveFile.prototype.getTag = function(tag) {}; | ||
@@ -465,3 +489,3 @@ /** | ||
*/ | ||
WaveFile.deleteTag = function(tag) {}; | ||
WaveFile.prototype.deleteTag = function(tag) {}; | ||
@@ -473,3 +497,3 @@ /** | ||
*/ | ||
WaveFile.setCuePoint = function(position, labl='') {}; | ||
WaveFile.prototype.setCuePoint = function(position, labl='') {}; | ||
@@ -481,3 +505,3 @@ /** | ||
*/ | ||
WaveFile.deleteCuePoint = function(index) {}; | ||
WaveFile.prototype.deleteCuePoint = function(index) {}; | ||
@@ -489,3 +513,3 @@ /** | ||
*/ | ||
WaveFile.updateLabel = function(pointIndex, label) {}; | ||
WaveFile.prototype.updateLabel = function(pointIndex, label) {}; | ||
@@ -496,3 +520,3 @@ /** | ||
*/ | ||
WaveFile.listTags = function() {}; | ||
WaveFile.prototype.listTags = function() {}; | ||
@@ -508,2 +532,2 @@ /** | ||
*/ | ||
WaveFile.listCuePoints = function() {}; | ||
WaveFile.prototype.listCuePoints = function() {}; |
526
index.d.ts
@@ -1,2 +0,2 @@ | ||
// Type definitions for wavefile 9.0 | ||
// Type definitions for wavefile 8.4 | ||
// Project: https://github.com/rochars/wavefile | ||
@@ -9,291 +9,291 @@ // Definitions by: Rafael S. Rocha <https://github.com/rochars> | ||
declare class WaveFile { | ||
/** | ||
* @param {?Uint8Array=} bytes A wave file buffer. | ||
* @throws {Error} If no 'RIFF' chunk is found. | ||
* @throws {Error} If no 'fmt ' chunk is found. | ||
* @throws {Error} If no 'data' chunk is found. | ||
*/ | ||
constructor(bytes?: Uint8Array); | ||
/** | ||
* @param {?Uint8Array=} bytes A wave file buffer. | ||
* @throws {Error} If no 'RIFF' chunk is found. | ||
* @throws {Error} If no 'fmt ' chunk is found. | ||
* @throws {Error} If no 'data' chunk is found. | ||
*/ | ||
constructor(bytes?: Uint8Array); | ||
/** | ||
* The bit depth code according to the samples. | ||
* @type {string} | ||
*/ | ||
bitDepth: string; | ||
/** | ||
* The container identifier. | ||
* 'RIFF', 'RIFX' and 'RF64' are supported. | ||
* @type {string} | ||
*/ | ||
container: string; | ||
/** | ||
* @type {number} | ||
*/ | ||
chunkSize: number; | ||
/** | ||
* The format. | ||
* Always 'WAVE'. | ||
* @type {string} | ||
*/ | ||
format: string; | ||
/** | ||
* The data of the 'fmt' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
fmt: object; | ||
/** | ||
* The data of the 'fact' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
fact: object; | ||
/** | ||
* The data of the 'cue ' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
cue: object; | ||
/** | ||
* The data of the 'smpl' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
smpl: object; | ||
/** | ||
* The data of the 'bext' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
bext: object; | ||
/** | ||
* The data of the 'ds64' chunk. | ||
* Used only with RF64 files. | ||
* @type {!Object<string, *>} | ||
*/ | ||
ds64: object; | ||
/** | ||
* The data of the 'data' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
data: object; | ||
/** | ||
* The data of the 'LIST' chunks. | ||
* Each item in this list look like this: | ||
* { | ||
* chunkId: '', | ||
* chunkSize: 0, | ||
* format: '', | ||
* subChunks: [] | ||
* } | ||
* @type {!Array<!Object>} | ||
*/ | ||
LIST: object[]; | ||
/** | ||
* The data of the 'junk' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
junk: object; | ||
/** | ||
* The bit depth code according to the samples. | ||
* @type {string} | ||
*/ | ||
bitDepth: string; | ||
/** | ||
* The container identifier. | ||
* 'RIFF', 'RIFX' and 'RF64' are supported. | ||
* @type {string} | ||
*/ | ||
container: string; | ||
/** | ||
* @type {number} | ||
*/ | ||
chunkSize: number; | ||
/** | ||
* The format. | ||
* Always 'WAVE'. | ||
* @type {string} | ||
*/ | ||
format: string; | ||
/** | ||
* The data of the 'fmt' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
fmt: object; | ||
/** | ||
* The data of the 'fact' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
fact: object; | ||
/** | ||
* The data of the 'cue ' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
cue: object; | ||
/** | ||
* The data of the 'smpl' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
smpl: object; | ||
/** | ||
* The data of the 'bext' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
bext: object; | ||
/** | ||
* The data of the 'ds64' chunk. | ||
* Used only with RF64 files. | ||
* @type {!Object<string, *>} | ||
*/ | ||
ds64: object; | ||
/** | ||
* The data of the 'data' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
data: object; | ||
/** | ||
* The data of the 'LIST' chunks. | ||
* Each item in this list look like this: | ||
* { | ||
* chunkId: '', | ||
* chunkSize: 0, | ||
* format: '', | ||
* subChunks: [] | ||
* } | ||
* @type {!Array<!Object>} | ||
*/ | ||
LIST: object[]; | ||
/** | ||
* The data of the 'junk' chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
junk: object; | ||
/** | ||
* Return the sample at a given index. | ||
* @param {number} index The sample index. | ||
* @return {number} The sample. | ||
* @throws {Error} If the sample index is off range. | ||
*/ | ||
getSample(index: number): number; | ||
/** | ||
* Return the sample at a given index. | ||
* @param {number} index The sample index. | ||
* @return {number} The sample. | ||
* @throws {Error} If the sample index is off range. | ||
*/ | ||
getSample(index: number): number; | ||
/** | ||
* Set the sample at a given index. | ||
* @param {number} index The sample index. | ||
* @param {number} sample The sample. | ||
* @throws {Error} If the sample index is off range. | ||
*/ | ||
setSample(index: number, sample: number): void; | ||
/** | ||
* Set the sample at a given index. | ||
* @param {number} index The sample index. | ||
* @param {number} sample The sample. | ||
* @throws {Error} If the sample index is off range. | ||
*/ | ||
setSample(index: number, sample: number): void; | ||
/** | ||
* Set up the WaveFile object based on the arguments passed. | ||
* @param {number} numChannels The number of channels | ||
* (Integer numbers: 1 for mono, 2 stereo and so on). | ||
* @param {number} sampleRate The sample rate. | ||
* Integer numbers like 8000, 44100, 48000, 96000, 192000. | ||
* @param {string} bitDepthCode The audio bit depth code. | ||
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64' | ||
* or any value between '8' and '32' (like '12'). | ||
* @param {!Array<number>|!Array<!Array<number>>|!ArrayBufferView} samples | ||
* The samples. Must be in the correct range according to the bit depth. | ||
* @param {?Object} options Optional. Used to force the container | ||
* as RIFX with {'container': 'RIFX'} | ||
* @throws {Error} If any argument does not meet the criteria. | ||
*/ | ||
fromScratch( | ||
numChannels: number, | ||
sampleRate: number, | ||
bitDepthCode: string, | ||
samples: any, | ||
options?: object): void; | ||
/** | ||
* Set up the WaveFile object based on the arguments passed. | ||
* @param {number} numChannels The number of channels | ||
* (Integer numbers: 1 for mono, 2 stereo and so on). | ||
* @param {number} sampleRate The sample rate. | ||
* Integer numbers like 8000, 44100, 48000, 96000, 192000. | ||
* @param {string} bitDepthCode The audio bit depth code. | ||
* One of '4', '8', '8a', '8m', '16', '24', '32', '32f', '64' | ||
* or any value between '8' and '32' (like '12'). | ||
* @param {!Array<number>|!Array<!Array<number>>|!ArrayBufferView} samples | ||
* The samples. Must be in the correct range according to the bit depth. | ||
* @param {?Object} options Optional. Used to force the container | ||
* as RIFX with {'container': 'RIFX'} | ||
* @throws {Error} If any argument does not meet the criteria. | ||
*/ | ||
fromScratch( | ||
numChannels: number, | ||
sampleRate: number, | ||
bitDepthCode: string, | ||
samples: Array<number>|Array<Array<number>>|ArrayBufferView, | ||
options?: object): void; | ||
/** | ||
* Set up the WaveFile object from a byte buffer. | ||
* @param {!Uint8Array} bytes The buffer. | ||
* @param {boolean=} samples True if the samples should be loaded. | ||
* @throws {Error} If container is not RIFF, RIFX or RF64. | ||
* @throws {Error} If no 'fmt ' chunk is found. | ||
* @throws {Error} If no 'data' chunk is found. | ||
*/ | ||
fromBuffer(bytes: Uint8Array, samples?:boolean): void; | ||
/** | ||
* Set up the WaveFile object from a byte buffer. | ||
* @param {!Uint8Array} bytes The buffer. | ||
* @param {boolean=} samples True if the samples should be loaded. | ||
* @throws {Error} If container is not RIFF, RIFX or RF64. | ||
* @throws {Error} If no 'fmt ' chunk is found. | ||
* @throws {Error} If no 'data' chunk is found. | ||
*/ | ||
fromBuffer(bytes: Uint8Array, samples?:boolean): void; | ||
/** | ||
* Return a byte buffer representig the WaveFile object as a .wav file. | ||
* The return value of this method can be written straight to disk. | ||
* @return {!Uint8Array} A .wav file. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
toBuffer(): Uint8Array; | ||
/** | ||
* Return a byte buffer representig the WaveFile object as a .wav file. | ||
* The return value of this method can be written straight to disk. | ||
* @return {!Uint8Array} A .wav file. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
toBuffer(): Uint8Array; | ||
/** | ||
* Use a .wav file encoded as a base64 string to load the WaveFile object. | ||
* @param {string} base64String A .wav file as a base64 string. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
fromBase64(base64String: string): void; | ||
/** | ||
* Use a .wav file encoded as a base64 string to load the WaveFile object. | ||
* @param {string} base64String A .wav file as a base64 string. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
fromBase64(base64String: string): void; | ||
/** | ||
* Return a base64 string representig the WaveFile object as a .wav file. | ||
* @return {string} A .wav file as a base64 string. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
toBase64(): string; | ||
/** | ||
* Return a base64 string representig the WaveFile object as a .wav file. | ||
* @return {string} A .wav file as a base64 string. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
toBase64(): string; | ||
/** | ||
* Return a DataURI string representig the WaveFile object as a .wav file. | ||
* The return of this method can be used to load the audio in browsers. | ||
* @return {string} A .wav file as a DataURI. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
toDataURI(): string; | ||
/** | ||
* Return a DataURI string representig the WaveFile object as a .wav file. | ||
* The return of this method can be used to load the audio in browsers. | ||
* @return {string} A .wav file as a DataURI. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
toDataURI(): string; | ||
/** | ||
* Use a .wav file encoded as a DataURI to load the WaveFile object. | ||
* @param {string} dataURI A .wav file as DataURI. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
fromDataURI(dataURI: string): void; | ||
/** | ||
* Use a .wav file encoded as a DataURI to load the WaveFile object. | ||
* @param {string} dataURI A .wav file as DataURI. | ||
* @throws {Error} If any property of the object appears invalid. | ||
*/ | ||
fromDataURI(dataURI: string): void; | ||
/** | ||
* Force a file as RIFF. | ||
*/ | ||
toRIFF(): void; | ||
/** | ||
* Force a file as RIFF. | ||
*/ | ||
toRIFF(): void; | ||
/** | ||
* Force a file as RIFX. | ||
*/ | ||
toRIFX(): void; | ||
/** | ||
* Force a file as RIFX. | ||
*/ | ||
toRIFX(): void; | ||
/** | ||
* Change the bit depth of the samples. | ||
* @param {string} newBitDepth The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats) | ||
* @param {boolean} changeResolution A boolean indicating if the | ||
* resolution of samples should be actually changed or not. | ||
* @throws {Error} If the bit depth is not valid. | ||
*/ | ||
toBitDepth(newBitDepth: string, changeResolution?: boolean): void; | ||
/** | ||
* Change the bit depth of the samples. | ||
* @param {string} newBitDepth The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats) | ||
* @param {boolean} changeResolution A boolean indicating if the | ||
* resolution of samples should be actually changed or not. | ||
* @throws {Error} If the bit depth is not valid. | ||
*/ | ||
toBitDepth(newBitDepth: string, changeResolution?: boolean): void; | ||
/** | ||
* Encode a 16-bit wave file as 4-bit IMA ADPCM. | ||
* @throws {Error} If sample rate is not 8000. | ||
* @throws {Error} If number of channels is not 1. | ||
*/ | ||
toIMAADPCM(): void; | ||
/** | ||
* Encode a 16-bit wave file as 4-bit IMA ADPCM. | ||
* @throws {Error} If sample rate is not 8000. | ||
* @throws {Error} If number of channels is not 1. | ||
*/ | ||
toIMAADPCM(): void; | ||
/** | ||
* Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file. | ||
* @param {string} bitDepthCode The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
fromIMAADPCM(bitDepthCode?: string): void; | ||
/** | ||
* Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file. | ||
* @param {string} bitDepthCode The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
fromIMAADPCM(bitDepthCode?: string): void; | ||
/** | ||
* Encode a 16-bit wave file as 8-bit A-Law. | ||
*/ | ||
toALaw(): void; | ||
/** | ||
* Encode a 16-bit wave file as 8-bit A-Law. | ||
*/ | ||
toALaw(): void; | ||
/** | ||
* Decode a 8-bit A-Law wave file into a 16-bit wave file. | ||
* @param {string} bitDepthCode The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
fromALaw(bitDepthCode?: string): void; | ||
/** | ||
* Decode a 8-bit A-Law wave file into a 16-bit wave file. | ||
* @param {string} bitDepthCode The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
fromALaw(bitDepthCode?: string): void; | ||
/** | ||
* Encode 16-bit wave file as 8-bit mu-Law. | ||
*/ | ||
toMuLaw(): void; | ||
/** | ||
* Encode 16-bit wave file as 8-bit mu-Law. | ||
*/ | ||
toMuLaw(): void; | ||
/** | ||
* Decode a 8-bit mu-Law wave file into a 16-bit wave file. | ||
* @param {string} bitDepthCode The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
fromMuLaw(bitDepthCode?: string): void; | ||
/** | ||
* Decode a 8-bit mu-Law wave file into a 16-bit wave file. | ||
* @param {string} bitDepthCode The new bit depth of the samples. | ||
* One of '8' ... '32' (integers), '32f' or '64' (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
fromMuLaw(bitDepthCode?: string): void; | ||
/** | ||
* Write a RIFF tag in the INFO chunk. If the tag do not exist, | ||
* then it is created. It if exists, it is overwritten. | ||
* @param {string} tag The tag name. | ||
* @param {string} value The tag value. | ||
* @throws {Error} If the tag name is not valid. | ||
*/ | ||
setTag(tag: string, value: string): void; | ||
/** | ||
* Write a RIFF tag in the INFO chunk. If the tag do not exist, | ||
* then it is created. It if exists, it is overwritten. | ||
* @param {string} tag The tag name. | ||
* @param {string} value The tag value. | ||
* @throws {Error} If the tag name is not valid. | ||
*/ | ||
setTag(tag: string, value: string): void; | ||
/** | ||
* Return the value of a RIFF tag in the INFO chunk. | ||
* @param {string} tag The tag name. | ||
* @return {?string} The value if the tag is found, null otherwise. | ||
*/ | ||
getTag(tag: string): string|null; | ||
/** | ||
* Return the value of a RIFF tag in the INFO chunk. | ||
* @param {string} tag The tag name. | ||
* @return {?string} The value if the tag is found, null otherwise. | ||
*/ | ||
getTag(tag: string): string|null; | ||
/** | ||
* Return a Object<tag, value> with the RIFF tags in the file. | ||
* @return {!Object<string, string>} The file tags. | ||
*/ | ||
listTags(): object; | ||
/** | ||
* Return a Object<tag, value> with the RIFF tags in the file. | ||
* @return {!Object<string, string>} The file tags. | ||
*/ | ||
listTags(): object; | ||
/** | ||
* Remove a RIFF tag in the INFO chunk. | ||
* @param {string} tag The tag name. | ||
* @return {boolean} True if a tag was deleted. | ||
*/ | ||
deleteTag(tag: string): boolean; | ||
/** | ||
* Remove a RIFF tag in the INFO chunk. | ||
* @param {string} tag The tag name. | ||
* @return {boolean} True if a tag was deleted. | ||
*/ | ||
deleteTag(tag: string): boolean; | ||
/** | ||
* Create a cue point in the wave file. | ||
* @param {number} position The cue point position in milliseconds. | ||
* @param {string} labl The LIST adtl labl text of the marker. Optional. | ||
*/ | ||
setCuePoint(position: number, labl?: string): void; | ||
/** | ||
* Create a cue point in the wave file. | ||
* @param {number} position The cue point position in milliseconds. | ||
* @param {string} labl The LIST adtl labl text of the marker. Optional. | ||
*/ | ||
setCuePoint(position: number, labl?: string): void; | ||
/** | ||
* Remove a cue point from a wave file. | ||
* @param {number} index the index of the point. First is 1, | ||
* second is 2, and so on. | ||
*/ | ||
deleteCuePoint(index: number): void; | ||
/** | ||
* Remove a cue point from a wave file. | ||
* @param {number} index the index of the point. First is 1, | ||
* second is 2, and so on. | ||
*/ | ||
deleteCuePoint(index: number): void; | ||
/** | ||
* Return an array with all cue points in the file, in the order they appear | ||
* in the file. | ||
* The difference between this method and using the list in WaveFile.cue | ||
* is that the return value of this method includes the position in | ||
* milliseconds of each cue point (WaveFile.cue only have the sample offset) | ||
* @return {!Array<!Object>} | ||
*/ | ||
listCuePoints(): Array<object>; | ||
/** | ||
* Return an array with all cue points in the file, in the order they appear | ||
* in the file. | ||
* The difference between this method and using the list in WaveFile.cue | ||
* is that the return value of this method includes the position in | ||
* milliseconds of each cue point (WaveFile.cue only have the sample offset) | ||
* @return {!Array<!Object>} | ||
*/ | ||
listCuePoints(): Array<object>; | ||
/** | ||
* Update the label of a cue point. | ||
* @param {number} pointIndex The ID of the cue point. | ||
* @param {string} label The new text for the label. | ||
*/ | ||
updateLabel(pointIndex: number, label: string): void; | ||
/** | ||
* Update the label of a cue point. | ||
* @param {number} pointIndex The ID of the cue point. | ||
* @param {string} label The new text for the label. | ||
*/ | ||
updateLabel(pointIndex: number, label: string): void; | ||
} |
@@ -48,3 +48,2 @@ /* | ||
* @extends WavBuffer | ||
* @ignore | ||
*/ | ||
@@ -293,2 +292,3 @@ export default class WaveFile extends WavBuffer { | ||
this.assure16Bit_(); | ||
/** @type {!Int16Array} */ | ||
let output = new Int16Array(this.data.samples.length / 2); | ||
@@ -328,2 +328,3 @@ unpackArrayTo(this.data.samples, this.dataType, output); | ||
this.assure16Bit_(); | ||
/** @type {!Int16Array} */ | ||
let output = new Int16Array(this.data.samples.length / 2); | ||
@@ -362,2 +363,3 @@ unpackArrayTo(this.data.samples, this.dataType, output); | ||
this.assure16Bit_(); | ||
/** @type {!Int16Array} */ | ||
let output = new Int16Array(this.data.samples.length / 2); | ||
@@ -837,3 +839,2 @@ unpackArrayTo(this.data.samples, this.dataType, output); | ||
updateDataType_() { | ||
/** @type {!Object} */ | ||
this.dataType = { | ||
@@ -840,0 +841,0 @@ bits: ((parseInt(this.bitDepth, 10) - 1) | 7) + 1, |
@@ -44,2 +44,3 @@ /* | ||
bitDepthCode, numChannels, sampleRate, numBytes, samplesLength, options) { | ||
/** @type {!Object} */ | ||
let header = {}; | ||
@@ -112,2 +113,3 @@ if (bitDepthCode == '4') { | ||
bitDepthCode, numChannels, sampleRate, numBytes, samplesLength, options) { | ||
/** @type {!Object} */ | ||
let header = createPCMHeader_( | ||
@@ -142,2 +144,3 @@ bitDepthCode, numChannels, sampleRate, numBytes, samplesLength, options); | ||
bitDepthCode, numChannels, sampleRate, numBytes, samplesLength, options) { | ||
/** @type {!Object} */ | ||
let header = createPCMHeader_( | ||
@@ -169,2 +172,3 @@ bitDepthCode, numChannels, sampleRate, numBytes, samplesLength, options); | ||
bitDepthCode, numChannels, sampleRate, numBytes, samplesLength, options) { | ||
/** @type {!Object} */ | ||
let header = createPCMHeader_( | ||
@@ -171,0 +175,0 @@ bitDepthCode, numChannels, sampleRate, numBytes, samplesLength, options); |
@@ -46,4 +46,6 @@ /* | ||
head_ = 0; | ||
/** @type {string} */ | ||
let chunkId = getChunkId_(buffer, 0); | ||
uInt32_.be = chunkId == 'RIFX'; | ||
/** @type {string} */ | ||
let format = unpackString(buffer, 8, 12); | ||
@@ -92,3 +94,5 @@ head_ += 4; | ||
function getSubChunksIndex_(buffer) { | ||
/** @type {!Array<!Object>} */ | ||
let chunks = []; | ||
/** @type {number} */ | ||
let i = head_; | ||
@@ -111,2 +115,3 @@ while(i <= buffer.length - 8) { | ||
function getSubChunkIndex_(buffer, index) { | ||
/** @type {!Object} */ | ||
let chunk = { | ||
@@ -121,2 +126,3 @@ chunkId: getChunkId_(buffer, index), | ||
} else { | ||
/** @type {number} */ | ||
let realChunkSize = chunk.chunkSize % 2 ? | ||
@@ -123,0 +129,0 @@ chunk.chunkSize + 1 : chunk.chunkSize; |
@@ -33,2 +33,3 @@ /* | ||
/** @type {!BufferIO} */ | ||
let io = new BufferIO(); | ||
@@ -47,3 +48,5 @@ | ||
io.head_ = 0; | ||
/** @type {!Object} */ | ||
let uInt32_ = {bits: 32, be: false}; | ||
/** @type {!Object} */ | ||
let uInt16_ = {bits: 16, be: false}; | ||
@@ -50,0 +53,0 @@ readRIFFChunk_(buffer, wav, uInt32_, uInt16_); |
@@ -122,3 +122,3 @@ /* | ||
function enforceBext_(wav) { | ||
for (var prop in wav.bext) { | ||
for (let prop in wav.bext) { | ||
if (wav.bext.hasOwnProperty(prop)) { | ||
@@ -125,0 +125,0 @@ if (wav.bext[prop] && prop != 'timeReference') { |
{ | ||
"name": "wavefile", | ||
"version": "8.4.1", | ||
"version": "8.4.2", | ||
"description": "Create, read and write wav files according to the specs.", | ||
@@ -74,3 +74,3 @@ "homepage": "https://github.com/rochars/wavefile", | ||
"test-dist": "npm run test-umd && npm run test-esm && npm run test-tsc && npm run test-cli && npm run test-cjs && npm run test-min", | ||
"rollup-bundle": "rollup --config && npm run test-dist", | ||
"rollup-bundle": "rollup -c && npm run test-dist", | ||
"doc": "./node_modules/.bin/jsdoc index.js -d docs -r README.md -t node_modules/docdash", | ||
@@ -87,2 +87,3 @@ "build": "npm run lint && npm test && npm run rollup-bundle && npm run doc", | ||
"esm": "^3.0.74", | ||
"google-closure-compiler": "^20180716.0.1", | ||
"jsdoc": "^3.5.5", | ||
@@ -95,2 +96,3 @@ "jshint": "^2.9.6", | ||
"rollup-plugin-babel": "^3.0.7", | ||
"rollup-plugin-closure-compiler-js": "^1.0.6", | ||
"rollup-plugin-commonjs": "^9.1.4", | ||
@@ -106,5 +108,5 @@ "rollup-plugin-node-resolve": "^3.3.0", | ||
"bitdepth": "^7.0.2", | ||
"byte-data": "^16.0.1", | ||
"byte-data": "^16.0.2", | ||
"imaadpcm": "^4.0.1" | ||
} | ||
} |
@@ -5,3 +5,3 @@ # wavefile | ||
[![NPM version](https://img.shields.io/npm/v/wavefile.svg?style=for-the-badge)](https://www.npmjs.com/package/wavefile) [![Docs](https://img.shields.io/badge/API-docs-blue.svg?style=for-the-badge)](https://rochars.github.io/wavefile/) [![Tests](https://img.shields.io/badge/tests-online-blue.svg?style=for-the-badge)](https://rawgit.com/rochars/wavefile/master/test/browser.html) | ||
[![NPM version](https://img.shields.io/npm/v/wavefile.svg?style=for-the-badge)](https://www.npmjs.com/package/wavefile) [![Docs](https://img.shields.io/badge/API-docs-blue.svg?style=for-the-badge)](https://rochars.github.io/wavefile/docs) [![Tests](https://img.shields.io/badge/tests-online-blue.svg?style=for-the-badge)](https://rochars.github.io/wavefile/test/browser.html) | ||
[![Codecov](https://img.shields.io/codecov/c/github/rochars/wavefile.svg?style=flat-square)](https://codecov.io/gh/rochars/wavefile) [![Unix Build](https://img.shields.io/travis/rochars/wavefile.svg?style=flat-square)](https://travis-ci.org/rochars/wavefile) [![Windows Build](https://img.shields.io/appveyor/ci/rochars/wavefile.svg?style=flat-square&logo=appveyor)](https://ci.appveyor.com/project/rochars/wavefile) [![Scrutinizer](https://img.shields.io/scrutinizer/g/rochars/wavefile.svg?style=flat-square&logo=scrutinizer)](https://scrutinizer-ci.com/g/rochars/wavefile/) [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/1880/badge)](https://bestpractices.coreinfrastructure.org/projects/1880) | ||
@@ -44,3 +44,3 @@ | ||
### Node | ||
If you installed via [NPM](https://www.npmjs.com/) or [Yarn](https://yarnpkg.com), **import WaveFile from wavefile**: | ||
**import WaveFile from wavefile**: | ||
```javascript | ||
@@ -51,3 +51,3 @@ import WaveFile from 'wavefile'; | ||
Or: | ||
Or **require**: | ||
```javascript | ||
@@ -144,3 +144,2 @@ const WaveFile = require('wavefile'); | ||
- [Use](#use) | ||
- [Example](#example) | ||
- [Operation Manual](#operation-manual) | ||
@@ -147,0 +146,0 @@ * [Create wave files from scratch](#create-wave-files-from-scratch) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
521534
12146
20
959
Updatedbyte-data@^16.0.2