Comparing version 8.3.2 to 8.4.0
# CHANGELOG | ||
## version 8.4.0 (2018-08-02) | ||
- Compatible with IE10+ | ||
## version 8.3.2 (2018-07-13) | ||
@@ -4,0 +7,0 @@ - Fix misssing properties in TypeScript declaration file. |
@@ -1,87 +0,1 @@ | ||
/* | ||
https://github.com/rochars/wavefile | ||
Copyright (c) 2017 Brett Zamir, 2012 Niklas von Hertzen. | ||
Copyright (c) 2016 acida, 2018 Rafael da Silva Rocha. | ||
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. | ||
*/ | ||
var aa="function"==typeof Object.create?Object.create:function(e){function n(){}n.prototype=e;return new n},R;if("function"==typeof Object.setPrototypeOf)R=Object.setPrototypeOf;else{var S;a:{var ba={K:!0},ca={};try{ca.__proto__=ba;S=ca.K;break a}catch(e){}S=!1}R=S?function(e,n){e.__proto__=n;if(e.__proto__!==n)throw new TypeError(e+" is not extensible");return e}:null}var wa=R; | ||
function xa(e,n){e.prototype=aa(n.prototype);e.prototype.constructor=e;if(wa)wa(e,n);else for(var l in n)if("prototype"!=l)if(Object.defineProperties){var m=Object.getOwnPropertyDescriptor(n,l);m&&Object.defineProperty(e,l,m)}else e[l]=n[l];e.O=n.prototype}var ya="function"==typeof Object.defineProperties?Object.defineProperty:function(e,n,l){e!=Array.prototype&&e!=Object.prototype&&(e[n]=l.value)},za="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this; | ||
function Aa(e,n){if(n){var l=za;e=e.split(".");for(var m=0;m<e.length-1;m++){var L=e[m];L in l||(l[L]={});l=l[L]}e=e[e.length-1];m=l[e];n=n(m);n!=m&&null!=n&&ya(l,e,{configurable:!0,writable:!0,value:n})}}Aa("Object.is",function(e){return e?e:function(e,l){return e===l?0!==e||1/e===1/l:e!==e&&l!==l}}); | ||
Aa("Array.prototype.includes",function(e){return e?e:function(e,l){var m=this;m instanceof String&&(m=String(m));var n=m.length;l=l||0;for(0>l&&(l=Math.max(l+n,0));l<n;l++){var O=m[l];if(O===e||Object.is(O,e))return!0}return!1}}); | ||
var ab=function(){function e(a){a=void 0===a?null:a;var b=n.call(this)||this;b.bitDepth="0";b.dataType={};a&&b.fromBuffer(a);return b}function n(){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.c=0}function m(a,b){this.b=a;this.w=b;this.offset=0;this.min=-Infinity;this.max=Infinity;this.c=this.b;this.g=255;this.j()}function L(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 h=new ArrayBuffer(c),f=new Uint8Array(h), | ||
e=0;e<b;e+=4){c=M[a.charCodeAt(e)];var g=M[a.charCodeAt(e+1)];var k=M[a.charCodeAt(e+2)];var l=M[a.charCodeAt(e+3)];f[d++]=c<<2|g>>4;f[d++]=(g&15)<<4|k>>2;f[d++]=(k&3)<<6|l&63}return h}function O(a,b){return a=0<a?parseInt(a/b.D*b.B,10):parseInt(a/b.F*b.C,10)}function Ba(a,b){return parseInt(0<a?a*b.B:a*b.C,10)}function Ca(a,b){return 0<a?a/b.D:a/b.F}function Da(a){da[0]=a;return da[0]}function Ea(a,b){function c(a){return a}a!=b&&(["32f","64"].includes(a)?["32f","64"].includes(b)?c=Da:c=Ba:c=["32f", | ||
"64"].includes(b)?Ca:O);return c}function ea(a){if("32f"!=a&&"64"!=a&&("8">parseInt(a,10)||"53"<parseInt(a,10)))throw Error("Invalid bit depth.");}function Fa(a){for(var b=new Uint8Array(a.length/2+512),c=[],d=0,h=0;h<a.length;h++)0==h%505&&0!=h&&(b.set(Ga(c),d),d+=256,c=[]),c.push(a[h]);return b}function Ha(a,b){b=void 0===b?256:b;for(var c=new Int16Array(2*a.length),d=[],h=0,f=0;f<a.length;f++)0==f%b&&0!=f&&(c.set(Ia(d),h),h+=2*b,d=[]),d.push(a[f]);return c}function Ga(a){var b=a[0];T(b);var c= | ||
[];c.push(b&255);c.push(b>>8&255);c.push(E);c.push(0);for(b=3;b<a.length;b+=2){var d=T(a[b]),h=T(a[b+1]);c.push(h<<4|d)}for(;256>c.length;)c.push(0);return c}function Ia(a){B=fa(a[1]<<8|a[0]);C=a[2];I=U[C];for(var b=[B,fa(a[3]<<8|a[2])],c=4;c<a.length;c++){var d=a[c],h=d>>4;b.push(ha(h<<4^d));b.push(ha(h))}return b}function fa(a){return 32768<a?a-65536:a}function T(a){var b=a-D;0<=b?a=0:(a=8,b=-b);var c=U[E],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;D=b&8? | ||
D-d:D+d;-32768>D?D=-32768:32767<D&&(D=32767);E+=ia[b&7];0>E?E=0:88<E&&(E=88);return a}function ha(a){var b=0;a&4&&(b+=I);a&2&&(b+=I>>1);a&1&&(b+=I>>2);b+=I>>3;a&8&&(b=-b);B+=b;32767<B?B=32767:-32767>B&&(B=-32767);C+=ia[a];0>C?C=0:88<C&&(C=88);I=U[C];return B}function Ja(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=a[c];d=-32768==d?-32767:d;var h=~d>>8&128;h||(d*=-1);32635<d&&(d=32635);if(256<=d){var f=Ka[d>>8&127];d=f<<4|d>>f+3&15}else d>>=4;b[c]=d^h^85}return b}function La(a){for(var b= | ||
new Int16Array(a.length),c=0;c<a.length;c++){var d=a[c],h=0;d^=85;d&128&&(d&=-129,h=-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===h?d:-d)}return b}function Ma(a){for(var b=new Uint8Array(a.length),c=0;c<a.length;c++){var d=a[c];var h=d>>8&128;0!=h&&(d=-d);32635<d&&(d=32635);d+=132;var f=Na[d>>7&255];b[c]=~(h|f<<4|d>>f+3&15)}return b}function Oa(a){for(var b=new Int16Array(a.length),c=0;c<a.length;c++){var d=a[c];d=~d;var h=d>>4&7;h=Pa[h]+((d&15)<<h+3);0!=(d&128)&&(h= | ||
-h);b[c]=h}return b}function F(a,b,c,d){c=void 0===c?0:c;d=void 0===d?a.length:d;if(d%b)throw Error("Bad buffer length.");for(;c<d;c+=b){var h=a,f=b,e=c;f--;for(var g=0;g<f;g++){var k=h[e+g];h[e+g]=h[e+f];h[e+f]=k;f--}}}function V(a){if(127<a)throw Error("Bad ASCII code.");}function ja(a){if(void 0===a)throw Error("Undefined value.");}function J(a){if(!a)throw Error("Undefined type.");if(a.o){if(-1==[16,32,64].indexOf(a.b))throw Error("Bad float type.");}else if(1>a.b||53<a.b)throw Error("Bad type definition."); | ||
a.offset=8>a.b?1:Math.ceil(a.b/8);a.f=a.f||!1;a.o?16==a.b?G=Qa:32==a.b?G=Ra:64==a.b&&(G=Sa):G=Ta;a.o?16==a.b?N=Ua:32==a.b?N=Va:64==a.b&&(N=Wa):N=Xa;v=new m(64==a.b?32:a.b,a.o?!1:a.w)}function ka(a,b,c,d,h,f,e){for(;d<h;)f(a,b),d=N(c,a,d);e&&F(c,b.offset,d-b.offset,d);return d}function Ta(a,b){return v.read(a,b)}function Qa(a,b){a=v.read(a,b);b=(a&31744)>>10;var c=a&1023;return(b?Math.pow(2,b-15)*(1+c/1024):c/1024*.00006103515625)*(a>>15?-1:1)}function Ra(a,b){H[0]=v.read(a,b);return W[0]}function Sa(a, | ||
b){H[la]=v.read(a,b);H[ma]=v.read(a,b+4);return na[0]}function Xa(a,b,c){return v.write(a,b,c)}function Ua(a,b,c){W[0]=b;var d=H[0];b=d>>16&32768;var h=d>>12&2047;d=d>>23&255;103<=d&&(b=(b|d-112<<10|h>>1)+(h&1));a[c++]=b&255;a[c++]=b>>>8&255;return c}function Va(a,b,c){W[0]=b;return v.write(a,H[0],c)}function Wa(a,b,c){na[0]=b;c=v.write(a,H[la],c);return v.write(a,H[ma],c)}function K(a,b,c){b=void 0===b?0:b;c=void 0===c?null:c;var d="";for(c=c?b+c:a.length;b<c;)V(a[b]),d+=String.fromCharCode(a[b]), | ||
b++;return d}function q(a){for(var b=[],c=0;c<a.length;c++){var d=a.charCodeAt(c);V(d);b[c]=d}return b}function oa(a,b,c){c=void 0===c?0:c;for(var d=0;d<a.length;d++){var h=a.charCodeAt(d);V(h);b[c]=h;c++}return c}function k(a,b){var c=[];X(a,b,c);return c}function X(a,b,c,d){d=void 0===d?0:d;J(b);return ka(a,b,c,d,d+b.offset,ja,b.f)}function pa(a,b,c){c=void 0===c?0:c;J(b);b.f&&F(a,b.offset,c,c+b.offset);var d=G(a,c);b.f&&F(a,b.offset,c,c+b.offset);return d}function Y(a,b,c,d){c=void 0===c?0:c;d= | ||
void 0===d?null:d;J(b);for(d=d||a.length;(d-c)%b.offset;)d--;b.f&&F(a,b.offset,c,d);for(var h=[],f=b.offset,e=c;e<d;e+=f)h.push(G(a,e));b.f&&F(a,b.offset,c,d);return h}function P(a,b,c,d,h){d=void 0===d?0:d;h=void 0===h?null:h;J(b);for(h=h||a.length;(h-d)%b.offset;)h--;b.f&&F(a,b.offset,d,h);for(var f=0,e=b.offset,g=d;g<h;g+=e)c.set([G(a,g)],f),f++;b.f&&F(a,b.offset,d,h)}function Q(a,b,c,d,h,f){return{container:f.container,chunkSize:36+h,format:"WAVE",bitDepth:a,fmt:{chunkId:"fmt ",chunkSize:16,audioFormat:Z[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 qa(a){if(!Z[a.bitDepth]){if(8<parseInt(a.bitDepth,10)&&54>parseInt(a.bitDepth,10))return!0;throw Error("Invalid bit depth.");}return!0}function ra(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 sa(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 Ya(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 Za(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),z.h(a.value,a.value.length))}function y(a,b,c){c=void 0===c?!1:c;for(var d=[],h=0;h<a.length;h++)if(a[h].chunkId==b)if(c)d.push(a[h]);else return a[h];return"LIST"==b?d.length?d:null:null}function ta(a){for(var b=[],c=w;c<=a.length-8;)b.push($a(a,c)),c+=8+b[b.length-1].chunkSize,c=c%2?c+1:c;return b}function $a(a,b){w+=4;var c={chunkId:K(a,b,4),chunkSize:ua(a,b)};"LIST"== | ||
c.chunkId?(c.format=K(a,b+8,4),w+=4,c.subChunks=ta(a)):(w=b+8+(c.chunkSize%2?c.chunkSize+1:c.chunkSize),c.chunkData={start:b+8,end:w});return c}function ua(a,b){w+=4;return pa(a,va,b+4)}for(var da=new Float32Array(1),ia=[-1,-1,-1,-1,2,4,6,8,-1,-1,-1,-1,2,4,6,8],U=[7,8,9,10,11,12,13,14,16,17,19,21,23,25,28,31,34,37,41,45,50,55,60,66,73,80,88,97,107,118,130,143,157,173,190,209,230,253,279,307,337,371,408,449,494,544,598,658,724,796,876,963,1060,1166,1282,1411,1552,1707,1878,2066,2272,2499,2749,3024, | ||
3327,3660,4026,4428,4871,5358,5894,6484,7132,7845,8630,9493,10442,11487,12635,13899,15289,16818,18500,20350,22385,24623,27086,29794,32767],D=0,E=0,B=0,C=0,I=7,Ka=[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],Na=[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],Pa=[0,132,396,924,1980,4092,8316,16764],M=new Uint8Array(256),r=0;64> | ||
r;r++)M["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(r)]=r;m.prototype.read=function(a,b){b=void 0===b?0:b;for(var c=0,d=this.offset-1;0<d;)c|=a[d+b]<<8*d,d--;c=(a[b]|c)>>>0;return this.a(this.h(c))};m.prototype.write=function(a,b,c){c=void 0===c?0:c;b=this.a(b);a[c++]=b&255;for(var d=2;d<=this.offset;d++)a[c++]=Math.floor(b/Math.pow(2,8*(d-1)))&255;return c};m.prototype.v=function(a,b,c){c=void 0===c?0:c;b=this.a(b);c=this.A(a,b,c);for(var d=2;d<this.offset;d++)a[c++]= | ||
Math.floor(b/Math.pow(2,8*(d-1)))&255;8<this.b&&(a[c++]=Math.floor(b/Math.pow(2,8*(this.offset-1)))&this.g);return c};m.prototype.l=function(a,b){b=void 0===b?0:b;for(var c="",d=0;d<this.offset;){var h=a[b+d].toString(2);c=Array(9-h.length).join("0")+h+c;d++}return this.a(this.h(parseInt(c,2)))};m.prototype.j=function(){this.u();this.m();this.s();this.offset=8>this.b?1:Math.ceil(this.c/8);if(this.c!=this.b||8>this.b||32<this.b)this.write=this.v,this.read=this.l};m.prototype.h=function(a){a>this.max&& | ||
(a-=2*this.max+2);return a};m.prototype.a=function(a){if(a>this.max)throw Error("Overflow.");if(a<this.min)throw Error("Underflow.");return a};m.prototype.s=function(){var a=Math.pow(2,this.b);this.w?(this.max=a/2-1,this.min=-a/2):(this.max=a-1,this.min=0)};m.prototype.u=function(){8<this.b&&(this.c=(this.b-1|7)+1)};m.prototype.m=function(){var a=8-(this.c-this.b);this.g=Math.pow(2,0<a?a:8)-1};m.prototype.A=function(a,b,c){8>this.b?a[c++]=0>b?b+Math.pow(2,this.b):b:a[c++]=b&255;return c};var la=(r= | ||
18===(new Uint8Array((new Uint32Array([305419896])).buffer))[0])?1:0,ma=r?0:1;r=new Int8Array(8);var H=new Uint32Array(r.buffer),W=new Float32Array(r.buffer),na=new Float64Array(r.buffer),G,N,v={},Z={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};l.prototype.h=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.j=function(a,b){var c="";for(b=void 0===b?0:b;b<a.length;b++){this.c++;if(0===a[b])break;c+=K(a,b,1)}return c};l.prototype.g=function(a, | ||
b){for(var c="",d=0;d<b;d++)c+=K(a,this.c,1),this.c++;return c};l.prototype.a=function(a,b){var c=b.b/8;a=pa(a,b,this.c);this.c+=c;return a};var z=new l,va={b:32},w=0,g=new l;xa(e,n);e.prototype.getSample=function(a){a*=this.dataType.b/8;if(a+this.dataType.b/8>this.data.samples.length)throw Error("Range error");a=this.data.samples.slice(a,a+this.dataType.b/8);var b=this.dataType;J(b);return Y(a.slice(0,b.offset),b)[0]};e.prototype.setSample=function(a,b){a*=this.dataType.b/8;if(a+this.dataType.b/ | ||
8>this.data.samples.length)throw Error("Range error");X(b,this.dataType,this.data.samples,a)};e.prototype.fromScratch=function(a,b,c,d,h){h=void 0===h?{}:h;h.container||(h.container="RIFF");this.container=h.container;this.bitDepth=c;d=this.G(d);this.v();var f=this.dataType.b/8;this.data.samples=new Uint8Array(d.length*f);var e=this.dataType,g=this.data.samples,k=void 0;k=void 0===k?0:k;J(e);for(var l=e.f,m=e.offset,n=d.length,p=0;p<n;p++)k=ka(d[p],e,g,k,k+m,ja,l);d=this.data.samples.length;"4"==c? | ||
(a=Q(c,a,b,f,d,h),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=Q(c,a,b,f,d,h),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(Z).indexOf(c)||2<a?(b=Q(c,a,b,f,d,h),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),c=0,1===a?c=4:2===a?c=3:4===a?c=51:6===a?c=63:8===a&&(c=1599),b.fmt.dwChannelMask=c,b.fmt.subformat=[1,1048576,2852126848,1905997824],a=b):a=Q(c,a,b,f,d,h);this.u();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;qa(this);ra(this);sa(this)};e.prototype.fromBuffer=function(a,b){b=void 0===b?!0:b;this.u();var c=b;b={b:32,f:!1}; | ||
var d={b:16,f:!1};g.c=0;this.container=g.g(a,4);if(-1===["RIFF","RIFX","RF64"].indexOf(this.container))throw Error("Not a supported format.");d.f="RIFX"===this.container;b.f=d.f;this.chunkSize=g.a(a,b);this.format=g.g(a,4);if("WAVE"!=this.format)throw Error('Could not find the "WAVE" format identifier');w=0;w+=4;var h=K(a,0,4);va.f="RIFX"==h;K(a,8,4);w+=4;ua(a,0);h=ta(a);var f=y(h,"ds64");if(f)g.c=f.chunkData.start,this.ds64.chunkId=f.chunkId,this.ds64.chunkSize=f.chunkSize,this.ds64.riffSizeHigh= | ||
g.a(a,b),this.ds64.riffSizeLow=g.a(a,b),this.ds64.dataSizeHigh=g.a(a,b),this.ds64.dataSizeLow=g.a(a,b),this.ds64.originationTime=g.a(a,b),this.ds64.sampleCountHigh=g.a(a,b),this.ds64.sampleCountLow=g.a(a,b);else if("RF64"==this.container)throw Error('Could not find the "ds64" chunk');if(f=y(h,"fmt "))g.c=f.chunkData.start,this.fmt.chunkId=f.chunkId,this.fmt.chunkSize=f.chunkSize,this.fmt.audioFormat=g.a(a,d),this.fmt.numChannels=g.a(a,d),this.fmt.sampleRate=g.a(a,b),this.fmt.byteRate=g.a(a,b),this.fmt.blockAlign= | ||
g.a(a,d),this.fmt.bitsPerSample=g.a(a,d),16<this.fmt.chunkSize&&(this.fmt.cbSize=g.a(a,d),18<this.fmt.chunkSize&&(this.fmt.validBitsPerSample=g.a(a,d),20<this.fmt.chunkSize&&(this.fmt.dwChannelMask=g.a(a,b),this.fmt.subformat=[g.a(a,b),g.a(a,b),g.a(a,b),g.a(a,b)])));else throw Error('Could not find the "fmt " chunk');if(f=y(h,"fact"))g.c=f.chunkData.start,this.fact.chunkId=f.chunkId,this.fact.chunkSize=f.chunkSize,this.fact.dwSampleLength=g.a(a,b);if(f=y(h,"bext"))g.c=f.chunkData.start,this.bext.chunkId= | ||
f.chunkId,this.bext.chunkSize=f.chunkSize,this.bext.description=g.g(a,256),this.bext.originator=g.g(a,32),this.bext.originatorReference=g.g(a,32),this.bext.originationDate=g.g(a,10),this.bext.originationTime=g.g(a,8),this.bext.timeReference=[g.a(a,b),g.a(a,b)],this.bext.version=g.a(a,d),this.bext.UMID=g.g(a,64),this.bext.loudnessValue=g.a(a,d),this.bext.loudnessRange=g.a(a,d),this.bext.maxTruePeakLevel=g.a(a,d),this.bext.maxMomentaryLoudness=g.a(a,d),this.bext.maxShortTermLoudness=g.a(a,d),this.bext.reserved= | ||
g.g(a,180),this.bext.codingHistory=g.g(a,this.bext.chunkSize-602);if(f=y(h,"cue "))for(g.c=f.chunkData.start,this.cue.chunkId=f.chunkId,this.cue.chunkSize=f.chunkSize,this.cue.dwCuePoints=g.a(a,b),f=0;f<this.cue.dwCuePoints;f++)this.cue.points.push({dwName:g.a(a,b),dwPosition:g.a(a,b),fccChunk:g.g(a,4),dwChunkStart:g.a(a,b),dwBlockStart:g.a(a,b),dwSampleOffset:g.a(a,b)});if(f=y(h,"smpl"))for(g.c=f.chunkData.start,this.smpl.chunkId=f.chunkId,this.smpl.chunkSize=f.chunkSize,this.smpl.dwManufacturer= | ||
g.a(a,b),this.smpl.dwProduct=g.a(a,b),this.smpl.dwSamplePeriod=g.a(a,b),this.smpl.dwMIDIUnityNote=g.a(a,b),this.smpl.dwMIDIPitchFraction=g.a(a,b),this.smpl.dwSMPTEFormat=g.a(a,b),this.smpl.dwSMPTEOffset=g.a(a,b),this.smpl.dwNumSampleLoops=g.a(a,b),this.smpl.dwSamplerData=g.a(a,b),f=0;f<this.smpl.dwNumSampleLoops;f++)this.smpl.loops.push({dwName:g.a(a,b),dwType:g.a(a,b),dwStart:g.a(a,b),dwEnd:g.a(a,b),dwFraction:g.a(a,b),dwPlayCount:g.a(a,b)});if(f=y(h,"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=y(h,"junk"))this.junk={chunkId:c.chunkId,chunkSize:c.chunkSize,chunkData:[].slice.call(a.slice(c.chunkData.start,c.chunkData.end))};h=y(h,"LIST",!0);if(null!==h)for(c=0;c<h.length;c++){f=h[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)&&(g.c=k.chunkData.start,l={chunkId:k.chunkId,chunkSize:k.chunkSize,dwName:g.a(m,n)},"ltxt"==k.chunkId&&(l.dwSampleLength=g.a(m,n),l.dwPurposeID=g.a(m,n),l.dwCountry=g.a(m,q),l.dwLanguage=g.a(m,q),l.dwDialect=g.a(m,q),l.dwCodePage=g.a(m,q)),l.value=g.j(m,g.c),this.LIST[this.LIST.length-1].subChunks.push(l)):"INFO"==l&&(g.c=k.chunkData.start,this.LIST[this.LIST.length-1].subChunks.push({chunkId:k.chunkId,chunkSize:k.chunkSize,value:g.j(m,g.c)}))}}this.A(); | ||
this.v()};e.prototype.toBuffer=function(){qa(this);ra(this);sa(this);var a={b:32,f:!1},b={b:16,f:!1};b.f="RIFX"===this.container;a.f=b.f;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 e=[];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,e=e.concat(q(this.bext.chunkId),k(602+this.bext.codingHistory.length,a),z.h(this.bext.description,256),z.h(this.bext.originator,32),z.h(this.bext.originatorReference,32),z.h(this.bext.originationDate, | ||
10),z.h(this.bext.originationTime,8),k(this.bext.timeReference[0],a),k(this.bext.timeReference[1],a),k(this.bext.version,b),z.h(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),z.h(this.bext.reserved,180),z.h(this.bext.codingHistory,this.bext.codingHistory.length)));var f=e;e=[];if(this.fmt.chunkId)e=e.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),Ya(this,a,b));else throw Error('Could not find the "fmt " chunk');var g=[];this.fact.chunkId&&(g=g.concat(q(this.fact.chunkId),k(this.fact.chunkSize,a),k(this.fact.dwSampleLength,a)));var l=q(this.data.chunkId),m=k(this.data.samples.length,a),n=this.data.samples;var v=[];if(this.cue.chunkId){var r=[];for(var p=0;p<this.cue.dwCuePoints;p++)r=r.concat(k(this.cue.points[p].dwName, | ||
a),k(this.cue.points[p].dwPosition,a),q(this.cue.points[p].fccChunk),k(this.cue.points[p].dwChunkStart,a),k(this.cue.points[p].dwBlockStart,a),k(this.cue.points[p].dwSampleOffset,a));v=v.concat(q(this.cue.chunkId),k(r.length+4,a),k(this.cue.dwCuePoints,a),r)}r=[];if(this.smpl.chunkId){p=[];for(var u=0;u<this.smpl.dwNumSampleLoops;u++)p=p.concat(k(this.smpl.loops[u].dwName,a),k(this.smpl.loops[u].dwType,a),k(this.smpl.loops[u].dwStart,a),k(this.smpl.loops[u].dwEnd,a),k(this.smpl.loops[u].dwFraction, | ||
a),k(this.smpl.loops[u].dwPlayCount,a));r=r.concat(q(this.smpl.chunkId),k(p.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),p)}p=[];for(u=0;u<this.LIST.length;u++){var t=this.LIST[u].subChunks;for(var y=this.LIST[u].format,w=a,B=b,A=[],x=0;x<t.length;x++)"INFO"==y?(A= | ||
A.concat(q(t[x].chunkId),k(t[x].value.length+1,w),z.h(t[x].value,t[x].value.length)),A.push(0)):"adtl"==y&&(-1<["labl","note"].indexOf(t[x].chunkId)?(A=A.concat(q(t[x].chunkId),k(t[x].value.length+4+1,w),k(t[x].dwName,w),z.h(t[x].value,t[x].value.length)),A.push(0)):"ltxt"==t[x].chunkId&&(A=A.concat(Za(t[x],this,w,B)))),A.length%2&&A.push(0);t=A;p=p.concat(q(this.LIST[u].chunkId),k(t.length+4,a),q(this.LIST[u].format),t)}b=[c,d,f,e,g,l,m,n,v,r,p];for(d=c=0;d<b.length;d++)c+=b[d].length;d=new Uint8Array(c+ | ||
12);f=oa(this.container,d,0);f=X(c+4,a,d,f);f=oa(this.format,d,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(L(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,Y(this.data.samples, | ||
this.dataType))};e.prototype.toRIFX=function(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,Y(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.b.toString()),d=this.dataType.b);this.s();var e=this.data.samples.length/(this.dataType.b/8);b=new Float64Array(e+1);e=new Float64Array(e+1);P(this.data.samples,this.dataType,b);"32f"!=d&&"64"!=d||this.J(b);var f=d;d=c;ea(f); | ||
ea(d);var g=Ea(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]=g(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.g();var a=new Int16Array(this.data.samples.length/2);P(this.data.samples,this.dataType,a);this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"4",Fa(a),{container:this.a()})};e.prototype.fromIMAADPCM=function(a){a=void 0===a?"16":a;this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",Ha(this.data.samples,this.fmt.blockAlign),{container:this.a()});"16"!=a&&this.toBitDepth(a)};e.prototype.toALaw=function(){this.g();var a=new Int16Array(this.data.samples.length/2);P(this.data.samples, | ||
this.dataType,a);this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8a",Ja(a),{container:this.a()})};e.prototype.fromALaw=function(a){a=void 0===a?"16":a;this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",La(this.data.samples),{container:this.a()});"16"!=a&&this.toBitDepth(a)};e.prototype.toMuLaw=function(){this.g();var a=new Int16Array(this.data.samples.length/2);P(this.data.samples,this.dataType,a);this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"8m",Ma(a),{container:this.a()})}; | ||
e.prototype.fromMuLaw=function(a){a=void 0===a?"16":a;this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,"16",Oa(this.data.samples),{container:this.a()});"16"!=a&&this.toBitDepth(a)};e.prototype.setTag=function(a,b){a=this.L(a);var c=this.m(a);null!==c.i?(this.LIST[c.LIST].subChunks[c.i].chunkSize=b.length+1,this.LIST[c.LIST].subChunks[c.i].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.m(a);return null!==a.i?this.LIST[a.LIST].subChunks[a.i].value:null};e.prototype.listTags=function(){var a=this.M(),b={};if(null!==a)for(var c=0;c<this.LIST[a].subChunks.length;c++)b[this.LIST[a].subChunks[c].chunkId]=this.LIST[a].subChunks[c].value;return b};e.prototype.deleteTag=function(a){a=this.m(a);return null!==a.i?(this.LIST[a.LIST].subChunks.splice(a.i, | ||
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.l();this.h();var d=this.cue.points.length;this.cue.points=[];var e=!1;if(0===d)this.c(a,1,b);else{for(var f=0;f<d;f++)c[f].dwPosition>a&&!e?(this.c(a,f+1,b),this.c(c[f].dwPosition,f+2,c[f].label),e=!0):this.c(c[f].dwPosition,f+1,c[f].label);e||this.c(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.l();this.h();var c=this.cue.points.length;this.cue.points=[];for(var d=0;d<c;d++)d+1!==a&&this.c(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.h())};e.prototype.listCuePoints=function(){for(var a=this.l(),b=0;b<a.length;b++)a[b].milliseconds=a[b].dwPosition/this.fmt.sampleRate*1E3;return a};e.prototype.updateLabel=function(a,b){var c=this.j();if(null!==c)for(var d=0;d<this.LIST[c].subChunks.length;d++)this.LIST[c].subChunks[d].dwName== | ||
a&&(this.LIST[c].subChunks[d].value=b)};e.prototype.A=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.c=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.l=function(){for(var a=[],b=0;b<this.cue.points.length;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.j();if(null!==b)for(var c=0;c<this.LIST[b].subChunks.length;c++)if(this.LIST[b].subChunks[c].dwName==a)return this.LIST[b].subChunks[c].value;return""};e.prototype.h=function(){for(var a=0;a<this.LIST.length;a++)"adtl"==this.LIST[a].format&&this.LIST.splice(a)};e.prototype.I=function(a,b){var c=this.j();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.j=function(){for(var a=0;a<this.LIST.length;a++)if("adtl"==this.LIST[a].format)return a;return null};e.prototype.M=function(){for(var a=null,b=0;b<this.LIST.length;b++)if("INFO"===this.LIST[b].format){a=b;break}return a};e.prototype.m=function(a){for(var b={LIST:null,i:null},c=0;c<this.LIST.length;c++)if("INFO"==this.LIST[c].format){b.LIST= | ||
c;for(var d=0;d<this.LIST[c].subChunks.length;d++)if(this.LIST[c].subChunks[d].chunkId==a){b.i=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;b<4-a.length;b++)a+=" ";return a};e.prototype.u=function(){this.fmt.cbSize=0;this.fmt.validBitsPerSample=0;this.fact.chunkId="";this.ds64.chunkId=""};e.prototype.g=function(){this.s();"16"!=this.bitDepth&&this.toBitDepth("16")};e.prototype.s=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;c<a[0].length;c++)for(var d=0;d<a.length;d++)b.push(a[d][c]);a=b}return a};e.prototype.v=function(){this.dataType={b:(parseInt(this.bitDepth,10)-1|7)+1,o:"32f"==this.bitDepth||"64"==this.bitDepth,w:"8"!=this.bitDepth,f:"RIFX"==this.container};-1<["4","8a","8m"].indexOf(this.bitDepth)&&(this.dataType.b=8,this.dataType.w=!1)}; | ||
e.prototype.a=function(){return"RF64"==this.container?"RIFF":this.container};e.prototype.J=function(a){for(var b=a.length,c=0;c<b;c++)1<a[c]?a[c]=1:-1>a[c]&&(a[c]=-1)};return e}();window.WaveFile=ab; | ||
var WaveFile=function(){"use strict";const t=new Float32Array(1);function e(t,e,h,u){s(e),s(h);let o=function(t,e){let s=function(t){return t};t!=e&&(s=["32f","64"].includes(t)?["32f","64"].includes(e)?a:r:["32f","64"].includes(e)?i:n);return s}(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 r(t,e){return parseInt(t>0?t*e.newMax:t*e.newMin,10)}function i(t,e){return t>0?t/e.oldMax:t/e.oldMin}function a(e){return t[0]=e,t[0]}function s(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 p(t){let e=function(t){S(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 r=S(t[n]),i=S(t[n+1]);e.push(i<<4|r)}for(;e.length<256;)e.push(0);return e}function m(t){c=k(t[1]<<8|t[0]),d=t[2],f=u[d];let e=[c,k(t[3]<<8|t[2])];for(let n=4;n<t.length;n++){let r=t[n],i=r>>4,a=i<<4^r;e.push(b(a)),e.push(b(i))}return e}function k(t){return t>32768?t-65536:t}function S(t){let e=t-o,n=0;e>=0?n=0:(n=8,e=-e);let r=u[l],i=r>>3;return e>r&&(n|=4,e-=r,i+=r),e>(r>>=1)&&(n|=2,e-=r,i+=r),e>(r>>=1)&&(n|=1,i+=r),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,i),n}function b(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 w=[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 g(t){let e,n=~(t=-32768==t?-32767:t)>>8&128;if(n||(t*=-1),t>32635&&(t=32635),t>=256){let n=w[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),r=0;return r=4!=n?1<<n|(15&t)<<n-4|1<<n-5:t<<1|1,8*(r=0===e?r:-r)*-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],y=[0,132,396,924,1980,4092,8316,16764];function L(t){let e,n,r,i;return 0!=(e=t>>8&128)&&(t=-t),t>C&&(t=C),i=~(e|(n=T[(t+=_)>>7&255])<<4|(r=t>>n+3&15))}function x(t){let e,n,r,i;return e=128&(t=~t),r=15&t,i=y[n=t>>4&7]+(r<<n+3),0!=e&&(i=-i),i}const z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",M=new Uint8Array(256);for(let t=0;t<z.length;t++)M[z.charCodeAt(t)]=t;const P=function(t,e,n){const r=new Uint8Array(t,e,n),i=r.length;let a="";for(let t=0;t<i;t+=3)a+=z[r[t]>>2],a+=z[(3&r[t])<<4|r[t+1]>>4],a+=z[(15&r[t+1])<<2|r[t+2]>>6],a+=z[63&r[t+2]];return i%3==2?a=a.substring(0,a.length-1)+"=":i%3==1&&(a=a.substring(0,a.length-2)+"=="),a},A=function(t){const e=t.length;let n,r,i,a,s=.75*t.length,h=0;"="===t[t.length-1]&&(s--,"="===t[t.length-2]&&s--);const u=new ArrayBuffer(s),o=new Uint8Array(u);for(let s=0;s<e;s+=4)n=M[t.charCodeAt(s)],r=M[t.charCodeAt(s+1)],i=M[t.charCodeAt(s+2)],a=M[t.charCodeAt(s+3)],o[h++]=n<<2|r>>4,o[h++]=(15&r)<<4|i>>2,o[h++]=(3&i)<<6|63&a;return u};function D(t,e,n=0,r=t.length){if(r%e)throw new Error("Bad buffer length.");for(let i=n;i<r;i+=e)F(t,e,i)}function F(t,e,n){e--;for(let r=0;r<e;r++){let i=t[n+r];t[n+r]=t[n+e],t[n+e]=i,e--}}function v(t,e,n=0){for(let r=0,i=t.length;r<i;r++){let i=t.codePointAt(r);if(i<128)e[n]=i,n++;else{let t=0,a=0;for(i<=2047?(t=1,a=192):i<=65535?(t=2,a=224):i<=1114111&&(t=3,a=240,r++),e[n]=(i>>6*t)+a,n++;t>0;)e[n]=128|i>>6*(t-1)&63,n++,t--}}return n}class R{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 r=this.bytes;for(let i=2;i<r;i++)t[n]=255&Math.floor(e/Math.pow(2,8*(i-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 r=0;r<this.bytes;r++)n+=t[e+r]*Math.pow(256,r);return n}overflow(t){if(t>this.max||t<this.min)throw new Error("Overflow")}}class N extends R{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 B{constructor(t,e){this.parser=e?new N(t):new R(t)}pack(t,e,n=0){return this.parser.pack(t,e,n)}unpack(t,e=0){return this.parser.unpack(t,e)}}const E="Unsupported type";function U(t){if(void 0===t)throw new Error("Undefined value");if(null!==t&&t.constructor!=Number&&t.constructor!=Boolean)throw new Error("Can't pack "+t.constructor)}function O(t){if(!t)throw new Error(E);t.float?function(t){if(16!=t.bits&&32!=t.bits&&64!=t.bits)throw new Error(E)}(t):function(t){if(t.bits<1||t.bits>53)throw new Error(E)}(t)}function H(t,e,n,r,i){let a=(1<<r-1)-1;Math.abs(n)>Math.pow(2,a+1)-2*(r+i)&&(n=n<0?-1/0:1/0);let s=((n=+n)||1/n)<0?1:n<0?1:0;n=Math.abs(n);let h=Math.min(Math.floor(Math.log(n)/Math.LN2),1023),u=G(n/Math.pow(2,h)*Math.pow(2,i));return n!=n?(u=Math.pow(2,i-1),h=(1<<r)-1):0!==n&&(n>=Math.pow(2,1-a)?(u/Math.pow(2,i)>=2&&(h+=1,u=1),h>a?(h=(1<<r)-1,u=0):(h+=a,u=G(u)-Math.pow(2,i))):(u=G(n/Math.pow(2,1-a-i)),h=0)),function(t,e,n,r,i,a,s){let h=[];h.push(i);for(let t=n;t>0;t-=1)h[t]=a%2?1:0,a=Math.floor(a/2);let u=h.length;for(let t=r;t>0;t-=1)h[u+t]=s%2?1:0,s=Math.floor(s/2);let o=h.join(""),l=Math.floor((n+r+1)/8)+e-1,c=e;for(;l>=e;)t[l]=parseInt(o.substring(0,8),2),o=o.substring(8),l--,c++;return c}(t,e,r,i,s,h,u)}function j(t,e,n,r){let i,a=(1<<n-1)-1,s=Math.ceil((n+r)/8),h=(1<<n)-1,u=Math.pow(2,-(8*s-1-n)),o="";for(let n=s-1;n>=0;n--){let r=t[n+e].toString(2);o+="00000000".substring(r.length)+r}let l="1"==o.charAt(0)?-1:1;o=o.substring(1);let c=parseInt(o.substring(0,n),2);return o=o.substring(n),c==h?0!==parseInt(o,2)?NaN:l*(1/0):(0===c?(c+=1,i=parseInt(o,2)):i=parseInt("1"+o,2),l*i*u*Math.pow(2,c-a))}function G(t){var e=Math.floor(t),n=t-e;return n<.5?e:n>.5?e+1:e%2?e+1:e}class W extends B{constructor(t){O(t),t.signed=!t.float&&t.signed,super(t.bits,t.signed),this.offset=this.parser.bytes,this.parser.bytes=64===this.parser.bits?4:this.parser.bytes,this.setReaderAndWriter_(t)}read16F_(t,e=0){return j(t,e,5,11)}read32F_(t,e=0){return j(t,e,8,23)}read64F_(t,e=0){return j(t,e,11,52)}write16F_(t,e,n=0){return H(t,n,e,5,11)}write32F_(t,e,n=0){return H(t,n,e,8,23)}write64F_(t,e,n=0){return H(t,n,e,11,52)}setReaderAndWriter_(t){t.float?16==t.bits?(this.unpack=this.read16F_,this.pack=this.write16F_):32==t.bits?(this.unpack=this.read32F_,this.pack=this.write32F_):(this.unpack=this.read64F_,this.pack=this.write64F_):(this.unpack=super.unpack,this.pack=super.pack)}}function X(t,e=0,n=null){return function(t,e=0,n=null){n=null!==n?n+1:t.length;let r="";for(let i=e;i<n;){let e=128,n=191,a=!1,s=t[i++];if(s>=0&&s<=127)r+=String.fromCharCode(s);else{let h=0;s>=194&&s<=223?h=1:s>=224&&s<=239?(h=2,224===t[i]&&(e=160),237===t[i]&&(n=159)):s>=240&&s<=244?(h=3,240===t[i]&&(e=144),244===t[i]&&(n=143)):a=!0,s&=(1<<8-h-1)-1;for(let r=0;r<h;r++)(t[i]<e||t[i]>n)&&(a=!0),s=s<<6|63&t[i],i++;a?r+=String.fromCharCode(65533):s<=65535?r+=String.fromCharCode(s):(s-=65536,r+=String.fromCharCode(55296+(s>>10&1023),56320+(1023&s)))}}return r}(t,e,n)}function V(t){let e=new Uint8Array(function(t){let e=0;for(let n=0,r=t.length;n<r;n++){let r=t.codePointAt(n);r<128?e++:(r<=2047?e++:r<=65535?e+=2:r<=1114111&&(n++,e+=3),e++)}return e}(t));return v(t,e,0),e}function Z(t,e,n=0){return v(t,e,n)}function q(t,e){let n=[];return J(t,e,n),n}function J(t,e,n,r=0){return K([t],e,n,r)}function K(t,e,n,r=0){let i=new W(e),a=t.length;for(let s=0;s<a;s++){U(t[s]);let a=r+i.offset;for(;r<a;)r=i.pack(n,t[s],r);e.be&&D(n,i.offset,r-i.offset,r)}return r}function Q(t,e,n=0){let r=new W(e);if(r.offset+n>t.length)throw Error("Bad buffer length");e.be&&D(t,r.offset,n,n+r.offset);let i=r.unpack(t,n);return e.be&&D(t,r.offset,n,n+r.offset),i}function Y(t,e,n=0,r=t.length){let i=[];return $(t,e,i,n,r),i}function $(t,e,n,r=0,i=t.length){let a=new W(e),s=r;for(;(i-r)%a.offset;)i--;e.be&&D(t,a.offset,r,i);for(let e=0;r<i;r+=a.offset)n[e]=a.unpack(t,r),e++;e.be&&D(t,a.offset,s,i)}var tt={4:17,8:1,"8a":6,"8m":7,16:1,24:1,32:1,"32f":3,64:3};function et(t,e,n,r,i,a){let s={};return s="4"==t?function(t,e,n,r,i,a){let s=nt(t,e,n,r,i,a);return s.chunkSize=40+i,s.fmt.chunkSize=20,s.fmt.byteRate=4055,s.fmt.blockAlign=256,s.fmt.bitsPerSample=4,s.fmt.cbSize=2,s.fmt.validBitsPerSample=505,s.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*i},s}(t,e,n,r,i,a):"8a"==t||"8m"==t?function(t,e,n,r,i,a){let s=nt(t,e,n,r,i,a);return s.chunkSize=40+i,s.fmt.chunkSize=20,s.fmt.cbSize=2,s.fmt.validBitsPerSample=8,s.fact={chunkId:"fact",chunkSize:4,dwSampleLength:i},s}(t,e,n,r,i,a):-1==Object.keys(tt).indexOf(t)||e>2?function(t,e,n,r,i,a){let s=nt(t,e,n,r,i,a);return s.chunkSize=60+i,s.fmt.chunkSize=40,s.fmt.bitsPerSample=1+(parseInt(t,10)-1|7),s.fmt.cbSize=22,s.fmt.validBitsPerSample=parseInt(t,10),s.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),s.fmt.subformat=[1,1048576,2852126848,1905997824],s}(t,e,n,r,i,a):nt(t,e,n,r,i,a)}function nt(t,e,n,r,i,a){return{container:a.container,chunkSize:36+i,format:"WAVE",bitDepth:t,fmt:{chunkId:"fmt ",chunkSize:16,audioFormat:tt[t]||65534,numChannels:e,sampleRate:n,byteRate:e*r*n,blockAlign:e*r,bitsPerSample:parseInt(t,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}}}function rt(t){!function(t){if(!tt[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 r=Array.prototype.slice.call(V(t));if(n)for(let t=r.length;t<e;t++)r.push(0);return r}readZSTR_(t,e=0){let n="";for(let r=e;r<t.length&&(this.head_++,0!==t[r]);r++)n+=X(t,r,r);return n}readString_(t,e){let n="";return n=X(t,this.head_,this.head_+e-1),this.head_+=e,n}read_(t,e){let n=e.bits/8,r=Q(t,e,this.head_);return this.head_+=n,r}}let at=new it;function st(t){let e={bits:32,be:!1},n={bits:16,be:!1};n.be="RIFX"===t.container,e.be=n.be;let r=[function(t,e){let n=[];if(t.junk.chunkId)return n.concat(Array.prototype.slice.call(V(t.junk.chunkId)),q(t.junk.chunkData.length,e),t.junk.chunkData);return n}(t,e),function(t,e){let n=[];t.ds64.chunkId&&(n=n.concat(Array.prototype.slice.call(V(t.ds64.chunkId)),q(t.ds64.chunkSize,e),q(t.ds64.riffSizeHigh,e),q(t.ds64.riffSizeLow,e),q(t.ds64.dataSizeHigh,e),q(t.ds64.dataSizeLow,e),q(t.ds64.originationTime,e),q(t.ds64.sampleCountHigh,e),q(t.ds64.sampleCountLow,e)));return n}(t,e),function(t,e,n){let r=[];(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,r=r.concat(Array.prototype.slice.call(V(t.bext.chunkId)),q(602+t.bext.codingHistory.length,e),at.writeString_(t.bext.description,256),at.writeString_(t.bext.originator,32),at.writeString_(t.bext.originatorReference,32),at.writeString_(t.bext.originationDate,10),at.writeString_(t.bext.originationTime,8),q(t.bext.timeReference[0],e),q(t.bext.timeReference[1],e),q(t.bext.version,n),Array.prototype.slice.call(at.writeString_(t.bext.UMID,64)),q(t.bext.loudnessValue,n),q(t.bext.loudnessRange,n),q(t.bext.maxTruePeakLevel,n),q(t.bext.maxMomentaryLoudness,n),q(t.bext.maxShortTermLoudness,n),at.writeString_(t.bext.reserved,180),at.writeString_(t.bext.codingHistory,t.bext.codingHistory.length)));return r}(t,e,n),function(t,e,n){let r=[];if(t.fmt.chunkId)return r.concat(Array.prototype.slice.call(V(t.fmt.chunkId)),q(t.fmt.chunkSize,e),q(t.fmt.audioFormat,n),q(t.fmt.numChannels,n),q(t.fmt.sampleRate,e),q(t.fmt.byteRate,e),q(t.fmt.blockAlign,n),q(t.fmt.bitsPerSample,n),function(t,e,n){let r=[];t.fmt.chunkSize>16&&(r=r.concat(q(t.fmt.cbSize,n)));t.fmt.chunkSize>18&&(r=r.concat(q(t.fmt.validBitsPerSample,n)));t.fmt.chunkSize>20&&(r=r.concat(q(t.fmt.dwChannelMask,e)));t.fmt.chunkSize>24&&(r=r.concat(q(t.fmt.subformat[0],e),q(t.fmt.subformat[1],e),q(t.fmt.subformat[2],e),q(t.fmt.subformat[3],e)));return r}(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(Array.prototype.slice.call(V(t.fact.chunkId)),q(t.fact.chunkSize,e),q(t.fact.dwSampleLength,e)));return n}(t,e),Array.prototype.slice.call(V(t.data.chunkId)),q(t.data.samples.length,e),t.data.samples,function(t,e){let n=[];if(t.cue.chunkId){let r=function(t,e){let n=[];for(let r=0;r<t.cue.dwCuePoints;r++)n=n.concat(q(t.cue.points[r].dwName,e),q(t.cue.points[r].dwPosition,e),Array.prototype.slice.call(V(t.cue.points[r].fccChunk)),q(t.cue.points[r].dwChunkStart,e),q(t.cue.points[r].dwBlockStart,e),q(t.cue.points[r].dwSampleOffset,e));return n}(t,e);n=n.concat(Array.prototype.slice.call(V(t.cue.chunkId)),q(r.length+4,e),q(t.cue.dwCuePoints,e),r)}return n}(t,e),function(t,e){let n=[];if(t.smpl.chunkId){let r=function(t,e){let n=[];for(let r=0;r<t.smpl.dwNumSampleLoops;r++)n=n.concat(q(t.smpl.loops[r].dwName,e),q(t.smpl.loops[r].dwType,e),q(t.smpl.loops[r].dwStart,e),q(t.smpl.loops[r].dwEnd,e),q(t.smpl.loops[r].dwFraction,e),q(t.smpl.loops[r].dwPlayCount,e));return n}(t,e);n=n.concat(Array.prototype.slice.call(V(t.smpl.chunkId)),q(r.length+36,e),q(t.smpl.dwManufacturer,e),q(t.smpl.dwProduct,e),q(t.smpl.dwSamplePeriod,e),q(t.smpl.dwMIDIUnityNote,e),q(t.smpl.dwMIDIPitchFraction,e),q(t.smpl.dwSMPTEFormat,e),q(t.smpl.dwSMPTEOffset,e),q(t.smpl.dwNumSampleLoops,e),q(t.smpl.dwSamplerData,e),r)}return n}(t,e),function(t,e,n){let r=[];for(let i=0;i<t.LIST.length;i++){let a=ht(t.LIST[i].subChunks,t.LIST[i].format,t,e,n);r=r.concat(Array.prototype.slice.call(V(t.LIST[i].chunkId)),q(a.length+4,e),Array.prototype.slice.call(V(t.LIST[i].format)),a)}return r}(t,e,n)],i=0;for(let t=0;t<r.length;t++)i+=r[t].length;let a=new Uint8Array(i+12),s=0;s=J(i+4,e,a,s=Z(t.container,a,s)),s=Z(t.format,a,s);for(let t=0;t<r.length;t++)a.set(r[t],s),s+=r[t].length;return a}function ht(t,e,n,r,i){let a=[];for(let s=0;s<t.length;s++)"INFO"==e?(a=a.concat(Array.prototype.slice.call(V(t[s].chunkId)),q(t[s].value.length+1,r),at.writeString_(t[s].value,t[s].value.length))).push(0):"adtl"==e&&(["labl","note"].indexOf(t[s].chunkId)>-1?(a=a.concat(Array.prototype.slice.call(V(t[s].chunkId)),q(t[s].value.length+4+1,r),q(t[s].dwName,r),at.writeString_(t[s].value,t[s].value.length))).push(0):"ltxt"==t[s].chunkId&&(a=a.concat(ut(t[s],n,r,i)))),a.length%2&&a.push(0);return a}function ut(t,e,n,r){return[].concat(Array.prototype.slice.call(V(t.chunkId)),q(t.value.length+20,n),q(t.dwName,n),q(t.dwSampleLength,n),q(t.dwPurposeID,n),q(t.dwCountry,r),q(t.dwLanguage,r),q(t.dwDialect,r),q(t.dwCodePage,r),at.writeString_(t.value,t.value.length))}const ot={bits:32};let lt=0;function ct(t){lt=0;let e=mt(t,0);ot.be="RIFX"==e;let n=X(t,8,11);return lt+=4,{chunkId:e,chunkSize:kt(t,0),format:n,subChunks:ft(t)}}function dt(t,e,n=!1){let r=[];for(let i=0;i<t.length;i++)if(t[i].chunkId==e){if(!n)return t[i];r.push(t[i])}return"LIST"==e&&r.length?r:null}function ft(t){let e=[],n=lt;for(;n<=t.length-8;)e.push(pt(t,n)),n=(n+=8+e[e.length-1].chunkSize)%2?n+1:n;return e}function pt(t,e){let n={chunkId:mt(t,e),chunkSize:kt(t,e)};if("LIST"==n.chunkId)n.format=X(t,e+8,e+11),lt+=4,n.subChunks=ft(t);else{let t=n.chunkSize%2?n.chunkSize+1:n.chunkSize;lt=e+8+t,n.chunkData={start:e+8,end:lt}}return n}function mt(t,e){return lt+=4,X(t,e,e+3)}function kt(t,e){return lt+=4,Q(t,ot,e+4)}let St=new it;function bt(t,e,n){St.head_=0;let r={bits:32,be:!1},i={bits:16,be:!1};!function(t,e,n,r){if(St.head_=0,e.container=St.readString_(t,4),-1===["RIFF","RIFX","RF64"].indexOf(e.container))throw Error("Not a supported format.");if(r.be="RIFX"===e.container,n.be=r.be,e.chunkSize=St.read_(t,n),e.format=St.readString_(t,4),"WAVE"!=e.format)throw Error('Could not find the "WAVE" format identifier')}(t,n,r,i);let a=ct(t);!function(t,e,n,r){let i=dt(e,"ds64");if(i)St.head_=i.chunkData.start,n.ds64.chunkId=i.chunkId,n.ds64.chunkSize=i.chunkSize,n.ds64.riffSizeHigh=St.read_(t,r),n.ds64.riffSizeLow=St.read_(t,r),n.ds64.dataSizeHigh=St.read_(t,r),n.ds64.dataSizeLow=St.read_(t,r),n.ds64.originationTime=St.read_(t,r),n.ds64.sampleCountHigh=St.read_(t,r),n.ds64.sampleCountLow=St.read_(t,r);else if("RF64"==n.container)throw Error('Could not find the "ds64" chunk')}(t,a.subChunks,n,r),function(t,e,n,r,i){let a=dt(e,"fmt ");if(!a)throw Error('Could not find the "fmt " chunk');St.head_=a.chunkData.start,n.fmt.chunkId=a.chunkId,n.fmt.chunkSize=a.chunkSize,n.fmt.audioFormat=St.read_(t,i),n.fmt.numChannels=St.read_(t,i),n.fmt.sampleRate=St.read_(t,r),n.fmt.byteRate=St.read_(t,r),n.fmt.blockAlign=St.read_(t,i),n.fmt.bitsPerSample=St.read_(t,i),function(t,e,n,r){e.fmt.chunkSize>16&&(e.fmt.cbSize=St.read_(t,r),e.fmt.chunkSize>18&&(e.fmt.validBitsPerSample=St.read_(t,r),e.fmt.chunkSize>20&&(e.fmt.dwChannelMask=St.read_(t,n),e.fmt.subformat=[St.read_(t,n),St.read_(t,n),St.read_(t,n),St.read_(t,n)])))}(t,n,r,i)}(t,a.subChunks,n,r,i),function(t,e,n,r){let i=dt(e,"fact");i&&(St.head_=i.chunkData.start,n.fact.chunkId=i.chunkId,n.fact.chunkSize=i.chunkSize,n.fact.dwSampleLength=St.read_(t,r))}(t,a.subChunks,n,r),function(t,e,n,r,i){let a=dt(e,"bext");a&&(St.head_=a.chunkData.start,n.bext.chunkId=a.chunkId,n.bext.chunkSize=a.chunkSize,n.bext.description=St.readString_(t,256),n.bext.originator=St.readString_(t,32),n.bext.originatorReference=St.readString_(t,32),n.bext.originationDate=St.readString_(t,10),n.bext.originationTime=St.readString_(t,8),n.bext.timeReference=[St.read_(t,r),St.read_(t,r)],n.bext.version=St.read_(t,i),n.bext.UMID=St.readString_(t,64),n.bext.loudnessValue=St.read_(t,i),n.bext.loudnessRange=St.read_(t,i),n.bext.maxTruePeakLevel=St.read_(t,i),n.bext.maxMomentaryLoudness=St.read_(t,i),n.bext.maxShortTermLoudness=St.read_(t,i),n.bext.reserved=St.readString_(t,180),n.bext.codingHistory=St.readString_(t,n.bext.chunkSize-602))}(t,a.subChunks,n,r,i),function(t,e,n,r){let i=dt(e,"cue ");if(i){St.head_=i.chunkData.start,n.cue.chunkId=i.chunkId,n.cue.chunkSize=i.chunkSize,n.cue.dwCuePoints=St.read_(t,r);for(let e=0;e<n.cue.dwCuePoints;e++)n.cue.points.push({dwName:St.read_(t,r),dwPosition:St.read_(t,r),fccChunk:St.readString_(t,4),dwChunkStart:St.read_(t,r),dwBlockStart:St.read_(t,r),dwSampleOffset:St.read_(t,r)})}}(t,a.subChunks,n,r),function(t,e,n,r){let i=dt(e,"smpl");if(i){St.head_=i.chunkData.start,n.smpl.chunkId=i.chunkId,n.smpl.chunkSize=i.chunkSize,n.smpl.dwManufacturer=St.read_(t,r),n.smpl.dwProduct=St.read_(t,r),n.smpl.dwSamplePeriod=St.read_(t,r),n.smpl.dwMIDIUnityNote=St.read_(t,r),n.smpl.dwMIDIPitchFraction=St.read_(t,r),n.smpl.dwSMPTEFormat=St.read_(t,r),n.smpl.dwSMPTEOffset=St.read_(t,r),n.smpl.dwNumSampleLoops=St.read_(t,r),n.smpl.dwSamplerData=St.read_(t,r);for(let e=0;e<n.smpl.dwNumSampleLoops;e++)n.smpl.loops.push({dwName:St.read_(t,r),dwType:St.read_(t,r),dwStart:St.read_(t,r),dwEnd:St.read_(t,r),dwFraction:St.read_(t,r),dwPlayCount:St.read_(t,r)})}}(t,a.subChunks,n,r),function(t,e,n,r){let i=dt(e,"data");if(!i)throw Error('Could not find the "data" chunk');r.data.chunkId="data",r.data.chunkSize=i.chunkSize,n&&(r.data.samples=t.slice(i.chunkData.start,i.chunkData.end))}(t,a.subChunks,e,n),function(t,e,n){let r=dt(e,"junk");r&&(n.junk={chunkId:r.chunkId,chunkSize:r.chunkSize,chunkData:[].slice.call(t.slice(r.chunkData.start,r.chunkData.end))})}(t,a.subChunks,n),function(t,e,n,r,i){let a=dt(e,"LIST",!0);if(null===a)return;for(let e=0;e<a.length;e++){let s=a[e];n.LIST.push({chunkId:s.chunkId,chunkSize:s.chunkSize,format:s.format,subChunks:[]});for(let e=0;e<s.subChunks.length;e++)wt(s.subChunks[e],s.format,t,n,r,i)}}(t,a.subChunks,n,r,i)}function wt(t,e,n,r,i,a){if("adtl"==e){if(["labl","note","ltxt"].indexOf(t.chunkId)>-1){St.head_=t.chunkData.start;let e={chunkId:t.chunkId,chunkSize:t.chunkSize,dwName:St.read_(n,i)};"ltxt"==t.chunkId&&(e.dwSampleLength=St.read_(n,i),e.dwPurposeID=St.read_(n,i),e.dwCountry=St.read_(n,a),e.dwLanguage=St.read_(n,a),e.dwDialect=St.read_(n,a),e.dwCodePage=St.read_(n,a)),e.value=St.readZSTR_(n,St.head_),r.LIST[r.LIST.length-1].subChunks.push(e)}}else"INFO"==e&&(St.head_=t.chunkData.start,r.LIST[r.LIST.length-1].subChunks.push({chunkId:t.chunkId,chunkSize:t.chunkSize,value:St.readZSTR_(n,St.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");J(e,this.dataType,this.data.samples,t)}fromScratch(t,e,n,r,i={}){i.container||(i.container="RIFF"),this.container=i.container,this.bitDepth=n,r=this.interleave_(r),this.updateDataType_();let a=this.dataType.bits/8;this.data.samples=new Uint8Array(r.length*a),K(r,this.dataType,this.data.samples);let s=et(n,t,e,a,this.data.samples.length,i);this.clearHeader_(),this.chunkSize=s.chunkSize,this.format=s.format,this.fmt=s.fmt,s.fact&&(this.fact=s.fact),this.data.chunkId="data",this.data.chunkSize=this.data.samples.length,rt(this)}fromBuffer(t,e=!0){this.clearHeader_(),bt(t,e,this),this.bitDepthFromFmt_(),this.updateDataType_()}toBuffer(){return rt(this),st(this)}fromBase64(t){this.fromBuffer(new Uint8Array(A(t)))}toBase64(){let t=this.toBuffer();return P(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,Y(this.data.samples,this.dataType))}toRIFX(){this.fromScratch(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,Y(this.data.samples,this.dataType),{container:"RIFX"})}toBitDepth(t,n=!0){let r=t,i=this.bitDepth;n||("32f"!=t&&(r=this.dataType.bits.toString()),i=this.dataType.bits),this.assureUncompressed_();let a=this.data.samples.length/(this.dataType.bits/8),s=new Float64Array(a+1),h=new Float64Array(a+1);$(this.data.samples,this.dataType,s),"32f"!=i&&"64"!=i||this.truncateSamples_(s),e(s,i,r,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);$(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=[],r=0;for(let i=0;i<t.length;i++)i%505==0&&0!=i&&(e.set(p(n),r),r+=256,n=[]),n.push(t[i]);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),r=[],i=0;for(let a=0;a<t.length;a++)a%e==0&&0!=a&&(n.set(m(r),i),i+=2*e,r=[]),r.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);$(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]=g(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);$(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]=L(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]=x(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,r=this.LIST[t].subChunks.length;n<r;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 r=this.cue.points.length;this.cue.points=[];let i=!1;if(0===r)this.setCuePoint_(t,1,e);else{for(let a=0;a<r;a++)n[a].dwPosition>t&&!i?(this.setCuePoint_(t,a+1,e),this.setCuePoint_(n[a].dwPosition,a+2,n[a].label),i=!0):this.setCuePoint_(n[a].dwPosition,a+1,n[a].label);i||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 r=0;r<n;r++)r+1!==t&&this.setCuePoint_(e[r].dwPosition,r+1,e[r].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 r=0,i=this.LIST[n].subChunks.length;r<i;r++)this.LIST[n].subChunks[r].dwName==t&&(this.LIST[n].subChunks[r].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,r=this.LIST[e].subChunks.length;n<r;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,r=this.LIST.length;n<r;n++)if("INFO"==this.LIST[n].format){e.LIST=n;for(let r=0,i=this.LIST[n].subChunks.length;r<i;r++)if(this.LIST[n].subChunks[r].chunkId==t){e.TAG=r;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,r=t[0].length;n<r;n++)for(let r=0,i=t.length;r<i;r++)e.push(t[r][n]);t=e}return t}updateDataType_(){this.dataType={bits:1+(parseInt(this.bitDepth,10)-1|7),float:"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; |
/** | ||
* @fileoverview Externs for wavefile 8.3 | ||
* @fileoverview Externs for wavefile 9.0 | ||
* | ||
@@ -9,3 +9,3 @@ * @see https://github.com/rochars/wavefile | ||
// WaveFile class | ||
const WaveFile = {}; | ||
var WaveFile = {}; | ||
@@ -12,0 +12,0 @@ /** |
235
index.d.ts
@@ -1,2 +0,2 @@ | ||
// Type definitions for wavefile 8.3 | ||
// Type definitions for wavefile 9.0 | ||
// Project: https://github.com/rochars/wavefile | ||
@@ -10,69 +10,290 @@ // Definitions by: Rafael S. Rocha <https://github.com/rochars> | ||
/** | ||
* @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; | ||
LIST: 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; | ||
/** | ||
* 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; | ||
fromScratch(numChannels: number, sampleRate: number, bitDepthCode: string, samples: Array<number>, 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>, | ||
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; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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 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; | ||
/** | ||
* 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; | ||
/** | ||
* 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; | ||
listTags(): object; | ||
listCuePoints(): Array<object>; | ||
} |
54
index.js
@@ -53,3 +53,3 @@ /* | ||
/** | ||
* @param {?Uint8Array} bytes A wave file buffer. | ||
* @param {?Uint8Array=} bytes A wave file buffer. | ||
* @throws {Error} If no 'RIFF' chunk is found. | ||
@@ -445,3 +445,3 @@ * @throws {Error} If no 'fmt ' chunk is found. | ||
if (index !== null) { | ||
for (let i=0; i<this.LIST[index].subChunks.length; i++) { | ||
for (let i = 0, len = this.LIST[index].subChunks.length; i < len; i++) { | ||
tags[this.LIST[index].subChunks[i].chunkId] = | ||
@@ -488,3 +488,3 @@ this.LIST[index].subChunks[i].value; | ||
} else { | ||
for (let i=0; i<len; i++) { | ||
for (let i = 0; i < len; i++) { | ||
if (existingPoints[i].dwPosition > position && !hasSet) { | ||
@@ -524,3 +524,3 @@ this.setCuePoint_(position, i + 1, labl); | ||
this.cue.points = []; | ||
for (let i=0; i<len; i++) { | ||
for (let i = 0; i < len; i++) { | ||
if (i + 1 !== index) { | ||
@@ -553,3 +553,3 @@ this.setCuePoint_( | ||
let points = this.getCuePoints_(); | ||
for (let i=0; i<points.length; i++) { | ||
for (let i = 0, len = points.length; i < len; i++) { | ||
points[i].milliseconds = | ||
@@ -568,8 +568,8 @@ (points[i].dwPosition / this.fmt.sampleRate) * 1000; | ||
/** @type {?number} */ | ||
let adtlIndex = this.getAdtlChunk_(); | ||
if (adtlIndex !== null) { | ||
for (let i=0; i<this.LIST[adtlIndex].subChunks.length; i++) { | ||
if (this.LIST[adtlIndex].subChunks[i].dwName == | ||
let cIndex = this.getAdtlChunk_(); | ||
if (cIndex !== null) { | ||
for (let i = 0, len = this.LIST[cIndex].subChunks.length; i < len; i++) { | ||
if (this.LIST[cIndex].subChunks[i].dwName == | ||
pointIndex) { | ||
this.LIST[adtlIndex].subChunks[i].value = label; | ||
this.LIST[cIndex].subChunks[i].value = label; | ||
} | ||
@@ -623,3 +623,3 @@ } | ||
let points = []; | ||
for (let i=0; i<this.cue.points.length; i++) { | ||
for (let i = 0, len = this.cue.points.length; i < len; i++) { | ||
points.push({ | ||
@@ -641,8 +641,8 @@ dwPosition: this.cue.points[i].dwPosition, | ||
/** @type {?number} */ | ||
let adtlIndex = this.getAdtlChunk_(); | ||
if (adtlIndex !== null) { | ||
for (let i=0; i<this.LIST[adtlIndex].subChunks.length; i++) { | ||
if (this.LIST[adtlIndex].subChunks[i].dwName == | ||
let cIndex = this.getAdtlChunk_(); | ||
if (cIndex !== null) { | ||
for (let i = 0, len = this.LIST[cIndex].subChunks.length; i < len; i++) { | ||
if (this.LIST[cIndex].subChunks[i].dwName == | ||
pointDwName) { | ||
return this.LIST[adtlIndex].subChunks[i].value; | ||
return this.LIST[cIndex].subChunks[i].value; | ||
} | ||
@@ -659,3 +659,3 @@ } | ||
clearLISTadtl_() { | ||
for (let i=0; i<this.LIST.length; i++) { | ||
for (let i = 0, len = this.LIST.length; i < len; i++) { | ||
if (this.LIST[i].format == 'adtl') { | ||
@@ -710,3 +710,3 @@ this.LIST.splice(i); | ||
getAdtlChunk_() { | ||
for (let i=0; i<this.LIST.length; i++) { | ||
for (let i = 0, len = this.LIST.length; i < len; i++) { | ||
if (this.LIST[i].format == 'adtl') { | ||
@@ -727,3 +727,3 @@ return i; | ||
let index = null; | ||
for (let i=0; i<this.LIST.length; i++) { | ||
for (let i = 0, len = this.LIST.length; i < len; i++) { | ||
if (this.LIST[i].format === 'INFO') { | ||
@@ -748,6 +748,6 @@ index = i; | ||
let index = {LIST: null, TAG: null}; | ||
for (let i=0; i<this.LIST.length; i++) { | ||
for (let i = 0, len = this.LIST.length; i < len; i++) { | ||
if (this.LIST[i].format == 'INFO') { | ||
index.LIST = i; | ||
for (let j=0; j<this.LIST[i].subChunks.length; j++) { | ||
for (let j=0, subLen = this.LIST[i].subChunks.length; j < subLen; j++) { | ||
if (this.LIST[i].subChunks[j].chunkId == tag) { | ||
@@ -774,3 +774,3 @@ index.TAG = j; | ||
} else if (tag.length < 4) { | ||
for (let i=0; i<4-tag.length; i++) { | ||
for (let i = 0, len = 4 - tag.length; i < len; i++) { | ||
tag += ' '; | ||
@@ -821,3 +821,4 @@ } | ||
* Set up the WaveFile object from a byte buffer. | ||
* @param {!Array<number>|!Array<!Array<number>>|!ArrayBufferView} samples The samples. | ||
* @param {!Array<number>|!Array<!Array<number>>|!ArrayBufferView} | ||
* samples The samples. | ||
* @private | ||
@@ -830,4 +831,4 @@ */ | ||
let finalSamples = []; | ||
for (let i=0; i < samples[0].length; i++) { | ||
for (let j=0; j < samples.length; j++) { | ||
for (let i = 0, len = samples[0].length; i < len; i++) { | ||
for (let j = 0, subLen = samples.length; j < subLen; j++) { | ||
finalSamples.push(samples[j][i]); | ||
@@ -876,4 +877,3 @@ } | ||
/** @type {number} */ | ||
let len = samples.length; | ||
for (let i=0; i<len; i++) { | ||
for (let i = 0, len = samples.length; i < len; i++) { | ||
if (samples[i] > 1) { | ||
@@ -880,0 +880,0 @@ samples[i] = 1; |
@@ -30,3 +30,3 @@ /* | ||
import {unpackFrom, unpackString, packString} from 'byte-data'; | ||
import {unpack, unpackString, packString} from 'byte-data'; | ||
@@ -56,3 +56,3 @@ /** | ||
/** @type {!Array<number>} */ | ||
let bytes = packString(str); | ||
let bytes = Array.prototype.slice.call(packString(str)); | ||
if (push) { | ||
@@ -80,3 +80,3 @@ for (let i=bytes.length; i<maxSize; i++) { | ||
} | ||
str += unpackString(bytes, i, 1); | ||
str += unpackString(bytes, i, i); | ||
} | ||
@@ -96,6 +96,4 @@ return str; | ||
let str = ''; | ||
for (let i=0; i<maxSize; i++) { | ||
str += unpackString(bytes, this.head_, 1); | ||
this.head_++; | ||
} | ||
str = unpackString(bytes, this.head_, this.head_ + maxSize - 1); | ||
this.head_ += maxSize; | ||
return str; | ||
@@ -115,3 +113,3 @@ } | ||
/** @type {number} */ | ||
let value = unpackFrom(bytes, bdType, this.head_); | ||
let value = unpack(bytes, bdType, this.head_); | ||
this.head_ += size; | ||
@@ -118,0 +116,0 @@ return value; |
@@ -30,3 +30,3 @@ /* | ||
import {riffChunks, findChunk} from 'riff-chunks'; | ||
import {riffChunks, findChunk} from './riff-chunks.js'; | ||
import BufferIO from './bufferio.js'; | ||
@@ -33,0 +33,0 @@ |
@@ -54,3 +54,3 @@ /* | ||
getFactBytes_(wav, uInt32_), | ||
packString(wav.data.chunkId), | ||
Array.prototype.slice.call(packString(wav.data.chunkId)), | ||
pack(wav.data.samples.length, uInt32_), | ||
@@ -94,3 +94,3 @@ wav.data.samples, | ||
bytes = bytes.concat( | ||
packString(wav.bext.chunkId), | ||
Array.prototype.slice.call(packString(wav.bext.chunkId)), | ||
pack(602 + wav.bext.codingHistory.length, uInt32_), | ||
@@ -105,3 +105,3 @@ io.writeString_(wav.bext.description, 256), | ||
pack(wav.bext.version, uInt16_), | ||
io.writeString_(wav.bext.UMID, 64), | ||
Array.prototype.slice.call(io.writeString_(wav.bext.UMID, 64)), | ||
pack(wav.bext.loudnessValue, uInt16_), | ||
@@ -149,3 +149,3 @@ pack(wav.bext.loudnessRange, uInt16_), | ||
bytes = bytes.concat( | ||
packString(wav.ds64.chunkId), | ||
Array.prototype.slice.call(packString(wav.ds64.chunkId)), | ||
pack(wav.ds64.chunkSize, uInt32_), | ||
@@ -181,3 +181,3 @@ pack(wav.ds64.riffSizeHigh, uInt32_), | ||
bytes = bytes.concat( | ||
packString(wav.cue.chunkId), | ||
Array.prototype.slice.call(packString(wav.cue.chunkId)), | ||
pack(cuePointsBytes.length + 4, uInt32_), | ||
@@ -203,3 +203,3 @@ pack(wav.cue.dwCuePoints, uInt32_), | ||
pack(wav.cue.points[i].dwPosition, uInt32_), | ||
packString(wav.cue.points[i].fccChunk), | ||
Array.prototype.slice.call(packString(wav.cue.points[i].fccChunk)), | ||
pack(wav.cue.points[i].dwChunkStart, uInt32_), | ||
@@ -225,3 +225,3 @@ pack(wav.cue.points[i].dwBlockStart, uInt32_), | ||
bytes = bytes.concat( | ||
packString(wav.smpl.chunkId), | ||
Array.prototype.slice.call(packString(wav.smpl.chunkId)), | ||
pack(smplLoopsBytes.length + 36, uInt32_), | ||
@@ -274,3 +274,3 @@ pack(wav.smpl.dwManufacturer, uInt32_), | ||
bytes = bytes.concat( | ||
packString(wav.fact.chunkId), | ||
Array.prototype.slice.call(packString(wav.fact.chunkId)), | ||
pack(wav.fact.chunkSize, uInt32_), | ||
@@ -294,3 +294,3 @@ pack(wav.fact.dwSampleLength, uInt32_)); | ||
return fmtBytes.concat( | ||
packString(wav.fmt.chunkId), | ||
Array.prototype.slice.call(packString(wav.fmt.chunkId)), | ||
pack(wav.fmt.chunkSize, uInt32_), | ||
@@ -352,5 +352,5 @@ pack(wav.fmt.audioFormat, uInt16_), | ||
bytes = bytes.concat( | ||
packString(wav.LIST[i].chunkId), | ||
Array.prototype.slice.call(packString(wav.LIST[i].chunkId)), | ||
pack(subChunksBytes.length + 4, uInt32_), | ||
packString(wav.LIST[i].format), | ||
Array.prototype.slice.call(packString(wav.LIST[i].format)), | ||
subChunksBytes); | ||
@@ -376,3 +376,3 @@ } | ||
bytes = bytes.concat( | ||
packString(subChunks[i].chunkId), | ||
Array.prototype.slice.call(packString(subChunks[i].chunkId)), | ||
pack(subChunks[i].value.length + 1, uInt32_), | ||
@@ -385,3 +385,3 @@ io.writeString_( | ||
bytes = bytes.concat( | ||
packString(subChunks[i].chunkId), | ||
Array.prototype.slice.call(packString(subChunks[i].chunkId)), | ||
pack( | ||
@@ -415,3 +415,3 @@ subChunks[i].value.length + 4 + 1, uInt32_), | ||
return [].concat( | ||
packString(ltxt.chunkId), | ||
Array.prototype.slice.call(packString(ltxt.chunkId)), | ||
pack(ltxt.value.length + 20, uInt32_), | ||
@@ -439,3 +439,3 @@ pack(ltxt.dwName, uInt32_), | ||
return bytes.concat( | ||
packString(wav.junk.chunkId), | ||
Array.prototype.slice.call(packString(wav.junk.chunkId)), | ||
pack(wav.junk.chunkData.length, uInt32_), | ||
@@ -442,0 +442,0 @@ wav.junk.chunkData); |
{ | ||
"name": "wavefile", | ||
"version": "8.3.2", | ||
"version": "8.4.0", | ||
"description": "Create, read and write wav files according to the specs.", | ||
@@ -8,9 +8,4 @@ "homepage": "https://github.com/rochars/wavefile", | ||
"license": "MIT", | ||
"module": "./index.js", | ||
"main": "./dist/wavefile.cjs.js", | ||
"module": "./index.js", | ||
"es2015": "./dist/wavefile.js", | ||
"browser": "./dist/wavefile.umd.js", | ||
"jsdelivr": "./dist/wavefile.min.js", | ||
"unpkg": "./dist/wavefile.min.js", | ||
"types": "./index.d.ts", | ||
"bin": "./bin/wavefile.js", | ||
@@ -54,3 +49,4 @@ "engines": { | ||
"externs": "externs", | ||
"lib": "lib" | ||
"lib": "lib", | ||
"scripts": "scripts" | ||
}, | ||
@@ -62,2 +58,3 @@ "files": [ | ||
"lib", | ||
"scripts", | ||
"index.js", | ||
@@ -71,12 +68,13 @@ "index.d.ts", | ||
"scripts": { | ||
"lint": "jshint index.js bin externs lib", | ||
"test": "nyc ./node_modules/mocha/bin/_mocha test --recursive -R dot --timeout=240000", | ||
"test-esm": "node ./node_modules/mocha/bin/_mocha test --esm --recursive -R dot --timeout=240000", | ||
"test-min": "node ./node_modules/mocha/bin/_mocha test --min --recursive -R dot --timeout=240000", | ||
"test-cjs": "node ./node_modules/mocha/bin/_mocha test --cjs --recursive -R dot --timeout=240000", | ||
"test-umd": "node ./node_modules/mocha/bin/_mocha test --umd --recursive -R dot --timeout=240000", | ||
"lint": "jshint index.js bin externs lib test/src", | ||
"test": "nyc ./node_modules/mocha/bin/_mocha test/dist test/src --recursive -R dot --timeout=240000", | ||
"test-esm": "node ./node_modules/mocha/bin/_mocha test/dist test/src --esm --recursive -R dot --timeout=240000", | ||
"test-umd": "node ./node_modules/mocha/bin/_mocha test/dist test/src --umd --recursive -R dot --timeout=240000", | ||
"test-cjs": "node ./node_modules/mocha/bin/_mocha test/dist test/src --cjs --recursive -R dot --timeout=240000", | ||
"test-min": "node ./node_modules/mocha/bin/_mocha test/dist test/src --min --recursive -R dot --timeout=240000", | ||
"test-tsc": "tsc ./test/TypeScript/index.ts && node -r esm ./test/TypeScript/index.js", | ||
"test-cli": "wavefile ./test/files/M1F1-int12WE-AFsp.wav --tag=ICMT", | ||
"test-dist": "npm run test-min && npm run test-cjs && npm run test-umd && npm run test-esm && npm run test-cli", | ||
"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", | ||
"doc": "./node_modules/.bin/jsdoc index.js -d docs/api -t node_modules/docdash", | ||
"doc": "./node_modules/.bin/jsdoc index.js -d docs -r README.md -t node_modules/docdash", | ||
"build": "npm run lint && npm test && npm run rollup-bundle && npm run doc", | ||
@@ -89,6 +87,6 @@ "coverage": "nyc report --reporter=lcov > coverage.lcov && codecov" | ||
"babel-preset-env": "^1.7.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"codecov": "^3.0.2", | ||
"docdash": "^0.4.0", | ||
"esm": "^3.0.51", | ||
"google-closure-compiler-js": "^20180610.0.0", | ||
"jsdoc": "^3.5.5", | ||
@@ -101,5 +99,7 @@ "jshint": "^2.9.5", | ||
"rollup-plugin-babel": "^3.0.7", | ||
"rollup-plugin-closure-compiler-js": "^1.0.6", | ||
"rollup-plugin-commonjs": "^9.1.3", | ||
"rollup-plugin-node-resolve": "^3.3.0" | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"rollup-plugin-terser": "^1.0.1", | ||
"terser": "^3.8.1", | ||
"typescript": "^2.9.2" | ||
}, | ||
@@ -110,6 +110,5 @@ "dependencies": { | ||
"bitdepth": "^7.0.2", | ||
"byte-data": "^13.2.5", | ||
"imaadpcm": "^4.0.1", | ||
"riff-chunks": "^9.0.0" | ||
"byte-data": "^15.0.0", | ||
"imaadpcm": "^4.0.1" | ||
} | ||
} |
908
README.md
@@ -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/api/) [![Manual](https://img.shields.io/badge/manual-online-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/) [![Tests](https://img.shields.io/badge/tests-online-blue.svg?style=for-the-badge)](https://rawgit.com/rochars/wavefile/master/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) | ||
@@ -11,10 +11,7 @@ | ||
- **All MIT licensed** | ||
- **Use it out of the box in the browser** | ||
- **Use it out of the box in Node** | ||
- **Use it out of the box with [TypeScript](https://www.typescriptlang.org/)** | ||
- **MIT licensed** | ||
- **Use it in the browser (IE10+)** | ||
- **Use it in Node.js** | ||
- **Use it as a command line tool** | ||
- **Handle files up to 2GB** | ||
- **Use it as a command line tool** | ||
- **Less than 10kb minified + compressed, less than 32kb minified** | ||
- Made with **[Closure Compiler](https://github.com/google/closure-compiler)** in mind (works great with others, too) | ||
@@ -35,4 +32,2 @@ With **wavefile** you can: | ||
## Install | ||
### NPM | ||
To use it in your programs: | ||
@@ -43,3 +38,3 @@ ``` | ||
To use it from the [command line](https://github.com/rochars/wavefile/blob/master/docs/README.md#cli-usage), install it globally: | ||
To use it from the [command line](#command-line), install it globally: | ||
``` | ||
@@ -49,27 +44,2 @@ npm install wavefile -g | ||
### Yarn | ||
To use it in your programs: | ||
``` | ||
yarn add wavefile | ||
``` | ||
To use it from the [command line](https://github.com/rochars/wavefile/blob/master/docs/README.md#cli-usage), install it globally: | ||
``` | ||
yarn global add wavefile | ||
``` | ||
### GitHub | ||
This is not recommended as it will also include test and build assets in your installation. If this is what you want, you can: | ||
``` | ||
git clone https://github.com/rochars/wavefile | ||
``` | ||
And then import/require what you want from the *wavefile* folder: | ||
``` | ||
const WaveFile = require('./wavefile/dist/wavefile.umd.js'); | ||
``` | ||
You can also download one of the files in the *./dist* folder: | ||
https://github.com/rochars/wavefile/tree/master/dist | ||
## Use | ||
@@ -91,5 +61,5 @@ | ||
### Browser | ||
Use the compiled file in the */dist* folder of this package: | ||
Load **wavefile.umd.js** with ```<script>``` tags: | ||
```html | ||
<script src="./dist/wavefile.min.js"></script> | ||
<script src="./dist/wavefile.umd.js"></script> | ||
<script> | ||
@@ -100,3 +70,3 @@ var WaveFile = new WaveFile(); | ||
Or get it from the [jsDelivr](https://cdn.jsdelivr.net/npm/wavefile) CDN: | ||
Or load it from the [jsDelivr](https://cdn.jsdelivr.net/npm/wavefile) CDN: | ||
```html | ||
@@ -106,3 +76,3 @@ <script src="https://cdn.jsdelivr.net/npm/wavefile"></script> | ||
Or get it from [unpkg](https://unpkg.com/wavefile): | ||
Or load it from [unpkg](https://unpkg.com/wavefile): | ||
```html | ||
@@ -112,30 +82,834 @@ <script src="https://unpkg.com/wavefile"></script> | ||
Or load it as a module using [jspm](https://jspm.io): | ||
```html | ||
<script type="module"> | ||
import WaveFile from 'https://dev.jspm.io/wavefile'; | ||
console.log(new WaveFile()); | ||
</script> | ||
#### Browser compatibility | ||
IE10+. Should work in all modern browsers that support ES5/ES6+. | ||
Cross-browser tests powered by | ||
<a href="https://www.browserstack.com"><img src="https://rochars.github.io/wavefile/docs/Browserstack-logo@2x.png" width="150px"/></a> | ||
### Command line | ||
To see the available options: | ||
``` | ||
wavefile --help | ||
``` | ||
#### Browser Compatibility | ||
**wavefile** need IE10+ to run. All moderns browsers should work fine. Cross-browser tests are on the [ROADMAP](https://github.com/rochars/wavefile/blob/master/docs/ROADMAP.md). | ||
The available options: | ||
``` | ||
--bitdepth Ex: wavefile input.wav --bitdepth=32f output.wav | ||
Change the bit depth. | ||
The input file is not affected. | ||
Possible values: 8, 16, 24, 32, 32f, 64 | ||
### ES bundle | ||
Import WaveFile from **wavefile.js** in the *./dist* folder of this package: | ||
--compress Ex: wavefile input.wav --compress=adpcm output.wav | ||
Apply compression to the file. | ||
The input file is not affected. | ||
Possible values: adpcm, alaw, mulaw | ||
--tag Ex: wavefile input.wav --tag=ICRD | ||
Print the value of tag if the tag exists. | ||
--list-tags Ex: wavefile input.wav --list-tags | ||
Print all tags of the file. | ||
--list-cue Ex: wavefile input.wav --list-cue | ||
Print all the cue points of the file. | ||
--bits Ex: wavefile input.wav --bits | ||
Print the bit depth of the file. | ||
--rate Ex: wavefile input.wav --rate | ||
Print the sample rate of the file. | ||
--help Ex: --help | ||
Show this help page. | ||
``` | ||
## Node.js Example | ||
```javascript | ||
import WaveFile from './dist/wavefile.js'; | ||
const WaveFile = require('wavefile'); | ||
// Load a wav file from disk into a WaveFile object | ||
let wav = new WaveFile(buffer); | ||
// Check some of the file properties | ||
console.log(wav.container); | ||
console.log(wav.chunkSize); | ||
console.log(wav.fmt.chunkId); | ||
// Call toBuffer() to get the bytes of the file. | ||
// You can write the output straight to disk: | ||
let wavBuffer = wav.toBuffer(); | ||
// Call toDataURI() to get the file as a DataURI: | ||
let wavDataURI = wav.toDataURI(); | ||
``` | ||
## Table of Contents | ||
- [Install](#install) | ||
- [Use](#use) | ||
- [Example](#example) | ||
- [Operation Manual](#operation-manual) | ||
* [Create wave files from scratch](#create-wave-files-from-scratch) | ||
* [Add RIFF tags to files](#add-riff-tags-to-files) | ||
* [Add cue points to files](#add-cue-points-to-files) | ||
* [RIFX](#rifx) | ||
* [IMA-ADPCM](#ima-adpcm) | ||
* [A-Law](#a-law) | ||
* [mu-Law](#mu-law) | ||
* [Change the bit depth](#change-the-bit-depth) | ||
* [Add BWF metadata](#add-bwf-metadata) | ||
* [RF64](#rf64) | ||
- [API](#api) | ||
* [The WaveFile methods:](#the-wavefile-methods-) | ||
* [The WaveFile properties](#the-wavefile-properties) | ||
+ [Cue points](#cue-points) | ||
+ [Sample loops](#sample-loops) | ||
+ [LIST chunk](#list-chunk) | ||
- [The samples](#the-samples) | ||
- [Distribution](#distribution) | ||
- [Contributing to wavefile](#contributing-to-wavefile) | ||
- [References](#references) | ||
- [Legal](#legal) | ||
## Operation Manual | ||
### Create wave files from scratch | ||
You must inform the number of channels, the sample rate, the bit depth and the samples (in this order). | ||
#### Mono: | ||
```javascript | ||
let wav = new WaveFile(); | ||
// Create a mono wave file, 44.1 kHz, 32-bit and 4 samples | ||
wav.fromScratch(1, 44100, '32', [0, -2147483648, 2147483647, 4]); | ||
fs.writeFileSync(path, wav.toBuffer()); | ||
``` | ||
## Manual | ||
Learn how to use **[wavefile](https://github.com/rochars/wavefile/blob/master/docs/README.md)** | ||
#### Stereo: | ||
Samples can be informed interleaved or de-interleaved. If they are de-interleaved, WaveFile will interleave them. In this example they are de-interleaved. | ||
```javascript | ||
// Stereo, 48 kHz, 8-bit, de-interleaved samples | ||
// WaveFile interleave the samples automatically | ||
wav.fromScratch(2, 48000, '8', [ | ||
[0, -2, 4, 3], | ||
[0, -1, 4, 3] | ||
]); | ||
fs.writeFileSync(path, wav.toBuffer()); | ||
``` | ||
Possible values for the bit depth are: | ||
"4" - 4-bit IMA-ADPCM | ||
"8" - 8-bit | ||
"8a" - 8-bit A-Law | ||
"8m" - 8-bit mu-Law | ||
"16" - 16-bit | ||
"24" - 24-bit | ||
"32" - 32-bit | ||
"32f" - 32-bit floating point | ||
"64" - 64-bit floating point | ||
You can also use any bit depth between "8" and "53", like **"11", "12", "17", "20" and so on**. | ||
#### A word on bit depth | ||
Resolutions other than 4-bit, 8-bit, 16-bit, 24-bit, 32-bit (integer), 32-bit (fp) and 64-bit (fp) are implemented as WAVE_FORMAT_EXTENSIBLE and may not be supported by some players. | ||
### Add RIFF tags to files | ||
You can create (or overwrite) tags on files with the **WaveFile.setTag()** method. | ||
```javascript | ||
// Write the ICMT tag with some comments to the file | ||
wav.setTag("ICMT", "some comments"); | ||
``` | ||
To get the value of a tag (if it exists), use **WaveFile.getTag()**: | ||
```javascript | ||
console.log(wav.getTag("ICMT")); | ||
// some comments | ||
``` | ||
You can delete a tag with **WaveFile.deleteTag()**: | ||
```javascript | ||
wav.deleteTag("ICMT"); | ||
``` | ||
### Add cue points to files | ||
You can create cue points using the **WaveFile.setCuePoint()** method. The method takes time in milliseconds, a text label and creates a cue point in the corresponding position of the file: | ||
```javascript | ||
wav.setCuePoint(1750, "some label for the cue point"); | ||
``` | ||
To delete a cue point use **WaveFile.deleteCuePoint()** informing the index of the point. Points are ordered according to their position. The first point is indexed as 1. | ||
```javascript | ||
wav.deleteCuePoint(1); | ||
``` | ||
Mind that creating or deleting cue points will change the index of other points if they exist. | ||
### RIFX | ||
**wavefile** can handle existing RIFX files and create RIFX files from scratch. Files created from scratch will default to RIFF; to create a file as RIFX you must define the container: | ||
```javascript | ||
wav.fromScratch(1, 48000, '16', [0, 1, -32768, 32767], {"container": "RIFX"}); | ||
``` | ||
RIFX to RIFF and RIFF to RIFX: | ||
```javascript | ||
// Turn a RIFF file to a RIFX file | ||
wav.toRIFX(); | ||
// Turn a RIFX file to a RIFF file | ||
wav.toRIFF(); | ||
``` | ||
### IMA-ADPCM | ||
16-bit 8000 Hz mono wave files can be compressed as IMA-ADPCM: | ||
```javascript | ||
// Encode a 16-bit wave file as 4-bit IMA-ADPCM: | ||
wav.toIMAADPCM(); | ||
``` | ||
IMA-ADPCM files compressed with **wavefile** will have a block align of 256 bytes. | ||
If the audio is not 16-bit it will be converted to 16-bit before compressing. Compressing audio with sample rate different from 8000 Hz or more than one channel is not supported and will throw errors. | ||
To decode 4-bit IMA-ADPCM as 16-bit linear PCM: | ||
```javascript | ||
// Decode 4-bit IMA-ADPCM as 16-bit: | ||
wav.fromIMAADPCM(); | ||
``` | ||
Decoding always result in 16-bit audio. To decode to another bit depth: | ||
```javascript | ||
// Decode 4-bit IMA-ADPCM as 24-bit: | ||
wav.fromIMAADPCM("24"); | ||
``` | ||
### A-Law | ||
16-bit wave files (mono or stereo) can be encoded as A-Law: | ||
```javascript | ||
// Encode a 16-bit wave file as 8-bit A-law: | ||
wav.toALaw(); | ||
``` | ||
If the audio is not 16-bit it will be converted to 16-bit before compressing. | ||
To decode 8-bit A-Law as 16-bit linear PCM: | ||
```javascript | ||
// Decode 8-bit A-Law as 16-bit: | ||
wav.fromALaw(); | ||
``` | ||
Decoding always result in 16-bit audio. To decode to another bit depth: | ||
```javascript | ||
// Decode 8-bit A-Law as 24-bit: | ||
wav.fromALaw("24"); | ||
``` | ||
### mu-Law | ||
16-bit wave files (mono or stereo) can be encoded as mu-Law: | ||
```javascript | ||
// Encode a 16-bit wave file as 8-bit mu-law: | ||
wav.toMuLaw(); | ||
``` | ||
If the audio is not 16-bit it will be converted to 16-bit before compressing. | ||
To decode 8-bit mu-Law as 16-bit linear PCM: | ||
```javascript | ||
// Decode 8-bit mu-Law as 16-bit: | ||
wav.fromMuLaw(); | ||
``` | ||
Decoding always result in 16-bit audio. To decode to another bit depth: | ||
```javascript | ||
// Decode 8-bit mu-Law as 24-bit: | ||
wav.fromMuLaw("24"); | ||
``` | ||
### Change the bit depth | ||
You can change the bit depth of the audio with the **toBitDepth(bitDepth)** method. | ||
```javascript | ||
// Load a wav file with 32-bit audio | ||
let wav = new WaveFile(fs.readFileSync("32bit-file.wav")); | ||
// Change the bit depth to 24-bit | ||
wav.toBitDepth("24"); | ||
// Write the new 24-bit file | ||
fs.writeFileSync("24bit-file.wav", wav.toBuffer()); | ||
``` | ||
### Add BWF metadata | ||
To add BWF data to a file you can use the **bext** property: | ||
```javascript | ||
// Load a wav file with no "bext" | ||
let wav = new WaveFile(fs.readFileSync("32bit-file.wav")); | ||
// Add some BWF metadata | ||
wav.bext.originator = "wavefile"; | ||
// Write the new BWF file | ||
fs.writeFileSync("32bit-file-with-bext.wav", wav.toBuffer()); | ||
``` | ||
By default **wavefile** will not insert a "bext" chunk in new files or in files that do not already have a "bext" chunk unless a property of **WaveFile.bext** is changed from it's default value. See below the full list of properties in **WaveFile.bext**. | ||
### RF64 | ||
**wavefile** have limited support of RF64 files. It possible to read (at least some) RF64 files, but changing the bit depth or applying compression to the samples will result in a RIFF file. | ||
## API | ||
Read the **[wavefile API docs](https://rochars.github.io/wavefile/api/)** | ||
To create a WaveFile object: | ||
```javascript | ||
/** | ||
* @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. | ||
*/ | ||
WaveFile(bytes=null); | ||
``` | ||
### The WaveFile methods | ||
```javascript | ||
/** | ||
* 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} bitDepth 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. | ||
*/ | ||
WaveFile.fromScratch(numChannels, sampleRate, bitDepth, samples, options={}) {} | ||
/** | ||
* Set up the WaveFile object from a byte buffer. | ||
* @param {!Uint8Array} bytes The buffer. | ||
* @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. | ||
*/ | ||
WaveFile.fromBuffer(bytes) {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.toBuffer() {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.fromBase64(base64String) {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.toBase64() {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.toDataURI() {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.fromDataURI(dataURI) {} | ||
/** | ||
* Force a file as RIFF. | ||
*/ | ||
WaveFile.toRIFF() {} | ||
/** | ||
* Force a file as RIFX. | ||
*/ | ||
WaveFile.toRIFX() {} | ||
/** | ||
* Change the bit depth of the samples. | ||
* @param {string} bitDepth 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. | ||
*/ | ||
WaveFile.toBitDepth(bitDepth, changeResolution=true) {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.toIMAADPCM() {} | ||
/** | ||
* Decode a 4-bit IMA ADPCM wave file as a 16-bit wave file. | ||
* @param {string} bitDepth The new bit depth of the samples. | ||
* One of "8" ... "32" (integers), "32f" or "64" (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
WaveFile.fromIMAADPCM(bitDepth='16') {} | ||
/** | ||
* Encode 16-bit wave file as 8-bit A-Law. | ||
*/ | ||
WaveFile.toALaw() {} | ||
/** | ||
* Decode a 8-bit A-Law wave file into a 16-bit wave file. | ||
* @param {string} bitDepth The new bit depth of the samples. | ||
* One of "8" ... "32" (integers), "32f" or "64" (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
WaveFile.fromALaw(bitDepth='16') {} | ||
/** | ||
* Encode 16-bit wave file as 8-bit mu-Law. | ||
*/ | ||
WaveFile.toMuLaw() {} | ||
/** | ||
* Decode a 8-bit mu-Law wave file into a 16-bit wave file. | ||
* @param {string} bitDepth The new bit depth of the samples. | ||
* One of "8" ... "32" (integers), "32f" or "64" (floats). | ||
* Optional. Default is 16. | ||
*/ | ||
WaveFile.fromMuLaw(bitDepth='16') {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.setTag(tag, value) {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.getTag(tag) {} | ||
/** | ||
* Remove a RIFF tag in the INFO chunk. | ||
* @param {string} tag The tag name. | ||
* @return {boolean} True if a tag was deleted. | ||
*/ | ||
WaveFile.deleteTag(tag) {} | ||
/** | ||
* Return a Object<tag, value> with the RIFF tags in the file. | ||
* @return {!Object<string, string>} The file tags. | ||
*/ | ||
WaveFile.listTags() {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.setCuePoint(position, labl='') {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.deleteCuePoint(index) {} | ||
/** | ||
* 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>} | ||
* @private | ||
*/ | ||
listCuePoints() {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.updateLabel(pointIndex, label) {} | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.getSample(index) {}; | ||
/** | ||
* 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. | ||
*/ | ||
WaveFile.setSample(index, sample) {}; | ||
``` | ||
#### WaveFile.listCuePoints() | ||
This method returns a list like this: | ||
```javascript | ||
[ | ||
{ | ||
milliseconds: 1000, // the position in milliseconds | ||
dwPosition: 8000, // the sample offset of the point | ||
label: "cue marker 2" // the label of the point | ||
}, | ||
] | ||
``` | ||
The list order reflects the order of the points in the file. | ||
### The WaveFile properties | ||
```javascript | ||
/** | ||
* The container identifier. | ||
* "RIFF", "RIFX" and "RF64" are supported. | ||
* @type {string} | ||
*/ | ||
WaveFile.container = ''; | ||
/** | ||
* @type {number} | ||
*/ | ||
WaveFile.chunkSize = 0; | ||
/** | ||
* The format. | ||
* Always 'WAVE'. | ||
* @type {string} | ||
*/ | ||
WaveFile.format = ''; | ||
/** | ||
* The data of the "fmt" chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.fmt = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {number} */ | ||
audioFormat: 0, | ||
/** @type {number} */ | ||
numChannels: 0, | ||
/** @type {number} */ | ||
sampleRate: 0, | ||
/** @type {number} */ | ||
byteRate: 0, | ||
/** @type {number} */ | ||
blockAlign: 0, | ||
/** @type {number} */ | ||
bitsPerSample: 0, | ||
/** @type {number} */ | ||
cbSize: 0, | ||
/** @type {number} */ | ||
validBitsPerSample: 0, | ||
/** @type {number} */ | ||
dwChannelMask: 0, | ||
/** | ||
* 4 32-bit values representing a 128-bit ID | ||
* @type {!Array<number>} | ||
*/ | ||
subformat: [] | ||
}; | ||
/** | ||
* The data of the "fact" chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.fact = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {number} */ | ||
dwSampleLength: 0 | ||
}; | ||
/** | ||
* The data of the "cue " chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.cue = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {number} */ | ||
dwCuePoints: 0, | ||
/** @type {!Array<!Object>} */ | ||
points: [], | ||
}; | ||
/** | ||
* The data of the "smpl" chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.smpl = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {number} */ | ||
dwManufacturer: 0, | ||
/** @type {number} */ | ||
dwProduct: 0, | ||
/** @type {number} */ | ||
dwSamplePeriod: 0, | ||
/** @type {number} */ | ||
dwMIDIUnityNote: 0, | ||
/** @type {number} */ | ||
dwMIDIPitchFraction: 0, | ||
/** @type {number} */ | ||
dwSMPTEFormat: 0, | ||
/** @type {number} */ | ||
dwSMPTEOffset: 0, | ||
/** @type {number} */ | ||
dwNumSampleLoops: 0, | ||
/** @type {number} */ | ||
dwSamplerData: 0, | ||
/** @type {!Array<!Object>} */ | ||
loops: [], | ||
}; | ||
/** | ||
* The data of the "bext" chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.bext = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {string} */ | ||
description: '', //256 | ||
/** @type {string} */ | ||
originator: '', //32 | ||
/** @type {string} */ | ||
originatorReference: '', //32 | ||
/** @type {string} */ | ||
originationDate: '', //10 | ||
/** @type {string} */ | ||
originationTime: '', //8 | ||
/** | ||
* 2 32-bit values, timeReference high and low | ||
* @type {!Array<number>} | ||
*/ | ||
timeReference: [0, 0], | ||
/** @type {number} */ | ||
version: 0, //WORD | ||
/** @type {string} */ | ||
UMID: '', // 64 chars | ||
/** @type {number} */ | ||
loudnessValue: 0, //WORD | ||
/** @type {number} */ | ||
loudnessRange: 0, //WORD | ||
/** @type {number} */ | ||
maxTruePeakLevel: 0, //WORD | ||
/** @type {number} */ | ||
maxMomentaryLoudness: 0, //WORD | ||
/** @type {number} */ | ||
maxShortTermLoudness: 0, //WORD | ||
/** @type {string} */ | ||
reserved: '', //180 | ||
/** @type {string} */ | ||
codingHistory: '' // string, unlimited | ||
}; | ||
/** | ||
* The data of the "ds64" chunk. | ||
* Used only with RF64 files. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.ds64 = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {number} */ | ||
riffSizeHigh: 0, // DWORD | ||
/** @type {number} */ | ||
riffSizeLow: 0, // DWORD | ||
/** @type {number} */ | ||
dataSizeHigh: 0, // DWORD | ||
/** @type {number} */ | ||
dataSizeLow: 0, // DWORD | ||
/** @type {number} */ | ||
originationTime: 0, // DWORD | ||
/** @type {number} */ | ||
sampleCountHigh: 0, // DWORD | ||
/** @type {number} */ | ||
sampleCountLow: 0, // DWORD | ||
/** @type {number} */ | ||
//"tableLength": 0, // DWORD | ||
/** @type {!Array<number>} */ | ||
//"table": [] | ||
}; | ||
/** | ||
* The data of the "data" chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.data = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {!Uint8Array} */ | ||
samples: new Uint8Array(0) | ||
}; | ||
/** | ||
* The data of the "LIST" chunks. | ||
* Each item in this list look like this: | ||
* { | ||
* chunkId: '', | ||
* chunkSize: 0, | ||
* format: '', | ||
* subChunks: [] | ||
* } | ||
* @type {!Array<!Object>} | ||
*/ | ||
WaveFile.LIST = []; | ||
/** | ||
* The data of the "junk" chunk. | ||
* @type {!Object<string, *>} | ||
*/ | ||
WaveFile.junk = { | ||
/** @type {string} */ | ||
chunkId: '', | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {!Array<number>} */ | ||
chunkData: [] | ||
}; | ||
/** | ||
* The bit depth code according to the samples. | ||
* @type {string} | ||
*/ | ||
WaveFile.bitDepth = ''; | ||
``` | ||
#### Cue points | ||
Items in *cue.points* are objects that look like this: | ||
```javascript | ||
{ | ||
/** @type {number} */ | ||
dwName: 0, // a cue point ID | ||
/** @type {number} */ | ||
dwPosition: 0, | ||
/** @type {number} */ | ||
fccChunk: 0, | ||
/** @type {number} */ | ||
dwChunkStart: 0, | ||
/** @type {number} */ | ||
dwBlockStart: 0, | ||
/** @type {number} */ | ||
dwSampleOffset: 0 | ||
} | ||
``` | ||
#### Sample loops | ||
Items in *smpl.loops* are objects that look like this: | ||
```javascript | ||
{ | ||
/** @type {string} */ | ||
dwName: '', // a cue point ID | ||
/** @type {number} */ | ||
dwType: 0, | ||
/** @type {number} */ | ||
dwStart: 0, | ||
/** @type {number} */ | ||
dwEnd: 0, | ||
/** @type {number} */ | ||
dwFraction: 0, | ||
/** @type {number} */ | ||
dwPlayCount: 0 | ||
} | ||
``` | ||
#### LIST chunk | ||
"LIST" chunk data is stored as follows: | ||
```javascript | ||
/** | ||
* An array of the "LIST" chunks present in the file. | ||
* @type {!Array<!Object>} | ||
*/ | ||
WaveFile.LIST = []; | ||
``` | ||
Items in *WaveFile.LIST* are objects that look like this: | ||
```javascript | ||
{ | ||
/** @type {string} */ | ||
chunkId: '', // always 'LIST' | ||
/** @type {number} */ | ||
chunkSize: 0, | ||
/** @type {string} */ | ||
format: '', // 'adtl' or 'INFO' | ||
/** @type {!Array<!Object>} */ | ||
subChunks: [] | ||
}; | ||
``` | ||
Where "subChunks" are the subChunks of the "LIST" chunk. A single file may have many "LIST" chunks as long as their formats ("INFO", "adtl", etc) are not the same. **wavefile** can read and write "LIST" chunks of format "INFO" and "adtl". | ||
For "LIST" chunks with the "INFO" format, "subChunks" will be an array of objects like this: | ||
```javascript | ||
{ | ||
/** @type {string} */ | ||
chunkId: '', // some RIFF tag | ||
/** @type {number} */ | ||
chunkSize 0, | ||
/** @type {string} */ | ||
value: '' | ||
} | ||
``` | ||
Where "chunkId" may be any RIFF tag: | ||
https://sno.phy.queensu.ca/~phil/exiftool/TagNames/RIFF.html#Info | ||
## The samples | ||
Samples are stored in WaveFile.data.samples as a Uint8Array representing a byte buffer. Once you inform the samples with fromScratch() they are packed as bytes and stay that way. | ||
To get and set samples in a WaveFile instance you should use WaveFile.getSample(index) and WaveFile.setSample(index, sample). The 'index' is the index of the sample in the sample array, not the index of the bytes in data.samples. | ||
Example: | ||
```javascript | ||
wav = new WaveFile(); | ||
// some samples | ||
let samples = [561, 1200, 423]; | ||
// Create a WaveFile using the samples | ||
wav.fromScratch(1, 8000, "16", samples); | ||
// Getting and setting a sample in the WaveFile instance: | ||
wav.getSample(1); // return 1200, the value of the second sample | ||
wav.setSample(1, 10); // change the second sample to 10 | ||
wav.getSample(1); // return 10, the new value of the second sample | ||
``` | ||
Range: | ||
- 0 to 255 for 8-bit | ||
- -32768 to 32767 for 16-bit | ||
- -8388608 to 8388607 for 24-bit | ||
- -2147483648 to 2147483647 for 32-bit | ||
- -1.0 to 1.0 for 32-bit (float) | ||
- -1.0 to 1.0 for 64-bit (float) | ||
## Contributing to wavefile | ||
**wavefile** welcomes all contributions from anyone willing to work in good faith with other contributors and the community. No contribution is too small and all contributions are valued. | ||
See [CONTRIBUTING.md](https://github.com/rochars/wavefile/blob/master/docs/CONTRIBUTING.md) for details. | ||
See [CONTRIBUTING.md](https://github.com/rochars/wavefile/blob/master/CONTRIBUTING.md) for details. | ||
@@ -147,4 +921,26 @@ ### Style guide | ||
### Code of conduct | ||
This project is bound by a Code of Conduct: The [Contributor Covenant, version 1.4](https://github.com/rochars/wavefile/blob/master/docs/CODE_OF_CONDUCT.md), also available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
This project is bound by a Code of Conduct: The [Contributor Covenant, version 1.4](https://github.com/rochars/wavefile/blob/master/CODE_OF_CONDUCT.md), also available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
## References | ||
### Papers | ||
https://tech.ebu.ch/docs/tech/tech3285.pdf | ||
https://tech.ebu.ch/docs/tech/tech3306-2009.pdf | ||
http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html | ||
https://www.loc.gov/preservation/digital/formats/fdd/fdd000356.shtml | ||
http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Docs/riffmci.pdf | ||
https://sites.google.com/site/musicgapi/technical-documents/wav-file-format | ||
http://www.neurophys.wisc.edu/auditory/riff-format.txt | ||
https://sno.phy.queensu.ca/~phil/exiftool/TagNames/RIFF.html#Info | ||
### Software | ||
https://github.com/erikd/libsndfile | ||
https://gist.github.com/hackNightly/3776503 | ||
https://github.com/chirlu/sox/blob/master/src/wav.c | ||
### Other | ||
https://developercertificate.org/ | ||
https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
https://google.github.io/styleguide/jsguide.html | ||
## Legal | ||
@@ -151,0 +947,0 @@ [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Frochars%2Fwavefile.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Frochars%2Fwavefile?ref=badge_large) |
Sorry, the diff of this file is too big to display
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
5
22
960
530957
19
12337
+ Addedbyte-data@15.1.0(transitive)
+ Addedendianness@8.0.2(transitive)
+ Addedieee754-buffer@0.0.1(transitive)
+ Addedtwos-complement-buffer@0.0.1(transitive)
+ Addeduint-buffer@0.1.0(transitive)
+ Addedutf8-buffer@0.1.0(transitive)
+ Addedutf8-buffer-size@0.0.4(transitive)
- Removedriff-chunks@^9.0.0
- Removedbyte-data@13.2.7(transitive)
- Removedriff-chunks@9.0.0(transitive)
Updatedbyte-data@^15.0.0