Comparing version 9.1.1 to 10.0.0
@@ -0,0 +0,0 @@ #!/usr/bin/env node |
# CHANGELOG | ||
## version 10.0.0 - 2020-01-07 | ||
Better handling of cue points and regions. | ||
### API Changes: | ||
- *listCuePoints()* now returns a list of objects with more information about each cue point: | ||
```javascript | ||
[ | ||
{ | ||
position: 500, // the position in milliseconds | ||
label: 'cue marker 1', | ||
end: 1500, // the end position in milliseconds | ||
dwName: 1, | ||
dwPosition: 0, | ||
fccChunk: 'data', | ||
dwChunkStart: 0, | ||
dwBlockStart: 0, | ||
dwSampleOffset: 22050, // the position as a sample offset | ||
dwSampleLength: 3646827, // the region length as a sample count | ||
dwPurposeID: 544106354, | ||
dwCountry: 0, | ||
dwLanguage: 0, | ||
dwDialect: 0, | ||
dwCodePage: 0, | ||
}, | ||
//... | ||
]; | ||
``` | ||
- *setCuePoint()* param is now a object with the cue point data: | ||
```javascript | ||
// to create a cue point the position in milliseconds | ||
// is the only required attribute | ||
wav.setCuePoint({position: 1500}); | ||
// to create a cue point with a label | ||
wav.setCuePoint({position: 1500, label: 'some label'}); | ||
// to create a cue region with a label: | ||
wav.setCuePoint({position: 1500, end: 2500, label: 'some label'}); | ||
``` | ||
Objects that define regions can also define the following optional properties: | ||
- dwPurposeID | ||
- dwCountry | ||
- dwLanguage | ||
- dwDialect | ||
- dwCodePage | ||
### New Features: | ||
- setCuePoint() now can create both cue points and regions. | ||
### Fixes: | ||
- Fix setCuePoint() bug that caused some labels to display the wrong text | ||
## version 9.1.1 - 2020-01-04 | ||
@@ -4,0 +57,0 @@ - Smaller dist file |
try{if(!Uint8Array.prototype.slice)Object.defineProperty(Uint8Array.prototype,"slice",{value:function(begin,end){return new Uint8Array(Array.prototype.slice.call(this,begin,end))}})}catch(err){}var fa="function"==typeof Object.create?Object.create:function(r){function m(){}m.prototype=r;return new m},D; | ||
if("function"==typeof Object.setPrototypeOf)D=Object.setPrototypeOf;else{var L;a:{var ha={ra:!0},O={};try{O.__proto__=ha;L=O.ra;break a}catch(r){}L=!1}D=L?function(r,m){r.__proto__=m;if(r.__proto__!==m)throw new TypeError(r+" is not extensible");return r}:null}var P=D; | ||
if("function"==typeof Object.setPrototypeOf)D=Object.setPrototypeOf;else{var L;a:{var ha={sa:!0},O={};try{O.__proto__=ha;L=O.sa;break a}catch(r){}L=!1}D=L?function(r,m){r.__proto__=m;if(r.__proto__!==m)throw new TypeError(r+" is not extensible");return r}:null}var P=D; | ||
function Q(r,m){r.prototype=fa(m.prototype);r.prototype.constructor=r;if(P)P(r,m);else for(var n in m)if("prototype"!=n)if(Object.defineProperties){var k=Object.getOwnPropertyDescriptor(m,n);k&&Object.defineProperty(r,n,k)}else r[n]=m[n]}var ia="function"==typeof Object.defineProperties?Object.defineProperty:function(r,m,n){r!=Array.prototype&&r!=Object.prototype&&(r[m]=n.value)},ja="undefined"!=typeof window&&window===this?this:"undefined"!=typeof global&&null!=global?global:this; | ||
@@ -29,48 +29,50 @@ function R(r,m){if(m){for(var n=ja,k=r.split("."),t=0;t<k.length-1;t++){var q=k[t];q in n||(n[q]={});n=n[q]}k=k[k.length-1];t=n[k];q=m(t);q!=t&&null!=q&&ia(n,k,{configurable:!0,writable:!0,value:q})}}R("Object.is",function(r){return r?r:function(m,n){return m===n?0!==m||1/m===1/n:m!==m&&n!==n}}); | ||
a,b,void 0===c?0:c)};J.prototype.D=function(a,b){var c=z.prototype.c.call(this,a,void 0===b?0:b);c=this.i(c);this.a(c);return c};J.prototype.i=function(a){a>this.max&&(a-=2*this.max+2);return a};F.prototype.D=function(a,b){return this.a.D(a,void 0===b?0:b)};F.prototype.w=function(a,b,c){return this.a.w(a,b,void 0===c?0:c)};F.prototype.c=function(a,b,c){if(b){if(!a||16!==a&&32!==a&&64!==a)throw Error("Unsupported type: float, bits: "+a);return this.b(a)}if(!a||1>a||53<a)throw Error("Unsupported type: int, bits: "+ | ||
a);return c?new J(a):new z(a)};F.prototype.b=function(a){return 16===a?new G(5,11):32===a?new G(8,23):new G(11,52)};y.prototype.ga=function(a){this.c=0;this.container=this.o(a,4);if(-1===this.U.indexOf(this.container))throw Error("Not a supported format.");this.a.m="RIFX"===this.container;this.chunkSize=this.b(a);this.format=this.o(a,4);this.T={chunkId:this.container,chunkSize:this.chunkSize,format:this.format,subChunks:this.P(a)}};y.prototype.l=function(a,b){b=void 0===b?!1:b;for(var c=this.T.subChunks, | ||
d=[],e=0;e<c.length;e++)if(c[e].chunkId==a)if(b)d.push(c[e]);else return c[e];return"LIST"==a?d.length?d:null:null};y.prototype.o=function(a,b){var c=I(a,this.c,this.c+b);this.c+=b;return c};y.prototype.b=function(a){a=N(a,this.a,this.c);this.c+=4;return a};y.prototype.P=function(a){for(var b=[],c=this.c;c<=a.length-8;)b.push(this.Ea(a,c)),c+=8+b[b.length-1].chunkSize,c=c%2?c+1:c;return b};y.prototype.Ea=function(a,b){var c={chunkId:this.oa(a,b),chunkSize:this.pa(a,b)};"LIST"==c.chunkId?(c.format= | ||
I(a,b+8,b+12),this.c+=4,c.subChunks=this.P(a)):(this.c=b+8+(c.chunkSize%2?c.chunkSize+1:c.chunkSize),c.chunkData={start:b+8,end:this.c});return c};y.prototype.oa=function(a,b){this.c+=4;return I(a,b,b+4)};y.prototype.pa=function(a,b){this.c+=4;return N(a,this.a,b+4)};Q(u,y);u.prototype.fromBuffer=function(a,b){b=void 0===b?!0:b;this.O();this.ga(a);this.g.m=this.a.m;if("WAVE"!=this.format)throw Error('Could not find the "WAVE" format identifier');this.La(a);this.Na(a);this.Ma(a);this.Ia(a);this.da(a); | ||
this.Ja(a);this.ba(a);this.Ka(a,b);this.Pa(a);this.Qa(a);this.ca(a)};u.prototype.O=function(){var a=new u;Object.assign(this.fmt,a.fmt);Object.assign(this.fact,a.fact);Object.assign(this.cue,a.cue);Object.assign(this.smpl,a.smpl);Object.assign(this.bext,a.bext);Object.assign(this.iXML,a.iXML);Object.assign(this.ds64,a.ds64);Object.assign(this.data,a.data);this.LIST=[];Object.assign(this.junk,a.junk);Object.assign(this._PMX,a._PMX)};u.prototype.Na=function(a){var b=this.l("fmt ");if(b)this.c=b.chunkData.start, | ||
this.fmt.chunkId=b.chunkId,this.fmt.chunkSize=b.chunkSize,this.fmt.audioFormat=this.i(a),this.fmt.numChannels=this.i(a),this.fmt.sampleRate=this.b(a),this.fmt.byteRate=this.b(a),this.fmt.blockAlign=this.i(a),this.fmt.bitsPerSample=this.i(a),this.Oa(a);else throw Error('Could not find the "fmt " chunk');};u.prototype.Oa=function(a){16<this.fmt.chunkSize&&(this.fmt.cbSize=this.i(a),18<this.fmt.chunkSize&&(this.fmt.validBitsPerSample=this.i(a),20<this.fmt.chunkSize&&(this.fmt.dwChannelMask=this.b(a), | ||
this.fmt.subformat=[this.b(a),this.b(a),this.b(a),this.b(a)])))};u.prototype.Ma=function(a){var b=this.l("fact");b&&(this.c=b.chunkData.start,this.fact.chunkId=b.chunkId,this.fact.chunkSize=b.chunkSize,this.fact.dwSampleLength=this.b(a))};u.prototype.Ja=function(a){var b=this.l("cue ");if(b)for(this.c=b.chunkData.start,this.cue.chunkId=b.chunkId,this.cue.chunkSize=b.chunkSize,this.cue.dwCuePoints=this.b(a),b=0;b<this.cue.dwCuePoints;b++)this.cue.points.push({dwName:this.b(a),dwPosition:this.b(a), | ||
a);return c?new J(a):new z(a)};F.prototype.b=function(a){return 16===a?new G(5,11):32===a?new G(8,23):new G(11,52)};y.prototype.ha=function(a){this.c=0;this.container=this.o(a,4);if(-1===this.U.indexOf(this.container))throw Error("Not a supported format.");this.a.m="RIFX"===this.container;this.chunkSize=this.b(a);this.format=this.o(a,4);this.T={chunkId:this.container,chunkSize:this.chunkSize,format:this.format,subChunks:this.P(a)}};y.prototype.l=function(a,b){b=void 0===b?!1:b;for(var c=this.T.subChunks, | ||
d=[],e=0;e<c.length;e++)if(c[e].chunkId==a)if(b)d.push(c[e]);else return c[e];return"LIST"==a?d.length?d:null:null};y.prototype.o=function(a,b){var c=I(a,this.c,this.c+b);this.c+=b;return c};y.prototype.b=function(a){a=N(a,this.a,this.c);this.c+=4;return a};y.prototype.P=function(a){for(var b=[],c=this.c;c<=a.length-8;)b.push(this.Fa(a,c)),c+=8+b[b.length-1].chunkSize,c=c%2?c+1:c;return b};y.prototype.Fa=function(a,b){var c={chunkId:this.pa(a,b),chunkSize:this.qa(a,b)};"LIST"==c.chunkId?(c.format= | ||
I(a,b+8,b+12),this.c+=4,c.subChunks=this.P(a)):(this.c=b+8+(c.chunkSize%2?c.chunkSize+1:c.chunkSize),c.chunkData={start:b+8,end:this.c});return c};y.prototype.pa=function(a,b){this.c+=4;return I(a,b,b+4)};y.prototype.qa=function(a,b){this.c+=4;return N(a,this.a,b+4)};Q(u,y);u.prototype.fromBuffer=function(a,b){b=void 0===b?!0:b;this.O();this.ha(a);this.g.m=this.a.m;if("WAVE"!=this.format)throw Error('Could not find the "WAVE" format identifier');this.Ma(a);this.Oa(a);this.Na(a);this.Ja(a);this.da(a); | ||
this.Ka(a);this.ba(a);this.La(a,b);this.Qa(a);this.Ra(a);this.ca(a)};u.prototype.O=function(){var a=new u;Object.assign(this.fmt,a.fmt);Object.assign(this.fact,a.fact);Object.assign(this.cue,a.cue);Object.assign(this.smpl,a.smpl);Object.assign(this.bext,a.bext);Object.assign(this.iXML,a.iXML);Object.assign(this.ds64,a.ds64);Object.assign(this.data,a.data);this.LIST=[];Object.assign(this.junk,a.junk);Object.assign(this._PMX,a._PMX)};u.prototype.Oa=function(a){var b=this.l("fmt ");if(b)this.c=b.chunkData.start, | ||
this.fmt.chunkId=b.chunkId,this.fmt.chunkSize=b.chunkSize,this.fmt.audioFormat=this.i(a),this.fmt.numChannels=this.i(a),this.fmt.sampleRate=this.b(a),this.fmt.byteRate=this.b(a),this.fmt.blockAlign=this.i(a),this.fmt.bitsPerSample=this.i(a),this.Pa(a);else throw Error('Could not find the "fmt " chunk');};u.prototype.Pa=function(a){16<this.fmt.chunkSize&&(this.fmt.cbSize=this.i(a),18<this.fmt.chunkSize&&(this.fmt.validBitsPerSample=this.i(a),20<this.fmt.chunkSize&&(this.fmt.dwChannelMask=this.b(a), | ||
this.fmt.subformat=[this.b(a),this.b(a),this.b(a),this.b(a)])))};u.prototype.Na=function(a){var b=this.l("fact");b&&(this.c=b.chunkData.start,this.fact.chunkId=b.chunkId,this.fact.chunkSize=b.chunkSize,this.fact.dwSampleLength=this.b(a))};u.prototype.Ka=function(a){var b=this.l("cue ");if(b)for(this.c=b.chunkData.start,this.cue.chunkId=b.chunkId,this.cue.chunkSize=b.chunkSize,this.cue.dwCuePoints=this.b(a),b=0;b<this.cue.dwCuePoints;b++)this.cue.points.push({dwName:this.b(a),dwPosition:this.b(a), | ||
fccChunk:this.o(a,4),dwChunkStart:this.b(a),dwBlockStart:this.b(a),dwSampleOffset:this.b(a)})};u.prototype.ba=function(a){var b=this.l("smpl");if(b)for(this.c=b.chunkData.start,this.smpl.chunkId=b.chunkId,this.smpl.chunkSize=b.chunkSize,this.smpl.dwManufacturer=this.b(a),this.smpl.dwProduct=this.b(a),this.smpl.dwSamplePeriod=this.b(a),this.smpl.dwMIDIUnityNote=this.b(a),this.smpl.dwMIDIPitchFraction=this.b(a),this.smpl.dwSMPTEFormat=this.b(a),this.smpl.dwSMPTEOffset=this.b(a),this.smpl.dwNumSampleLoops= | ||
this.b(a),this.smpl.dwSamplerData=this.b(a),b=0;b<this.smpl.dwNumSampleLoops;b++)this.smpl.loops.push({dwName:this.b(a),dwType:this.b(a),dwStart:this.b(a),dwEnd:this.b(a),dwFraction:this.b(a),dwPlayCount:this.b(a)})};u.prototype.Ka=function(a,b){var c=this.l("data");if(c)this.data.chunkId="data",this.data.chunkSize=c.chunkSize,b&&(this.data.samples=a.slice(c.chunkData.start,c.chunkData.end));else throw Error('Could not find the "data" chunk');};u.prototype.Ia=function(a){var b=this.l("bext");b&&(this.c= | ||
this.b(a),this.smpl.dwSamplerData=this.b(a),b=0;b<this.smpl.dwNumSampleLoops;b++)this.smpl.loops.push({dwName:this.b(a),dwType:this.b(a),dwStart:this.b(a),dwEnd:this.b(a),dwFraction:this.b(a),dwPlayCount:this.b(a)})};u.prototype.La=function(a,b){var c=this.l("data");if(c)this.data.chunkId="data",this.data.chunkSize=c.chunkSize,b&&(this.data.samples=a.slice(c.chunkData.start,c.chunkData.end));else throw Error('Could not find the "data" chunk');};u.prototype.Ja=function(a){var b=this.l("bext");b&&(this.c= | ||
b.chunkData.start,this.bext.chunkId=b.chunkId,this.bext.chunkSize=b.chunkSize,this.bext.description=this.o(a,256),this.bext.originator=this.o(a,32),this.bext.originatorReference=this.o(a,32),this.bext.originationDate=this.o(a,10),this.bext.originationTime=this.o(a,8),this.bext.timeReference=[this.b(a),this.b(a)],this.bext.version=this.i(a),this.bext.UMID=this.o(a,64),this.bext.loudnessValue=this.i(a),this.bext.loudnessRange=this.i(a),this.bext.maxTruePeakLevel=this.i(a),this.bext.maxMomentaryLoudness= | ||
this.i(a),this.bext.maxShortTermLoudness=this.i(a),this.bext.reserved=this.o(a,180),this.bext.codingHistory=this.o(a,this.bext.chunkSize-602))};u.prototype.da=function(a){var b=this.l("iXML");b&&(this.c=b.chunkData.start,this.iXML.chunkId=b.chunkId,this.iXML.chunkSize=b.chunkSize,this.iXML.value=I(a,this.c,this.c+this.iXML.chunkSize))};u.prototype.La=function(a){var b=this.l("ds64");if(b)this.c=b.chunkData.start,this.ds64.chunkId=b.chunkId,this.ds64.chunkSize=b.chunkSize,this.ds64.riffSizeHigh=this.b(a), | ||
this.ds64.riffSizeLow=this.b(a),this.ds64.dataSizeHigh=this.b(a),this.ds64.dataSizeLow=this.b(a),this.ds64.originationTime=this.b(a),this.ds64.sampleCountHigh=this.b(a),this.ds64.sampleCountLow=this.b(a);else if("RF64"==this.container)throw Error('Could not find the "ds64" chunk');};u.prototype.Qa=function(a){var b=this.l("LIST",!0);if(null!==b)for(var c=0;c<b.length;c++){var d=b[c];this.LIST.push({chunkId:d.chunkId,chunkSize:d.chunkSize,format:d.format,subChunks:[]});for(var e=0;e<d.subChunks.length;e++)this.Ra(d.subChunks[e], | ||
d.format,a)}};u.prototype.Ra=function(a,b,c){"adtl"==b?-1<["labl","note","ltxt"].indexOf(a.chunkId)&&(this.c=a.chunkData.start,b={chunkId:a.chunkId,chunkSize:a.chunkSize,dwName:this.b(c)},"ltxt"==a.chunkId?(b.dwSampleLength=this.b(c),b.dwPurposeID=this.b(c),b.dwCountry=this.i(c),b.dwLanguage=this.i(c),b.dwDialect=this.i(c),b.dwCodePage=this.i(c),b.value=""):b.value=this.S(c,this.c),this.LIST[this.LIST.length-1].subChunks.push(b)):"INFO"==b&&(this.c=a.chunkData.start,this.LIST[this.LIST.length-1].subChunks.push({chunkId:a.chunkId, | ||
chunkSize:a.chunkSize,value:this.S(c,this.c)}))};u.prototype.Pa=function(a){var b=this.l("junk");b&&(this.junk={chunkId:b.chunkId,chunkSize:b.chunkSize,chunkData:[].slice.call(a.slice(b.chunkData.start,b.chunkData.end))})};u.prototype.ca=function(a){var b=this.l("_PMX");b&&(this.c=b.chunkData.start,this._PMX.chunkId=b.chunkId,this._PMX.chunkSize=b.chunkSize,this._PMX.value=I(a,this.c,this.c+this._PMX.chunkSize))};u.prototype.S=function(a,b){for(var c=b=void 0===b?0:b;c<a.length&&(this.c++,0!==a[c]);c++); | ||
return I(a,b,this.c-1)};u.prototype.i=function(a){a=N(a,this.g,this.c);this.c+=2;return a};Q(q,u);q.prototype.toBuffer=function(){this.g.m="RIFX"===this.container;this.a.m=this.g.m;for(var a=[this.wa(),this.sa(),this.na(),this.Ga(),this.ua(),this.ta(),w(this.data.chunkId),g(this.data.samples.length,this.a),this.data.samples,this.qa(),this.Ca(),this.xa(),this.Fa()],b=0,c=0;c<a.length;c++)b+=a[c].length;c=new Uint8Array(b+12);var d=V(this.container,c,0);d=M([b+4],this.a,c,void 0===d?0:d);d=V(this.format, | ||
c,void 0===d?0:d);for(b=0;b<a.length;b++)c.set(a[b],d),d+=a[b].length;return c};q.prototype.na=function(){var a=[];this.ma();this.bext.chunkId&&(this.bext.chunkSize=602+this.bext.codingHistory.length,a=a.concat(w(this.bext.chunkId),g(602+this.bext.codingHistory.length,this.a),x(this.bext.description,256),x(this.bext.originator,32),x(this.bext.originatorReference,32),x(this.bext.originationDate,10),x(this.bext.originationTime,8),g(this.bext.timeReference[0],this.a),g(this.bext.timeReference[1],this.a), | ||
g(this.bext.version,this.g),x(this.bext.UMID,64),g(this.bext.loudnessValue,this.g),g(this.bext.loudnessRange,this.g),g(this.bext.maxTruePeakLevel,this.g),g(this.bext.maxMomentaryLoudness,this.g),g(this.bext.maxShortTermLoudness,this.g),x(this.bext.reserved,180),x(this.bext.codingHistory,this.bext.codingHistory.length)));this.j(a);return a};q.prototype.ma=function(){for(var a in this.bext)if(this.bext.hasOwnProperty(a)&&this.bext[a]&&"timeReference"!=a){this.bext.chunkId="bext";break}if(this.bext.timeReference[0]|| | ||
this.bext.timeReference[1])this.bext.chunkId="bext"};q.prototype.Ga=function(){var a=[];if(this.iXML.chunkId){var b=w(this.iXML.value);this.iXML.chunkSize=b.length;a=a.concat(w(this.iXML.chunkId),g(this.iXML.chunkSize,this.a),b)}this.j(a);return a};q.prototype.sa=function(){var a=[];this.ds64.chunkId&&(a=a.concat(w(this.ds64.chunkId),g(this.ds64.chunkSize,this.a),g(this.ds64.riffSizeHigh,this.a),g(this.ds64.riffSizeLow,this.a),g(this.ds64.dataSizeHigh,this.a),g(this.ds64.dataSizeLow,this.a),g(this.ds64.originationTime, | ||
this.a),g(this.ds64.sampleCountHigh,this.a),g(this.ds64.sampleCountLow,this.a)));this.j(a);return a};q.prototype.qa=function(){var a=[];if(this.cue.chunkId){var b=this.aa();a=a.concat(w(this.cue.chunkId),g(b.length+4,this.a),g(this.cue.dwCuePoints,this.a),b)}this.j(a);return a};q.prototype.aa=function(){for(var a=[],b=0;b<this.cue.dwCuePoints;b++)a=a.concat(g(this.cue.points[b].dwName,this.a),g(this.cue.points[b].dwPosition,this.a),w(this.cue.points[b].fccChunk),g(this.cue.points[b].dwChunkStart, | ||
this.a),g(this.cue.points[b].dwBlockStart,this.a),g(this.cue.points[b].dwSampleOffset,this.a));return a};q.prototype.Ca=function(){var a=[];if(this.smpl.chunkId){var b=this.Da();a=a.concat(w(this.smpl.chunkId),g(b.length+36,this.a),g(this.smpl.dwManufacturer,this.a),g(this.smpl.dwProduct,this.a),g(this.smpl.dwSamplePeriod,this.a),g(this.smpl.dwMIDIUnityNote,this.a),g(this.smpl.dwMIDIPitchFraction,this.a),g(this.smpl.dwSMPTEFormat,this.a),g(this.smpl.dwSMPTEOffset,this.a),g(this.smpl.dwNumSampleLoops, | ||
this.a),g(this.smpl.dwSamplerData,this.a),b)}this.j(a);return a};q.prototype.Da=function(){for(var a=[],b=0;b<this.smpl.dwNumSampleLoops;b++)a=a.concat(g(this.smpl.loops[b].dwName,this.a),g(this.smpl.loops[b].dwType,this.a),g(this.smpl.loops[b].dwStart,this.a),g(this.smpl.loops[b].dwEnd,this.a),g(this.smpl.loops[b].dwFraction,this.a),g(this.smpl.loops[b].dwPlayCount,this.a));return a};q.prototype.ta=function(){var a=[];this.fact.chunkId&&(a=a.concat(w(this.fact.chunkId),g(this.fact.chunkSize,this.a), | ||
g(this.fact.dwSampleLength,this.a)));this.j(a);return a};q.prototype.ua=function(){var a=[];if(this.fmt.chunkId)return a=a.concat(w(this.fmt.chunkId),g(this.fmt.chunkSize,this.a),g(this.fmt.audioFormat,this.g),g(this.fmt.numChannels,this.g),g(this.fmt.sampleRate,this.a),g(this.fmt.byteRate,this.a),g(this.fmt.blockAlign,this.g),g(this.fmt.bitsPerSample,this.g),this.va()),this.j(a),a;throw Error('Could not find the "fmt " chunk');};q.prototype.va=function(){var a=[];16<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.cbSize, | ||
this.g)));18<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.validBitsPerSample,this.g)));20<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.dwChannelMask,this.a)));24<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.subformat[0],this.a),g(this.fmt.subformat[1],this.a),g(this.fmt.subformat[2],this.a),g(this.fmt.subformat[3],this.a)));return a};q.prototype.xa=function(){for(var a=[],b=0;b<this.LIST.length;b++){var c=this.za(this.LIST[b].subChunks,this.LIST[b].format);a=a.concat(w(this.LIST[b].chunkId),g(c.length+ | ||
4,this.a),w(this.LIST[b].format),c)}this.j(a);return a};q.prototype.za=function(a,b){for(var c=[],d=0;d<a.length;d++){if("INFO"==b){var e=x(a[d].value,a[d].value.length);c=c.concat(w(a[d].chunkId),g(e.length+1,this.a),e);c.push(0)}else"adtl"==b&&(-1<["labl","note"].indexOf(a[d].chunkId)?(e=x(a[d].value,a[d].value.length),c=c.concat(w(a[d].chunkId),g(e.length+5,this.a),g(a[d].dwName,this.a),e),c.push(0)):"ltxt"==a[d].chunkId&&(c=c.concat(this.Ba(a[d]))));this.j(c)}return c};q.prototype.Fa=function(){var a= | ||
[];if(this._PMX.chunkId){var b=w(this._PMX.value);this._PMX.chunkSize=b.length;a=a.concat(w(this._PMX.chunkId),g(this._PMX.chunkSize,this.a),b)}this.j(a);return a};q.prototype.Ba=function(a){return w(a.chunkId).concat(g(a.value.length+20,this.a),g(a.dwName,this.a),g(a.dwSampleLength,this.a),g(a.dwPurposeID,this.a),g(a.dwCountry,this.g),g(a.dwLanguage,this.g),g(a.dwDialect,this.g),g(a.dwCodePage,this.g),x(a.value,a.value.length))};q.prototype.wa=function(){var a=[];if(this.junk.chunkId)return a.concat(w(this.junk.chunkId), | ||
this.i(a),this.bext.maxShortTermLoudness=this.i(a),this.bext.reserved=this.o(a,180),this.bext.codingHistory=this.o(a,this.bext.chunkSize-602))};u.prototype.da=function(a){var b=this.l("iXML");b&&(this.c=b.chunkData.start,this.iXML.chunkId=b.chunkId,this.iXML.chunkSize=b.chunkSize,this.iXML.value=I(a,this.c,this.c+this.iXML.chunkSize))};u.prototype.Ma=function(a){var b=this.l("ds64");if(b)this.c=b.chunkData.start,this.ds64.chunkId=b.chunkId,this.ds64.chunkSize=b.chunkSize,this.ds64.riffSizeHigh=this.b(a), | ||
this.ds64.riffSizeLow=this.b(a),this.ds64.dataSizeHigh=this.b(a),this.ds64.dataSizeLow=this.b(a),this.ds64.originationTime=this.b(a),this.ds64.sampleCountHigh=this.b(a),this.ds64.sampleCountLow=this.b(a);else if("RF64"==this.container)throw Error('Could not find the "ds64" chunk');};u.prototype.Ra=function(a){var b=this.l("LIST",!0);if(null!==b)for(var c=0;c<b.length;c++){var d=b[c];this.LIST.push({chunkId:d.chunkId,chunkSize:d.chunkSize,format:d.format,subChunks:[]});for(var e=0;e<d.subChunks.length;e++)this.Sa(d.subChunks[e], | ||
d.format,a)}};u.prototype.Sa=function(a,b,c){"adtl"==b?-1<["labl","note","ltxt"].indexOf(a.chunkId)&&(this.c=a.chunkData.start,b={chunkId:a.chunkId,chunkSize:a.chunkSize,dwName:this.b(c)},"ltxt"==a.chunkId?(b.dwSampleLength=this.b(c),b.dwPurposeID=this.b(c),b.dwCountry=this.i(c),b.dwLanguage=this.i(c),b.dwDialect=this.i(c),b.dwCodePage=this.i(c),b.value=""):b.value=this.S(c,this.c),this.LIST[this.LIST.length-1].subChunks.push(b)):"INFO"==b&&(this.c=a.chunkData.start,this.LIST[this.LIST.length-1].subChunks.push({chunkId:a.chunkId, | ||
chunkSize:a.chunkSize,value:this.S(c,this.c)}))};u.prototype.Qa=function(a){var b=this.l("junk");b&&(this.junk={chunkId:b.chunkId,chunkSize:b.chunkSize,chunkData:[].slice.call(a.slice(b.chunkData.start,b.chunkData.end))})};u.prototype.ca=function(a){var b=this.l("_PMX");b&&(this.c=b.chunkData.start,this._PMX.chunkId=b.chunkId,this._PMX.chunkSize=b.chunkSize,this._PMX.value=I(a,this.c,this.c+this._PMX.chunkSize))};u.prototype.S=function(a,b){for(var c=b=void 0===b?0:b;c<a.length&&(this.c++,0!==a[c]);c++); | ||
return I(a,b,this.c-1)};u.prototype.i=function(a){a=N(a,this.g,this.c);this.c+=2;return a};Q(q,u);q.prototype.toBuffer=function(){this.g.m="RIFX"===this.container;this.a.m=this.g.m;for(var a=[this.ya(),this.ua(),this.oa(),this.Ha(),this.wa(),this.va(),w(this.data.chunkId),g(this.data.samples.length,this.a),this.data.samples,this.ra(),this.Da(),this.za(),this.Ga()],b=0,c=0;c<a.length;c++)b+=a[c].length;c=new Uint8Array(b+12);var d=V(this.container,c,0);d=M([b+4],this.a,c,void 0===d?0:d);d=V(this.format, | ||
c,void 0===d?0:d);for(b=0;b<a.length;b++)c.set(a[b],d),d+=a[b].length;return c};q.prototype.oa=function(){var a=[];this.na();this.bext.chunkId&&(this.bext.chunkSize=602+this.bext.codingHistory.length,a=a.concat(w(this.bext.chunkId),g(602+this.bext.codingHistory.length,this.a),x(this.bext.description,256),x(this.bext.originator,32),x(this.bext.originatorReference,32),x(this.bext.originationDate,10),x(this.bext.originationTime,8),g(this.bext.timeReference[0],this.a),g(this.bext.timeReference[1],this.a), | ||
g(this.bext.version,this.g),x(this.bext.UMID,64),g(this.bext.loudnessValue,this.g),g(this.bext.loudnessRange,this.g),g(this.bext.maxTruePeakLevel,this.g),g(this.bext.maxMomentaryLoudness,this.g),g(this.bext.maxShortTermLoudness,this.g),x(this.bext.reserved,180),x(this.bext.codingHistory,this.bext.codingHistory.length)));this.j(a);return a};q.prototype.na=function(){for(var a in this.bext)if(this.bext.hasOwnProperty(a)&&this.bext[a]&&"timeReference"!=a){this.bext.chunkId="bext";break}if(this.bext.timeReference[0]|| | ||
this.bext.timeReference[1])this.bext.chunkId="bext"};q.prototype.Ha=function(){var a=[];if(this.iXML.chunkId){var b=w(this.iXML.value);this.iXML.chunkSize=b.length;a=a.concat(w(this.iXML.chunkId),g(this.iXML.chunkSize,this.a),b)}this.j(a);return a};q.prototype.ua=function(){var a=[];this.ds64.chunkId&&(a=a.concat(w(this.ds64.chunkId),g(this.ds64.chunkSize,this.a),g(this.ds64.riffSizeHigh,this.a),g(this.ds64.riffSizeLow,this.a),g(this.ds64.dataSizeHigh,this.a),g(this.ds64.dataSizeLow,this.a),g(this.ds64.originationTime, | ||
this.a),g(this.ds64.sampleCountHigh,this.a),g(this.ds64.sampleCountLow,this.a)));this.j(a);return a};q.prototype.ra=function(){var a=[];if(this.cue.chunkId){var b=this.aa();a=a.concat(w(this.cue.chunkId),g(b.length+4,this.a),g(this.cue.dwCuePoints,this.a),b)}this.j(a);return a};q.prototype.aa=function(){for(var a=[],b=0;b<this.cue.dwCuePoints;b++)a=a.concat(g(this.cue.points[b].dwName,this.a),g(this.cue.points[b].dwPosition,this.a),w(this.cue.points[b].fccChunk),g(this.cue.points[b].dwChunkStart, | ||
this.a),g(this.cue.points[b].dwBlockStart,this.a),g(this.cue.points[b].dwSampleOffset,this.a));return a};q.prototype.Da=function(){var a=[];if(this.smpl.chunkId){var b=this.Ea();a=a.concat(w(this.smpl.chunkId),g(b.length+36,this.a),g(this.smpl.dwManufacturer,this.a),g(this.smpl.dwProduct,this.a),g(this.smpl.dwSamplePeriod,this.a),g(this.smpl.dwMIDIUnityNote,this.a),g(this.smpl.dwMIDIPitchFraction,this.a),g(this.smpl.dwSMPTEFormat,this.a),g(this.smpl.dwSMPTEOffset,this.a),g(this.smpl.dwNumSampleLoops, | ||
this.a),g(this.smpl.dwSamplerData,this.a),b)}this.j(a);return a};q.prototype.Ea=function(){for(var a=[],b=0;b<this.smpl.dwNumSampleLoops;b++)a=a.concat(g(this.smpl.loops[b].dwName,this.a),g(this.smpl.loops[b].dwType,this.a),g(this.smpl.loops[b].dwStart,this.a),g(this.smpl.loops[b].dwEnd,this.a),g(this.smpl.loops[b].dwFraction,this.a),g(this.smpl.loops[b].dwPlayCount,this.a));return a};q.prototype.va=function(){var a=[];this.fact.chunkId&&(a=a.concat(w(this.fact.chunkId),g(this.fact.chunkSize,this.a), | ||
g(this.fact.dwSampleLength,this.a)));this.j(a);return a};q.prototype.wa=function(){var a=[];if(this.fmt.chunkId)return a=a.concat(w(this.fmt.chunkId),g(this.fmt.chunkSize,this.a),g(this.fmt.audioFormat,this.g),g(this.fmt.numChannels,this.g),g(this.fmt.sampleRate,this.a),g(this.fmt.byteRate,this.a),g(this.fmt.blockAlign,this.g),g(this.fmt.bitsPerSample,this.g),this.xa()),this.j(a),a;throw Error('Could not find the "fmt " chunk');};q.prototype.xa=function(){var a=[];16<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.cbSize, | ||
this.g)));18<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.validBitsPerSample,this.g)));20<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.dwChannelMask,this.a)));24<this.fmt.chunkSize&&(a=a.concat(g(this.fmt.subformat[0],this.a),g(this.fmt.subformat[1],this.a),g(this.fmt.subformat[2],this.a),g(this.fmt.subformat[3],this.a)));return a};q.prototype.za=function(){for(var a=[],b=0;b<this.LIST.length;b++){var c=this.Ba(this.LIST[b].subChunks,this.LIST[b].format);a=a.concat(w(this.LIST[b].chunkId),g(c.length+ | ||
4,this.a),w(this.LIST[b].format),c)}this.j(a);return a};q.prototype.Ba=function(a,b){for(var c=[],d=0;d<a.length;d++){if("INFO"==b){var e=x(a[d].value,a[d].value.length);c=c.concat(w(a[d].chunkId),g(e.length+1,this.a),e);c.push(0)}else"adtl"==b&&(-1<["labl","note"].indexOf(a[d].chunkId)?(e=x(a[d].value,a[d].value.length),c=c.concat(w(a[d].chunkId),g(e.length+5,this.a),g(a[d].dwName,this.a),e),c.push(0)):"ltxt"==a[d].chunkId&&(c=c.concat(this.Ca(a[d]))));this.j(c)}return c};q.prototype.Ga=function(){var a= | ||
[];if(this._PMX.chunkId){var b=w(this._PMX.value);this._PMX.chunkSize=b.length;a=a.concat(w(this._PMX.chunkId),g(this._PMX.chunkSize,this.a),b)}this.j(a);return a};q.prototype.Ca=function(a){return w(a.chunkId).concat(g(a.value.length+20,this.a),g(a.dwName,this.a),g(a.dwSampleLength,this.a),g(a.dwPurposeID,this.a),g(a.dwCountry,this.g),g(a.dwLanguage,this.g),g(a.dwDialect,this.g),g(a.dwCodePage,this.g),x(a.value,a.value.length))};q.prototype.ya=function(){var a=[];if(this.junk.chunkId)return a.concat(w(this.junk.chunkId), | ||
g(this.junk.chunkData.length,this.a),this.junk.chunkData);this.j(a);return a};q.prototype.j=function(a){a.length%2&&a.push(0)};Q(t,q);t.prototype.fromScratch=function(a,b,c,d,e){e=void 0===e?{}:e;this.O();this.R(a,b,c,d,e)};t.prototype.R=function(a,b,c,d,e){e=void 0===e?{}:e;e.container||(e.container="RIFF");this.container=e.container;this.bitDepth=c;if(0<d.length&&d[0].constructor===Array){for(var f=[],h=0,l=d[0].length;h<l;h++)for(var p=0,v=d.length;p<v;p++)f.push(d[p][h]);d=f}this.V();f=this.f.h/ | ||
8;this.data.samples=new Uint8Array(d.length*f);M(d,this.f,this.data.samples);this.Ha(c,a,b,f,this.data.samples.length,e);this.data.chunkId="data";this.data.chunkSize=this.data.samples.length;this.W()};t.prototype.fromBuffer=function(a,b){q.prototype.fromBuffer.call(this,a,void 0===b?!0:b);this.ia();this.V()};t.prototype.toBuffer=function(){this.W();return q.prototype.toBuffer.call(this)};t.prototype.getSample=function(a){a*=this.f.h/8;if(a+this.f.h/8>this.data.samples.length)throw Error("Range error"); | ||
8;this.data.samples=new Uint8Array(d.length*f);M(d,this.f,this.data.samples);this.Ia(c,a,b,f,this.data.samples.length,e);this.data.chunkId="data";this.data.chunkSize=this.data.samples.length;this.W()};t.prototype.fromBuffer=function(a,b){q.prototype.fromBuffer.call(this,a,void 0===b?!0:b);this.ja();this.V()};t.prototype.toBuffer=function(){this.W();return q.prototype.toBuffer.call(this)};t.prototype.getSample=function(a){a*=this.f.h/8;if(a+this.f.h/8>this.data.samples.length)throw Error("Range error"); | ||
return N(this.data.samples.slice(a,a+this.f.h/8),this.f)};t.prototype.setSample=function(a,b){a*=this.f.h/8;if(a+this.f.h/8>this.data.samples.length)throw Error("Range error");M([b],this.f,this.data.samples,void 0===a?0:a)};t.prototype.getiXML=function(){return this.iXML.value};t.prototype.setiXML=function(a){if("string"!==typeof a)throw new TypeError("iXML value must be a string.");this.iXML.value=a;this.iXML.chunkId="iXML"};t.prototype.get_PMX=function(){return this._PMX.value};t.prototype.set_PMX= | ||
function(a){if("string"!==typeof a)throw new TypeError("_PMX value must be a string.");this._PMX.value=a;this._PMX.chunkId="_PMX"};t.prototype.Ha=function(a,b,c,d,e,f){"4"==a?this.ja(a,b,c,d,e,f):"8a"==a||"8m"==a?this.ka(a,b,c,d,e,f):-1==Object.keys(this.M).indexOf(a)||2<b?this.la(a,b,c,d,e,f):this.F(a,b,c,d,e,f)};t.prototype.F=function(a,b,c,d,e,f){this.container=f.container;this.chunkSize=36+e;this.format="WAVE";this.bitDepth=a;this.fmt={chunkId:"fmt ",chunkSize:16,audioFormat:this.M[a]||65534, | ||
numChannels:b,sampleRate:c,byteRate:b*d*c,blockAlign:b*d,bitsPerSample:parseInt(a,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}};t.prototype.ja=function(a,b,c,d,e,f){this.F(a,b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.byteRate=4055;this.fmt.blockAlign=256;this.fmt.bitsPerSample=4;this.fmt.cbSize=2;this.fmt.validBitsPerSample=505;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*e}};t.prototype.la=function(a,b,c,d,e,f){this.F(a,b,c,d,e,f);this.chunkSize=60+ | ||
e;this.fmt.chunkSize=40;this.fmt.bitsPerSample=(parseInt(a,10)-1|7)+1;this.fmt.cbSize=22;this.fmt.validBitsPerSample=parseInt(a,10);a=this.fmt;c=0;1===b?c=4:2===b?c=3:4===b?c=51:6===b?c=63:8===b&&(c=1599);a.dwChannelMask=c;this.fmt.subformat=[1,1048576,2852126848,1905997824]};t.prototype.ka=function(a,b,c,d,e,f){this.F(a,b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.cbSize=2;this.fmt.validBitsPerSample=8;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:e}};t.prototype.ia=function(){3=== | ||
this.fmt.audioFormat&&32===this.fmt.bitsPerSample?this.bitDepth="32f":6===this.fmt.audioFormat?this.bitDepth="8a":7===this.fmt.audioFormat?this.bitDepth="8m":this.bitDepth=this.fmt.bitsPerSample.toString()};t.prototype.ha=function(){if(!(this.M[this.bitDepth]||8<parseInt(this.bitDepth,10)&&54>parseInt(this.bitDepth,10)))throw Error("Invalid bit depth.");};t.prototype.V=function(){this.f={h:(parseInt(this.bitDepth,10)-1|7)+1,C:"32f"==this.bitDepth||"64"==this.bitDepth,A:"8"!=this.bitDepth,m:"RIFX"== | ||
this.container};-1<["4","8a","8m"].indexOf(this.bitDepth)&&(this.f.h=8,this.f.A=!1)};t.prototype.W=function(){this.ha();var a=this.fmt.numChannels;if(1>a||65535<a*this.fmt.bitsPerSample/8)throw Error("Invalid number of channels.");a=this.fmt.sampleRate;if(1>a||4294967295<this.fmt.bitsPerSample/8*this.fmt.numChannels*a)throw Error("Invalid sample rate.");};Q(k,t);k.prototype.getTag=function(a){a=this.K(a);return null!==a.u?this.LIST[a.LIST].subChunks[a.u].value:null};k.prototype.setTag=function(a, | ||
function(a){if("string"!==typeof a)throw new TypeError("_PMX value must be a string.");this._PMX.value=a;this._PMX.chunkId="_PMX"};t.prototype.Ia=function(a,b,c,d,e,f){"4"==a?this.ka(a,b,c,d,e,f):"8a"==a||"8m"==a?this.la(a,b,c,d,e,f):-1==Object.keys(this.M).indexOf(a)||2<b?this.ma(a,b,c,d,e,f):this.F(a,b,c,d,e,f)};t.prototype.F=function(a,b,c,d,e,f){this.container=f.container;this.chunkSize=36+e;this.format="WAVE";this.bitDepth=a;this.fmt={chunkId:"fmt ",chunkSize:16,audioFormat:this.M[a]||65534, | ||
numChannels:b,sampleRate:c,byteRate:b*d*c,blockAlign:b*d,bitsPerSample:parseInt(a,10),cbSize:0,validBitsPerSample:0,dwChannelMask:0,subformat:[]}};t.prototype.ka=function(a,b,c,d,e,f){this.F(a,b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.byteRate=4055;this.fmt.blockAlign=256;this.fmt.bitsPerSample=4;this.fmt.cbSize=2;this.fmt.validBitsPerSample=505;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:2*e}};t.prototype.ma=function(a,b,c,d,e,f){this.F(a,b,c,d,e,f);this.chunkSize=60+ | ||
e;this.fmt.chunkSize=40;this.fmt.bitsPerSample=(parseInt(a,10)-1|7)+1;this.fmt.cbSize=22;this.fmt.validBitsPerSample=parseInt(a,10);a=this.fmt;c=0;1===b?c=4:2===b?c=3:4===b?c=51:6===b?c=63:8===b&&(c=1599);a.dwChannelMask=c;this.fmt.subformat=[1,1048576,2852126848,1905997824]};t.prototype.la=function(a,b,c,d,e,f){this.F(a,b,c,d,e,f);this.chunkSize=40+e;this.fmt.chunkSize=20;this.fmt.cbSize=2;this.fmt.validBitsPerSample=8;this.fact={chunkId:"fact",chunkSize:4,dwSampleLength:e}};t.prototype.ja=function(){3=== | ||
this.fmt.audioFormat&&32===this.fmt.bitsPerSample?this.bitDepth="32f":6===this.fmt.audioFormat?this.bitDepth="8a":7===this.fmt.audioFormat?this.bitDepth="8m":this.bitDepth=this.fmt.bitsPerSample.toString()};t.prototype.ia=function(){if(!(this.M[this.bitDepth]||8<parseInt(this.bitDepth,10)&&54>parseInt(this.bitDepth,10)))throw Error("Invalid bit depth.");};t.prototype.V=function(){this.f={h:(parseInt(this.bitDepth,10)-1|7)+1,C:"32f"==this.bitDepth||"64"==this.bitDepth,A:"8"!=this.bitDepth,m:"RIFX"== | ||
this.container};-1<["4","8a","8m"].indexOf(this.bitDepth)&&(this.f.h=8,this.f.A=!1)};t.prototype.W=function(){this.ia();var a=this.fmt.numChannels;if(1>a||65535<a*this.fmt.bitsPerSample/8)throw Error("Invalid number of channels.");a=this.fmt.sampleRate;if(1>a||4294967295<this.fmt.bitsPerSample/8*this.fmt.numChannels*a)throw Error("Invalid sample rate.");};Q(k,t);k.prototype.getTag=function(a){a=this.K(a);return null!==a.u?this.LIST[a.LIST].subChunks[a.u].value:null};k.prototype.setTag=function(a, | ||
b){var c=a;if(c.constructor!==String)throw Error("Invalid tag name.");if(4>c.length)for(var d=0,e=4-c.length;d<e;d++)c+=" ";a=c;c=this.K(a);null!==c.u?(this.LIST[c.LIST].subChunks[c.u].chunkSize=b.length+1,this.LIST[c.LIST].subChunks[c.u].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}))}; | ||
k.prototype.deleteTag=function(a){a=this.K(a);return null!==a.u?(this.LIST[a.LIST].subChunks.splice(a.u,1),!0):!1};k.prototype.listTags=function(){var a=this.ya(),b={};if(null!==a)for(var c=0,d=this.LIST[a].subChunks.length;c<d;c++)b[this.LIST[a].subChunks[c].chunkId]=this.LIST[a].subChunks[c].value;return b};k.prototype.listCuePoints=function(){for(var a=this.J(),b=0,c=a.length;b<c;b++)a[b].milliseconds=a[b].dwPosition/this.fmt.sampleRate*1E3;return a};k.prototype.setCuePoint=function(a,b){b=void 0=== | ||
b?"":b;this.cue.chunkId="cue ";a=a*this.fmt.sampleRate/1E3;var c=this.J();this.H();var d=this.cue.points.length;this.cue.points=[];var e=!1;if(0===d)this.B(a,1,b);else{for(var f=0;f<d;f++)c[f].dwPosition>a&&!e?(this.B(a,f+1,b),this.B(c[f].dwPosition,f+2,c[f].label),e=!0):this.B(c[f].dwPosition,f+1,c[f].label);e||this.B(a,this.cue.points.length+1,b)}this.cue.dwCuePoints=this.cue.points.length};k.prototype.deleteCuePoint=function(a){this.cue.chunkId="cue ";var b=this.J();this.H();var c=this.cue.points.length; | ||
this.cue.points=[];for(var d=0;d<c;d++)d+1!==a&&this.B(b[d].dwPosition,d+1,b[d].label);this.cue.dwCuePoints=this.cue.points.length;this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.H())};k.prototype.updateLabel=function(a,b){var c=this.I();if(null!==c)for(var d=0,e=this.LIST[c].subChunks.length;d<e;d++)this.LIST[c].subChunks[d].dwName==a&&(this.LIST[c].subChunks[d].value=b)};k.prototype.J=function(){for(var a=[],b=0,c=this.cue.points.length;b<c;b++)a.push({dwPosition:this.cue.points[b].dwPosition, | ||
label:this.Aa(this.cue.points[b].dwName)});return a};k.prototype.Aa=function(a){var b=this.I();if(null!==b)for(var c=0,d=this.LIST[b].subChunks.length;c<d;c++)if(this.LIST[b].subChunks[c].dwName==a)return this.LIST[b].subChunks[c].value;return""};k.prototype.ya=function(){for(var a=null,b=0,c=this.LIST.length;b<c;b++)if("INFO"===this.LIST[b].format){a=b;break}return a};k.prototype.I=function(){for(var a=0,b=this.LIST.length;a<b;a++)if("adtl"==this.LIST[a].format)return a;return null};k.prototype.K= | ||
function(a){for(var b={LIST:null,u:null},c=0,d=this.LIST.length;c<d;c++)if("INFO"==this.LIST[c].format){b.LIST=c;d=0;for(var e=this.LIST[c].subChunks.length;d<e;d++)if(this.LIST[c].subChunks[d].chunkId==a){b.u=d;break}break}return b};k.prototype.B=function(a,b,c){this.cue.points.push({dwName:b,dwPosition:a,fccChunk:"data",dwChunkStart:0,dwBlockStart:0,dwSampleOffset:a});this.fa(b,c)};k.prototype.H=function(){for(var a=0,b=this.LIST.length;a<b;a++)"adtl"==this.LIST[a].format&&this.LIST.splice(a)}; | ||
k.prototype.fa=function(a,b){var c=this.I();null===c&&(this.LIST.push({chunkId:"LIST",chunkSize:4,format:"adtl",subChunks:[]}),c=this.LIST.length-1);this.ea(null===c?0:c,a,b)};k.prototype.ea=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};Q(n,k);n.prototype.toRIFF=function(){this.s(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,X(this.data.samples,this.f))};n.prototype.toRIFX=function(){this.s(this.fmt.numChannels, | ||
this.fmt.sampleRate,this.bitDepth,X(this.data.samples,this.f),{container:"RIFX"})};n.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.L());K(this.data.samples,this.f,a);this.s(this.fmt.numChannels,this.fmt.sampleRate,"4",ra(a),{container:this.v()})};n.prototype.fromIMAADPCM=function(a){a=void 0=== | ||
a?"16":a;this.s(this.fmt.numChannels,this.fmt.sampleRate,"16",ta(this.data.samples,this.fmt.blockAlign),{container:this.v()});"16"!=a&&this.toBitDepth(a)};n.prototype.toALaw=function(){this.G();var a=new Int16Array(this.L());K(this.data.samples,this.f,a);this.s(this.fmt.numChannels,this.fmt.sampleRate,"8a",ua(a),{container:this.v()})};n.prototype.fromALaw=function(a){a=void 0===a?"16":a;this.s(this.fmt.numChannels,this.fmt.sampleRate,"16",wa(this.data.samples),{container:this.v()});"16"!=a&&this.toBitDepth(a)}; | ||
n.prototype.toMuLaw=function(){this.G();var a=new Int16Array(this.L());K(this.data.samples,this.f,a);this.s(this.fmt.numChannels,this.fmt.sampleRate,"8m",xa(a),{container:this.v()})};n.prototype.fromMuLaw=function(a){a=void 0===a?"16":a;this.s(this.fmt.numChannels,this.fmt.sampleRate,"16",za(this.data.samples),{container:this.v()});"16"!=a&&this.toBitDepth(a)};n.prototype.toBitDepth=function(a,b){var c=a,d=this.bitDepth;void 0===b||b||("32f"!=a&&(c=this.f.h.toString()),d=""+this.f.h);this.N();var e= | ||
this.data.samples.length/(this.f.h/8),f=new Float64Array(e);e=new Float64Array(e);K(this.data.samples,this.f,f);if("32f"==d||"64"==d)for(var h=0,l=f.length;h<l;h++)1<f[h]?f[h]=1:-1>f[h]&&(f[h]=-1);var p=d;d=c;ba(p);ba(d);h=qa(p,d);l={$:Math.pow(2,parseInt(p,10))/2,Y:Math.pow(2,parseInt(d,10))/2,Z:Math.pow(2,parseInt(p,10))/2-1,X:Math.pow(2,parseInt(d,10))/2-1};c=f.length;if("8"==p)for(var v=0;v<c;v++)e[v]=f[v]-=128;if("32f"==p||"64"==p)for(p=f.length,v=0;v<p;v++)1<f[v]?f[v]=1:-1>f[v]&&(f[v]=-1);for(p= | ||
0;p<c;p++)e[p]=h(f[p],l);if("8"==d)for(f=0;f<c;f++)e[f]=e[f]+=128;this.s(this.fmt.numChannels,this.fmt.sampleRate,a,e,{container:this.v()})};n.prototype.G=function(){this.N();"16"!=this.bitDepth&&this.toBitDepth("16")};n.prototype.N=function(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()};n.prototype.v=function(){return"RF64"==this.container?"RIFF":this.container};n.prototype.s=function(a,b,c,d,e){e=void 0===e?{}:e;var f=new k;Object.assign(this.fmt, | ||
f.fmt);Object.assign(this.fact,f.fact);Object.assign(this.ds64,f.ds64);Object.assign(this.data,f.data);this.R(a,b,c,d,e)};n.prototype.L=function(){var a=this.data.samples.length/2;a%2&&a++;return a};Q(m,n);m.prototype.fromBase64=function(a){this.fromBuffer(new Uint8Array(la(a)))};m.prototype.toBase64=function(){for(var a=this.toBuffer(),b="",c=0;c<a.length;c+=3)b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c]>>2],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c]& | ||
3)<<4|a[c+1]>>4],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c+1]&15)<<2|a[c+2]>>6],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c+2]&63];2===a.length%3?b=b.substring(0,b.length-1)+"=":1===a.length%3&&(b=b.substring(0,b.length-2)+"==");return b};m.prototype.toDataURI=function(){return"data:audio/wav;base64,"+this.toBase64()};m.prototype.fromDataURI=function(a){this.fromBase64(a.replace("data:audio/wav;base64,",""))};r.WaveFile=m;Object.defineProperty(r, | ||
"__esModule",{value:!0})}"object"===typeof exports&&"undefined"!==typeof module?Z(exports):"function"===typeof define&&define.amd?define(["exports"],Z):(Y=Y||self,Z(Y.wavefile={})); | ||
k.prototype.deleteTag=function(a){a=this.K(a);return null!==a.u?(this.LIST[a.LIST].subChunks.splice(a.u,1),!0):!1};k.prototype.listTags=function(){var a=this.Aa(),b={};if(null!==a)for(var c=0,d=this.LIST[a].subChunks.length;c<d;c++)b[this.LIST[a].subChunks[c].chunkId]=this.LIST[a].subChunks[c].value;return b};k.prototype.listCuePoints=function(){for(var a=this.J(),b=0,c=a.length;b<c;b++)a[b].position=a[b].dwSampleOffset/this.fmt.sampleRate*1E3,a[b].dwSampleLength?(a[b].end=a[b].dwSampleLength/this.fmt.sampleRate* | ||
1E3,a[b].end+=a[b].position):a[b].end=null,delete a[b].value;return a};k.prototype.setCuePoint=function(a){this.cue.chunkId="cue ";a.label||(a.label="");var b=this.J();this.H();var c=this.cue.points.length;this.cue.points=[];a.dwSampleOffset=a.position*this.fmt.sampleRate/1E3;a.dwSampleLength=0;a.end&&(a.dwSampleLength=a.end*this.fmt.sampleRate/1E3-a.dwSampleOffset);if(0===c)this.B(a,1);else{for(var d=!1,e=0;e<c;e++)b[e].dwSampleOffset>a.dwSampleOffset&&!d?(this.B(a,e+1),this.B(b[e],e+2),d=!0):this.B(b[e], | ||
d?e+2:e+1);d||this.B(a,this.cue.points.length+1)}this.cue.dwCuePoints=this.cue.points.length};k.prototype.deleteCuePoint=function(a){this.cue.chunkId="cue ";var b=this.J();this.H();var c=this.cue.points.length;this.cue.points=[];for(var d=0;d<c;d++)d+1!==a&&this.B(b[d],d+1);this.cue.dwCuePoints=this.cue.points.length;this.cue.dwCuePoints?this.cue.chunkId="cue ":(this.cue.chunkId="",this.H())};k.prototype.updateLabel=function(a,b){var c=this.I();if(null!==c)for(var d=0,e=this.LIST[c].subChunks.length;d< | ||
e;d++)this.LIST[c].subChunks[d].dwName==a&&(this.LIST[c].subChunks[d].value=b)};k.prototype.J=function(){for(var a=[],b=0;b<this.cue.points.length;b++){var c=this.cue.points[b],d=this.ta(c.dwName);d.label=d.value?d.value:"";d.dwPosition=c.dwPosition;d.fccChunk=c.fccChunk;d.dwChunkStart=c.dwChunkStart;d.dwBlockStart=c.dwBlockStart;d.dwSampleOffset=c.dwSampleOffset;a.push(d)}return a};k.prototype.ta=function(a){var b=this.I(),c={};if(null!==b)for(var d=0,e=this.LIST[b].subChunks.length;d<e;d++)if(this.LIST[b].subChunks[d].dwName== | ||
a&&this.LIST[b].subChunks[d].chunkId){var f=this.LIST[b].subChunks[d];c.value=f.value?f.value:c.value;c.dwName=f.dwName?f.dwName:0;c.dwSampleLength=f.dwSampleLength?f.dwSampleLength:0;c.dwPurposeID=f.dwPurposeID?f.dwPurposeID:0;c.dwCountry=f.dwCountry?f.dwCountry:0;c.dwLanguage=f.dwLanguage?f.dwLanguage:0;c.dwDialect=f.dwDialect?f.dwDialect:0;c.dwCodePage=f.dwCodePage?f.dwCodePage:0}return c};k.prototype.Aa=function(){for(var a=null,b=0,c=this.LIST.length;b<c;b++)if("INFO"===this.LIST[b].format){a= | ||
b;break}return a};k.prototype.I=function(){for(var a=0,b=this.LIST.length;a<b;a++)if("adtl"==this.LIST[a].format)return a;return null};k.prototype.K=function(a){for(var b={LIST:null,u:null},c=0,d=this.LIST.length;c<d;c++)if("INFO"==this.LIST[c].format){b.LIST=c;d=0;for(var e=this.LIST[c].subChunks.length;d<e;d++)if(this.LIST[c].subChunks[d].chunkId==a){b.u=d;break}break}return b};k.prototype.B=function(a,b){this.cue.points.push({dwName:b,dwPosition:a.dwPosition?a.dwPosition:0,fccChunk:a.fccChunk? | ||
a.fccChunk:"data",dwChunkStart:a.dwChunkStart?a.dwChunkStart:0,dwBlockStart:a.dwBlockStart?a.dwBlockStart:0,dwSampleOffset:a.dwSampleOffset});this.fa(a,b)};k.prototype.H=function(){for(var a=0,b=this.LIST.length;a<b;a++)"adtl"==this.LIST[a].format&&this.LIST.splice(a)};k.prototype.fa=function(a,b){var c=this.I();null===c&&(this.LIST.push({chunkId:"LIST",chunkSize:4,format:"adtl",subChunks:[]}),c=this.LIST.length-1);this.ea(c,a,b);a.dwSampleLength&&this.ga(c,a,b)};k.prototype.ea=function(a,b,c){this.LIST[a].subChunks.push({chunkId:"labl", | ||
chunkSize:4,dwName:c,value:b.label});this.LIST[a].chunkSize+=12};k.prototype.ga=function(a,b,c){this.LIST[a].subChunks.push({chunkId:"ltxt",chunkSize:20,dwName:c,dwSampleLength:b.dwSampleLength,dwPurposeID:b.dwPurposeID?b.dwPurposeID:0,dwCountry:b.dwCountry?b.dwCountry:0,dwLanguage:b.dwLanguage?b.dwLanguage:0,dwDialect:b.dwDialect?b.dwDialect:0,dwCodePage:b.dwCodePage?b.dwCodePage:0,value:b.label});this.LIST[a].chunkSize+=28};Q(n,k);n.prototype.toRIFF=function(){this.s(this.fmt.numChannels,this.fmt.sampleRate, | ||
this.bitDepth,X(this.data.samples,this.f))};n.prototype.toRIFX=function(){this.s(this.fmt.numChannels,this.fmt.sampleRate,this.bitDepth,X(this.data.samples,this.f),{container:"RIFX"})};n.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.L());K(this.data.samples,this.f,a);this.s(this.fmt.numChannels, | ||
this.fmt.sampleRate,"4",ra(a),{container:this.v()})};n.prototype.fromIMAADPCM=function(a){a=void 0===a?"16":a;this.s(this.fmt.numChannels,this.fmt.sampleRate,"16",ta(this.data.samples,this.fmt.blockAlign),{container:this.v()});"16"!=a&&this.toBitDepth(a)};n.prototype.toALaw=function(){this.G();var a=new Int16Array(this.L());K(this.data.samples,this.f,a);this.s(this.fmt.numChannels,this.fmt.sampleRate,"8a",ua(a),{container:this.v()})};n.prototype.fromALaw=function(a){a=void 0===a?"16":a;this.s(this.fmt.numChannels, | ||
this.fmt.sampleRate,"16",wa(this.data.samples),{container:this.v()});"16"!=a&&this.toBitDepth(a)};n.prototype.toMuLaw=function(){this.G();var a=new Int16Array(this.L());K(this.data.samples,this.f,a);this.s(this.fmt.numChannels,this.fmt.sampleRate,"8m",xa(a),{container:this.v()})};n.prototype.fromMuLaw=function(a){a=void 0===a?"16":a;this.s(this.fmt.numChannels,this.fmt.sampleRate,"16",za(this.data.samples),{container:this.v()});"16"!=a&&this.toBitDepth(a)};n.prototype.toBitDepth=function(a,b){var c= | ||
a,d=this.bitDepth;void 0===b||b||("32f"!=a&&(c=this.f.h.toString()),d=""+this.f.h);this.N();var e=this.data.samples.length/(this.f.h/8),f=new Float64Array(e);e=new Float64Array(e);K(this.data.samples,this.f,f);if("32f"==d||"64"==d)for(var h=0,l=f.length;h<l;h++)1<f[h]?f[h]=1:-1>f[h]&&(f[h]=-1);var p=d;d=c;ba(p);ba(d);h=qa(p,d);l={$:Math.pow(2,parseInt(p,10))/2,Y:Math.pow(2,parseInt(d,10))/2,Z:Math.pow(2,parseInt(p,10))/2-1,X:Math.pow(2,parseInt(d,10))/2-1};c=f.length;if("8"==p)for(var v=0;v<c;v++)e[v]= | ||
f[v]-=128;if("32f"==p||"64"==p)for(p=f.length,v=0;v<p;v++)1<f[v]?f[v]=1:-1>f[v]&&(f[v]=-1);for(p=0;p<c;p++)e[p]=h(f[p],l);if("8"==d)for(f=0;f<c;f++)e[f]=e[f]+=128;this.s(this.fmt.numChannels,this.fmt.sampleRate,a,e,{container:this.v()})};n.prototype.G=function(){this.N();"16"!=this.bitDepth&&this.toBitDepth("16")};n.prototype.N=function(){"8a"==this.bitDepth?this.fromALaw():"8m"==this.bitDepth?this.fromMuLaw():"4"==this.bitDepth&&this.fromIMAADPCM()};n.prototype.v=function(){return"RF64"==this.container? | ||
"RIFF":this.container};n.prototype.s=function(a,b,c,d,e){e=void 0===e?{}:e;var f=new k;Object.assign(this.fmt,f.fmt);Object.assign(this.fact,f.fact);Object.assign(this.ds64,f.ds64);Object.assign(this.data,f.data);this.R(a,b,c,d,e)};n.prototype.L=function(){var a=this.data.samples.length/2;a%2&&a++;return a};Q(m,n);m.prototype.fromBase64=function(a){this.fromBuffer(new Uint8Array(la(a)))};m.prototype.toBase64=function(){for(var a=this.toBuffer(),b="",c=0;c<a.length;c+=3)b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c]>> | ||
2],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c]&3)<<4|a[c+1]>>4],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[(a[c+1]&15)<<2|a[c+2]>>6],b+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[a[c+2]&63];2===a.length%3?b=b.substring(0,b.length-1)+"=":1===a.length%3&&(b=b.substring(0,b.length-2)+"==");return b};m.prototype.toDataURI=function(){return"data:audio/wav;base64,"+this.toBase64()};m.prototype.fromDataURI=function(a){this.fromBase64(a.replace("data:audio/wav;base64,", | ||
""))};r.WaveFile=m;Object.defineProperty(r,"__esModule",{value:!0})}"object"===typeof exports&&"undefined"!==typeof module?Z(exports):"function"===typeof define&&define.amd?define(["exports"],Z):(Y=Y||self,Z(Y.wavefile={})); |
@@ -26,3 +26,3 @@ /* | ||
/** | ||
* @fileoverview Externs for wavefile 9.0 | ||
* @fileoverview Externs for wavefile 10.0 | ||
* @see https://github.com/rochars/wavefile | ||
@@ -118,3 +118,3 @@ * @externs | ||
dwSampleOffset: 0, | ||
milliseconds: 0 | ||
position: 0 | ||
}], | ||
@@ -490,6 +490,14 @@ }; | ||
* 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. | ||
* @param {!{ | ||
* position: number, | ||
* label: ?string, | ||
* end: ?number, | ||
* dwPurposeID: ?number, | ||
* dwCountry: ?number, | ||
* dwLanguage: ?number, | ||
* dwDialect: ?number, | ||
* dwCodePage: ?number | ||
* }} pointData A object with the data of the cue point. | ||
*/ | ||
WaveFile.prototype.setCuePoint = function(position, labl='') {}; | ||
WaveFile.prototype.setCuePoint = function(pointData) {}; | ||
@@ -519,7 +527,21 @@ /** | ||
* 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 | ||
* Objects representing cue points/regions look like this: | ||
* { | ||
* position: 500, // the position in milliseconds | ||
* label: 'cue marker 1', | ||
* end: 1500, // the end position in milliseconds | ||
* dwName: 1, | ||
* dwPosition: 0, | ||
* fccChunk: 'data', | ||
* dwChunkStart: 0, | ||
* dwBlockStart: 0, | ||
* dwSampleOffset: 22050, // the position as a sample offset | ||
* dwSampleLength: 3646827, // the region length as a sample count | ||
* dwPurposeID: 544106354, | ||
* dwCountry: 0, | ||
* dwLanguage: 0, | ||
* dwDialect: 0, | ||
* dwCodePage: 0, | ||
* } | ||
* @return {!Array<Object>} | ||
*/ | ||
@@ -526,0 +548,0 @@ WaveFile.prototype.listCuePoints = function() {}; |
@@ -1,2 +0,2 @@ | ||
// Type definitions for wavefile 9.0 | ||
// Type definitions for wavefile 10.0 | ||
// Project: https://github.com/rochars/wavefile | ||
@@ -282,6 +282,5 @@ // Definitions by: Rafael da Silva Rocha <https://github.com/rochars> | ||
* 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. | ||
* @param {!Object<string, *>} pointData The data of the cue point. | ||
*/ | ||
setCuePoint(position: number, labl?: string): void; | ||
setCuePoint(pointData: object): void; | ||
@@ -298,6 +297,21 @@ /** | ||
* 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>} | ||
* Objects representing cue points/regions look like this: | ||
* { | ||
* position: 500, // the position in milliseconds | ||
* label: 'cue marker 1', | ||
* end: 1500, // the end position in milliseconds | ||
* dwName: 1, | ||
* dwPosition: 0, | ||
* fccChunk: 'data', | ||
* dwChunkStart: 0, | ||
* dwBlockStart: 0, | ||
* dwSampleOffset: 22050, // the position as a sample offset | ||
* dwSampleLength: 3646827, // the region length as a sample count | ||
* dwPurposeID: 544106354, | ||
* dwCountry: 0, | ||
* dwLanguage: 0, | ||
* dwDialect: 0, | ||
* dwCodePage: 0, | ||
* } | ||
* @return {!Array<Object>} | ||
*/ | ||
@@ -304,0 +318,0 @@ listCuePoints(): Array<object>; |
@@ -123,6 +123,21 @@ /* | ||
* 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>} | ||
* Objects representing cue points/regions look like this: | ||
* { | ||
* position: 500, // the position in milliseconds | ||
* label: 'cue marker 1', | ||
* end: 1500, // the end position in milliseconds | ||
* dwName: 1, | ||
* dwPosition: 0, | ||
* fccChunk: 'data', | ||
* dwChunkStart: 0, | ||
* dwBlockStart: 0, | ||
* dwSampleOffset: 22050, // the position as a sample offset | ||
* dwSampleLength: 3646827, // length as a sample count, 0 if not a region | ||
* dwPurposeID: 544106354, | ||
* dwCountry: 0, | ||
* dwLanguage: 0, | ||
* dwDialect: 0, | ||
* dwCodePage: 0, | ||
* } | ||
* @return {!Array<Object>} | ||
*/ | ||
@@ -133,4 +148,20 @@ listCuePoints() { | ||
for (let i = 0, len = points.length; i < len; i++) { | ||
points[i].milliseconds = | ||
(points[i].dwPosition / this.fmt.sampleRate) * 1000; | ||
// Add attrs that should exist in the object | ||
points[i].position = | ||
(points[i].dwSampleOffset / this.fmt.sampleRate) * 1000; | ||
// If it is a region, calc the end | ||
// position in milliseconds | ||
if (points[i].dwSampleLength) { | ||
points[i].end = | ||
(points[i].dwSampleLength / this.fmt.sampleRate) * 1000; | ||
points[i].end += points[i].position; | ||
// If its not a region, end should be null | ||
} else { | ||
points[i].end = null; | ||
} | ||
// Remove attrs that should not go in the results | ||
delete points[i].value; | ||
} | ||
@@ -142,36 +173,120 @@ return points; | ||
* 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. | ||
* @param {!{ | ||
* position: number, | ||
* label: ?string, | ||
* end: ?number, | ||
* dwPurposeID: ?number, | ||
* dwCountry: ?number, | ||
* dwLanguage: ?number, | ||
* dwDialect: ?number, | ||
* dwCodePage: ?number | ||
* }} pointData A object with the data of the cue point. | ||
* | ||
* # Only required attribute to create a cue point: | ||
* pointData.position: The position of the point in milliseconds | ||
* | ||
* # Optional attribute for cue points: | ||
* pointData.label: A string label for the cue point | ||
* | ||
* # Extra data used for regions | ||
* pointData.end: A number representing the end of the region, | ||
* in milliseconds, counting from the start of the file. If | ||
* no end attr is specified then no region is created. | ||
* | ||
* # You may also specify the following attrs for regions, all optional: | ||
* pointData.dwPurposeID | ||
* pointData.dwCountry | ||
* pointData.dwLanguage | ||
* pointData.dwDialect | ||
* pointData.dwCodePage | ||
*/ | ||
setCuePoint(position, labl='') { | ||
setCuePoint(pointData) { | ||
this.cue.chunkId = 'cue '; | ||
position = (position * this.fmt.sampleRate) / 1000; | ||
/** @type {!Array<!Object>} */ | ||
// label attr should always exist | ||
if (!pointData.label) { | ||
pointData.label = ''; | ||
} | ||
/** | ||
* Load the existing points before erasing | ||
* the LIST 'adtl' chunk and the cue attr | ||
* @type {!Array<!Object>} | ||
*/ | ||
let existingPoints = this.getCuePoints_(); | ||
// Clear any LIST labeled 'adtl' | ||
// The LIST chunk should be re-written | ||
// after the new cue point is created | ||
this.clearLISTadtl_(); | ||
/** @type {number} */ | ||
/** | ||
* Get the current len of the cue points | ||
* in the file before erasing the cue attr | ||
* @type {number} | ||
*/ | ||
let len = this.cue.points.length; | ||
// Erase this.cue so it can be re-written | ||
// after the point is added | ||
this.cue.points = []; | ||
/** @type {boolean} */ | ||
let hasSet = false; | ||
/** | ||
* Cue position param is informed in milliseconds, | ||
* here its value is converted to the sample offset | ||
* @type {number} | ||
*/ | ||
pointData.dwSampleOffset = | ||
(pointData.position * this.fmt.sampleRate) / 1000; | ||
/** | ||
* end param is informed in milliseconds, counting | ||
* from the start of the file. | ||
* here its value is converted to the sample length | ||
* of the region. | ||
* @type {number} | ||
*/ | ||
pointData.dwSampleLength = 0; | ||
if (pointData.end) { | ||
pointData.dwSampleLength = | ||
((pointData.end * this.fmt.sampleRate) / 1000) - | ||
pointData.dwSampleOffset; | ||
} | ||
// If there were no cue points in the file, | ||
// insert the new cue point as the first | ||
if (len === 0) { | ||
this.setCuePoint_(position, 1, labl); | ||
this.setCuePoint_(pointData, 1); | ||
// If the file already had cue points, This new one | ||
// must be added in the list according to its position. | ||
} else { | ||
/** @type {boolean} */ | ||
let hasSet = false; | ||
// Iterate over the cue points that existed | ||
// before this one was added | ||
for (let i = 0; i < len; i++) { | ||
if (existingPoints[i].dwPosition > position && !hasSet) { | ||
this.setCuePoint_(position, i + 1, labl); | ||
this.setCuePoint_( | ||
existingPoints[i].dwPosition, | ||
i + 2, | ||
existingPoints[i].label); | ||
// If the new point is located before this original point | ||
// and the new point have not been created, create the | ||
// new point and then the original point | ||
if (existingPoints[i].dwSampleOffset > | ||
pointData.dwSampleOffset && !hasSet) { | ||
// create the new point | ||
this.setCuePoint_(pointData, i + 1); | ||
// create the original point | ||
this.setCuePoint_(existingPoints[i], i + 2); | ||
hasSet = true; | ||
// Otherwise, re-create the original point | ||
} else { | ||
this.setCuePoint_( | ||
existingPoints[i].dwPosition, | ||
i + 1, | ||
existingPoints[i].label); | ||
this.setCuePoint_(existingPoints[i], hasSet ? i + 2 : i + 1); | ||
} | ||
} | ||
// If no point was created in the above loop, | ||
// create the new point as the last one | ||
if (!hasSet) { | ||
this.setCuePoint_(position, this.cue.points.length + 1, labl); | ||
this.setCuePoint_(pointData, this.cue.points.length + 1); | ||
} | ||
@@ -197,6 +312,3 @@ } | ||
if (i + 1 !== index) { | ||
this.setCuePoint_( | ||
existingPoints[i].dwPosition, | ||
i + 1, | ||
existingPoints[i].label); | ||
this.setCuePoint_(existingPoints[i], i + 1); | ||
} | ||
@@ -240,7 +352,14 @@ } | ||
let points = []; | ||
for (let i = 0, len = this.cue.points.length; i < len; i++) { | ||
points.push({ | ||
dwPosition: this.cue.points[i].dwPosition, | ||
label: this.getLabelForCuePoint_( | ||
this.cue.points[i].dwName)}); | ||
for (let i = 0; i < this.cue.points.length; i++) { | ||
/** @type {!Object} */ | ||
let chunk = this.cue.points[i]; | ||
/** @type {!Object} */ | ||
let pointData = this.getDataForCuePoint_(chunk.dwName); | ||
pointData.label = pointData.value ? pointData.value : ''; | ||
pointData.dwPosition = chunk.dwPosition; | ||
pointData.fccChunk = chunk.fccChunk; | ||
pointData.dwChunkStart = chunk.dwChunkStart; | ||
pointData.dwBlockStart = chunk.dwBlockStart; | ||
pointData.dwSampleOffset = chunk.dwSampleOffset; | ||
points.push(pointData); | ||
} | ||
@@ -251,19 +370,40 @@ return points; | ||
/** | ||
* Return the label of a cue point. | ||
* Return the associated data of a cue point. | ||
* @param {number} pointDwName The ID of the cue point. | ||
* @return {string} | ||
* @return {!Object} | ||
* @private | ||
*/ | ||
getLabelForCuePoint_(pointDwName) { | ||
getDataForCuePoint_(pointDwName) { | ||
/** @type {?number} */ | ||
let cIndex = this.getAdtlChunk_(); | ||
/** @type {!Object} */ | ||
let pointData = {}; | ||
if (cIndex !== null) { | ||
// got through all chunks in the adtl LIST checking | ||
// for references to this cue point | ||
for (let i = 0, len = this.LIST[cIndex].subChunks.length; i < len; i++) { | ||
if (this.LIST[cIndex].subChunks[i].dwName == | ||
pointDwName) { | ||
return this.LIST[cIndex].subChunks[i].value; | ||
pointDwName && this.LIST[cIndex].subChunks[i].chunkId) { | ||
/** @type {!Object} */ | ||
let chunk = this.LIST[cIndex].subChunks[i]; | ||
// Some chunks may reference the point but | ||
// have a empty text; this is to ensure that if | ||
// one chunk that reference the point has a text, | ||
// this value will be kept as the associated data label | ||
// for the cue point. | ||
// If different values are present, the last value found | ||
// will be considered the label for the cue point. | ||
pointData.value = chunk.value ? chunk.value : pointData.value; | ||
pointData.dwName = chunk.dwName ? chunk.dwName : 0; | ||
pointData.dwSampleLength = | ||
chunk.dwSampleLength ? chunk.dwSampleLength : 0; | ||
pointData.dwPurposeID = chunk.dwPurposeID ? chunk.dwPurposeID : 0; | ||
pointData.dwCountry = chunk.dwCountry ? chunk.dwCountry : 0; | ||
pointData.dwLanguage = chunk.dwLanguage ? chunk.dwLanguage : 0; | ||
pointData.dwDialect = chunk.dwDialect ? chunk.dwDialect : 0; | ||
pointData.dwCodePage = chunk.dwCodePage ? chunk.dwCodePage : 0; | ||
} | ||
} | ||
} | ||
return ''; | ||
return pointData; | ||
} | ||
@@ -330,16 +470,16 @@ | ||
* Push a new cue point in this.cue.points. | ||
* @param {number} position The position in milliseconds. | ||
* @param {!Object} pointData A object with data of the cue point. | ||
* @param {number} dwName the dwName of the cue point | ||
* @private | ||
*/ | ||
setCuePoint_(position, dwName, label) { | ||
setCuePoint_(pointData, dwName) { | ||
this.cue.points.push({ | ||
dwName: dwName, | ||
dwPosition: position, | ||
fccChunk: 'data', | ||
dwChunkStart: 0, | ||
dwBlockStart: 0, | ||
dwSampleOffset: position, | ||
dwPosition: pointData.dwPosition ? pointData.dwPosition : 0, | ||
fccChunk: pointData.fccChunk ? pointData.fccChunk : 'data', | ||
dwChunkStart: pointData.dwChunkStart ? pointData.dwChunkStart : 0, | ||
dwBlockStart: pointData.dwBlockStart ? pointData.dwBlockStart : 0, | ||
dwSampleOffset: pointData.dwSampleOffset | ||
}); | ||
this.setLabl_(dwName, label); | ||
this.setLabl_(pointData, dwName); | ||
} | ||
@@ -361,10 +501,18 @@ | ||
* Create a new 'labl' subchunk in a 'LIST' chunk of type 'adtl'. | ||
* This method creates a LIST adtl chunk in the file if one | ||
* is not present. | ||
* @param {!Object} pointData A object with data of the cue point. | ||
* @param {number} dwName The ID of the cue point. | ||
* @param {string} label The label for the cue point. | ||
* @private | ||
*/ | ||
setLabl_(dwName, label) { | ||
/** @type {?number} */ | ||
setLabl_(pointData, dwName) { | ||
/** | ||
* Get the index of the LIST chunk labeled as adtl. | ||
* A file can have many LIST chunks with unique labels. | ||
* @type {?number} | ||
*/ | ||
let adtlIndex = this.getAdtlChunk_(); | ||
// If there is no adtl LIST, create one | ||
if (adtlIndex === null) { | ||
// Include a new item LIST chunk | ||
this.LIST.push({ | ||
@@ -375,5 +523,9 @@ chunkId: 'LIST', | ||
subChunks: []}); | ||
// Get the index of the new LIST chunk | ||
adtlIndex = this.LIST.length - 1; | ||
} | ||
this.setLabelText_(adtlIndex === null ? 0 : adtlIndex, dwName, label); | ||
this.setLabelText_(adtlIndex, pointData, dwName); | ||
if (pointData.dwSampleLength) { | ||
this.setLtxtChunk_(adtlIndex, pointData, dwName); | ||
} | ||
} | ||
@@ -384,15 +536,37 @@ | ||
* @param {number} adtlIndex The index of the 'adtl' LIST in this.LIST. | ||
* @param {!Object} pointData A object with data of the cue point. | ||
* @param {number} dwName The ID of the cue point. | ||
* @param {string} label The label for the cue point. | ||
* @private | ||
*/ | ||
setLabelText_(adtlIndex, dwName, label) { | ||
setLabelText_(adtlIndex, pointData, dwName) { | ||
this.LIST[adtlIndex].subChunks.push({ | ||
chunkId: 'labl', | ||
chunkSize: label.length, | ||
chunkSize: 4, // should be 4 + label length in bytes | ||
dwName: dwName, | ||
value: label | ||
value: pointData.label | ||
}); | ||
this.LIST[adtlIndex].chunkSize += label.length + 4 + 4 + 4 + 1; | ||
this.LIST[adtlIndex].chunkSize += 12; // should be 4 + label byte length | ||
} | ||
/** | ||
* Create a new 'ltxt' subchunk in a 'LIST' chunk of type 'adtl'. | ||
* @param {number} adtlIndex The index of the 'adtl' LIST in this.LIST. | ||
* @param {!Object} pointData A object with data of the cue point. | ||
* @param {number} dwName The ID of the cue point. | ||
* @private | ||
*/ | ||
setLtxtChunk_(adtlIndex, pointData, dwName) { | ||
this.LIST[adtlIndex].subChunks.push({ | ||
chunkId: 'ltxt', | ||
chunkSize: 20, // should be 12 + label byte length | ||
dwName: dwName, | ||
dwSampleLength: pointData.dwSampleLength, | ||
dwPurposeID: pointData.dwPurposeID ? pointData.dwPurposeID : 0, | ||
dwCountry: pointData.dwCountry ? pointData.dwCountry : 0, | ||
dwLanguage: pointData.dwLanguage ? pointData.dwLanguage : 0, | ||
dwDialect: pointData.dwDialect ? pointData.dwDialect : 0, | ||
dwCodePage: pointData.dwCodePage ? pointData.dwCodePage : 0, | ||
value: pointData.label // kept for compatibility | ||
}); | ||
this.LIST[adtlIndex].chunkSize += 28; | ||
} | ||
} |
{ | ||
"name": "wavefile", | ||
"version": "9.1.1", | ||
"version": "10.0.0", | ||
"description": "Create, read and write wav files according to the specs.", | ||
@@ -38,3 +38,4 @@ "homepage": "https://github.com/rochars/wavefile", | ||
"_PMX", | ||
"iXML" | ||
"iXML", | ||
"cue" | ||
], | ||
@@ -41,0 +42,0 @@ "repository": { |
137
README.md
@@ -28,2 +28,3 @@ # wavefile | ||
- Set and delete cue points and their labels | ||
- Create regions in wav files | ||
- Encode/decode files as ADPCM, A-Law and μ-Law | ||
@@ -153,2 +154,3 @@ - Turn RIFF files to RIFX and RIFX to RIFF | ||
* [Add cue points to files](#add-cue-points-to-files) | ||
* [Create regions in files](#create-regions-in-files) | ||
* [RIFX](#rifx) | ||
@@ -233,9 +235,16 @@ * [IMA-ADPCM](#ima-adpcm) | ||
### 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: | ||
You can create cue points using the **WaveFile.setCuePoint()** method. The method takes a object with the cue point data and creates a cue point in the corresponding position of the file. The only required attribute of the object is *position*, a number representing the position of the point in milliseconds: | ||
```javascript | ||
wav.setCuePoint(1750, "some label for the cue point"); | ||
// to create a cue point | ||
wav.setCuePoint({position: 1500}); | ||
``` | ||
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. | ||
You can also create cue points with labels by defining a *label* attribute: | ||
```javascript | ||
// to create a cue point with a label | ||
wav.setCuePoint({position: 1500, label: 'some label'}); | ||
``` | ||
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); | ||
@@ -246,2 +255,45 @@ ``` | ||
To list all the cue points in a file, in the order they appear: | ||
```javascript | ||
let cuePoints = wav.listCuePoints(); | ||
``` | ||
This method will return a list with cue points ordered as they appear in the file. | ||
```javascript | ||
[ | ||
{ | ||
position: 500, // the position in milliseconds | ||
label: 'cue marker 1', | ||
end: 1500, // the end position in milliseconds | ||
dwName: 1, | ||
dwPosition: 0, | ||
fccChunk: 'data', | ||
dwChunkStart: 0, | ||
dwBlockStart: 0, | ||
dwSampleOffset: 22050, // the position as a sample offset | ||
dwSampleLength: 3646827, // the region length as a sample count | ||
dwPurposeID: 544106354, | ||
dwCountry: 0, | ||
dwLanguage: 0, | ||
dwDialect: 0, | ||
dwCodePage: 0, | ||
}, | ||
//... | ||
]; | ||
``` | ||
### Create regions in files | ||
You can create regions using the **WaveFile.setCuePoint()** method. Regions are cue points with extra data. | ||
If you define a not null *end* attribute in the object describing the cue point, the point will be created as a region. The *end* attribute should be the end of the region, in milliseconds, counting from the start of the file, and always greater than the *position* of the point: | ||
```javascript | ||
// to create a region with a label: | ||
wav.setCuePoint({position: 1500, end: 2500, label: 'some label'}); | ||
``` | ||
You can also define the following optional properties when creating a region: | ||
- dwPurposeID | ||
- dwCountry | ||
- dwLanguage | ||
- dwDialect | ||
- dwCodePage | ||
### RIFX | ||
@@ -545,6 +597,32 @@ **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: | ||
* 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. | ||
* @param {!{ | ||
* position: number, | ||
* label: ?string, | ||
* end: ?number, | ||
* dwPurposeID: ?number, | ||
* dwCountry: ?number, | ||
* dwLanguage: ?number, | ||
* dwDialect: ?number, | ||
* dwCodePage: ?number | ||
* }} pointData A object with the data of the cue point. | ||
* | ||
* # Only required attribute to create a cue point: | ||
* pointData.position: The position of the point in milliseconds | ||
* | ||
* # Optional attribute for cue points: | ||
* pointData.label: A string label for the cue point | ||
* | ||
* # Extra data used for regions | ||
* pointData.end: A number representing the end of the region, | ||
* in milliseconds, counting from the start of the file. If | ||
* no end attr is specified then no region is created. | ||
* | ||
* # You may also specify the following attrs for regions, all optional: | ||
* pointData.dwPurposeID | ||
* pointData.dwCountry | ||
* pointData.dwLanguage | ||
* pointData.dwDialect | ||
* pointData.dwCodePage | ||
*/ | ||
WaveFile.setCuePoint(position, labl='') {} | ||
WaveFile.setCuePoint(pointData) {} | ||
@@ -561,9 +639,23 @@ /** | ||
* 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 | ||
* Objects representing cue points/regions look like this: | ||
* { | ||
* position: 500, // the position in milliseconds | ||
* label: 'cue marker 1', | ||
* end: 1500, // the end position in milliseconds | ||
* dwName: 1, | ||
* dwPosition: 0, | ||
* fccChunk: 'data', | ||
* dwChunkStart: 0, | ||
* dwBlockStart: 0, | ||
* dwSampleOffset: 22050, // the position as a sample offset | ||
* dwSampleLength: 3646827, // the region length as a sample count | ||
* dwPurposeID: 544106354, | ||
* dwCountry: 0, | ||
* dwLanguage: 0, | ||
* dwDialect: 0, | ||
* dwCodePage: 0, | ||
* } | ||
* @return {!Array<Object>} | ||
*/ | ||
listCuePoints() {} | ||
WaveFile.listCuePoints() {} | ||
@@ -623,10 +715,23 @@ /** | ||
#### WaveFile.listCuePoints() | ||
This method returns a list like this: | ||
This method returns a list of objects, each object representing a cue point or region. The list looks like this: | ||
```javascript | ||
[ | ||
{ | ||
milliseconds: 1000, // the position in milliseconds | ||
dwPosition: 8000, // the sample offset of the point | ||
label: "some cue marker" // the label of the point | ||
position: 500, // the position in milliseconds | ||
label: 'cue marker 1', | ||
end: 1500, // the end position in milliseconds | ||
dwName: 1, | ||
dwPosition: 0, | ||
fccChunk: 'data', | ||
dwChunkStart: 0, | ||
dwBlockStart: 0, | ||
dwSampleOffset: 22050, // the position as a sample offset | ||
dwSampleLength: 3646827, // the region length as a sample count | ||
dwPurposeID: 544106354, | ||
dwCountry: 0, | ||
dwLanguage: 0, | ||
dwDialect: 0, | ||
dwCodePage: 0 | ||
}, | ||
// ... | ||
] | ||
@@ -633,0 +738,0 @@ ``` |
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
223065
4192
1144