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

wavefile

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wavefile - npm Package Compare versions

Comparing version 0.6.0 to 1.0.0

docs/styles/jsdoc.css

117

dist/wavefile-min.js
/*
endianness: Swap byte endianness in arrays.
Copyright (c) 2017 Rafael da Silva Rocha.
https://github.com/rochars/endianness
wavefile

@@ -11,14 +7,19 @@ Read & write wave files with 8, 16, 24, 32 & 64-bit data.

byte-data
Readable data to and from byte buffers.
Copyright (c) 2017 Rafael da Silva Rocha.
https://github.com/rochars/byte-data
bitdepth
Change the bit depth of samples to and from 8, 16, 24, 32 & 64-bit..
Change the bit depth of samples to and from 8, 16, 24, 32 & 64-bit.
Copyright (c) 2017 Rafael da Silva Rocha.
https://github.com/rochars/bitdepth
byte-data
Readable data to and from byte buffers.
endianness
Swap endianness in byte arrays.
Copyright (c) 2017 Rafael da Silva Rocha.
https://github.com/rochars/byte-data
https://github.com/rochars/endianness
riff-chunks
Get the chunks of RIFF and RIFX files.
Read and write the chunks of RIFF and RIFX files.
Copyright (c) 2017 Rafael da Silva Rocha.

@@ -28,52 +29,48 @@ https://github.com/rochars/riff-chunks

*/
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.objectCreate=$jscomp.ASSUME_ES5||"function"==typeof Object.create?Object.create:function(a){var l=function(){};l.prototype=a;return new l};$jscomp.underscoreProtoCanBeSet=function(){var a={a:!0},l={};try{return l.__proto__=a,l.a}catch(h){}return!1};
$jscomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(a,l){a.__proto__=l;if(a.__proto__!==l)throw new TypeError(a+" is not extensible");return a}:null;
$jscomp.inherits=function(a,l){a.prototype=$jscomp.objectCreate(l.prototype);a.prototype.constructor=a;if($jscomp.setPrototypeOf){var h=$jscomp.setPrototypeOf;h(a,l)}else for(h in l)if("prototype"!=h)if(Object.defineProperties){var g=Object.getOwnPropertyDescriptor(l,h);g&&Object.defineProperty(a,h,g)}else a[h]=l[h];a.superClass_=l.prototype};
(function(a){function l(g){if(h[g])return h[g].exports;var k=h[g]={i:g,l:!1,exports:{}};a[g].call(k.exports,k,k.exports,l);k.l=!0;return k.exports}var h={};l.m=a;l.c=h;l.d=function(a,k,f){l.o(a,k)||Object.defineProperty(a,k,{configurable:!1,enumerable:!0,get:f})};l.n=function(a){var k=a&&a.__esModule?function(){return a["default"]}:function(){return a};l.d(k,"a",k);return k};l.o=function(a,k){return Object.prototype.hasOwnProperty.call(a,k)};l.p="";return l(l.s=8)})([function(a,l){function h(a){g[0]=
a;return k[0]}l=new Int8Array(4);var g=new Int32Array(l.buffer,0,1),k=new Float32Array(l.buffer,0,1);a.exports=h;a.exports.pack=h;a.exports.unpack=function(a){k[0]=a;return g[0]}},function(a,l){function h(a,f){var b=a.length+1;2==f?b=8:16==f&&(b=2);return g(a,b)}function g(a,f){for(;a.length<f;)a="0"+a;return a}a.exports.fixByteArraySize=function(a,f){var b=0,c=a.length%f;if(c)for(c=-1*(c-f);b<c;)a.push(0),b++};a.exports.padding=function(a,f,b){a[b]=h(a[b],f)};a.exports.paddingNibble=function(a,f,
b){2==f&&4>a[b].length&&(a[b]=Array(5-a[b].length).join("0")+a[b])};a.exports.paddingCrumb=function(a,f,b){(2==f||16==f)&&2>a[b].length&&(a[b]="0"+a[b])};a.exports.bytePadding=h;a.exports.lPadZeros=g},function(a,l){a.exports.endianness=function(a,g){for(var k=a.length,f=0;f<k;){for(var b,c=a,e=f,d=0,m=g-1,h=parseInt(g/2,10);d<h;)b=c[e+d],c[e+d]=c[e+m],c[e+m]=b,d++,m--;f+=g}return a}},function(a,l){function h(a,f){var b=a.length+1;2==f?b=8:16==f&&(b=2);return g(a,b)}function g(a,f){for(;a.length<f;)a=
"0"+a;return a}a.exports.fixByteArraySize=function(a,f){var b=0,c=a.length%f;if(c)for(c=-1*(c-f);b<c;)a.push(0),b++};a.exports.padding=function(a,f,b){a[b]=h(a[b],f)};a.exports.paddingNibble=function(a,f,b){2==f&&4>a[b].length&&(a[b]=Array(5-a[b].length).join("0")+a[b])};a.exports.paddingCrumb=function(a,f,b){(2==f||16==f)&&2>a[b].length&&(a[b]="0"+a[b])};a.exports.bytePadding=h;a.exports.lPadZeros=g},function(a,l){a.exports.BitDepthOffsets={1:1,2:1,4:1,8:1,16:2,24:3,32:4,40:5,48:6,64:8};a.exports.BitDepthMaxValues=
{2:4,4:16,8:256,16:65536,24:16777216,32:4294967296,40:1099511627776,48:281474976710656}},function(a,l){a.exports.BitDepthOffsets={1:1,2:1,4:1,8:1,16:2,24:3,32:4,40:5,48:6,64:8};a.exports.BitDepthMaxValues={2:4,4:16,8:256,16:65536,24:16777216,32:4294967296,40:1099511627776,48:281474976710656}},function(a,l,h){function g(b,e){e=void 0===e?!1:e;for(var d="",c=0,a=b.length;c<a;){var f=k.lPadZeros(b[c].toString(2),8);d=e?d+f:f+d;c++}return d}var k=h(1),f=new Float32Array(1),b=new Int32Array(f.buffer);
a.exports.getBinary=g;a.exports.decodeFloat16=function(b){b=parseInt(g(b,!0),2);var c=(b&31744)>>10,d=b&1023;return(c?Math.pow(2,c-15)*(1+d/1024):d/1024*.00006103515625)*(b>>15?-1:1)};a.exports.decodeFloat64=function(b){if("0,0,0,0,0,0,0,0"==b.toString())return 0;b=g(b);for(var c="1"+b.substr(12,52),d=1,a=0,f=0;f<c.length;)a+=d*parseInt(c.charAt(f),10),d/=2,f++;return("1"==b.charAt(0)?-1:1)*a*Math.pow(2,parseInt(b.substr(1,11),2)-1023)};a.exports.toFloat64=function(b){if(0==b)return[0,0];var c=0;
0>=b&&(c=2147483648,b=-b);var d=Math.floor(Math.log(b)/Math.log(2)),a=Math.floor(b/Math.pow(2,d)*Math.pow(2,52));b=a&4294967295;a/=Math.pow(2,32);return[c|d+1023<<20|a&1048575,b]};a.exports.toHalf=function(c){f[0]=c;var e=b[0];c=e>>16&32768;var d=e>>12&2047;e=e>>23&255;return 103>e?c:(c|e-112<<10|d>>1)+(d&1)}},function(a,l,h){function g(b,e){e=void 0===e?!1:e;for(var d="",c=0,a=b.length;c<a;){var f=k.lPadZeros(b[c].toString(2),8);d=e?d+f:f+d;c++}return d}var k=h(3),f=new Float32Array(1),b=new Int32Array(f.buffer);
a.exports.getBinary=g;a.exports.decodeFloat16=function(b){b=parseInt(g(b,!0),2);var c=(b&31744)>>10,d=b&1023;return(c?Math.pow(2,c-15)*(1+d/1024):d/1024*.00006103515625)*(b>>15?-1:1)};a.exports.decodeFloat64=function(b){if("0,0,0,0,0,0,0,0"==b.toString())return 0;b=g(b);for(var c="1"+b.substr(12,52),d=1,a=0,f=0;f<c.length;)a+=d*parseInt(c.charAt(f),10),d/=2,f++;return("1"==b.charAt(0)?-1:1)*a*Math.pow(2,parseInt(b.substr(1,11),2)-1023)};a.exports.toFloat64=function(b){if(0==b)return[0,0];var c=0;
0>=b&&(c=2147483648,b=-b);var d=Math.floor(Math.log(b)/Math.log(2)),a=Math.floor(b/Math.pow(2,d)*Math.pow(2,52));b=a&4294967295;a/=Math.pow(2,32);return[c|d+1023<<20|a&1048575,b]};a.exports.toHalf=function(c){f[0]=c;var e=b[0];c=e>>16&32768;var d=e>>12&2047;e=e>>23&255;return 103>e?c:(c|e-112<<10|d>>1)+(d&1)}},function(a,l,h){var g=h(9),k=h(10);a=function(a){var b=k.WaveFileReaderWriter.call(this)||this;a&&b.fromBuffer(a);return b};$jscomp.inherits(a,k.WaveFileReaderWriter);a.prototype.fromScratch=
function(a,b,c,e,d){d=void 0===d?{}:d;d.container||(d.container="RIFF");var f=parseInt(c,10)/8;this.chunkSize=36+e.length*f;this.fmtChunkSize=16;this.byteRate=a*f*b;this.blockAlign=a*f;this.chunkId=d.container;this.format="WAVE";this.fmtChunkId="fmt ";this.audioFormat=this.headerFormats_[c];this.numChannels=a;this.sampleRate=b;this.bitsPerSample=parseInt(c,10);this.dataChunkId="data";this.dataChunkSize=e.length*f;this.samples_=e;this.bitDepth_=c};a.prototype.toRIFF=function(){this.chunkId="RIFF"};
a.prototype.toRIFX=function(){this.chunkId="RIFX"};a.prototype.toBitDepth=function(a){g.toBitDepth(this.samples_,this.bitDepth_,a);this.fromScratch(this.numChannels,this.sampleRate,a,this.samples_,{container:this.chunkId})};a.prototype.interleave=function(){var a=[],b,c,e=this.samples_[0].length;for(b=0;b<e;b++)for(c=0;c<this.samples_.length;c++)a.push(this.samples_[c][b]);this.samples_=a};a.prototype.deInterleave=function(){var a=[],b;for(b=0;b<this.numChannels;b++)a[b]=[];b=0;for(var c;b<this.samples_.length;){for(c=
0;c<this.numChannels;c++)a[c].push(this.samples_[b+c]);b+=c}this.samples_=a};window.WaveFile=a},function(a,l){var h={8:256,16:65536,24:16777216,32:4294967296};a.exports.toBitDepth=function(a,k,f){var b="8 16 24 32 32f 64".split(" ");if(-1==b.indexOf(k)||-1==b.indexOf(f))throw Error("Invalid bit depth.");b=a.length;for(var c=0;c<b;c++){var e=a[c];"8"==k&&(e-=128);if("32f"==f||"64"==f){var d=k,g=parseInt(h[d]/2,10);"32f"!=d&&"64"!=d&&(e=0<e?e/(g-1):e/g)}else{g=e;var l=k;e=f;d=parseInt(h[e]/2,10);"32f"==
l||"64"==l?g=0<g?g*(d-1):g*d:(l=parseInt(h[l]/2,10),g=0<g?parseInt(g/(l-1)*d-1,10):parseInt(g/l*d,10));d=g=d=g;"8"==e&&(d+=128);e=d}a[c]=e}};a.exports.BitDepthMaxValues=h},function(a,l,h){var g=h(11),k=h(17),f=h(18);l=function(){var b=k.WaveFileHeader.call(this)||this;b.enforceFact_=!1;b.WaveErrors={format:"Not a supported format.",wave:"Could not find the 'WAVE' format identifier","fmt ":"Could not find the 'fmt ' chunk",data:"Could not find the 'data' chunk",fact:"Could not find the 'fact' chunk",
bitDepth:"Invalid bit depth.",numChannels:"Invalid number of channels.",sampleRate:"Invalid sample rate."};b.headerFormats_={4:17,8:1,16:1,24:1,32:1,"32f":3,64:3};b.samples_=[];return b};$jscomp.inherits(l,k.WaveFileHeader);l.prototype.fromBuffer=function(b){this.readRIFFChunk_(b);var c="RIFX"==this.chunkId;b=f.getChunks(b,c);c={be:c,single:!0};this.readFmtChunk_(b.subChunks,c);this.readFactChunk_(b.subChunks,c);this.readBextChunk_(b.subChunks,c);this.readCueChunk_(b.subChunks,c);this.readDataChunk_(b.subChunks,
c);this.bitDepth_=3==this.audioFormat&&32==this.bitsPerSample?"32f":this.bitsPerSample.toString()};l.prototype.toBuffer=function(){this.checkWriteInput_();return new Uint8Array(this.createWaveFile_())};l.prototype.readRIFFChunk_=function(b){this.chunkId=g.fromBytes(b.slice(0,4),8,{"char":!0});if("RIFF"!=this.chunkId&&"RIFX"!=this.chunkId)throw Error(this.WaveErrors.format);this.chunkSize=g.fromBytes(b.slice(4,8),32,{be:"RIFX"==this.chunkId,single:!0});this.format=g.fromBytes(b.slice(8,12),8,g.str);
if("WAVE"!=this.format)throw Error(this.WaveErrors.wave);};l.prototype.readFmtChunk_=function(b,c){if(b=this.findChunk(b,"fmt "))this.fmtChunkId="fmt ",this.fmtChunkSize=b.subChunkSize,this.audioFormat=g.fromBytes(b.subChunkData.slice(0,2),16,c),this.numChannels=g.fromBytes(b.subChunkData.slice(2,4),16,c),this.sampleRate=g.fromBytes(b.subChunkData.slice(4,8),32,c),this.byteRate=g.fromBytes(b.subChunkData.slice(8,12),32,c),this.blockAlign=g.fromBytes(b.subChunkData.slice(12,14),16,c),this.bitsPerSample=
g.fromBytes(b.subChunkData.slice(14,16),16,c),16<this.fmtChunkSize&&(this.cbSize=g.fromBytes(b.subChunkData.slice(16,18),16),18<this.fmtChunkSize&&(this.validBitsPerSample=g.fromBytes(b.subChunkData.slice(18,20),16)));else throw Error(this.WaveErrors["fmt "]);};l.prototype.readFactChunk_=function(b,c){if(b=this.findChunk(b,"fact"))this.factChunkId="fact",this.factChunkSize=b.subChunkSize,this.dwSampleLength=g.fromBytes(b.subChunkData.slice(0,4),32,c);else if(this.enforceFact)throw Error(this.WaveErrors.fact);
};l.prototype.readBextChunk_=function(b,c){if(b=this.findChunk(b,"bext"))this.bextChunkId="bext",this.bextChunkSize=b.subChunkSize,this.bextChunkData=g.fromBytes(b.subChunkData,8)};l.prototype.readCueChunk_=function(b,c){if(b=this.findChunk(b,"cue "))this.cueChunkId="cue ",this.cueChunkSize=b.subChunkSize,this.cueChunkData=g.fromBytes(b.subChunkData,8)};l.prototype.readDataChunk_=function(b,c){if(b=this.findChunk(b,"data"))this.dataChunkId="data",this.dataChunkSize=b.subChunkSize,this.samplesFromBytes_(b.subChunkData,
c);else throw Error(this.WaveErrors.data);};l.prototype.samplesFromBytes_=function(b,c){c.signed=8==this.bitsPerSample?!1:!0;32==this.bitsPerSample&&3==this.audioFormat&&(c.float=!0);c.single=!1;this.samples_=4==this.bitsPerSample?g.fromBytes(b,8,c):g.fromBytes(b,this.bitsPerSample,c)};l.prototype.findChunk=function(b,c){for(var a=0;a<b.length;a++)if(b[a].subChunkId==c)return b[a];return null};l.prototype.checkWriteInput_=function(){this.validateBitDepth_();this.validateNumChannels_();this.validateSampleRate_()};
l.prototype.validateBitDepth_=function(){if(!this.headerFormats_[this.bitDepth_])throw Error(this.WaveErrors.bitDepth);return!0};l.prototype.validateNumChannels_=function(){var b=this.numChannels*this.bitsPerSample/8;if(1>this.numChannels||65535<b)throw Error(this.WaveErrors.numChannels);return!0};l.prototype.validateSampleRate_=function(){var b=this.bitsPerSample/8*this.numChannels*this.sampleRate;if(1>this.sampleRate||4294967295<b)throw Error(this.WaveErrors.sampleRate);return!0};l.prototype.samplesToBytes_=
function(b){32==this.bitsPerSample&&3==this.audioFormat&&(b.float=!0);b=g.toBytes(this.samples_,4==this.bitsPerSample?8:this.bitsPerSample,b);b.length%2&&b.push(0);return b};l.prototype.getBextBytes=function(b){var c=[];this.bextChunkId&&(c=c.concat(g.toBytes(this.bextChunkId,8,{"char":!0}),g.toBytes(this.bextChunkSize,32,b),g.toBytes(this.bextChunkData,8)));return c};l.prototype.getCueBytes=function(b){var c=[];this.cueChunkId&&(c=c.concat(g.toBytes(this.cueChunkId,8,{"char":!0}),g.toBytes(this.cueChunkSize,
32,b),g.toBytes(this.cueChunkData,8)));return c};l.prototype.getFactBytes=function(b){var c=[];this.factChunkId&&(c=c.concat(g.toBytes(this.factChunkId,8,{"char":!0}),g.toBytes(this.factChunkSize,32,b),g.toBytes(this.dwSampleLength,32,b)));return c};l.prototype.createWaveFile_=function(){var b={be:"RIFX"==this.chunkId},c=[],a=[];16<this.fmtChunkSize&&(c=g.toBytes(this.cbSize,16,b),18<this.fmtChunkSize&&(a=g.toBytes(this.validBitsPerSample,16,b)));return g.toBytes(this.chunkId,8,{"char":!0}).concat(g.toBytes(this.chunkSize,
32,b),g.toBytes(this.format,8,{"char":!0}),this.getBextBytes(b),g.toBytes(this.fmtChunkId,8,{"char":!0}),g.toBytes(this.fmtChunkSize,32,b),g.toBytes(this.audioFormat,16,b),g.toBytes(this.numChannels,16,b),g.toBytes(this.sampleRate,32,b),g.toBytes(this.byteRate,32,b),g.toBytes(this.blockAlign,16,b),g.toBytes(this.bitsPerSample,16,b),c,a,this.getFactBytes(b),g.toBytes(this.dataChunkId,8,{"char":!0}),g.toBytes(this.dataChunkSize,32,b),this.samplesToBytes_(b),this.getCueBytes(b))};a.exports.WaveFileReaderWriter=
l},function(a,l,h){l=h(12);var g=h(14),k=h(16);h=h(4);a.exports.findString=function(a,b){for(var c,e=0;e<a.length;e++)if(c=g.fromBytes(a.slice(e,e+b.length),8,{"char":!0}),c==b)return e;return-1};a.exports.toBytes=l.toBytes;a.exports.fromBytes=g.fromBytes;a.exports.packBooleans=k.packBooleans;a.exports.unpackBooleans=k.unpackBooleans;a.exports.packCrumbs=k.packCrumbs;a.exports.unpackCrumbs=k.unpackCrumbs;a.exports.packNibbles=k.packNibbles;a.exports.unpackNibbles=k.unpackNibbles;a.exports.BitDepthOffsets=
h.BitDepthOffsets;a.exports.BitDepthMaxValues=h.BitDepthMaxValues;a.exports.floatLE={"float":!0,single:!0};a.exports.intLE={signed:!0,single:!0};a.exports.uIntLE={single:!0};a.exports.floatBE={"float":!0,single:!0,be:!0};a.exports.intBE={signed:!0,single:!0,be:!0};a.exports.uIntBE={single:!0,be:!0};a.exports.char={"char":!0,single:!0};a.exports.floatArrayLE={"float":!0};a.exports.intArrayLE={signed:!0};a.exports.uIntArrayLE={};a.exports.floatArrayBE={"float":!0,be:!0};a.exports.intArrayBE={signed:!0,
be:!0};a.exports.uIntArrayBE={be:!0};a.exports.str={"char":!0}},function(a,l,h){function g(b,a,c){4==a?k(b,c,f.paddingNibble):2==a?k(b,c,f.paddingCrumb):1==a?k(b,c,function(){}):k(b,c)}function k(b,a,c){c=void 0===c?f.padding:c;if(10!=a)for(var d=0,e=b.length;d<e;)b[d]=b[d].toString(a),c(b,a,d),d++}h(0);var f=h(1),b=h(2),c=h(13),e=h(4);a.exports.toBytes=function(d,a,f){f=void 0===f?{}:f;if(!f.char&&"string"!=typeof d){var k=d;Array.isArray(k)||(k=[k]);d=k}k=10;"base"in f&&(k=f.base);var h=f.char?
c.writeString:c["write"+a+"Bit"+(f.float?"Float":"")];for(var l=0,m=0,p=d.length,n=[];l<p;)m=h(n,d,l,m),l++;d=n;f.be&&b.endianness(d,e.BitDepthOffsets[a]);g(d,a,k);f.buffer&&(d=new Uint8Array(d));return d}},function(a,l,h){function g(b,a,e,d){b[d++]=a[e]&255;b[d++]=a[e]>>>8&255;b[d++]=a[e]>>>16&255;b[d++]=a[e]>>>24&255;return d}var k=h(6),f=h(0);a.exports.write64Bit=function(b,a,e,d){a=k.toFloat64(a[e]);d=g(b,a,1,d);return g(b,a,0,d)};a.exports.write48Bit=function(b,a,e,d){b[d++]=a[e]&255;b[d++]=
a[e]>>8&255;b[d++]=a[e]>>16&255;b[d++]=a[e]>>24&255;b[d++]=a[e]/4294967296&255;b[d++]=a[e]/1099511627776&255;return d};a.exports.write40Bit=function(b,a,e,d){b[d++]=a[e]&255;b[d++]=a[e]>>8&255;b[d++]=a[e]>>16&255;b[d++]=a[e]>>24&255;b[d++]=a[e]/4294967296&255;return d};a.exports.write32BitFloat=function(b,a,e,d){a=f.unpack(a[e]);b[d++]=a&255;b[d++]=a>>>8&255;b[d++]=a>>>16&255;b[d++]=a>>>24&255;return d};a.exports.write32Bit=g;a.exports.write24Bit=function(b,a,e,d){b[d++]=a[e]&255;b[d++]=a[e]>>>8&
255;b[d++]=a[e]>>>16&255;return d};a.exports.write16Bit=function(b,a,e,d){b[d++]=a[e]&255;b[d++]=a[e]>>>8&255;return d};a.exports.write16BitFloat=function(b,a,e,d){a=k.toHalf(a[e]);b[d++]=a>>>8&255;b[d++]=a&255;return d};a.exports.write8Bit=function(b,a,e,d){b[d++]=a[e]&255;return d};a.exports.write4Bit=function(b,a,e,d){b[d++]=a[e]&15;return d};a.exports.write2Bit=function(b,a,e,d){b[d++]=0>a[e]?a[e]+4:a[e];return d};a.exports.write1Bit=function(b,a,e,d){b[d++]=a[e]?1:0;return d};a.exports.writeString=
function(b,a,e,d){b[d++]=a.charCodeAt(e);return d}},function(a,l,h){function g(b,a,f,g){var d=[],e=0,h=0,l=c.BitDepthOffsets[a],m=b.length-(l-1);a=c.BitDepthMaxValues[a];for(f=f?k:function(b,a){return b};e<m;)d[h]=f(g(b,e),a),e+=l,h++;return d}function k(b,a){b>parseInt(a/2,10)-1&&(b-=a);return b}var f=h(2),b=h(15),c=h(4);a.exports.fromBytes=function(a,d,c){c=void 0===c?{}:c;var e=10;"base"in c&&(e=c.base);c.be&&f.endianness(a,d/8);if(10!=e)for(var k=0,h=a.length;k<h;)a[k]=parseInt(a[k],e),k++;a=
g(a,d,c.signed,c.char?b.readChar:b["read"+(2==d||4==d?8:d)+"Bit"+(c.float?"Float":"")]);c.char&&(a=a.join(""));c.single&&(a=a[0]);return a}},function(a,l,h){function g(b,a,c){--c;for(var d="";0<=c;)d+=f.bytePadding(b[c+a].toString(2),2),c--;return parseInt(d,2)}function k(b,a){return(b[3+a]<<24|b[2+a]<<16|b[1+a]<<8|b[a])>>>0}var f=h(1),b=h(6),c=h(0);a.exports.readChar=function(b,a){return String.fromCharCode(b[a])};a.exports.read1Bit=function(b,a){return parseInt(b[a],2)};a.exports.read8Bit=function(b,
a){return b[a]};a.exports.read16Bit=function(b,a){return b[1+a]<<8|b[a]};a.exports.read16BitFloat=function(a,d){return b.decodeFloat16(a.slice(d,d+2))};a.exports.read24Bit=function(b,a){return b[2+a]<<16|b[1+a]<<8|b[a]};a.exports.read32Bit=k;a.exports.read32BitFloat=function(b,a){return c.pack(k(b,a))};a.exports.read40Bit=function(b,a){return g(b,a,5)};a.exports.read48Bit=function(b,a){return g(b,a,6)};a.exports.read64Bit=function(a,d){return b.decodeFloat64(a.slice(d,d+8))}},function(a,l,h){var g=
h(1);a.exports.packBooleans=function(a){var f=[],b=0,c=0;g.fixByteArraySize(a,8);for(var e=a.length-7;b<e;)f[c++]=parseInt(a[b].toString(2)+a[b+1].toString(2)+a[b+2].toString(2)+a[b+3].toString(2)+a[b+4].toString(2)+a[b+5].toString(2)+a[b+6].toString(2)+a[b+7].toString(2),2),b+=8;return f};a.exports.unpackBooleans=function(a){for(var f=[],b=0,c=0,e=a.length,d;b<e;)d=g.lPadZeros(a[b].toString(2),8),f[c++]=parseInt(d[0],2),f[c++]=parseInt(d[1],2),f[c++]=parseInt(d[2],2),f[c++]=parseInt(d[3],2),f[c++]=
parseInt(d[4],2),f[c++]=parseInt(d[5],2),f[c++]=parseInt(d[6],2),f[c++]=parseInt(d[7],2),b++;return f};a.exports.packCrumbs=function(a){var f=[],b=0,c=0;g.fixByteArraySize(a,4);for(var e=a.length-3;b<e;)f[c++]=parseInt(g.lPadZeros(a[b].toString(2),2)+g.lPadZeros(a[b+1].toString(2),2)+g.lPadZeros(a[b+2].toString(2),2)+g.lPadZeros(a[b+3].toString(2),2),2),b+=4;return f};a.exports.unpackCrumbs=function(a){var f=[],b=0,c=0,e=a.length;for(console.log(e);b<e;){var d=g.lPadZeros(a[b].toString(2),8);f[c++]=
parseInt(d[0]+d[1],2);f[c++]=parseInt(d[2]+d[3],2);f[c++]=parseInt(d[4]+d[5],2);f[c++]=parseInt(d[6]+d[7],2);b++}return f};a.exports.packNibbles=function(a){var f=[],b=0,c=0,e=a.length;for(e%2&&a.push(0);b<e;)f[c++]=parseInt(a[b].toString(16)+a[b+1].toString(16),16),b+=2;return f};a.exports.unpackNibbles=function(a){for(var f=[],b=0,c=0,e=a.length;b<e;)f[c++]=parseInt(a[b].toString(16)[0],16),f[c++]=parseInt(a[b].toString(16)[1],16),b++;return f}},function(a,l){a.exports.WaveFileHeader=function(){this.chunkId=
"";this.chunkSize=0;this.fmtChunkId=this.format="";this.validBitsPerSample=this.cbSize=this.bitsPerSample=this.blockAlign=this.byteRate=this.sampleRate=this.numChannels=this.audioFormat=this.fmtChunkSize=0;this.factChunkId="";this.factChunkSize=0;this.factChunkData=[];this.dwSampleLength=0;this.cueChunkId="";this.cueChunkSize=-1;this.cueChunkData=[];this.dataChunkId="";this.dataChunkSize=0;this.bextChunkId="";this.bextChunkSize=0;this.bextChunkData=[]}},function(a,l,h){function g(a,b){for(var c=[],
e=a.length,d=12,f,h;d<e;)h=k.fromBytes(a.slice(d,d+4),8,{"char":!0}),f=k.fromBytes(a.slice(d+4,d+8),32,{be:b})[0],"LIST"==h?c.push({subChunkId:h,subChunkSize:f,subChunks:g(a.slice(d,d+f),b)}):c.push({subChunkId:h,subChunkSize:f,subChunkData:a.slice(d+8,d+8+f)}),d=d+8+f;return c}var k=h(19);a.exports.getChunks=function(a,b){b=void 0===b?!1:b;return{chunkId:k.fromBytes(a.slice(0,4),8,{"char":!0}),chunkSize:k.fromBytes(a.slice(4,8),32,{be:b})[0],format:k.fromBytes(a.slice(8,12),8,{"char":!0}),subChunks:g(a,
b)}}},function(a,l,h){l=h(20);var g=h(22),k=h(24);h=h(5);a.exports.findString=function(a,b){for(var c,e=0;e<a.length;e++)if(c=g.fromBytes(a.slice(e,e+b.length),8,{"char":!0}),c==b)return e;return-1};a.exports.toBytes=l.toBytes;a.exports.fromBytes=g.fromBytes;a.exports.packBooleans=k.packBooleans;a.exports.unpackBooleans=k.unpackBooleans;a.exports.packCrumbs=k.packCrumbs;a.exports.unpackCrumbs=k.unpackCrumbs;a.exports.packNibbles=k.packNibbles;a.exports.unpackNibbles=k.unpackNibbles;a.exports.BitDepthOffsets=
h.BitDepthOffsets;a.exports.BitDepthMaxValues=h.BitDepthMaxValues},function(a,l,h){function g(a,b,c){4==b?k(a,c,f.paddingNibble):2==b?k(a,c,f.paddingCrumb):1==b?k(a,c,function(){}):k(a,c)}function k(a,b,c){c=void 0===c?f.padding:c;if(10!=b)for(var d=0,e=a.length;d<e;)a[d]=a[d].toString(b),c(a,b,d),d++}h(0);var f=h(3),b=h(2),c=h(21),e=h(5);a.exports.toBytes=function(a,f,k){k=void 0===k?{}:k;var d=10;"base"in k&&(d=k.base);var h=k.char?c.writeString:c["write"+f+"Bit"+(k.float?"Float":"")];for(var l=
0,m=0,p=a.length,n=[];l<p;)m=h(n,a,l,m),l++;a=n;k.be&&b.endianness(a,e.BitDepthOffsets[f]);g(a,f,d);k.buffer&&(a=new Uint8Array(a));return a}},function(a,l,h){function g(a,c,e,d){a[d++]=c[e]&255;a[d++]=c[e]>>>8&255;a[d++]=c[e]>>>16&255;a[d++]=c[e]>>>24&255;return d}var k=h(7),f=h(0);a.exports.write64Bit=function(a,c,e,d){c=k.toFloat64(c[e]);d=g(a,c,1,d);return g(a,c,0,d)};a.exports.write48Bit=function(a,c,e,d){a[d++]=c[e]&255;a[d++]=c[e]>>8&255;a[d++]=c[e]>>16&255;a[d++]=c[e]>>24&255;a[d++]=c[e]/
4294967296&255;a[d++]=c[e]/1099511627776&255;return d};a.exports.write40Bit=function(a,c,e,d){a[d++]=c[e]&255;a[d++]=c[e]>>8&255;a[d++]=c[e]>>16&255;a[d++]=c[e]>>24&255;a[d++]=c[e]/4294967296&255;return d};a.exports.write32BitFloat=function(a,c,e,d){c=f.unpack(c[e]);a[d++]=c&255;a[d++]=c>>>8&255;a[d++]=c>>>16&255;a[d++]=c>>>24&255;return d};a.exports.write32Bit=g;a.exports.write24Bit=function(a,c,e,d){a[d++]=c[e]&255;a[d++]=c[e]>>>8&255;a[d++]=c[e]>>>16&255;return d};a.exports.write16Bit=function(a,
c,e,d){a[d++]=c[e]&255;a[d++]=c[e]>>>8&255;return d};a.exports.write16BitFloat=function(a,c,e,d){c=k.toHalf(c[e]);a[d++]=c>>>8&255;a[d++]=c&255;return d};a.exports.write8Bit=function(a,c,e,d){a[d++]=c[e]&255;return d};a.exports.write4Bit=function(a,c,e,d){a[d++]=c[e]&15;return d};a.exports.write2Bit=function(a,c,e,d){a[d++]=0>c[e]?c[e]+4:c[e];return d};a.exports.write1Bit=function(a,c,e,d){a[d++]=c[e]?1:0;return d};a.exports.writeString=function(a,c,e,d){a[d++]=c.charCodeAt(e);return d}},function(a,
l,h){function g(a,b,f,g){var d=[],e=0,h=0,l=c.BitDepthOffsets[b],m=a.length-(l-1);b=c.BitDepthMaxValues[b];for(f=f?k:function(a,b){return a};e<m;)d[h]=f(g(a,e),b),e+=l,h++;return d}function k(a,b){a>parseInt(b/2,10)-1&&(a-=b);return a}var f=h(2),b=h(23),c=h(5);a.exports.fromBytes=function(a,d,c){c=void 0===c?{}:c;var e=10;"base"in c&&(e=c.base);c.be&&f.endianness(a,d/8);if(10!=e)for(var k=0,h=a.length;k<h;)a[k]=parseInt(a[k],e),k++;a=g(a,d,c.signed,c.char?b.readChar:b["read"+(2==d||4==d?8:d)+"Bit"+
(c.float?"Float":"")]);c.char&&(a=a.join(""));return a}},function(a,l,h){function g(a,b,c){--c;for(var d="";0<=c;)d+=f.bytePadding(a[c+b].toString(2),2),c--;return parseInt(d,2)}function k(a,b){return(a[3+b]<<24|a[2+b]<<16|a[1+b]<<8|a[b])>>>0}var f=h(3),b=h(7),c=h(0);a.exports.readChar=function(a,b){return String.fromCharCode(a[b])};a.exports.read1Bit=function(a,b){return parseInt(a[b],2)};a.exports.read8Bit=function(a,b){return a[b]};a.exports.read16Bit=function(a,b){return a[1+b]<<8|a[b]};a.exports.read16BitFloat=
function(a,d){return b.decodeFloat16(a.slice(d,d+2))};a.exports.read24Bit=function(a,b){return a[2+b]<<16|a[1+b]<<8|a[b]};a.exports.read32Bit=k;a.exports.read32BitFloat=function(a,b){return c.pack(k(a,b))};a.exports.read40Bit=function(a,b){return g(a,b,5)};a.exports.read48Bit=function(a,b){return g(a,b,6)};a.exports.read64Bit=function(a,c){return b.decodeFloat64(a.slice(c,c+8))}},function(a,l,h){var g=h(3);a.exports.packBooleans=function(a){var f=[],b=0,c=0;g.fixByteArraySize(a,8);for(var e=a.length-
7;b<e;)f[c++]=parseInt(a[b].toString(2)+a[b+1].toString(2)+a[b+2].toString(2)+a[b+3].toString(2)+a[b+4].toString(2)+a[b+5].toString(2)+a[b+6].toString(2)+a[b+7].toString(2),2),b+=8;return f};a.exports.unpackBooleans=function(a){for(var f=[],b=0,c=0,e=a.length,d;b<e;)d=g.lPadZeros(a[b].toString(2),8),f[c++]=parseInt(d[0],2),f[c++]=parseInt(d[1],2),f[c++]=parseInt(d[2],2),f[c++]=parseInt(d[3],2),f[c++]=parseInt(d[4],2),f[c++]=parseInt(d[5],2),f[c++]=parseInt(d[6],2),f[c++]=parseInt(d[7],2),b++;return f};
a.exports.packCrumbs=function(a){var f=[],b=0,c=0;g.fixByteArraySize(a,4);for(var e=a.length-3;b<e;)f[c++]=parseInt(g.lPadZeros(a[b].toString(2),2)+g.lPadZeros(a[b+1].toString(2),2)+g.lPadZeros(a[b+2].toString(2),2)+g.lPadZeros(a[b+3].toString(2),2),2),b+=4;return f};a.exports.unpackCrumbs=function(a){var f=[],b=0,c=0,e=a.length;for(console.log(e);b<e;){var d=g.lPadZeros(a[b].toString(2),8);f[c++]=parseInt(d[0]+d[1],2);f[c++]=parseInt(d[2]+d[3],2);f[c++]=parseInt(d[4]+d[5],2);f[c++]=parseInt(d[6]+
d[7],2);b++}return f};a.exports.packNibbles=function(a){var f=[],b=0,c=0,e=a.length;for(e%2&&a.push(0);b<e;)f[c++]=parseInt(a[b].toString(16)+a[b+1].toString(16),16),b+=2;return f};a.exports.unpackNibbles=function(a){for(var f=[],b=0,c=0,e=a.length;b<e;)f[c++]=parseInt(a[b].toString(16)[0],16),f[c++]=parseInt(a[b].toString(16)[1],16),b++;return f}}]);
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.objectCreate=$jscomp.ASSUME_ES5||"function"==typeof Object.create?Object.create:function(a){var f=function(){};f.prototype=a;return new f};$jscomp.underscoreProtoCanBeSet=function(){var a={a:!0},f={};try{return f.__proto__=a,f.a}catch(h){}return!1};
$jscomp.setPrototypeOf="function"==typeof Object.setPrototypeOf?Object.setPrototypeOf:$jscomp.underscoreProtoCanBeSet()?function(a,f){a.__proto__=f;if(a.__proto__!==f)throw new TypeError(a+" is not extensible");return a}:null;
$jscomp.inherits=function(a,f){a.prototype=$jscomp.objectCreate(f.prototype);a.prototype.constructor=a;if($jscomp.setPrototypeOf){var h=$jscomp.setPrototypeOf;h(a,f)}else for(h in f)if("prototype"!=h)if(Object.defineProperties){var e=Object.getOwnPropertyDescriptor(f,h);e&&Object.defineProperty(a,h,e)}else a[h]=f[h];a.superClass_=f.prototype};$jscomp.owns=function(a,f){return Object.prototype.hasOwnProperty.call(a,f)};
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(a,f,h){a!=Array.prototype&&a!=Object.prototype&&(a[f]=h.value)};$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);
$jscomp.polyfill=function(a,f,h,e){if(f){h=$jscomp.global;a=a.split(".");for(e=0;e<a.length-1;e++){var l=a[e];l in h||(h[l]={});h=h[l]}a=a[a.length-1];e=h[a];f=f(e);f!=e&&null!=f&&$jscomp.defineProperty(h,a,{configurable:!0,writable:!0,value:f})}};$jscomp.polyfill("Object.assign",function(a){return a?a:function(a,h){for(var e=1;e<arguments.length;e++){var f=arguments[e];if(f)for(var k in f)$jscomp.owns(f,k)&&(a[k]=f[k])}return a}},"es6","es3");
$jscomp.polyfill("Object.is",function(a){return a?a:function(a,h){return a===h?0!==a||1/a===1/h:a!==a&&h!==h}},"es6","es3");$jscomp.polyfill("Array.prototype.includes",function(a){return a?a:function(a,h){var e=this;e instanceof String&&(e=String(e));var f=e.length;for(h=h||0;h<f;h++)if(e[h]==a||Object.is(e[h],a))return!0;return!1}},"es7","es3");
$jscomp.checkStringArgs=function(a,f,h){if(null==a)throw new TypeError("The 'this' value for String.prototype."+h+" must not be null or undefined");if(f instanceof RegExp)throw new TypeError("First argument to String.prototype."+h+" must not be a regular expression");return a+""};$jscomp.polyfill("String.prototype.includes",function(a){return a?a:function(a,h){return-1!==$jscomp.checkStringArgs(this,a,"includes").indexOf(a,h||0)}},"es6","es3");
(function(a){function f(e){if(h[e])return h[e].exports;var l=h[e]={i:e,l:!1,exports:{}};a[e].call(l.exports,l,l.exports,f);l.l=!0;return l.exports}var h={};f.m=a;f.c=h;f.d=function(a,l,k){f.o(a,l)||Object.defineProperty(a,l,{configurable:!1,enumerable:!0,get:k})};f.n=function(a){var e=a&&a.__esModule?function(){return a["default"]}:function(){return a};f.d(e,"a",e);return e};f.o=function(a,f){return Object.prototype.hasOwnProperty.call(a,f)};f.p="";return f(f.s=6)})([function(a,f,h){function e(a,
b,c){a[c]=l(a[c],b)}function l(a,c){var g=a.length+1;2==c?g=8:16==c&&(g=2);return b(a,g)}function k(a,b,c){2==b&&4>a[c].length&&(a[c]=Array(5-a[c].length).join("0")+a[c])}function d(a,b,c){(2==b||16==b)&&2>a[c].length&&(a[c]="0"+a[c])}function b(a,b){for(;a.length<b;)a="0"+a;return a}function g(a,b,c){c=void 0===c?e:c;if(10!=b)for(var g=0,d=a.length;g<d;)a[g]=a[g].toString(b),c(a,b,g),g++}var c=h(11),m=h(1);a.exports.makeBigEndian=function(a,b,g){b&&c(a,m.BitDepthOffsets[g])};a.exports.bytesToBase=
g;a.exports.outputToBase=function(a,b,c){4==b?g(a,c,k):2==b?g(a,c,d):1==b?g(a,c,function(){}):g(a,c)};a.exports.turnToArray=function(a){Array.isArray(a)||"string"==typeof a||(a=[a]);return a};a.exports.signed=function(a,b){a>parseInt(b/2,10)-1&&(a-=b);return a};a.exports.bytesToInt=function(a,b){if(10!=b)for(var c=0,g=a.length;c<g;)a[c]=parseInt(a[c],b),c++};a.exports.fixByteArraySize=function(a,b){var c=0,g=a.length%b;if(g)for(g=-1*(g-b);c<g;)a.push(0),c++};a.exports.padding=e;a.exports.paddingNibble=
k;a.exports.paddingCrumb=d;a.exports.bytePadding=l;a.exports.lPadZeros=b},function(a,f){a.exports.BitDepthOffsets={1:1,2:1,4:1,8:1,16:2,24:3,32:4,40:5,48:6,64:8};a.exports.BitDepthMaxValues={2:4,4:16,8:256,16:65536,24:16777216,32:4294967296,40:1099511627776,48:281474976710656}},function(a,f){a.exports={format:"Not a supported format.",wave:"Could not find the 'WAVE' format identifier","fmt ":"Could not find the 'fmt ' chunk",data:"Could not find the 'data' chunk",fact:"Could not find the 'fact' chunk",
bitDepth:"Invalid bit depth.",numChannels:"Invalid number of channels.",sampleRate:"Invalid sample rate."}},function(a,f,h){var e=h(9),l=h(12);f=h(14);h=h(1);window.WaveFile.pack=function(a,d,b){b=void 0===b?10:b;d=Object.assign({},d);d.base=b;d.single=!0;a=d.char?a[0]:a;return e.toBytes(a,d.bitDepth,d)};a.exports.unpack=function(a,d,b){b=void 0===b?10:b;d=Object.assign({},d);d.base=b;d.single=!0;return l.fromBytes(a,d.bitDepth,d)};a.exports.packSequence=function(a,d,b){b=void 0===b?10:b;d=Object.assign({},
d);d.base=b;d.single=!1;return e.toBytes(a,d.bitDepth,d)};a.exports.unpackSequence=function(a,d,b){b=void 0===b?10:b;d=Object.assign({},d);d.base=b;d.single=!1;return l.fromBytes(a,d.bitDepth,d)};a.exports.char={bitDepth:8,"char":!0,single:!0};a.exports.bool={bitDepth:1,single:!0};a.exports.int2={bitDepth:2,signed:!0,single:!0};a.exports.uInt2={bitDepth:2,single:!0};a.exports.int4={bitDepth:4,signed:!0,single:!0};a.exports.uInt4={bitDepth:4,single:!0};a.exports.int8={bitDepth:8,signed:!0,single:!0};
a.exports.uInt8={bitDepth:8,single:!0};a.exports.int16={bitDepth:16,signed:!0,single:!0};a.exports.uInt16={bitDepth:16,single:!0};a.exports.float16={bitDepth:16,"float":!0,single:!0};a.exports.int24={bitDepth:24,signed:!0,single:!0};a.exports.uInt24={bitDepth:24,single:!0};a.exports.int32={bitDepth:32,signed:!0,single:!0};a.exports.uInt32={bitDepth:32,single:!0};a.exports.float32={bitDepth:32,"float":!0,single:!0};a.exports.int40={bitDepth:40,signed:!0,single:!0};a.exports.uInt40={bitDepth:40,single:!0};
a.exports.int48={bitDepth:48,signed:!0,single:!0};a.exports.uInt48={bitDepth:48,single:!0};a.exports.float64={bitDepth:64,"float":!0,single:!0};a.exports.floatLE={"float":!0,single:!0};a.exports.intLE={signed:!0,single:!0};a.exports.uIntLE={single:!0};a.exports.floatBE={"float":!0,single:!0,be:!0};a.exports.intBE={signed:!0,single:!0,be:!0};a.exports.uIntBE={single:!0,be:!0};a.exports.floatArrayLE={"float":!0};a.exports.intArrayLE={signed:!0};a.exports.uIntArrayLE={base:10};a.exports.floatArrayBE=
{"float":!0,be:!0};a.exports.intArrayBE={signed:!0,be:!0};a.exports.uIntArrayBE={be:!0};a.exports.str={"char":!0};a.exports.findString=function(a,d){for(var b,g=0;g<a.length;g++)if(b=l.fromBytes(a.slice(g,g+d.length),8,{"char":!0}),b==d)return g;return-1};a.exports.toBytes=e.toBytes;a.exports.fromBytes=l.fromBytes;a.exports.packBooleans=f.packBooleans;a.exports.unpackBooleans=f.unpackBooleans;a.exports.packCrumbs=f.packCrumbs;a.exports.unpackCrumbs=f.unpackCrumbs;a.exports.packNibbles=f.packNibbles;
a.exports.unpackNibbles=f.unpackNibbles;a.exports.BitDepthOffsets=h.BitDepthOffsets;a.exports.BitDepthMaxValues=h.BitDepthMaxValues},function(a,f,h){function e(a,g){g=void 0===g?!1:g;for(var b="",d=0,k=a.length;d<k;){var e=l.lPadZeros(a[d].toString(2),8);b=g?b+e:e+b;d++}return b}var l=h(0),k=new Float32Array(1),d=new Int32Array(k.buffer);a.exports.getBinary=e;a.exports.decodeFloat16=function(a){a=parseInt(e(a,!0),2);var b=(a&31744)>>10,c=a&1023;return(b?Math.pow(2,b-15)*(1+c/1024):c/1024*.00006103515625)*
(a>>15?-1:1)};a.exports.decodeFloat64=function(a){if("0,0,0,0,0,0,0,0"==a.toString())return 0;a=e(a);for(var b="1"+a.substr(12,52),c=1,d=0,k=0;k<b.length;)d+=c*parseInt(b.charAt(k),10),c/=2,k++;return("1"==a.charAt(0)?-1:1)*d*Math.pow(2,parseInt(a.substr(1,11),2)-1023)};a.exports.toFloat64=function(a){if(0==a)return[0,0];var b=0;0>=a&&(b=2147483648,a=-a);var c=Math.floor(Math.log(a)/Math.log(2)),d=Math.floor(a/Math.pow(2,c)*Math.pow(2,52));a=d&4294967295;d/=Math.pow(2,32);return[b|c+1023<<20|d&1048575,
a]};a.exports.toHalf=function(a){k[0]=a;var b=d[0];a=b>>16&32768;var c=b>>12&2047;b=b>>23&255;return 103>b?a:(a|b-112<<10|c>>1)+(c&1)}},function(a,f){function h(a){e[0]=a;return l[0]}f=new Int8Array(4);var e=new Int32Array(f.buffer,0,1),l=new Float32Array(f.buffer,0,1);window.WaveFile=h;a.exports.pack=h;a.exports.unpack=function(a){l[0]=a;return e[0]}},function(a,f,h){var e=h(7),l=h(2),k=h(8),d=h(16);a=function(a){var b=k.call(this)||this;a&&b.fromBuffer(a);return b};$jscomp.inherits(a,k);a.unpackNibbles=
k.unpackNibbles;a.packNibbles=k.packNibbles;a.unpackCrumbs=k.unpackCrumbs;a.packCrumbs=k.packCrumbs;a.unpackBooleans=k.unpackBooleans;a.packBooleans=k.packBooleans;a.read64Bit=k.read64Bit;a.read48Bit=k.read48Bit;a.read40Bit=k.read40Bit;a.read32BitFloat=k.read32BitFloat;a.read32Bit=k.read32Bit;a.read24Bit=k.read24Bit;a.read16BitFloat=k.read16BitFloat;a.read16Bit=k.read16Bit;a.read8Bit=k.read8Bit;a.read1Bit=k.read1Bit;a.readChar=k.readChar;a.fromBytes=k.fromBytes;a.writeString=k.writeString;a.write1Bit=
k.write1Bit;a.write2Bit=k.write2Bit;a.write4Bit=k.write4Bit;a.write8Bit=k.write8Bit;a.write16BitFloat=k.write16BitFloat;a.write16Bit=k.write16Bit;a.write24Bit=k.write24Bit;a.write32Bit=k.write32Bit;a.write32BitFloat=k.write32BitFloat;a.write40Bit=k.write40Bit;a.write48Bit=k.write48Bit;a.write64Bit=k.write64Bit;a.toBytes=k.toBytes;a.prototype.fromScratch=function(a,d,c,k,e){e=void 0===e?{}:e;e.container||(e.container="RIFF");var b=parseInt(c,10)/8;this.chunkSize=36+k.length*b;this.fmtChunkSize=16;
this.byteRate=a*b*d;this.blockAlign=a*b;this.chunkId=e.container;this.format="WAVE";this.fmtChunkId="fmt ";this.audioFormat=this.headerFormats_[c];this.numChannels=a;this.sampleRate=d;this.bitsPerSample=parseInt(c,10);this.dataChunkId="data";this.dataChunkSize=k.length*b;this.samples_=k;this.bitDepth_=c};a.prototype.fromBuffer=function(a){this.readRIFFChunk_(a);var b="RIFX"==this.chunkId;a=d.read(a,b);this.readFmtChunk_(a.subChunks);this.readFactChunk_(a.subChunks);this.readBextChunk_(a.subChunks);
this.readCueChunk_(a.subChunks);this.readDataChunk_(a.subChunks,{be:b,single:!0});this.bitDepth_=3==this.audioFormat&&32==this.bitsPerSample?"32f":this.bitsPerSample.toString()};a.prototype.toBuffer=function(){this.checkWriteInput_();return new Uint8Array(this.createWaveFile_())};a.prototype.toRIFF=function(){this.chunkId="RIFF";this.LEorBE()};a.prototype.toRIFX=function(){this.chunkId="RIFX";this.LEorBE()};a.prototype.toBitDepth=function(a){e.toBitDepth(this.samples_,this.bitDepth_,a);this.fromScratch(this.numChannels,
this.sampleRate,a,this.samples_,{container:this.chunkId})};a.prototype.interleave=function(){var a=[],d,c,k=this.samples_[0].length;for(d=0;d<k;d++)for(c=0;c<this.samples_.length;c++)a.push(this.samples_[c][d]);this.samples_=a};a.prototype.deInterleave=function(){var a=[],d;for(d=0;d<this.numChannels;d++)a[d]=[];d=0;for(var c;d<this.samples_.length;){for(c=0;c<this.numChannels;c++)a[c].push(this.samples_[d+c]);d+=c}this.samples_=a};a.prototype.checkWriteInput_=function(){this.validateBitDepth_();
this.validateNumChannels_();this.validateSampleRate_()};a.prototype.validateBitDepth_=function(){if(!this.headerFormats_[this.bitDepth_])throw Error(l.bitDepth);return!0};a.prototype.validateNumChannels_=function(){var a=this.numChannels*this.bitsPerSample/8;if(1>this.numChannels||65535<a)throw Error(l.numChannels);return!0};a.prototype.validateSampleRate_=function(){var a=this.bitsPerSample/8*this.numChannels*this.sampleRate;if(1>this.sampleRate||4294967295<a)throw Error(l.sampleRate);return!0};
window.WaveFile=a},function(a,f){var h=new Float32Array(1),e={8:256,16:65536,24:16777216,32:4294967296,"32f":1,64:1},l={intToInt:function(a,d){return a=0<a?parseInt(a/d.oldPositive*d.newPositive,10):parseInt(a/d.oldNegative*d.newNegative,10)},floatToInt:function(a,d){return 0<a?a*d.newPositive:a*d.newNegative},intToFloat:function(a,d){return 0<a?a/d.oldPositive:a/d.oldNegative},floatToFloat:function(a,d){"64"==d.original&&"32f"==d.target&&(h[0]=a,a=h[0]);return a}};window.WaveFile.toBitDepth=function(a,
d,b){var g="8 16 24 32 32f 64".split(" ");if(-1==g.indexOf(d)||-1==g.indexOf(b))throw Error("Invalid bit depth.");g=["32f","64"].includes(d)?"float":"int";var c=["32f","64"].includes(b)?"Float":"Int";g=l[g+"To"+c];c=a.length;for(var m=0;m<c;m++){var k=m,f=a[m];"8"==d&&(f-=128);a[k]=f;a[m]=g(a[m],{oldNegative:e[d]/2,newNegative:e[b]/2,oldPositive:e[d]/2-1,newPositive:e[b]/2-1,original:d,target:b});k=m;f=a[m];"8"==b&&(f+=128);a[k]=f}};a.exports.BitDepthMaxValues=e},function(a,f,h){var e=h(3),l=h(2),
k=e.uInt8,d=e.uInt16,b=e.uInt32,g=e.char,c=h(15);f=function(){var a=c.call(this)||this;a.headerFormats_={4:17,8:1,16:1,24:1,32:1,"32f":3,64:3};a.samples_=[];return a};$jscomp.inherits(f,c);f.write=c.write;f.prototype.readRIFFChunk_=function(a){this.chunkId=e.unpackSequence(a.slice(0,4),g);if("RIFF"!=this.chunkId&&"RIFX"!=this.chunkId)throw Error(l.format);var b=this.LEorBE();this.chunkSize=e.fromBytes(a.slice(4,8),32,{be:b,single:!0});this.format=e.unpackSequence(a.slice(8,12),g);if("WAVE"!=this.format)throw Error(l.wave);
};f.prototype.LEorBE=function(){var a="RIFX"==this.chunkId;k.be=a;d.be=a;return b.be=a};f.prototype.readFmtChunk_=function(a){if(a=this.findChunk(a,"fmt "))this.fmtChunkId="fmt ",this.fmtChunkSize=a.chunkSize,this.audioFormat=e.unpack(a.chunkData.slice(0,2),d),this.numChannels=e.unpack(a.chunkData.slice(2,4),d),this.sampleRate=e.unpack(a.chunkData.slice(4,8),b),this.byteRate=e.unpack(a.chunkData.slice(8,12),b),this.blockAlign=e.unpack(a.chunkData.slice(12,14),d),this.bitsPerSample=e.unpack(a.chunkData.slice(14,
16),d),this.readFmtExtension(a);else throw Error(l["fmt "]);};f.prototype.readFmtExtension=function(a){16<this.fmtChunkSize&&(this.cbSize=e.unpack(a.chunkData.slice(16,18),d),18<this.fmtChunkSize&&(this.validBitsPerSample=e.unpack(a.chunkData.slice(18,20),d)))};f.prototype.readFactChunk_=function(a){if(a=this.findChunk(a,"fact"))this.factChunkId="fact",this.factChunkSize=a.chunkSize,this.dwSampleLength=e.unpack(a.chunkData.slice(0,4),b);else if(this.enforceFact)throw Error(l.fact);};f.prototype.readBextChunk_=
function(a){if(a=this.findChunk(a,"bext"))this.bextChunkId="bext",this.bextChunkSize=a.chunkSize,this.bextChunkData=a.chunkData};f.prototype.readCueChunk_=function(a){if(a=this.findChunk(a,"cue "))this.cueChunkId="cue ",this.cueChunkSize=a.chunkSize,this.cueChunkData=a.chunkData};f.prototype.readDataChunk_=function(a,b){if(a=this.findChunk(a,"data"))this.dataChunkId="data",this.dataChunkSize=a.chunkSize,this.samplesFromBytes_(a.chunkData,b);else throw Error(l.data);};f.prototype.samplesFromBytes_=
function(a,b){b.signed=8==this.bitsPerSample?!1:!0;32==this.bitsPerSample&&3==this.audioFormat&&(b.float=!0);b.single=!1;this.samples_=4==this.bitsPerSample?e.pack(a,k):e.fromBytes(a,this.bitsPerSample,b)};f.prototype.findChunk=function(a,b){for(var c=0;c<a.length;c++)if(a[c].chunkId==b)return a[c];return null};f.prototype.samplesToBytes_=function(a){32==this.bitsPerSample&&3==this.audioFormat&&(a.float=!0);a=e.toBytes(this.samples_,4==this.bitsPerSample?8:this.bitsPerSample,a);a.length%2&&a.push(0);
return a};f.prototype.getBextBytes_=function(){return this.bextChunkId?[].concat(e.packSequence(this.bextChunkId,g),e.pack(this.bextChunkSize,b),this.bextChunkData):[]};f.prototype.getCueBytes_=function(){return this.cueChunkId?[].concat(e.packSequence(this.cueChunkId,g),e.pack(this.cueChunkSize,b),this.cueChunkData):[]};f.prototype.getFactBytes_=function(){return this.factChunkId?[].concat(e.packSequence(this.factChunkId,g),e.pack(this.factChunkSize,b),e.pack(this.dwSampleLength,b)):[]};f.prototype.getCbSizeBytes_=
function(){return 16<this.fmtChunkSize?e.pack(this.cbSize,d):[]};f.prototype.getValidBitsPerSampleBytes_=function(){return 18<this.fmtChunkSize?e.pack(this.validBitsPerSample,d):[]};f.prototype.createWaveFile_=function(){var a={be:this.LEorBE()};return e.packSequence(this.chunkId,g).concat(e.pack(this.chunkSize,b),e.packSequence(this.format,g),this.getBextBytes_(),e.packSequence(this.fmtChunkId,g),e.pack(this.fmtChunkSize,b),e.pack(this.audioFormat,d),e.pack(this.numChannels,d),e.pack(this.sampleRate,
b),e.pack(this.byteRate,b),e.pack(this.blockAlign,d),e.pack(this.bitsPerSample,d),this.getCbSizeBytes_(),this.getValidBitsPerSampleBytes_(),this.getFactBytes_(),e.packSequence(this.dataChunkId,g),e.pack(this.dataChunkSize,b),this.samplesToBytes_(a),this.getCueBytes_())};a.exports=f},function(a,f,h){var e=h(10),l=h(0);a.exports.toBytes=function(a,d,b){b=void 0===b?{base:10}:b;a=l.turnToArray(a);var g=b.char?e.writeString:e["write"+d+"Bit"+(b.float?"Float":"")];for(var c=0,k=0,f=a.length,h=[];c<f;)k=
g(h,a,c,k),c++;a=h;l.makeBigEndian(a,b.be,d);l.outputToBase(a,d,b.base);b.buffer&&(a=new Uint8Array(a));return a}},function(a,f,h){function e(a,b,g,c){a[c++]=b[g]&255;a[c++]=b[g]>>>8&255;a[c++]=b[g]>>>16&255;a[c++]=b[g]>>>24&255;return c}var l=h(4),k=h(5);a.exports.write64Bit=function(a,b,g,c){b=l.toFloat64(b[g]);c=e(a,b,1,c);return e(a,b,0,c)};a.exports.write48Bit=function(a,b,g,c){a[c++]=b[g]&255;a[c++]=b[g]>>8&255;a[c++]=b[g]>>16&255;a[c++]=b[g]>>24&255;a[c++]=b[g]/4294967296&255;a[c++]=b[g]/1099511627776&
255;return c};a.exports.write40Bit=function(a,b,g,c){a[c++]=b[g]&255;a[c++]=b[g]>>8&255;a[c++]=b[g]>>16&255;a[c++]=b[g]>>24&255;a[c++]=b[g]/4294967296&255;return c};a.exports.write32BitFloat=function(a,b,g,c){b=k.unpack(b[g]);a[c++]=b&255;a[c++]=b>>>8&255;a[c++]=b>>>16&255;a[c++]=b>>>24&255;return c};a.exports.write32Bit=e;a.exports.write24Bit=function(a,b,g,c){a[c++]=b[g]&255;a[c++]=b[g]>>>8&255;a[c++]=b[g]>>>16&255;return c};a.exports.write16Bit=function(a,b,g,c){a[c++]=b[g]&255;a[c++]=b[g]>>>8&
255;return c};a.exports.write16BitFloat=function(a,b,g,c){b=l.toHalf(b[g]);a[c++]=b>>>8&255;a[c++]=b&255;return c};a.exports.write8Bit=function(a,b,g,c){a[c++]=b[g]&255;return c};a.exports.write4Bit=function(a,b,g,c){a[c++]=b[g]&15;return c};a.exports.write2Bit=function(a,b,g,c){a[c++]=0>b[g]?b[g]+4:b[g];return c};a.exports.write1Bit=function(a,b,g,c){a[c++]=b[g]?1:0;return c};a.exports.writeString=function(a,b,g,c){a[c++]=b.charCodeAt(g);return c}},function(a,f){window.WaveFile=function(a,e){for(var f=
a.length,k=0;k<f;){for(var d,b=a,g=k,c=0,h=e-1,n=parseInt(e/2,10);c<n;)d=b[g+c],b[g+c]=b[g+h],b[g+h]=d,c++,h--;k+=e}}},function(a,f,h){function e(a,g,c,e){var b=[],f=0,h=0,l=k.BitDepthOffsets[g],m=a.length-(l-1);g=k.BitDepthMaxValues[g];for(c=c?d.signed:function(a,b){return a};f<m;)b[h]=c(e(a,f),g),f+=l,h++;return b}var l=h(13),k=h(1),d=h(0);a.exports.fromBytes=function(a,g,c){c=void 0===c?{base:10}:c;d.makeBigEndian(a,c.be,g);d.bytesToInt(a,c.base);a=e(a,g,c.signed,c.char?l.readChar:l["read"+(2==
g||4==g?8:g)+"Bit"+(c.float?"Float":"")]);c.char&&(a=a.join(""));c.single&&(a=a[0]);return a}},function(a,f,h){function e(a,b,d){--d;for(var c="";0<=d;)c+=k.bytePadding(a[d+b].toString(2),2),d--;return parseInt(c,2)}function l(a,b){return(a[3+b]<<24|a[2+b]<<16|a[1+b]<<8|a[b])>>>0}var k=h(0),d=h(4),b=h(5);a.exports.readChar=function(a,b){return String.fromCharCode(a[b])};a.exports.read1Bit=function(a,b){return parseInt(a[b],2)};a.exports.read8Bit=function(a,b){return a[b]};a.exports.read16Bit=function(a,
b){return a[1+b]<<8|a[b]};a.exports.read16BitFloat=function(a,b){return d.decodeFloat16(a.slice(b,b+2))};a.exports.read24Bit=function(a,b){return a[2+b]<<16|a[1+b]<<8|a[b]};a.exports.read32Bit=l;a.exports.read32BitFloat=function(a,c){return b.pack(l(a,c))};a.exports.read40Bit=function(a,b){return e(a,b,5)};a.exports.read48Bit=function(a,b){return e(a,b,6)};a.exports.read64Bit=function(a,b){return d.decodeFloat64(a.slice(b,b+8))}},function(a,f,h){var e=h(0);a.exports.packBooleans=function(a){var f=
[],d=0,b=0;e.fixByteArraySize(a,8);for(var g=a.length-7;d<g;)f[b++]=parseInt(a[d].toString(2)+a[d+1].toString(2)+a[d+2].toString(2)+a[d+3].toString(2)+a[d+4].toString(2)+a[d+5].toString(2)+a[d+6].toString(2)+a[d+7].toString(2),2),d+=8;return f};a.exports.unpackBooleans=function(a){for(var f=[],d=0,b=0,g=a.length,c;d<g;)c=e.lPadZeros(a[d].toString(2),8),f[b++]=parseInt(c[0],2),f[b++]=parseInt(c[1],2),f[b++]=parseInt(c[2],2),f[b++]=parseInt(c[3],2),f[b++]=parseInt(c[4],2),f[b++]=parseInt(c[5],2),f[b++]=
parseInt(c[6],2),f[b++]=parseInt(c[7],2),d++;return f};a.exports.packCrumbs=function(a){var f=[],d=0,b=0;e.fixByteArraySize(a,4);for(var g=a.length-3;d<g;)f[b++]=parseInt(e.lPadZeros(a[d].toString(2),2)+e.lPadZeros(a[d+1].toString(2),2)+e.lPadZeros(a[d+2].toString(2),2)+e.lPadZeros(a[d+3].toString(2),2),2),d+=4;return f};a.exports.unpackCrumbs=function(a){for(var f=[],d=0,b=0,g=a.length,c;d<g;)c=e.lPadZeros(a[d].toString(2),8),f[b++]=parseInt(c[0]+c[1],2),f[b++]=parseInt(c[2]+c[3],2),f[b++]=parseInt(c[4]+
c[5],2),f[b++]=parseInt(c[6]+c[7],2),d++;return f};a.exports.packNibbles=function(a){var e=[],d=0,b=0,g=a.length;for(g%2&&a.push(0);d<g;)e[b++]=parseInt(a[d].toString(16)+a[d+1].toString(16),16),d+=2;return e};a.exports.unpackNibbles=function(a){for(var e=[],d=0,b=0,g=a.length;d<g;)e[b++]=parseInt(a[d].toString(16)[0],16),e[b++]=parseInt(a[d].toString(16)[1],16),d++;return e}},function(a,f){a.exports=function(){this.chunkId="";this.chunkSize=0;this.fmtChunkId=this.format="";this.validBitsPerSample=
this.cbSize=this.bitsPerSample=this.blockAlign=this.byteRate=this.sampleRate=this.numChannels=this.audioFormat=this.fmtChunkSize=0;this.factChunkId="";this.factChunkSize=0;this.factChunkData=[];this.dwSampleLength=0;this.cueChunkId="";this.cueChunkSize=-1;this.cueChunkData=[];this.dataChunkId="";this.dataChunkSize=0;this.bextChunkId="";this.bextChunkSize=0;this.bextChunkData=[]}},function(a,f,h){function e(a,d){void 0!==d&&d||(g.be="RIFX"==a.chunkId);d=b.packSequence(a.chunkId,c).concat(b.pack(a.chunkSize,
g),b.packSequence(a.format,c),l(a.subChunks,g.be));if("RIFF"==a.chunkId||"RIFX"==a.chunkId)d=new Uint8Array(d);return d}function l(a,d){for(var f=[],h=0;h<a.length;)f="LIST"==a[h].chunkId?f.concat(e(a[h],d)):f.concat(b.packSequence(a[h].chunkId,c),b.pack(a[h].chunkSize,g),a[h].chunkData),h++;return f}function k(a){for(var b=[],c=12;c<a.length;)b.push(d(a,c)),c+=8+b[b.length-1].chunkSize;return b}function d(a,d){var e={chunkId:b.unpackSequence(a.slice(d,d+4),c),chunkSize:b.unpack(a.slice(d+4,d+8),
g)};"LIST"==e.chunkId?(e.format=b.unpackSequence(a.slice(8,12),c),e.subChunks=k(a.slice(d,d+e.chunkSize))):e.chunkData=a.slice(d+8,d+8+e.chunkSize);return e}var b=h(3),g=b.uInt32,c=b.char;window.WaveFile.read=function(a){a=[].slice.call(a);var d=b.unpackSequence(a.slice(0,4),c);g.be="RIFX"==d;var e=b.unpack(a.slice(4,8),g);return{chunkId:d,chunkSize:e,format:b.unpackSequence(a.slice(8,12),c),subChunks:k(a)}};a.exports.write=e}]);

@@ -0,0 +0,0 @@ /*global document */

PR.registerLangHandler(PR.createSimpleLexer([["pln",/^[\t\n\f\r ]+/,null," \t\r\n "]],[["str",/^"(?:[^\n\f\r"\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*"/,null],["str",/^'(?:[^\n\f\r'\\]|\\(?:\r\n?|\n|\f)|\\[\S\s])*'/,null],["lang-css-str",/^url\(([^"')]*)\)/i],["kwd",/^(?:url|rgb|!important|@import|@page|@media|@charset|inherit)(?=[^\w-]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*)\s*:/i],["com",/^\/\*[^*]*\*+(?:[^*/][^*]*\*+)*\//],["com",
/^(?:<\!--|--\>)/],["lit",/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],["lit",/^#[\da-f]{3,6}/i],["pln",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i],["pun",/^[^\s\w"']+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[["kwd",/^-?(?:[_a-z]|\\[\da-f]+ ?)(?:[\w-]|\\\\[\da-f]+ ?)*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[["str",/^[^"')]+/]]),["css-str"]);

@@ -0,0 +0,0 @@ var q=null;window.PR_SHOULD_USE_CONTINUATION=!0;

@@ -10,3 +10,5 @@ /*!

const bitDepthLib = require("bitdepth");
const waveFileReaderWriter = require("./src/wavefile-reader-writer");
const WaveErrors = require("./src/wave-errors");
const WaveFileReaderWriter = require("./src/wavefile-reader-writer");
const riffChunks = require("riff-chunks");

@@ -16,3 +18,3 @@ /**

*/
class WaveFile extends waveFileReaderWriter.WaveFileReaderWriter {
class WaveFile extends WaveFileReaderWriter {

@@ -62,4 +64,36 @@ /**

}
/**
* Init a WaveFile object from a byte buffer.
* @param {Uint8Array} bytes The buffer.
*/
fromBuffer(bytes) {
this.readRIFFChunk_(bytes);
let bigEndian = this.chunkId == "RIFX";
let chunk = riffChunks.read(bytes, bigEndian);
this.readFmtChunk_(chunk.subChunks);
this.readFactChunk_(chunk.subChunks);
this.readBextChunk_(chunk.subChunks);
this.readCueChunk_(chunk.subChunks);
this.readDataChunk_(
chunk.subChunks,
{"be": bigEndian, "single": true}
);
if (this.audioFormat == 3 && this.bitsPerSample == 32) {
this.bitDepth_ = "32f";
}else {
this.bitDepth_ = this.bitsPerSample.toString();
}
}
/**
* Turn the WaveFile object into a byte buffer.
* @return {Uint8Array}
*/
toBuffer() {
this.checkWriteInput_();
return new Uint8Array(this.createWaveFile_());
}
/**
* Turn the file to RIFF.

@@ -70,2 +104,3 @@ * All values will be little-endian when writing.

this.chunkId = "RIFF";
this.LEorBE();
}

@@ -79,2 +114,3 @@

this.chunkId = "RIFX";
this.LEorBE();
}

@@ -133,4 +169,50 @@

}
/**
* Validate the input for wav writing.
* @throws {Error} If any argument does not meet the criteria.
*/
checkWriteInput_() {
this.validateBitDepth_();
this.validateNumChannels_();
this.validateSampleRate_();
}
/**
* Validate the bit depth.
* @throws {Error} If any argument does not meet the criteria.
*/
validateBitDepth_() {
if (!this.headerFormats_[this.bitDepth_]) {
throw new Error(WaveErrors.bitDepth);
}
return true;
}
/**
* Validate the sample rate value.
* @throws {Error} If any argument does not meet the criteria.
*/
validateNumChannels_() {
let blockAlign = this.numChannels * this.bitsPerSample / 8;
if (this.numChannels < 1 || blockAlign > 65535) {
throw new Error(WaveErrors.numChannels);
}
return true;
}
/**
* Validate the sample rate value.
* @throws {Error} If any argument does not meet the criteria.
*/
validateSampleRate_() {
let byteRate = this.numChannels *
(this.bitsPerSample / 8) * this.sampleRate;
if (this.sampleRate < 1 || byteRate > 4294967295) {
throw new Error(WaveErrors.sampleRate);
}
return true;
}
}
module.exports.WaveFile = WaveFile;
module.exports = WaveFile;
{
"name": "wavefile",
"version": "0.6.0",
"version": "1.0.0",
"description": "Read & write wave files with 8, 16, 24, 32 & 64-bit data.",

@@ -40,3 +40,3 @@ "homepage": "https://github.com/rochars/wavefile",

"compile": "google-closure-compiler-js dist/wavefile.js > dist/wavefile-min.js",
"doc": "./node_modules/.bin/jsdoc index.js -d docs",
"doc": "./node_modules/.bin/jsdoc index.js -d docs -r README.md -t node_modules/docdash",
"qa": "npm run lint && npm test",

@@ -49,2 +49,3 @@ "pack": "npm run bundle && npm run compile && npm run doc",

"codecov": "^3.0.0",
"docdash": "^0.4.0",
"google-closure-compiler-js": "^20170910.0.1",

@@ -60,7 +61,7 @@ "jsdoc": "~3.5.5",

"dependencies": {
"bitdepth": "1.0.2",
"byte-data": "0.5.0",
"riff-chunks": "1.0.0"
"bitdepth": "1.0.4",
"byte-data": "0.7.0",
"riff-chunks": "3.0.1"
},
"main": "index.js"
}

@@ -6,3 +6,3 @@ # wavefile

[![Build Status](https://travis-ci.org/rochars/wavefile.svg?branch=master)](https://travis-ci.org/rochars/wavefile) [![Build status](https://ci.appveyor.com/api/projects/status/kgaqhpahfgsta50s?svg=true)](https://ci.appveyor.com/project/rochars/wavefile) [![codecov](https://codecov.io/gh/rochars/wavefile/branch/master/graph/badge.svg)](https://codecov.io/gh/rochars/wavefile) [![NPM version](https://img.shields.io/npm/v/wavefile.svg?style=flat)](https://www.npmjs.com/package/wavefile) [![NPM downloads](https://img.shields.io/npm/dm/wavefile.svg?style=flat)](https://www.npmjs.com/package/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/docs-online-blue.svg?style=for-the-badge)](https://rochars.github.io/wavefile/index.html)

@@ -22,5 +22,5 @@ ## Install

let fs = require("fs");
let wavefile = require("wavefile");
let Wavefile = require("wavefile");
let wav = new wavefile.Wavefile(fs.readFileSync("file.wav"));
let wav = new Wavefile(fs.readFileSync("file.wav"));
console.log(wav.chunkId);

@@ -34,3 +34,3 @@ console.log(wav.chunkSize);

```javascript
let wav = new wavefile.WaveFile();
let wav = new WaveFile();

@@ -50,4 +50,3 @@ // mono

// Default is RIFF. To create RIFX files:
wav.fromScratch(
1, 44100, '32', [0, -2147483648, 2147483647, 4], {"container": "RIFX"});
wav.fromScratch(1, 44100, '32', samples, {"container": "RIFX"});
fs.writeFileSync(path, wav.toBuffer());

@@ -62,3 +61,3 @@ ```

```javascript
let wav = new wavefile.Wavefile(fs.readFileSync("file.wav"));
let wav = new Wavefile(fs.readFileSync("file.wav"));

@@ -72,3 +71,3 @@ // Possible values are:

```javascript
let wav = new wavefile.Wavefile(fs.readFileSync("file.wav"));
let wav = new Wavefile(fs.readFileSync("file.wav"));

@@ -84,3 +83,3 @@ // Interleave stereo samples

```javascript
let wav = new wavefile.Wavefile(fs.readFileSync("file.wav"));
let wav = new Wavefile(fs.readFileSync("file.wav"));

@@ -96,3 +95,3 @@ // Turn a RIFF file to a RIFX file

```javascript
let wav = new wavefile.Wavefile(fs.readFileSync("file.wav"));
let wav = new Wavefile(fs.readFileSync("file.wav"));

@@ -99,0 +98,0 @@ // The container, "RIFF" or "RIFX"

@@ -12,3 +12,3 @@ /*

*/
module.exports.WaveFileHeader = class {
class WaveFileHeader {

@@ -90,1 +90,3 @@ constructor() {

}
module.exports = WaveFileHeader;

@@ -9,4 +9,8 @@ /*

const byteData = require("byte-data");
const waveFileHeader = require("../src/wavefile-header");
const riff = require("riff-chunks");
const WaveErrors = require("../src/wave-errors");
const uInt8 = byteData.uInt8;
const uInt16 = byteData.uInt16;
const uInt32 = byteData.uInt32;
const char = byteData.char;
let WaveFileHeader = require("../src/wavefile-header");

@@ -16,24 +20,7 @@ /**

*/
class WaveFileReaderWriter extends waveFileHeader.WaveFileHeader {
class WaveFileReaderWriter extends WaveFileHeader {
constructor() {
super();
/** @type {boolean} */
// TODO fact must be enforced in some cases
this.enforceFact_ = false;
/**
* Error messages.
* @enum {string}
*/
this.WaveErrors = {
"format": "Not a supported format.",
"wave": "Could not find the 'WAVE' format identifier",
"fmt ": "Could not find the 'fmt ' chunk",
"data": "Could not find the 'data' chunk",
"fact": "Could not find the 'fact' chunk",
"bitDepth": "Invalid bit depth.",
"numChannels": "Invalid number of channels.",
"sampleRate": "Invalid sample rate."
};
/**
* Header formats.

@@ -56,32 +43,2 @@ * @enum {number}

/**
* Read a wave file from a byte buffer.
* @param {Uint8Array} bytes The buffer.
*/
fromBuffer(bytes) {
this.readRIFFChunk_(bytes);
let bigEndian = this.chunkId == "RIFX";
let chunk = riff.getChunks(bytes, bigEndian);
let options = {"be": bigEndian, "single": true};
this.readFmtChunk_(chunk.subChunks, options);
this.readFactChunk_(chunk.subChunks, options);
this.readBextChunk_(chunk.subChunks, options);
this.readCueChunk_(chunk.subChunks, options);
this.readDataChunk_(chunk.subChunks, options);
if (this.audioFormat == 3 && this.bitsPerSample == 32) {
this.bitDepth_ = "32f";
}else {
this.bitDepth_ = this.bitsPerSample.toString();
}
}
/**
* Turn the WaveFile object into a byte buffer.
* @return {Uint8Array}
*/
toBuffer() {
this.checkWriteInput_();
return new Uint8Array(this.createWaveFile_());
}
/**
* Read the RIFF chunk a wave file.

@@ -92,69 +49,82 @@ * @param {Uint8Array} bytes an array representing the wave file.

readRIFFChunk_(bytes) {
this.chunkId = byteData.fromBytes(bytes.slice(0, 4),
8, {"char": true});
this.chunkId = byteData.unpackSequence(bytes.slice(0, 4), char);
if (this.chunkId != "RIFF" && this.chunkId != "RIFX") {
throw Error(this.WaveErrors.format);
throw Error(WaveErrors.format);
}
let bigEndian = this.LEorBE();
this.chunkSize = byteData.fromBytes(
bytes.slice(4, 8),
32,
{"be": this.chunkId == "RIFX", "single": true});
this.format = byteData.fromBytes(
bytes.slice(8, 12), 8, byteData.str);
{"be": bigEndian, "single": true});
this.format = byteData.unpackSequence(bytes.slice(8, 12), char);
if (this.format != "WAVE") {
throw Error(this.WaveErrors.wave);
throw Error(WaveErrors.wave);
}
}
LEorBE() {
let bigEndian = this.chunkId == "RIFX";
uInt8.be = bigEndian;
uInt16.be = bigEndian;
uInt32.be = bigEndian;
return bigEndian;
}
/**
* Read the "fmt " chunk of a wave file.
* @param {Object} chunks The RIFF file chunks.
* @param {Object} options The options to read the bytes.
* @throws {Error} If no "fmt " chunk is found.
*/
readFmtChunk_(chunks, options) {
readFmtChunk_(chunks) {
let chunk = this.findChunk(chunks, "fmt ");
if (chunk) {
this.fmtChunkId = "fmt ";
this.fmtChunkSize = chunk.subChunkSize;
this.audioFormat = byteData.fromBytes(
chunk.subChunkData.slice(0, 2), 16, options);
this.numChannels = byteData.fromBytes(
chunk.subChunkData.slice(2, 4), 16, options);
this.sampleRate = byteData.fromBytes(
chunk.subChunkData.slice(4, 8), 32, options);
this.byteRate = byteData.fromBytes(
chunk.subChunkData.slice(8, 12), 32, options);
this.blockAlign = byteData.fromBytes(
chunk.subChunkData.slice(12, 14), 16, options);
this.bitsPerSample = byteData.fromBytes(
chunk.subChunkData.slice(14, 16), 16, options);
if (this.fmtChunkSize > 16) {
this.cbSize = byteData.fromBytes(
chunk.subChunkData.slice(16, 18), 16);
if (this.fmtChunkSize > 18) {
this.validBitsPerSample = byteData.fromBytes(
chunk.subChunkData.slice(18, 20), 16);
}
}
this.fmtChunkSize = chunk.chunkSize;
this.audioFormat = byteData.unpack(
chunk.chunkData.slice(0, 2), uInt16);
this.numChannels = byteData.unpack(
chunk.chunkData.slice(2, 4), uInt16);
this.sampleRate = byteData.unpack(
chunk.chunkData.slice(4, 8), uInt32);
this.byteRate = byteData.unpack(
chunk.chunkData.slice(8, 12), uInt32);
this.blockAlign = byteData.unpack(
chunk.chunkData.slice(12, 14), uInt16);
this.bitsPerSample = byteData.unpack(
chunk.chunkData.slice(14, 16), uInt16);
this.readFmtExtension(chunk);
} else {
throw Error(this.WaveErrors["fmt "]);
throw Error(WaveErrors["fmt "]);
}
}
/**
* Read the "fmt " chunk extension.
* @param {Object} chunk The "fmt " chunk.
*/
readFmtExtension(chunk) {
if (this.fmtChunkSize > 16) {
this.cbSize = byteData.unpack(
chunk.chunkData.slice(16, 18), uInt16);
if (this.fmtChunkSize > 18) {
this.validBitsPerSample = byteData.unpack(
chunk.chunkData.slice(18, 20), uInt16);
}
}
}
/**
* Read the "fact" chunk of a wave file.
* @param {Object} chunks The RIFF file chunks.
* @param {Object} options The options to read the bytes.
* @throws {Error} If no "fact" chunk is found.
*/
readFactChunk_(chunks, options) {
readFactChunk_(chunks) {
let chunk = this.findChunk(chunks, "fact");
if (chunk) {
this.factChunkId = "fact";
this.factChunkSize = chunk.subChunkSize;
this.dwSampleLength = byteData.fromBytes(
chunk.subChunkData.slice(0, 4), 32, options);
this.factChunkSize = chunk.chunkSize;
this.dwSampleLength = byteData.unpack(
chunk.chunkData.slice(0, 4), uInt32);
} else if (this.enforceFact) {
throw Error(this.WaveErrors["fact"]);
throw Error(WaveErrors["fact"]);
}

@@ -166,11 +136,10 @@ }

* @param {Object} chunks The RIFF file chunks.
* @param {Object} options The options to read the bytes.
* @throws {Error} If no "bext" chunk is found.
*/
readBextChunk_(chunks, options) {
readBextChunk_(chunks) {
let chunk = this.findChunk(chunks, "bext");
if (chunk) {
this.bextChunkId = "bext";
this.bextChunkSize = chunk.subChunkSize;
this.bextChunkData = byteData.fromBytes(chunk.subChunkData, 8);
this.bextChunkSize = chunk.chunkSize;
this.bextChunkData = chunk.chunkData;
}

@@ -182,11 +151,10 @@ }

* @param {Object} chunks The RIFF file chunks.
* @param {Object} options The options to read the bytes.
* @throws {Error} If no "cue" chunk is found.
*/
readCueChunk_(chunks, options) {
readCueChunk_(chunks) {
let chunk = this.findChunk(chunks, "cue ");
if (chunk) {
this.cueChunkId = "cue ";
this.cueChunkSize = chunk.subChunkSize;
this.cueChunkData = byteData.fromBytes(chunk.subChunkData, 8);
this.cueChunkSize = chunk.chunkSize;
this.cueChunkData = chunk.chunkData;
}

@@ -204,6 +172,6 @@ }

this.dataChunkId = "data";
this.dataChunkSize = chunk.subChunkSize;
this.samplesFromBytes_(chunk.subChunkData, options);
this.dataChunkSize = chunk.chunkSize;
this.samplesFromBytes_(chunk.chunkData, options);
} else {
throw Error(this.WaveErrors["data"]);
throw Error(WaveErrors["data"]);
}

@@ -223,3 +191,3 @@ }

if (this.bitsPerSample == 4) {
this.samples_ = byteData.fromBytes(bytes, 8, options);
this.samples_ = byteData.pack(bytes, uInt8);
} else {

@@ -237,3 +205,3 @@ this.samples_ = byteData.fromBytes(

for (let i = 0; i<chunks.length; i++) {
if (chunks[i].subChunkId == fourCC) {
if (chunks[i].chunkId == fourCC) {
return chunks[i];

@@ -246,52 +214,5 @@ }

/**
* Validate the input for wav writing.
* @throws {Error} If any argument does not meet the criteria.
*/
checkWriteInput_() {
this.validateBitDepth_();
this.validateNumChannels_();
this.validateSampleRate_();
}
/**
* Validate the bit depth.
* @throws {Error} If any argument does not meet the criteria.
*/
validateBitDepth_() {
if (!this.headerFormats_[this.bitDepth_]) {
throw new Error(this.WaveErrors.bitDepth);
}
return true;
}
/**
* Validate the sample rate value.
* @throws {Error} If any argument does not meet the criteria.
*/
validateNumChannels_() {
let blockAlign = this.numChannels * this.bitsPerSample / 8;
if (this.numChannels < 1 || blockAlign > 65535) {
throw new Error(this.WaveErrors.numChannels);
}
return true;
}
/**
* Validate the sample rate value.
* @throws {Error} If any argument does not meet the criteria.
*/
validateSampleRate_() {
let byteRate = this.numChannels *
(this.bitsPerSample / 8) * this.sampleRate;
if (this.sampleRate < 1 || byteRate > 4294967295) {
throw new Error(this.WaveErrors.sampleRate);
}
return true;
}
/**
* Split each sample into bytes.
*/
samplesToBytes_(options) {
let bytes = [];
if (this.bitsPerSample == 32 && this.audioFormat == 3) {

@@ -301,3 +222,3 @@ options.float = true;

let bitDepth = this.bitsPerSample == 4 ? 8 : this.bitsPerSample;
bytes = byteData.toBytes(this.samples_, bitDepth, options);
let bytes = byteData.toBytes(this.samples_, bitDepth, options);
if (bytes.length % 2) {

@@ -309,39 +230,70 @@ bytes.push(0);

getBextBytes(options) {
let bext = [];
/**
* Get the bytes of the "bext" chunk.
* @return {!Array<number>} The "bext" chunk bytes.
*/
getBextBytes_() {
if (this.bextChunkId) {
bext = bext.concat(
byteData.toBytes(this.bextChunkId, 8, {"char": true}),
byteData.toBytes(this.bextChunkSize, 32, options),
byteData.toBytes(this.bextChunkData, 8)
return [].concat(
byteData.packSequence(this.bextChunkId, char),
byteData.pack(this.bextChunkSize, uInt32),
this.bextChunkData
);
}
return bext;
return [];
}
getCueBytes(options) {
let cue = [];
/**
* Get the bytes of the "cue " chunk.
* @return {!Array<number>} The "cue " chunk bytes.
*/
getCueBytes_() {
if (this.cueChunkId) {
cue = cue.concat(
byteData.toBytes(this.cueChunkId, 8, {"char": true}),
byteData.toBytes(this.cueChunkSize, 32, options),
byteData.toBytes(this.cueChunkData, 8)
return [].concat(
byteData.packSequence(this.cueChunkId, char),
byteData.pack(this.cueChunkSize, uInt32),
this.cueChunkData
);
}
return cue;
return [];
}
getFactBytes(options) {
let fact = []
/**
* Get the bytes of the "fact" chunk.
* @return {!Array<number>} The "fact" chunk bytes.
*/
getFactBytes_() {
if (this.factChunkId) {
fact = fact.concat(
byteData.toBytes(this.factChunkId, 8, {"char": true}),
byteData.toBytes(this.factChunkSize, 32, options),
byteData.toBytes(this.dwSampleLength, 32, options)
return [].concat(
byteData.packSequence(this.factChunkId, char),
byteData.pack(this.factChunkSize, uInt32),
byteData.pack(this.dwSampleLength, uInt32)
);
}
return fact;
return [];
}
/**
* Get the bytes of the cbSize field.
* @return {!Array<number>} The cbSize bytes.
*/
getCbSizeBytes_() {
if (this.fmtChunkSize > 16) {
return byteData.pack(this.cbSize, uInt16);
}
return [];
}
/**
* Get the bytes of the validBitsPerSample field.
* @return {!Array<number>} The validBitsPerSample bytes.
*/
getValidBitsPerSampleBytes_() {
if (this.fmtChunkSize > 18) {
return byteData.pack(this.validBitsPerSample, uInt16);
}
return [];
}
/**
* Turn a WaveFile object into a file.

@@ -351,31 +303,22 @@ * @return {Uint8Array} The wav file bytes.

createWaveFile_() {
let options = {"be": this.chunkId == "RIFX"};
let cbSize = [];
let validBitsPerSample = []
if (this.fmtChunkSize > 16) {
cbSize = byteData.toBytes(this.cbSize, 16, options);
if (this.fmtChunkSize > 18) {
validBitsPerSample = byteData.toBytes(
this.validBitsPerSample, 16, options);
}
}
return byteData.toBytes(this.chunkId, 8, {"char": true}).concat(
byteData.toBytes(this.chunkSize, 32, options),
byteData.toBytes(this.format, 8, {"char": true}),
this.getBextBytes(options),
byteData.toBytes(this.fmtChunkId, 8, {"char": true}),
byteData.toBytes(this.fmtChunkSize, 32, options),
byteData.toBytes(this.audioFormat, 16, options),
byteData.toBytes(this.numChannels, 16, options),
byteData.toBytes(this.sampleRate, 32, options),
byteData.toBytes(this.byteRate, 32, options),
byteData.toBytes(this.blockAlign, 16, options),
byteData.toBytes(this.bitsPerSample, 16, options),
cbSize,
validBitsPerSample,
this.getFactBytes(options),
byteData.toBytes(this.dataChunkId, 8, {"char": true}),
byteData.toBytes(this.dataChunkSize, 32, options),
let options = {"be": this.LEorBE()};
return byteData.packSequence(this.chunkId, char).concat(
byteData.pack(this.chunkSize, uInt32),
byteData.packSequence(this.format, char),
this.getBextBytes_(),
byteData.packSequence(this.fmtChunkId, char),
byteData.pack(this.fmtChunkSize, uInt32),
byteData.pack(this.audioFormat, uInt16),
byteData.pack(this.numChannels, uInt16),
byteData.pack(this.sampleRate, uInt32),
byteData.pack(this.byteRate, uInt32),
byteData.pack(this.blockAlign, uInt16),
byteData.pack(this.bitsPerSample, uInt16),
this.getCbSizeBytes_(),
this.getValidBitsPerSampleBytes_(),
this.getFactBytes_(),
byteData.packSequence(this.dataChunkId, char),
byteData.pack(this.dataChunkSize, uInt32),
this.samplesToBytes_(options),
this.getCueBytes(options)
this.getCueBytes_()
);

@@ -385,2 +328,2 @@ }

module.exports.WaveFileReaderWriter = WaveFileReaderWriter;
module.exports = WaveFileReaderWriter;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc