// -----------------------
// Wimpy FLAC Controller 
// -----------------------
// 0.3.2 - 2019-11-29
// By Mike Gieson
// http://www.wimpyplayer.com/docs/common/file_formats_FLAC.html
// 
// -----------------------
// Usage
// -----------------------
// To use on your page, reference the "wimpy.flac.js" file 
// just after the reference to the "wimpy.js" engine.
/* 
	<!-- Wimpy Engine -->
	<script src="wimpy.js"></script>

	<!-- Wimpy FLAC Plugin (must be below wimpy.js) -->
	<script src="wimpy.flac.js"></script>
*/
// 
// -----------------------
// USING: Aurora.js - https://github.com/audiocogs/aurora.js/
// Written by @jensnockert and @devongovett of Audiocogs.
// -----------------------


this.wimpy=this.wimpy||{},function(){"use strict";if(jbeeb.mimes.audio.flac="audio/flac",window.AudioContext||window.webkitAudioContext){wimpy.flac_supported=!0;var t=jbeeb.MediaController,e=t.prototype;e._AROR_player=null,e._AROR_volume=1,e._AROR_live=!1,e._CORE_MC_loadAndPlay=e.loadAndPlay,e.loadAndPlay=function(e,r){var i=t.getMediaInfo(e,r);if("flac"==i.ext||"flac"==r){this.destroy_AROR_player(),this._AROR_live=!0,this.disableOthers(),this.fileInfo=i,this.file=e;var s=AV.Player.fromURL(e);s.on("buffer",this._AROR_watchLoadState.bind(this)),s.on("ready",this._AROR_readyPlay.bind(this)),s.on("progress",this._AROR_updateProgress.bind(this)),s.on("end",this._AROR_end.bind(this)),s.on("error",this._AROR_error.bind(this)),this._AROR_player=s,this.dispatchEvent("playpause",1),this.dispatchEvent("loadStart",this.file),s.preload()}else this._AROR_live=!1,this._CORE_MC_loadAndPlay(e,r)},e._AROR_error=function(t){console.log("_AROR_error",t)},e._CORE_MC_play=e.play,e.play=function(t,e){var r=!1;t&&t!=this.file&&(this.loadAndPlay(jbeeb.Utils.absoluteURL(t),e),r=!0),r||(this._AROR_live?(this._AROR_player.play(),this.dispatchEvent("start",this.file)):this._CORE_MC_play())},e._CORE_MC_pause=e.pause,e.pause=function(t){this._AROR_live?this._AROR_player&&(this._AROR_player.pause(),this.dispatchEvent("pause",this.file)):this._CORE_MC_pause(t)},e._CORE_MC_stop=e.stop,e.stop=function(t){this._AROR_live?(this.reset(t),this.dispatchEvent("stop",this.file)):this._CORE_MC_stop(t)},e._CORE_MC_reset=e.reset,e.reset=function(t){this._AROR_live?(this.pause(),this.rewind(),this.fileInfo=null,this.file=null,this.amMuted?this.setVolume(this._muteVolMem||1):this.setVolume(this._volume),t&&this.destroy_AROR_player()):this._CORE_MC_reset(t)},e.destroy_AROR_player=function(){var t=this._AROR_player;t&&(t.stop(),t.off("buffer"),t.off("format"),t.off("progress"),t.off("duration"),t.off("metadata"),this._AROR_player=null)},e._CORE_MC_rewind=e.rewind,e.rewind=function(){this._AROR_live?this.setPlayheadPercent(0):this._CORE_MC_rewind()},e._CORE_MC_setPlayheadPercent=e.setPlayheadPercent,e.setPlayheadPercent=function(t){if(this._AROR_live){if(this._AROR_player){var e=this._AROR_player.duration;e&&e!==1/0&&NaN!==e||(e=0);var r=e*t;r<0?r=0:r>e&&(r=e),this._AROR_player.seek(r)}}else this._CORE_MC_setPlayheadPercent(t)},e._CORE_MC_setVolume=e.setVolume,e.setVolume=function(t){this._AROR_live?(this._AROR_player&&(this._AROR_player.volume=100*t),this._AROR_volume=t):this._CORE_MC_setVolume(t)},e._CORE_MC_mute=e.mute,e.mute=function(t){this._AROR_live?(t?this._muteVolMem=this._AROR_volume||1:this._muteVolMem,this.amMuted=t,this.setVolume(v)):this._CORE_MC_mute(t)},e._AROR_readyPlay=function(t){this._AROR_player.play(),this.setVolume(this._AROR_volume),this.dispatchEvent("launch",this.file),this.dispatchEvent("start",this.file)},e._AROR_updateProgress=function(t){this._AROR_watchPlayerState()},e._AROR_end=function(){this.reset(),this._AROR_watchPlayerState(!0),this.dispatchEvent("done",this.file)},e._AROR_watchLoadState=function(t){var e={loaded:1*t,percent:t/100||0,total:100,status:0};e.percent=1,t>90?(this.LOAD_STATUS=300,this.canPlayThrough()):(this.setLoadState(e),this.dispatchEvent("loading",e))},e._AROR_watchPlayerState=function(t){var e=this._AROR_player.playing?1:0,r=this._AROR_player.currentTime||0,i=this._AROR_player.duration||r+1;t&&(e=0,i=1);var s=r/1e3,n=i/1e3,a=s/n,o=n-s,h="00:00",u="00:00",f="00:00";s>0&&(h=this.niceTime(s),u=this.niceTime(n),f=this.niceTime(o));var l={init:1,status:e,percent:a,duration:n,duration_nice:u,remaining:o,remaining_nice:f,current:s,current_nice:h,buffering:!1,thinking:0};this.setPlayerState(l),this.dispatchEvent("update",l)}}}(),function(){function t(t,e,r,i,s){this.fromSampleRate=t,this.toSampleRate=e,this.channels=0|r,this.outputBufferSize=i,this.noReturn=!!s,this.initialize()}var e;e=this;var r;r={};var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n=[].indexOf||function(t){for(var e=0,r=this.length;e<r;e++)if(e in this&&this[e]===t)return e;return-1};r.Base=function(){function t(){}var e;return e=/\b_super\b/,t.extend=function(t){var r,i,a,o,h,u;if(r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e}(this),"function"==typeof t){o=Object.keys(r.prototype),t.call(r,r),t={},h=r.prototype;for(a in h)i=h[a],n.call(o,a)<0&&(t[a]=i)}u=r.__super__;for(a in t)i=t[a],"function"==typeof i&&e.test(i)?function(t,e){r.prototype[t]=function(){var r,i;return i=this._super,this._super=u[t],r=e.apply(this,arguments),this._super=i,r}}(a,i):r.prototype[a]=i;return r},t}(),r.Buffer=function(){function t(t){var i;if(t instanceof Uint8Array)this.data=t;else if(t instanceof ArrayBuffer||Array.isArray(t)||"number"==typeof t||r.isNode&&(null!=(i=e.Buffer)?i.isBuffer(t):void 0))this.data=new Uint8Array(t);else if(t.buffer instanceof ArrayBuffer)this.data=new Uint8Array(t.buffer,t.byteOffset,t.length*t.BYTES_PER_ELEMENT);else{if(!(t instanceof r.Buffer))throw new Error("Constructing buffer with unknown type.");this.data=t.data}this.length=this.data.length,this.next=null,this.prev=null}var i,s;return t.allocate=function(t){return new r.Buffer(t)},t.prototype.copy=function(){return new r.Buffer(new Uint8Array(this.data))},t.prototype.slice=function(t,e){return null==e&&(e=this.length),0===t&&e>=this.length?new r.Buffer(this.data):new r.Buffer(this.data.subarray(t,t+e))},i=e.BlobBuilder||e.MozBlobBuilder||e.WebKitBlobBuilder,s=e.URL||e.webkitURL||e.mozURL,t.makeBlob=function(t,e){var r;null==e&&(e="application/octet-stream");try{return new Blob([t],{type:e})}catch(t){}return null!=i?(r=new i,r.append(t),r.getBlob(e)):null},t.makeBlobURL=function(t,e){return null!=s?s.createObjectURL(this.makeBlob(t,e)):void 0},t.revokeBlobURL=function(t){return null!=s?s.revokeObjectURL(t):void 0},t.prototype.toBlob=function(){return t.makeBlob(this.data.buffer)},t.prototype.toBlobURL=function(){return t.makeBlobURL(this.data.buffer)},t}(),r.BufferList=function(){function t(){this.first=null,this.last=null,this.numBuffers=0,this.availableBytes=0,this.availableBuffers=0}return t.prototype.copy=function(){var t;return t=new r.BufferList,t.first=this.first,t.last=this.last,t.numBuffers=this.numBuffers,t.availableBytes=this.availableBytes,t.availableBuffers=this.availableBuffers,t},t.prototype.append=function(t){var e;return t.prev=this.last,null!=(e=this.last)&&(e.next=t),this.last=t,null==this.first&&(this.first=t),this.availableBytes+=t.length,this.availableBuffers++,this.numBuffers++},t.prototype.advance=function(){return!!this.first&&(this.availableBytes-=this.first.length,this.availableBuffers--,this.first=this.first.next,null!=this.first)},t.prototype.rewind=function(){var t;return!(this.first&&!this.first.prev)&&(this.first=(null!=(t=this.first)?t.prev:void 0)||this.last,this.first&&(this.availableBytes+=this.first.length,this.availableBuffers++),null!=this.first)},t.prototype.reset=function(){var t;for(t=[];this.rewind(););return t},t}();var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.Stream=function(){function t(t){this.list=t,this.localOffset=0,this.offset=0}var e,i,n,a,o,h,u,f,l,c,p,d,m;return e=new ArrayBuffer(16),m=new Uint8Array(e),l=new Int8Array(e),p=new Uint16Array(e),u=new Int16Array(e),d=new Uint32Array(e),f=new Int32Array(e),n=new Float32Array(e),"undefined"!=typeof Float64Array&&null!==Float64Array&&(a=new Float64Array(e)),c=13330===new Uint16Array(new Uint8Array([18,52]).buffer)[0],r.UnderflowError=function(t){function e(){this.name="AV.UnderflowError"}return s(e,t),e}(Error),t.fromBuffer=function(t){var e;return e=new r.BufferList,e.append(t),new r.Stream(e)},t.prototype.copy=function(){var t;return t=new r.Stream(this.list.copy()),t.localOffset=this.localOffset,t.offset=this.offset,t},t.prototype.available=function(t){return t<=this.list.availableBytes-this.localOffset},t.prototype.remainingBytes=function(){return this.list.availableBytes-this.localOffset},t.prototype.advance=function(t){if(!this.available(t))throw new r.UnderflowError;for(this.localOffset+=t,this.offset+=t;this.list.first&&this.localOffset>=this.list.first.length;)this.localOffset-=this.list.first.length,this.list.advance();return this},t.prototype.rewind=function(t){if(t>this.offset)throw new r.UnderflowError;for(this.list.first||(this.list.rewind(),this.localOffset=this.list.first.length),this.localOffset-=t,this.offset-=t;this.list.first.prev&&this.localOffset<0;)this.list.rewind(),this.localOffset+=this.list.first.length;return this},t.prototype.seek=function(t){return t>this.offset?this.advance(t-this.offset):t<this.offset?this.rewind(this.offset-t):void 0},t.prototype.readUInt8=function(){var t;if(!this.available(1))throw new r.UnderflowError;return t=this.list.first.data[this.localOffset],this.localOffset+=1,this.offset+=1,this.localOffset===this.list.first.length&&(this.localOffset=0,this.list.advance()),t},t.prototype.peekUInt8=function(t){var e;if(null==t&&(t=0),!this.available(t+1))throw new r.UnderflowError;for(t=this.localOffset+t,e=this.list.first;e;){if(e.length>t)return e.data[t];t-=e.length,e=e.next}return 0},t.prototype.read=function(t,e){var r,i,s;if(null==e&&(e=!1),e===c)for(r=i=0;i<t;r=i+=1)m[r]=this.readUInt8();else for(r=s=t-1;s>=0;r=s+=-1)m[r]=this.readUInt8()},t.prototype.peek=function(t,e,r){var i,s,n;if(null==r&&(r=!1),r===c)for(i=s=0;s<t;i=s+=1)m[i]=this.peekUInt8(e+i);else for(i=n=0;n<t;i=n+=1)m[t-i-1]=this.peekUInt8(e+i)},t.prototype.readInt8=function(){return this.read(1),l[0]},t.prototype.peekInt8=function(t){return null==t&&(t=0),this.peek(1,t),l[0]},t.prototype.readUInt16=function(t){return this.read(2,t),p[0]},t.prototype.peekUInt16=function(t,e){return null==t&&(t=0),this.peek(2,t,e),p[0]},t.prototype.readInt16=function(t){return this.read(2,t),u[0]},t.prototype.peekInt16=function(t,e){return null==t&&(t=0),this.peek(2,t,e),u[0]},t.prototype.readUInt24=function(t){return t?this.readUInt16(!0)+(this.readUInt8()<<16):(this.readUInt16()<<8)+this.readUInt8()},t.prototype.peekUInt24=function(t,e){return null==t&&(t=0),e?this.peekUInt16(t,!0)+(this.peekUInt8(t+2)<<16):(this.peekUInt16(t)<<8)+this.peekUInt8(t+2)},t.prototype.readInt24=function(t){return t?this.readUInt16(!0)+(this.readInt8()<<16):(this.readInt16()<<8)+this.readUInt8()},t.prototype.peekInt24=function(t,e){return null==t&&(t=0),e?this.peekUInt16(t,!0)+(this.peekInt8(t+2)<<16):(this.peekInt16(t)<<8)+this.peekUInt8(t+2)},t.prototype.readUInt32=function(t){return this.read(4,t),d[0]},t.prototype.peekUInt32=function(t,e){return null==t&&(t=0),this.peek(4,t,e),d[0]},t.prototype.readInt32=function(t){return this.read(4,t),f[0]},t.prototype.peekInt32=function(t,e){return null==t&&(t=0),this.peek(4,t,e),f[0]},t.prototype.readFloat32=function(t){return this.read(4,t),n[0]},t.prototype.peekFloat32=function(t,e){return null==t&&(t=0),this.peek(4,t,e),n[0]},t.prototype.readFloat64=function(t){return this.read(8,t),a?a[0]:o()},o=function(){var t,e,r,i,s,n;return i=d[0],(r=d[1])&&2147483648!==r?(n=1-2*(r>>>31),t=r>>>20&2047,e=1048575&r,2047===t?e?NaN:n*(1/0):(t-=1023,s=(1048576|e)*Math.pow(2,t-20),s+=i*Math.pow(2,t-52),n*s)):0},t.prototype.peekFloat64=function(t,e){return null==t&&(t=0),this.peek(8,t,e),a?a[0]:o()},t.prototype.readFloat80=function(t){return this.read(10,t),h()},h=function(){var t,e,r,i,s,n,a;return i=d[0],s=d[1],t=m[9],e=m[8],a=1-2*(t>>>7),0===(r=(127&t)<<8|e)&&0===s&&0===i?0:32767===r?0===s&&0===i?a*(1/0):NaN:(r-=16383,n=s*Math.pow(2,r-31),n+=i*Math.pow(2,r-63),a*n)},t.prototype.peekFloat80=function(t,e){return null==t&&(t=0),this.peek(10,t,e),h()},t.prototype.readBuffer=function(t){var e,i,s,n;for(i=r.Buffer.allocate(t),s=i.data,e=n=0;n<t;e=n+=1)s[e]=this.readUInt8();return i},t.prototype.peekBuffer=function(t,e){var i,s,n,a;for(null==t&&(t=0),s=r.Buffer.allocate(e),n=s.data,i=a=0;a<e;i=a+=1)n[i]=this.peekUInt8(t+i);return s},t.prototype.readSingleBuffer=function(t){var e;return e=this.list.first.slice(this.localOffset,t),this.advance(e.length),e},t.prototype.peekSingleBuffer=function(t,e){return this.list.first.slice(this.localOffset+t,e)},t.prototype.readString=function(t,e){return null==e&&(e="ascii"),i.call(this,0,t,e,!0)},t.prototype.peekString=function(t,e,r){return null==t&&(t=0),null==r&&(r="ascii"),i.call(this,t,e,r,!1)},i=function(t,e,r,i){var s,n,a,o,h,u,f,l,c,p,d,m,v;switch(r=r.toLowerCase(),c=null===e?0:-1,null==e&&(e=1/0),f=t+e,d="",r){case"ascii":case"latin1":for(;t<f&&(u=this.peekUInt8(t++))!==c;)d+=String.fromCharCode(u);break;case"utf8":case"utf-8":for(;t<f&&(s=this.peekUInt8(t++))!==c;)0==(128&s)?d+=String.fromCharCode(s):192==(224&s)?(n=63&this.peekUInt8(t++),d+=String.fromCharCode((31&s)<<6|n)):224==(240&s)?(n=63&this.peekUInt8(t++),a=63&this.peekUInt8(t++),d+=String.fromCharCode((15&s)<<12|n<<6|a)):240==(248&s)&&(n=63&this.peekUInt8(t++),a=63&this.peekUInt8(t++),o=63&this.peekUInt8(t++),p=((15&s)<<18|n<<12|a<<6|o)-65536,d+=String.fromCharCode(55296+(p>>10),56320+(1023&p)));break;case"utf16-be":case"utf16be":case"utf16le":case"utf16-le":case"utf16bom":case"utf16-bom":switch(r){case"utf16be":case"utf16-be":l=!1;break;case"utf16le":case"utf16-le":l=!0;break;case"utf16bom":case"utf16-bom":if(e<2||(h=this.peekUInt16(t))===c)return i&&this.advance(t+=2),d;l=65534===h,t+=2}for(;t<f&&(m=this.peekUInt16(t,l))!==c;)if(t+=2,m<55296||m>57343)d+=String.fromCharCode(m);else{if(m>56319)throw new Error("Invalid utf16 sequence.");if((v=this.peekUInt16(t,l))<56320||v>57343)throw new Error("Invalid utf16 sequence.");d+=String.fromCharCode(m,v),t+=2}m===c&&(t+=2);break;default:throw new Error("Unknown encoding: "+r)}return i&&this.advance(t),d},t}(),r.Bitstream=function(){function t(t){this.stream=t,this.bitPosition=0}return t.prototype.copy=function(){var t;return t=new r.Bitstream(this.stream.copy()),t.bitPosition=this.bitPosition,t},t.prototype.offset=function(){return 8*this.stream.offset+this.bitPosition},t.prototype.available=function(t){return this.stream.available((t+8-this.bitPosition)/8)},t.prototype.advance=function(t){var e;return e=this.bitPosition+t,this.stream.advance(e>>3),this.bitPosition=7&e},t.prototype.rewind=function(t){var e;return e=this.bitPosition-t,this.stream.rewind(Math.abs(e>>3)),this.bitPosition=7&e},t.prototype.seek=function(t){var e;return e=this.offset(),t>e?this.advance(t-e):t<e?this.rewind(e-t):void 0},t.prototype.align=function(){if(0!==this.bitPosition)return this.bitPosition=0,this.stream.advance(1)},t.prototype.read=function(t,e){var r,i,s,n,a,o,h;if(0===t)return 0;if((h=t+this.bitPosition)<=8)r=(this.stream.peekUInt8()<<this.bitPosition&255)>>>8-t;else if(h<=16)r=(this.stream.peekUInt16()<<this.bitPosition&65535)>>>16-t;else if(h<=24)r=(this.stream.peekUInt24()<<this.bitPosition&16777215)>>>24-t;else if(h<=32)r=this.stream.peekUInt32()<<this.bitPosition>>>32-t;else{if(!(h<=40))throw new Error("Too many bits!");i=4294967296*this.stream.peekUInt8(0),s=this.stream.peekUInt8(1)<<24>>>0,n=this.stream.peekUInt8(2)<<16,a=this.stream.peekUInt8(3)<<8,o=this.stream.peekUInt8(4),r=i+s+n+a+o,r%=Math.pow(2,40-this.bitPosition),r=Math.floor(r/Math.pow(2,40-this.bitPosition-t))}return e&&(h<32?r>>>t-1&&(r=-1*((1<<t>>>0)-r)):r/Math.pow(2,t-1)|0&&(r=-1*(Math.pow(2,t)-r))),this.advance(t),r},t.prototype.peek=function(t,e){var r,i,s,n,a,o,h;if(0===t)return 0;if((h=t+this.bitPosition)<=8)r=(this.stream.peekUInt8()<<this.bitPosition&255)>>>8-t;else if(h<=16)r=(this.stream.peekUInt16()<<this.bitPosition&65535)>>>16-t;else if(h<=24)r=(this.stream.peekUInt24()<<this.bitPosition&16777215)>>>24-t;else if(h<=32)r=this.stream.peekUInt32()<<this.bitPosition>>>32-t;else{if(!(h<=40))throw new Error("Too many bits!");i=4294967296*this.stream.peekUInt8(0),s=this.stream.peekUInt8(1)<<24>>>0,n=this.stream.peekUInt8(2)<<16,a=this.stream.peekUInt8(3)<<8,o=this.stream.peekUInt8(4),r=i+s+n+a+o,r%=Math.pow(2,40-this.bitPosition),r=Math.floor(r/Math.pow(2,40-this.bitPosition-t))}return e&&(h<32?r>>>t-1&&(r=-1*((1<<t>>>0)-r)):r/Math.pow(2,t-1)|0&&(r=-1*(Math.pow(2,t)-r))),r},t.prototype.readLSB=function(t,e){var r,i;if(0===t)return 0;if(t>40)throw new Error("Too many bits!");return i=t+this.bitPosition,r=this.stream.peekUInt8(0)>>>this.bitPosition,i>8&&(r|=this.stream.peekUInt8(1)<<8-this.bitPosition),i>16&&(r|=this.stream.peekUInt8(2)<<16-this.bitPosition),i>24&&(r+=this.stream.peekUInt8(3)<<24-this.bitPosition>>>0),i>32&&(r+=this.stream.peekUInt8(4)*Math.pow(2,32-this.bitPosition)),i>=32?r%=Math.pow(2,t):r&=(1<<t)-1,e&&(i<32?r>>>t-1&&(r=-1*((1<<t>>>0)-r)):r/Math.pow(2,t-1)|0&&(r=-1*(Math.pow(2,t)-r))),this.advance(t),r},t.prototype.peekLSB=function(t,e){var r,i;if(0===t)return 0;if(t>40)throw new Error("Too many bits!");return i=t+this.bitPosition,r=this.stream.peekUInt8(0)>>>this.bitPosition,i>8&&(r|=this.stream.peekUInt8(1)<<8-this.bitPosition),i>16&&(r|=this.stream.peekUInt8(2)<<16-this.bitPosition),i>24&&(r+=this.stream.peekUInt8(3)<<24-this.bitPosition>>>0),i>32&&(r+=this.stream.peekUInt8(4)*Math.pow(2,32-this.bitPosition)),i>=32?r%=Math.pow(2,t):r&=(1<<t)-1,e&&(i<32?r>>>t-1&&(r=-1*((1<<t>>>0)-r)):r/Math.pow(2,t-1)|0&&(r=-1*(Math.pow(2,t)-r))),r},t}();var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},a=[].slice;r.EventEmitter=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.on=function(t,e){var r;return null==this.events&&(this.events={}),null==(r=this.events)[t]&&(r[t]=[]),this.events[t].push(e)},e.prototype.off=function(t,e){var r,i;if(null!=(i=this.events)?i[t]:void 0)return r=this.events[t].indexOf(e),~r?this.events[t].splice(r,1):void 0},e.prototype.once=function(t,e){var r;return this.on(t,r=function(){return this.off(t,r),e.apply(this,arguments)})},e.prototype.emit=function(){var t,e,r,i,s,n,o;if(e=arguments[0],t=2<=arguments.length?a.call(arguments,1):[],null!=(n=this.events)?n[e]:void 0)for(o=this.events[e].slice(),i=0,s=o.length;i<s;i++)r=o[i],r.apply(this,t)},e}(r.Base);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.BufferSource=function(t){function i(t){this.loop=o(this.loop,this),t instanceof r.BufferList?this.list=t:(this.list=new r.BufferList,this.list.append(new r.Buffer(t))),this.paused=!0}var n,a;return s(i,t),a=e.setImmediate||function(t){return e.setTimeout(t,0)},n=e.clearImmediate||function(t){return e.clearTimeout(t)},i.prototype.start=function(){return this.paused=!1,this._timer=a(this.loop)},i.prototype.loop=function(){return this.emit("progress",(this.list.numBuffers-this.list.availableBuffers+1)/this.list.numBuffers*100|0),this.emit("data",this.list.first),this.list.advance()?a(this.loop):this.emit("end")},i.prototype.pause=function(){return n(this._timer),this.paused=!0},i.prototype.reset=function(){return this.pause(),this.list.rewind()},i}(r.EventEmitter);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.Demuxer=function(t){function e(t,e){var i,s;i=new r.BufferList,i.append(e),this.stream=new r.Stream(i),s=!1,t.on("data",function(t){return function(e){return s=!0,i.append(e),t.readChunk(e)}}(this)),t.on("error",function(t){return function(e){return t.emit("error",e)}}(this)),t.on("end",function(t){return function(){return s||t.readChunk(e),t.emit("end")}}(this)),this.seekPoints=[],this.init()}var i;return s(e,t),e.probe=function(t){return!1},e.prototype.init=function(){},e.prototype.readChunk=function(t){},e.prototype.addSeekPoint=function(t,e){var r;return r=this.searchTimestamp(e),this.seekPoints.splice(r,0,{offset:t,timestamp:e})},e.prototype.searchTimestamp=function(t,e){var r,i,s,n;if(i=0,(r=this.seekPoints.length)>0&&this.seekPoints[r-1].timestamp<t)return r;for(;i<r;)s=i+r>>1,n=this.seekPoints[s].timestamp,n<t?i=s+1:n>=t&&(r=s);return r>this.seekPoints.length&&(r=this.seekPoints.length),r},e.prototype.seek=function(t){var e;return this.format&&this.format.framesPerPacket>0&&this.format.bytesPerPacket>0?{timestamp:t,offset:this.format.bytesPerPacket*t/this.format.framesPerPacket}:(e=this.searchTimestamp(t),this.seekPoints[e])},i=[],e.register=function(t){return i.push(t)},e.find=function(t){var e,s,n,a;for(s=r.Stream.fromBuffer(t),n=0,a=i.length;n<a;n++)if(e=i[n],e.probe(s))return e;return null},e}(r.EventEmitter);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.Decoder=function(t){function e(t,e){var i;this.demuxer=t,this.format=e,i=new r.BufferList,this.stream=new r.Stream(i),this.bitstream=new r.Bitstream(this.stream),this.receivedFinalBuffer=!1,this.waiting=!1,this.demuxer.on("cookie",function(t){return function(e){var r;try{return t.setCookie(e)}catch(e){return r=e,t.emit("error",r)}}}(this)),this.demuxer.on("data",function(t){return function(e){if(i.append(e),t.waiting)return t.decode()}}(this)),this.demuxer.on("end",function(t){return function(){if(t.receivedFinalBuffer=!0,t.waiting)return t.decode()}}(this)),this.init()}var i;return s(e,t),e.prototype.init=function(){},e.prototype.setCookie=function(t){},e.prototype.readChunk=function(){},e.prototype.decode=function(){var t,e,i;this.waiting=!1,e=this.bitstream.offset();try{i=this.readChunk()}catch(e){if(!((t=e)instanceof r.UnderflowError))return this.emit("error",t),!1}return i?(this.emit("data",i),!0):(this.receivedFinalBuffer?this.emit("end"):(this.bitstream.seek(e),this.waiting=!0),!1)},e.prototype.seek=function(t){var e;return e=this.demuxer.seek(t),e?(this.stream.seek(e.offset),e.timestamp):0},i={},e.register=function(t,e){return i[t]=e},e.find=function(t){return i[t]||null},e}(r.EventEmitter);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.Queue=function(t){function e(t){this.asset=t,this.write=o(this.write,this),this.readyMark=64,this.finished=!1,this.buffering=!0,this.ended=!1,this.buffers=[],this.asset.on("data",this.write),this.asset.on("end",function(t){return function(){return t.ended=!0}}(this)),this.asset.decodePacket()}return s(e,t),e.prototype.write=function(t){if(t&&this.buffers.push(t),this.buffering)return this.buffers.length>=this.readyMark||this.ended?(this.buffering=!1,this.emit("ready")):this.asset.decodePacket()},e.prototype.read=function(){return 0===this.buffers.length?null:(this.asset.decodePacket(),this.buffers.shift())},e.prototype.reset=function(){return this.buffers.length=0,this.buffering=!0,this.asset.decodePacket()},e}(r.EventEmitter);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.AudioDevice=function(t){function e(t,e){this.sampleRate=t,this.channels=e,this.updateTime=o(this.updateTime,this),this.playing=!1,this.currentTime=0,this._lastTime=0}var i;return s(e,t),e.prototype.start=function(){if(!this.playing){if(this.playing=!0,null==this.device&&(this.device=r.AudioDevice.create(this.sampleRate,this.channels)),!this.device)throw new Error("No supported audio device found.");return this._lastTime=this.device.getDeviceTime(),this._timer=setInterval(this.updateTime,200),this.device.on("refill",this.refill=function(t){return function(e){return t.emit("refill",e)}}(this))}},e.prototype.stop=function(){if(this.playing)return this.playing=!1,this.device.off("refill",this.refill),clearInterval(this._timer)},e.prototype.destroy=function(){return this.stop(),this.device.destroy()},e.prototype.seek=function(t){return this.currentTime=t,this.playing&&(this._lastTime=this.device.getDeviceTime()),this.emit("timeUpdate",this.currentTime)},e.prototype.updateTime=function(){var t;return t=this.device.getDeviceTime(),this.currentTime+=(t-this._lastTime)/this.device.sampleRate*1e3|0,this._lastTime=t,this.emit("timeUpdate",this.currentTime)},i=[],e.register=function(t){return i.push(t)},e.create=function(t,e){var r,s,n;for(s=0,n=i.length;s<n;s++)if(r=i[s],r.supported)return new r(t,e);return null},e}(r.EventEmitter);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.Asset=function(t){function e(t){this.source=t,this._decode=o(this._decode,this),this.findDecoder=o(this.findDecoder,this),this.probe=o(this.probe,this),this.buffered=0,this.duration=null,this.format=null,this.metadata=null,this.active=!1,this.demuxer=null,this.decoder=null,this.source.once("data",this.probe),this.source.on("error",function(t){return function(e){return t.emit("error",e),t.stop()}}(this)),this.source.on("progress",function(t){return function(e){return t.buffered=e,t.emit("buffer",t.buffered)}}(this))}return s(e,t),e.fromURL=function(t){return new r.Asset(new r.HTTPSource(t))},e.fromFile=function(t){return new r.Asset(new r.FileSource(t))},e.fromBuffer=function(t){return new r.Asset(new r.BufferSource(t))},e.prototype.start=function(t){if(!this.active)return null!=t&&(this.shouldDecode=t),null==this.shouldDecode&&(this.shouldDecode=!0),this.active=!0,this.source.start(),this.decoder&&this.shouldDecode?this._decode():void 0},e.prototype.stop=function(){if(this.active)return this.active=!1,this.source.pause()},e.prototype.get=function(t,e){if("format"===t||"duration"===t||"metadata"===t)return null!=this[t]?e(this[t]):(this.once(t,function(t){return function(r){return t.stop(),e(r)}}(this)),this.start())},e.prototype.decodePacket=function(){return this.decoder.decode()},e.prototype.decodeToBuffer=function(t){var e,r,i;return i=0,e=[],this.on("data",r=function(t){return i+=t.length,e.push(t)}),this.once("end",function(){var s,n,a,o,h;for(s=new Float32Array(i),a=0,o=0,h=e.length;o<h;o++)n=e[o],s.set(n,a),a+=n.length;return this.off("data",r),t(s)}),this.start()},e.prototype.probe=function(t){var e;if(this.active)return(e=r.Demuxer.find(t))?(this.demuxer=new e(this.source,t),this.demuxer.on("format",this.findDecoder),this.demuxer.on("duration",function(t){return function(e){return t.duration=e,t.emit("duration",t.duration)}}(this)),this.demuxer.on("metadata",function(t){return function(e){return t.metadata=e,t.emit("metadata",t.metadata)}}(this)),this.demuxer.on("error",function(t){return function(e){return t.emit("error",e),t.stop()}}(this))):this.emit("error","A demuxer for this container was not found.")},e.prototype.findDecoder=function(t){var e,i;if(this.format=t,this.active)return this.emit("format",this.format),(e=r.Decoder.find(this.format.formatID))?(this.decoder=new e(this.demuxer,this.format),this.format.floatingPoint?this.decoder.on("data",function(t){return function(e){return t.emit("data",e)}}(this)):(i=Math.pow(2,this.format.bitsPerChannel-1),this.decoder.on("data",function(t){return function(e){var r,s,n,a,o;for(r=new Float32Array(e.length),s=a=0,o=e.length;a<o;s=++a)n=e[s],r[s]=n/i;return t.emit("data",r)}}(this))),this.decoder.on("error",function(t){return function(e){return t.emit("error",e),t.stop()}}(this)),this.decoder.on("end",function(t){return function(){return t.emit("end")}}(this)),this.emit("decodeStart"),this.shouldDecode?this._decode():void 0):this.emit("error","A decoder for "+this.format.formatID+" was not found.")},e.prototype._decode=function(){for(;this.decoder.decode()&&this.active;);if(this.active)return this.decoder.once("data",this._decode)},e}(r.EventEmitter);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.Player=function(t){function e(t){this.asset=t,this.startPlaying=o(this.startPlaying,this),this.playing=!1,this.buffered=0,this.currentTime=0,this.duration=0,this.volume=100,this.pan=0,this.metadata={},this.filters=[new r.VolumeFilter(this,"volume"),new r.BalanceFilter(this,"pan")],this.asset.on("buffer",function(t){return function(e){return t.buffered=e,t.emit("buffer",t.buffered)}}(this)),this.asset.on("decodeStart",function(t){return function(){return t.queue=new r.Queue(t.asset),t.queue.once("ready",t.startPlaying)}}(this)),this.asset.on("format",function(t){return function(e){return t.format=e,t.emit("format",t.format)}}(this)),this.asset.on("metadata",function(t){return function(e){return t.metadata=e,t.emit("metadata",t.metadata)}}(this)),this.asset.on("duration",function(t){return function(e){return t.duration=e,t.emit("duration",t.duration)}}(this)),this.asset.on("error",function(t){return function(e){return t.emit("error",e)}}(this))}return s(e,t),e.fromURL=function(t){return new r.Player(r.Asset.fromURL(t))},e.fromFile=function(t){return new r.Player(r.Asset.fromFile(t))},e.fromBuffer=function(t){return new r.Player(r.Asset.fromBuffer(t))},e.prototype.preload=function(){if(this.asset)return this.startedPreloading=!0,this.asset.start(!1)},e.prototype.play=function(){var t;if(!this.playing)return this.startedPreloading||this.preload(),this.playing=!0,null!=(t=this.device)?t.start():void 0},e.prototype.pause=function(){var t;if(this.playing)return this.playing=!1,null!=(t=this.device)?t.stop():void 0},e.prototype.togglePlayback=function(){return this.playing?this.pause():this.play()},e.prototype.stop=function(){var t;return this.pause(),this.asset.stop(),null!=(t=this.device)?t.destroy():void 0},e.prototype.seek=function(t){var e;return null!=(e=this.device)&&e.stop(),this.queue.once("ready",function(t){return function(){var e,r;if(null!=(e=t.device)&&e.seek(t.currentTime),t.playing)return null!=(r=t.device)?r.start():void 0}}(this)),t=t/1e3*this.format.sampleRate,t=this.asset.decoder.seek(t),this.currentTime=t/this.format.sampleRate*1e3|0,this.queue.reset(),this.currentTime},e.prototype.startPlaying=function(){var t,e;return t=this.queue.read(),e=0,this.device=new r.AudioDevice(this.format.sampleRate,this.format.channelsPerFrame),this.device.on("timeUpdate",function(t){return function(e){return t.currentTime=e,t.emit("progress",t.currentTime)}}(this)),this.refill=function(r){return function(i){var s,n,a,o,h,u,f;if(r.playing){for(t||(t=r.queue.read(),e=0),s=0;t&&s<i.length;){for(a=Math.min(t.length-e,i.length-s),o=0;o<a;o+=1)i[s++]=t[e++];e===t.length&&(t=r.queue.read(),e=0)}for(f=r.filters,h=0,u=f.length;h<u;h++)n=f[h],n.process(i);t||(r.queue.ended?(r.currentTime=r.duration,r.emit("progress",r.currentTime),r.emit("end"),r.stop()):r.device.stop())}}}(this),this.device.on("refill",this.refill),this.playing&&this.device.start(),this.emit("ready")},e}(r.EventEmitter),r.Filter=function(){function t(t,e){t&&e&&Object.defineProperty(this,"value",{get:function(){return t[e]}})}return t.prototype.process=function(t){},t}();var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.VolumeFilter=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.process=function(t){var e,r,i,s
;if(!(this.value>=100))for(r=Math.max(0,Math.min(100,this.value))/100,e=i=0,s=t.length;i<s;e=i+=1)t[e]*=r},e}(r.Filter);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.BalanceFilter=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return s(e,t),e.prototype.process=function(t){var e,r,i,s;if(0!==this.value)for(r=Math.max(-50,Math.min(50,this.value)),e=i=0,s=t.length;i<s;e=i+=2)t[e]*=Math.min(1,(50-r)/50),t[e+1]*=Math.min(1,(50+r)/50)},e}(r.Filter);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(t){function e(){return e.__super__.constructor.apply(this,arguments)}s(e,t),r.Demuxer.register(e),e.probe=function(t){return"caff"===t.peekString(0,4)},e.prototype.readChunk=function(){var t,e,r,i,s,n,a,o,u,f,l,c,p;if(!this.format&&this.stream.available(64)){if("caff"!==this.stream.readString(4))return this.emit("error","Invalid CAF, does not begin with 'caff'");if(this.stream.advance(4),"desc"!==this.stream.readString(4))return this.emit("error","Invalid CAF, 'caff' is not followed by 'desc'");if(0!==this.stream.readUInt32()||32!==this.stream.readUInt32())return this.emit("error","Invalid 'desc' size, should be 32");this.format={},this.format.sampleRate=this.stream.readFloat64(),this.format.formatID=this.stream.readString(4),s=this.stream.readUInt32(),"lpcm"===this.format.formatID&&(this.format.floatingPoint=Boolean(1&s),this.format.littleEndian=Boolean(2&s)),this.format.bytesPerPacket=this.stream.readUInt32(),this.format.framesPerPacket=this.stream.readUInt32(),this.format.channelsPerFrame=this.stream.readUInt32(),this.format.bitsPerChannel=this.stream.readUInt32(),this.emit("format",this.format)}for(;this.stream.available(1);){if(!this.headerCache&&(this.headerCache={type:this.stream.readString(4),oversize:0!==this.stream.readUInt32(),size:this.stream.readUInt32()},this.headerCache.oversize))return this.emit("error","Holy Shit, an oversized file, not supported in JS");switch(this.headerCache.type){case"kuki":this.stream.available(this.headerCache.size)&&("aac "===this.format.formatID?(o=this.stream.offset+this.headerCache.size,(r=h.readEsds(this.stream))&&this.emit("cookie",r),this.stream.seek(o)):(t=this.stream.readBuffer(this.headerCache.size),this.emit("cookie",t)),this.headerCache=null);break;case"pakt":if(this.stream.available(this.headerCache.size)){if(0!==this.stream.readUInt32())return this.emit("error","Sizes greater than 32 bits are not supported.");if(this.numPackets=this.stream.readUInt32(),0!==this.stream.readUInt32())return this.emit("error","Sizes greater than 32 bits are not supported.");for(this.numFrames=this.stream.readUInt32(),this.primingFrames=this.stream.readUInt32(),this.remainderFrames=this.stream.readUInt32(),this.emit("duration",this.numFrames/this.format.sampleRate*1e3|0),this.sentDuration=!0,e=0,u=0,l=0,p=this.numPackets;l<p;l+=1)this.addSeekPoint(e,u),e+=this.format.bytesPerPacket||h.readDescrLen(this.stream),u+=this.format.framesPerPacket||h.readDescrLen(this.stream);this.headerCache=null}break;case"info":for(i=this.stream.readUInt32(),a={},c=0;0<=i?c<i:c>i;0<=i?++c:--c)n=this.stream.readString(null),f=this.stream.readString(null),a[n]=f;this.emit("metadata",a),this.headerCache=null;break;case"data":this.sentFirstDataChunk||(this.stream.advance(4),this.headerCache.size-=4,0===this.format.bytesPerPacket||this.sentDuration||(this.numFrames=this.headerCache.size/this.format.bytesPerPacket,this.emit("duration",this.numFrames/this.format.sampleRate*1e3|0)),this.sentFirstDataChunk=!0),t=this.stream.readSingleBuffer(this.headerCache.size),this.headerCache.size-=t.length,this.emit("data",t),this.headerCache.size<=0&&(this.headerCache=null);break;default:this.stream.available(this.headerCache.size)&&(this.stream.advance(this.headerCache.size),this.headerCache=null)}}}})(r.Demuxer);var h,i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},n=[].indexOf||function(t){for(var e=0,r=this.length;e<r;e++)if(e in this&&this[e]===t)return e;return-1};h=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}var i,a,o,h,u,f,l,c,p,d,m;return s(e,t),r.Demuxer.register(e),a=["M4A ","M4P ","M4B ","M4V ","isom","mp42","qt  "],e.probe=function(t){var e;return"ftyp"===t.peekString(4,4)&&(e=t.peekString(8,4),n.call(a,e)>=0)},e.prototype.init=function(){return this.atoms=[],this.offsets=[],this.track=null,this.tracks=[]},u={},l={},h=function(t,e){var r,i,s,n,a;for(r=[],a=t.split(".").slice(0,-1),s=0,n=a.length;s<n;s++)i=a[s],r.push(i),l[r.join(".")]=!0;return null==u[t]&&(u[t]={}),u[t].fn=e},o=function(t,e){return null==u[t]&&(u[t]={}),u[t].after=e},e.prototype.readChunk=function(){var t,e;for(this.break=!1;this.stream.available(1)&&!this.break;){if(!this.readHeaders){if(!this.stream.available(8))return;if(this.len=this.stream.readUInt32()-8,this.type=this.stream.readString(4),0===this.len)continue;this.atoms.push(this.type),this.offsets.push(this.stream.offset+this.len),this.readHeaders=!0}if(e=this.atoms.join("."),t=u[e],null!=t?t.fn:void 0){if(!this.stream.available(this.len)&&"mdat"!==e)return;t.fn.call(this),e in l&&(this.readHeaders=!1)}else if(e in l)this.readHeaders=!1;else{if(!this.stream.available(this.len))return;this.stream.advance(this.len)}for(;this.stream.offset>=this.offsets[this.offsets.length-1];)t=u[this.atoms.join(".")],(null!=t?t.after:void 0)&&t.after.call(this),this.atoms.pop(),this.offsets.pop(),this.readHeaders=!1}},h("ftyp",function(){var t;return t=this.stream.readString(4),n.call(a,t)<0?this.emit("error","Not a valid M4A file."):this.stream.advance(this.len-4)}),h("moov.trak",function(){return this.track={},this.tracks.push(this.track)}),h("moov.trak.tkhd",function(){return this.stream.advance(4),this.stream.advance(8),this.track.id=this.stream.readUInt32(),this.stream.advance(this.len-16)}),h("moov.trak.mdia.hdlr",function(){return this.stream.advance(4),this.stream.advance(4),this.track.type=this.stream.readString(4),this.stream.advance(12),this.stream.advance(this.len-24)}),h("moov.trak.mdia.mdhd",function(){return this.stream.advance(4),this.stream.advance(8),this.track.timeScale=this.stream.readUInt32(),this.track.duration=this.stream.readUInt32(),this.stream.advance(4)}),i={ulaw:8,alaw:8,in24:24,in32:32,fl32:32,fl64:64},h("moov.trak.mdia.minf.stbl.stsd",function(){var t,e,r,s,n;return this.stream.advance(4),e=this.stream.readUInt32(),"soun"!==this.track.type?this.stream.advance(this.len-8):1!==e?this.emit("error","Only expecting one entry in sample description atom!"):(this.stream.advance(4),t=this.track.format={},t.formatID=this.stream.readString(4),this.stream.advance(6),this.stream.advance(2),r=this.stream.readUInt16(),this.stream.advance(6),t.channelsPerFrame=this.stream.readUInt16(),t.bitsPerChannel=this.stream.readUInt16(),this.stream.advance(4),t.sampleRate=this.stream.readUInt16(),this.stream.advance(2),1===r?(t.framesPerPacket=this.stream.readUInt32(),this.stream.advance(4),t.bytesPerFrame=this.stream.readUInt32(),this.stream.advance(4)):0!==r&&this.emit("error","Unknown version in stsd atom"),null!=i[t.formatID]&&(t.bitsPerChannel=i[t.formatID]),t.floatingPoint="fl32"===(s=t.formatID)||"fl64"===s,t.littleEndian="sowt"===t.formatID&&t.bitsPerChannel>8,"twos"===(n=t.formatID)||"sowt"===n||"in24"===n||"in32"===n||"fl32"===n||"fl64"===n||"raw "===n||"NONE"===n?t.formatID="lpcm":void 0)}),h("moov.trak.mdia.minf.stbl.stsd.alac",function(){return this.stream.advance(4),this.track.cookie=this.stream.readBuffer(this.len-4)}),h("moov.trak.mdia.minf.stbl.stsd.esds",function(){var t;return t=this.stream.offset+this.len,this.track.cookie=e.readEsds(this.stream),this.stream.seek(t)}),h("moov.trak.mdia.minf.stbl.stsd.wave.enda",function(){return this.track.format.littleEndian=!!this.stream.readUInt16()}),e.readDescrLen=function(t){var e,r,i;for(i=0,r=4;r--&&(e=t.readUInt8(),i=i<<7|127&e,128&e););return i},e.readEsds=function(t){var r,i,s;return t.advance(4),s=t.readUInt8(),i=e.readDescrLen(t),3===s?(t.advance(2),r=t.readUInt8(),128&r&&t.advance(2),64&r&&t.advance(t.readUInt8()),32&r&&t.advance(2)):t.advance(2),s=t.readUInt8(),i=e.readDescrLen(t),4===s&&(t.readUInt8(),t.advance(1),t.advance(3),t.advance(4),t.advance(4),s=t.readUInt8(),i=e.readDescrLen(t),5===s)?t.readBuffer(i):null},h("moov.trak.mdia.minf.stbl.stts",function(){var t,e,r;for(this.stream.advance(4),t=this.stream.readUInt32(),this.track.stts=[],e=r=0;r<t;e=r+=1)this.track.stts[e]={count:this.stream.readUInt32(),duration:this.stream.readUInt32()};return this.setupSeekPoints()}),h("moov.trak.mdia.minf.stbl.stsc",function(){var t,e,r;for(this.stream.advance(4),t=this.stream.readUInt32(),this.track.stsc=[],e=r=0;r<t;e=r+=1)this.track.stsc[e]={first:this.stream.readUInt32(),count:this.stream.readUInt32(),id:this.stream.readUInt32()};return this.setupSeekPoints()}),h("moov.trak.mdia.minf.stbl.stsz",function(){var t,e,r;if(this.stream.advance(4),this.track.sampleSize=this.stream.readUInt32(),t=this.stream.readUInt32(),0===this.track.sampleSize&&t>0)for(this.track.sampleSizes=[],e=r=0;r<t;e=r+=1)this.track.sampleSizes[e]=this.stream.readUInt32();return this.setupSeekPoints()}),h("moov.trak.mdia.minf.stbl.stco",function(){var t,e,r;for(this.stream.advance(4),t=this.stream.readUInt32(),this.track.chunkOffsets=[],e=r=0;r<t;e=r+=1)this.track.chunkOffsets[e]=this.stream.readUInt32();return this.setupSeekPoints()}),h("moov.trak.tref.chap",function(){var t,e,r;for(t=this.len>>2,this.track.chapterTracks=[],e=r=0;r<t;e=r+=1)this.track.chapterTracks[e]=this.stream.readUInt32()}),e.prototype.setupSeekPoints=function(){var t,e,r,i,s,n,a,o,h,u,f,l,c,p,d;if(null!=this.track.chunkOffsets&&null!=this.track.stsc&&null!=this.track.sampleSize&&null!=this.track.stts){for(n=0,a=0,a=0,o=0,i=0,e=0,h=0,this.track.seekPoints=[],c=this.track.chunkOffsets,d=[],t=u=0,l=c.length;u<l;t=++u){for(r=c[t],f=0,p=this.track.stsc[n].count;f<p;f+=1)this.track.seekPoints.push({offset:e,position:r,timestamp:h}),s=this.track.sampleSize||this.track.sampleSizes[i++],e+=s,r+=s,h+=this.track.stts[a].duration,a+1<this.track.stts.length&&++o===this.track.stts[a].count&&(o=0,a++);n+1<this.track.stsc.length&&t+1===this.track.stsc[n+1].first?d.push(n++):d.push(void 0)}return d}},o("moov",function(){var t,e,r,i;for(null!=this.mdatOffset&&this.stream.seek(this.mdatOffset-8),i=this.tracks,e=0,r=i.length;e<r;e++)if(t=i[e],"soun"===t.type){this.track=t;break}return"soun"!==this.track.type?(this.track=null,this.emit("error","No audio tracks in m4a file.")):(this.emit("format",this.track.format),this.emit("duration",this.track.duration/this.track.timeScale*1e3|0),this.track.cookie&&this.emit("cookie",this.track.cookie),this.seekPoints=this.track.seekPoints)}),h("mdat",function(){var t,e,r,i,s,n,a,o;if(!this.startedData){if(null==this.mdatOffset&&(this.mdatOffset=this.stream.offset),0===this.tracks.length)return t=Math.min(this.stream.remainingBytes(),this.len),this.stream.advance(t),void(this.len-=t);this.chunkIndex=0,this.stscIndex=0,this.sampleIndex=0,this.tailOffset=0,this.tailSamples=0,this.startedData=!0}if(!this.readChapters){if(this.readChapters=this.parseChapters(),this.break=!this.readChapters)return;this.stream.seek(this.mdatOffset)}if(s=this.track.chunkOffsets[this.chunkIndex]+this.tailOffset,r=0,!this.stream.available(s-this.stream.offset))return void(this.break=!0);for(this.stream.seek(s);this.chunkIndex<this.track.chunkOffsets.length;){for(i=this.track.stsc[this.stscIndex].count-this.tailSamples,e=0,n=o=0;o<i&&(a=this.track.sampleSize||this.track.sampleSizes[this.sampleIndex],this.stream.available(r+a));n=o+=1)r+=a,e+=a,this.sampleIndex++;if(n<i){this.tailOffset+=e,this.tailSamples+=n;break}if(this.chunkIndex++,this.tailOffset=0,this.tailSamples=0,this.stscIndex+1<this.track.stsc.length&&this.chunkIndex+1===this.track.stsc[this.stscIndex+1].first&&this.stscIndex++,s+r!==this.track.chunkOffsets[this.chunkIndex])break}return r>0?(this.emit("data",this.stream.readBuffer(r)),this.break=this.chunkIndex===this.track.chunkOffsets.length):this.break=!0}),e.prototype.parseChapters=function(){var t,e,r,i,s,n,a,o,h,u,f,l,c;if(!((null!=(u=this.track.chapterTracks)?u.length:void 0)>0))return!0;for(e=this.track.chapterTracks[0],f=this.tracks,o=0,h=f.length;o<h&&(a=f[o],a.id!==e);o++);for(a.id!==e&&this.emit("error","Chapter track does not exist."),null==this.chapters&&(this.chapters=[]);this.chapters.length<a.seekPoints.length;){if(s=a.seekPoints[this.chapters.length],!this.stream.available(s.position-this.stream.offset+32))return!1;if(this.stream.seek(s.position),r=this.stream.readUInt16(),n=null,!this.stream.available(r))return!1;r>2&&(65279!==(t=this.stream.peekUInt16())&&65534!==t||(n=this.stream.readString(r,"utf16-bom"))),null==n&&(n=this.stream.readString(r,"utf8")),i=null!=(l=null!=(c=a.seekPoints[this.chapters.length+1])?c.timestamp:void 0)?l:a.duration,this.chapters.push({title:n,timestamp:s.timestamp/a.timeScale*1e3|0,duration:(i-s.timestamp)/a.timeScale*1e3|0})}return this.emit("chapters",this.chapters),!0},h("moov.udta.meta",function(){return this.metadata={},this.stream.advance(4)}),o("moov.udta.meta",function(){return this.emit("metadata",this.metadata)}),d=function(t,e,r){return h("moov.udta.meta.ilst."+t+".data",function(){return this.stream.advance(8),this.len-=8,r.call(this,e)})},m=function(t){return this.metadata[t]=this.stream.readString(this.len,"utf8")},d("©alb","album",m),d("©arg","arranger",m),d("©art","artist",m),d("©ART","artist",m),d("aART","albumArtist",m),d("catg","category",m),d("©com","composer",m),d("©cpy","copyright",m),d("cprt","copyright",m),d("©cmt","comments",m),d("©day","releaseDate",m),d("desc","description",m),d("©gen","genre",m),d("©grp","grouping",m),d("©isr","ISRC",m),d("keyw","keywords",m),d("©lab","recordLabel",m),d("ldes","longDescription",m),d("©lyr","lyrics",m),d("©nam","title",m),d("©phg","recordingCopyright",m),d("©prd","producer",m),d("©prf","performers",m),d("purd","purchaseDate",m),d("purl","podcastURL",m),d("©swf","songwriter",m),d("©too","encoder",m),d("©wrt","composer",m),d("covr","coverArt",function(t){return this.metadata[t]=this.stream.readBuffer(this.len)}),p=["Blues","Classic Rock","Country","Dance","Disco","Funk","Grunge","Hip-Hop","Jazz","Metal","New Age","Oldies","Other","Pop","R&B","Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska","Death Metal","Pranks","Soundtrack","Euro-Techno","Ambient","Trip-Hop","Vocal","Jazz+Funk","Fusion","Trance","Classical","Instrumental","Acid","House","Game","Sound Clip","Gospel","Noise","AlternRock","Bass","Soul","Punk","Space","Meditative","Instrumental Pop","Instrumental Rock","Ethnic","Gothic","Darkwave","Techno-Industrial","Electronic","Pop-Folk","Eurodance","Dream","Southern Rock","Comedy","Cult","Gangsta","Top 40","Christian Rap","Pop/Funk","Jungle","Native American","Cabaret","New Wave","Psychadelic","Rave","Showtunes","Trailer","Lo-Fi","Tribal","Acid Punk","Acid Jazz","Polka","Retro","Musical","Rock & Roll","Hard Rock","Folk","Folk/Rock","National Folk","Swing","Fast Fusion","Bebob","Latin","Revival","Celtic","Bluegrass","Avantgarde","Gothic Rock","Progressive Rock","Psychedelic Rock","Symphonic Rock","Slow Rock","Big Band","Chorus","Easy Listening","Acoustic","Humour","Speech","Chanson","Opera","Chamber Music","Sonata","Symphony","Booty Bass","Primus","Porn Groove","Satire","Slow Jam","Club","Tango","Samba","Folklore","Ballad","Power Ballad","Rhythmic Soul","Freestyle","Duet","Punk Rock","Drum Solo","A Capella","Euro-House","Dance Hall"],d("gnre","genre",function(t){return this.metadata[t]=p[this.stream.readUInt16()-1]}),d("tmpo","tempo",function(t){return this.metadata[t]=this.stream.readUInt16()}),d("rtng","rating",function(t){var e;return e=this.stream.readUInt8(),this.metadata[t]=2===e?"Clean":0!==e?"Explicit":"None"}),c=function(t){return this.stream.advance(2),this.metadata[t]=this.stream.readUInt16()+" of "+this.stream.readUInt16(),this.stream.advance(this.len-6)},d("disk","diskNumber",c),d("trkn","trackNumber",c),f=function(t){return this.metadata[t]=1===this.stream.readUInt8()},d("cpil","compilation",f),d("pcst","podcast",f),d("pgap","gapless",f),e}(r.Demuxer);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(t){function e(){return e.__super__.constructor.apply(this,arguments)}s(e,t),r.Demuxer.register(e),e.probe=function(t){var e;return"FORM"===t.peekString(0,4)&&("AIFF"===(e=t.peekString(8,4))||"AIFC"===e)},e.prototype.readChunk=function(){var t,e,r,i;if(!this.readStart&&this.stream.available(12)){if("FORM"!==this.stream.readString(4))return this.emit("error","Invalid AIFF.");if(this.fileSize=this.stream.readUInt32(),this.fileType=this.stream.readString(4),this.readStart=!0,"AIFF"!==(i=this.fileType)&&"AIFC"!==i)return this.emit("error","Invalid AIFF.")}for(;this.stream.available(1);){switch(!this.readHeaders&&this.stream.available(8)&&(this.type=this.stream.readString(4),this.len=this.stream.readUInt32()),this.type){case"COMM":if(!this.stream.available(this.len))return;this.format={formatID:"lpcm",channelsPerFrame:this.stream.readUInt16(),sampleCount:this.stream.readUInt32(),bitsPerChannel:this.stream.readUInt16(),sampleRate:this.stream.readFloat80(),framesPerPacket:1,littleEndian:!1,floatingPoint:!1},this.format.bytesPerPacket=this.format.bitsPerChannel/8*this.format.channelsPerFrame,"AIFC"===this.fileType&&(e=this.stream.readString(4),this.format.littleEndian="sowt"===e&&this.format.bitsPerChannel>8,this.format.floatingPoint="fl32"===e||"fl64"===e,"twos"!==e&&"sowt"!==e&&"fl32"!==e&&"fl64"!==e&&"NONE"!==e||(e="lpcm"),this.format.formatID=e,this.len-=4),this.stream.advance(this.len-18),this.emit("format",this.format),this.emit("duration",this.format.sampleCount/this.format.sampleRate*1e3|0);break;case"SSND":this.readSSNDHeader&&this.stream.available(4)||(r=this.stream.readUInt32(),this.stream.advance(4),this.stream.advance(r),this.readSSNDHeader=!0),t=this.stream.readSingleBuffer(this.len),this.len-=t.length,this.readHeaders=this.len>0,this.emit("data",t);break;default:if(!this.stream.available(this.len))return;this.stream.advance(this.len)}"SSND"!==this.type&&(this.readHeaders=!1)}}})(r.Demuxer);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(t){function e(){return e.__super__.constructor.apply(this,arguments)}var i;s(e,t),r.Demuxer.register(e),e.probe=function(t){return"RIFF"===t.peekString(0,4)&&"WAVE"===t.peekString(8,4)},i={1:"lpcm",3:"lpcm",6:"alaw",7:"ulaw"},e.prototype.readChunk=function(){var t,e,r;if(!this.readStart&&this.stream.available(12)){if("RIFF"!==this.stream.readString(4))return this.emit("error","Invalid WAV file.");if(this.fileSize=this.stream.readUInt32(!0),this.readStart=!0,"WAVE"!==this.stream.readString(4))return this.emit("error","Invalid WAV file.")}for(;this.stream.available(1);){switch(!this.readHeaders&&this.stream.available(8)&&(this.type=this.stream.readString(4),this.len=this.stream.readUInt32(!0)),this.type){case"fmt ":if(!((r=this.stream.readUInt16(!0))in i))return this.emit("error","Unsupported format in WAV file.");this.format={formatID:i[r],floatingPoint:3===r,littleEndian:"lpcm"===i[r],channelsPerFrame:this.stream.readUInt16(!0),sampleRate:this.stream.readUInt32(!0),framesPerPacket:1},this.stream.advance(4),this.stream.advance(2),this.format.bitsPerChannel=this.stream.readUInt16(!0),this.format.bytesPerPacket=this.format.bitsPerChannel/8*this.format.channelsPerFrame,this.emit("format",this.format),this.stream.advance(this.len-16);break;case"data":this.sentDuration||(e=this.format.bitsPerChannel/8,this.emit("duration",this.len/e/this.format.channelsPerFrame/this.format.sampleRate*1e3|0),this.sentDuration=!0),t=this.stream.readSingleBuffer(this.len),this.len-=t.length,this.readHeaders=this.len>0,this.emit("data",t);break;default:if(!this.stream.available(this.len))return;this.stream.advance(this.len)}"data"!==this.type&&(this.readHeaders=!1)}}})(r.Demuxer);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(t){function e(){return e.__super__.constructor.apply(this,arguments)}var i,n;s(e,t),r.Demuxer.register(e),e.probe=function(t){return".snd"===t.peekString(0,4)},i=[8,8,16,24,32,32,64],i[26]=8,n={1:"ulaw",27:"alaw"},e.prototype.readChunk=function(){var t,e,r;if(!this.readHeader&&this.stream.available(24)){if(".snd"!==this.stream.readString(4))return this.emit("error","Invalid AU file.");if(this.stream.readUInt32(),e=this.stream.readUInt32(),r=this.stream.readUInt32(),this.format={formatID:n[r]||"lpcm",littleEndian:!1,floatingPoint:6===r||7===r,bitsPerChannel:i[r-1],sampleRate:this.stream.readUInt32(),channelsPerFrame:this.stream.readUInt32(),framesPerPacket:1},null==this.format.bitsPerChannel)return this.emit("error","Unsupported encoding in AU file.");this.format.bytesPerPacket=this.format.bitsPerChannel/8*this.format.channelsPerFrame,4294967295!==e&&(t=this.format.bitsPerChannel/8,this.emit("duration",e/t/this.format.channelsPerFrame/this.format.sampleRate*1e3|0)),this.emit("format",this.format),this.readHeader=!0}if(this.readHeader)for(;this.stream.available(1);)this.emit("data",this.stream.readSingleBuffer(this.stream.remainingBytes()))}})(r.Demuxer);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(t){function e(){return this.readChunk=o(this.readChunk,this),e.__super__.constructor.apply(this,arguments)}s(e,t),r.Decoder.register("lpcm",e),e.prototype.readChunk=function(){var t,e,r,i,s,n,a,o,h,u,f,l;if(n=this.stream,r=this.format.littleEndian,t=Math.min(4096,n.remainingBytes()),s=t/(this.format.bitsPerChannel/8)|0,t<this.format.bitsPerChannel/8)return null;if(this.format.floatingPoint)switch(this.format.bitsPerChannel){case 32:for(i=new Float32Array(s),e=a=0;a<s;e=a+=1)i[e]=n.readFloat32(r);break;case 64:for(i=new Float64Array(s),e=o=0;o<s;e=o+=1)i[e]=n.readFloat64(r);break;default:throw new Error("Unsupported bit depth.")}else switch(this.format.bitsPerChannel){case 8:for(i=new Int8Array(s),e=h=0;h<s;e=h+=1)i[e]=n.readInt8();break;case 16:for(i=new Int16Array(s),e=u=0;u<s;e=u+=1)i[e]=n.readInt16(r);break;case 24:for(i=new Int32Array(s),e=f=0;f<s;e=f+=1)i[e]=n.readInt24(r);break;case 32:for(i=new Int32Array(s),e=l=0;l<s;e=l+=1)i[e]=n.readInt32(r);break;default:throw new Error("Unsupported bit depth.")}return i}})(r.Decoder);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(t){function e(){return this.readChunk=o(this.readChunk,this),e.__super__.constructor.apply(this,arguments)}var i,n,a,h,u;s(e,t),r.Decoder.register("ulaw",e),r.Decoder.register("alaw",e),u=128,n=15,h=4,a=112,i=132,e.prototype.init=function(){var t,e,r,s,o,f,l;if(this.format.bitsPerChannel=16,this.table=s=new Int16Array(256),"ulaw"===this.format.formatID)for(t=f=0;f<256;t=++f)o=~t,r=((o&n)<<3)+i,r<<=(o&a)>>>h,s[t]=o&u?i-r:r-i;else for(t=l=0;l<256;t=++l)o=85^t,r=o&n,e=(o&a)>>>h,r=e?r+r+1+32<<e+2:r+r+1<<3,s[t]=o&u?r:-r},e.prototype.readChunk=function(){var t,e,r,i,s,n;if(i=this.stream,s=this.table,0!==(r=Math.min(4096,this.stream.remainingBytes()))){for(e=new Int16Array(r),t=n=0;n<r;t=n+=1)e[t]=s[i.readUInt8()];return e}}})(r.Decoder);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.HTTPSource=function(t){function e(t){this.url=t,this.chunkSize=1<<20,this.inflight=!1,this.reset()}return s(e,t),e.prototype.start=function(){return this.length&&!this.inflight?this.loop():(this.inflight=!0,this.xhr=new XMLHttpRequest,this.xhr.onload=function(t){return function(e){return t.length=parseInt(t.xhr.getResponseHeader("Content-Length")),t.inflight=!1,t.loop()}}(this),this.xhr.onerror=function(t){return function(e){return t.pause(),t.emit("error",e)}}(this),this.xhr.onabort=function(t){return function(e){return t.inflight=!1}}(this),this.xhr.open("HEAD",this.url,!0),this.xhr.send(null))},e.prototype.loop=function(){var t;return this.inflight||!this.length?this.emit("error","Something is wrong in HTTPSource.loop"):(this.inflight=!0,this.xhr=new XMLHttpRequest,this.xhr.onload=function(t){return function(e){var i,s,n,a,o,h;if(t.xhr.response)i=new Uint8Array(t.xhr.response);else for(a=t.xhr.responseText,i=new Uint8Array(a.length),n=o=0,h=a.length;0<=h?o<h:o>h;n=0<=h?++o:--o)i[n]=255&a.charCodeAt(n);if(s=new r.Buffer(i),t.offset+=s.length,t.emit("data",s),t.offset>=t.length&&t.emit("end"),t.inflight=!1,!(t.offset>=t.length))return t.loop()}}(this),this.xhr.onprogress=function(t){return function(e){return t.emit("progress",(t.offset+e.loaded)/t.length*100)}}(this),this.xhr.onerror=function(t){return function(e){return t.emit("error",e),t.pause()}}(this),this.xhr.onabort=function(t){return function(e){return t.inflight=!1}}(this),this.xhr.open("GET",this.url,!0),this.xhr.responseType="arraybuffer",t=Math.min(this.offset+this.chunkSize,this.length),this.xhr.setRequestHeader("Range","bytes="+this.offset+"-"+t),this.xhr.overrideMimeType("text/plain; charset=x-user-defined"),this.xhr.send(null))},e.prototype.pause=function(){var t;return this.inflight=!1,null!=(t=this.xhr)?t.abort():void 0},e.prototype.reset=function(){return this.pause(),this.offset=0},e}(r.EventEmitter);var i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};r.FileSource=function(t){function e(t){if(this.file=t,"undefined"==typeof FileReader||null===FileReader)return this.emit("error","This browser does not have FileReader support.");this.offset=0,this.length=this.file.size,this.chunkSize=1<<20,this.file[this.slice="slice"]||this.file[this.slice="webkitSlice"]||this.file[this.slice="mozSlice"]}return s(e,t),e.prototype.start=function(){return this.reader&&!this.active?this.loop():(this.reader=new FileReader,this.active=!0,this.reader.onload=function(t){return function(e){var i;if(i=new r.Buffer(new Uint8Array(e.target.result)),t.offset+=i.length,t.emit("data",i),t.active=!1,t.offset<t.length)return t.loop()}}(this),this.reader.onloadend=function(t){return function(){if(t.offset===t.length)return t.emit("end"),t.reader=null}}(this),this.reader.onerror=function(t){return function(e){return t.emit("error",e)}}(this),this.reader.onprogress=function(t){return function(e){return t.emit("progress",(t.offset+e.loaded)/t.length*100)}}(this),this.loop())},e.prototype.loop=function(){var t,e;return this.active=!0,e=Math.min(this.offset+this.chunkSize,this.length),t=this.file[this.slice](this.offset,e),this.reader.readAsArrayBuffer(t)},e.prototype.pause=function(){var t;this.active=!1;try{return null!=(t=this.reader)?t.abort():void 0}catch(t){}},e.prototype.reset=function(){return this.pause(),this.offset=0},e}(r.EventEmitter),t.prototype.initialize=function(){if(!(this.fromSampleRate>0&&this.toSampleRate>0&&this.channels>0))throw new Error("Invalid settings specified for the resampler.");this.fromSampleRate==this.toSampleRate?(this.resampler=this.bypassResampler,this.ratioWeight=1):(this.fromSampleRate<this.toSampleRate?(this.compileLinearInterpolationFunction(),this.lastWeight=1):(this.compileMultiTapFunction(),this.tailExists=!1,this.lastWeight=0),this.ratioWeight=this.fromSampleRate/this.toSampleRate,this.initializeBuffers())},t.prototype.compileLinearInterpolationFunction=function(){for(var t="var bufferLength = buffer.length;\tvar outLength = this.outputBufferSize;\tif ((bufferLength % "+this.channels+") == 0) {\t\tif (bufferLength > 0) {\t\t\tvar ratioWeight = this.ratioWeight;\t\t\tvar weight = this.lastWeight;\t\t\tvar firstWeight = 0;\t\t\tvar secondWeight = 0;\t\t\tvar sourceOffset = 0;\t\t\tvar outputOffset = 0;\t\t\tvar outputBuffer = this.outputBuffer;\t\t\tfor (; weight < 1; weight += ratioWeight) {\t\t\t\tsecondWeight = weight % 1;\t\t\t\tfirstWeight = 1 - secondWeight;",e=0;e<this.channels;++e)t+="outputBuffer[outputOffset++] = (this.lastOutput["+e+"] * firstWeight) + (buffer["+e+"] * secondWeight);";t+="}\t\t\tweight -= 1;\t\t\tfor (bufferLength -= "+this.channels+", sourceOffset = Math.floor(weight) * "+this.channels+"; outputOffset < outLength && sourceOffset < bufferLength;) {\t\t\t\tsecondWeight = weight % 1;\t\t\t\tfirstWeight = 1 - secondWeight;";for(var e=0;e<this.channels;++e)t+="outputBuffer[outputOffset++] = (buffer[sourceOffset"+(e>0?" + "+e:"")+"] * firstWeight) + (buffer[sourceOffset + "+(this.channels+e)+"] * secondWeight);";t+="weight += ratioWeight;\t\t\t\tsourceOffset = Math.floor(weight) * "+this.channels+";\t\t\t}";for(var e=0;e<this.channels;++e)t+="this.lastOutput["+e+"] = buffer[sourceOffset++];";t+='this.lastWeight = weight % 1;\t\t\treturn this.bufferSlice(outputOffset);\t\t}\t\telse {\t\t\treturn (this.noReturn) ? 0 : [];\t\t}\t}\telse {\t\tthrow(new Error("Buffer was of incorrect sample length."));\t}',this.resampler=Function("buffer",t)},t.prototype.compileMultiTapFunction=function(){for(var t="var bufferLength = buffer.length;\tvar outLength = this.outputBufferSize;\tif ((bufferLength % "+this.channels+") == 0) {\t\tif (bufferLength > 0) {\t\t\tvar ratioWeight = this.ratioWeight;\t\t\tvar weight = 0;",e=0;e<this.channels;++e)t+="var output"+e+" = 0;";for(t+="var actualPosition = 0;\t\t\tvar amountToNext = 0;\t\t\tvar alreadyProcessedTail = !this.tailExists;\t\t\tthis.tailExists = false;\t\t\tvar outputBuffer = this.outputBuffer;\t\t\tvar outputOffset = 0;\t\t\tvar currentPosition = 0;\t\t\tdo {\t\t\t\tif (alreadyProcessedTail) {\t\t\t\t\tweight = ratioWeight;",e=0;e<this.channels;++e)t+="output"+e+" = 0;";for(t+="}\t\t\t\telse {\t\t\t\t\tweight = this.lastWeight;",e=0;e<this.channels;++e)t+="output"+e+" = this.lastOutput["+e+"];";for(t+="alreadyProcessedTail = true;\t\t\t\t}\t\t\t\twhile (weight > 0 && actualPosition < bufferLength) {\t\t\t\t\tamountToNext = 1 + actualPosition - currentPosition;\t\t\t\t\tif (weight >= amountToNext) {",e=0;e<this.channels;++e)t+="output"+e+" += buffer[actualPosition++] * amountToNext;";for(t+="currentPosition = actualPosition;\t\t\t\t\t\tweight -= amountToNext;\t\t\t\t\t}\t\t\t\t\telse {",e=0;e<this.channels;++e)t+="output"+e+" += buffer[actualPosition"+(e>0?" + "+e:"")+"] * weight;";for(t+="currentPosition += weight;\t\t\t\t\t\tweight = 0;\t\t\t\t\t\tbreak;\t\t\t\t\t}\t\t\t\t}\t\t\t\tif (weight == 0) {",e=0;e<this.channels;++e)t+="outputBuffer[outputOffset++] = output"+e+" / ratioWeight;";for(t+="}\t\t\t\telse {\t\t\t\t\tthis.lastWeight = weight;",e=0;e<this.channels;++e)t+="this.lastOutput["+e+"] = output"+e+";";t+='this.tailExists = true;\t\t\t\t\tbreak;\t\t\t\t}\t\t\t} while (actualPosition < bufferLength && outputOffset < outLength);\t\t\treturn this.bufferSlice(outputOffset);\t\t}\t\telse {\t\t\treturn (this.noReturn) ? 0 : [];\t\t}\t}\telse {\t\tthrow(new Error("Buffer was of incorrect sample length."));\t}',this.resampler=Function("buffer",t)},t.prototype.bypassResampler=function(t){
return this.noReturn?(this.outputBuffer=t,t.length):t},t.prototype.bufferSlice=function(t){if(this.noReturn)return t;try{return this.outputBuffer.subarray(0,t)}catch(e){try{return this.outputBuffer.length=t,this.outputBuffer}catch(e){return this.outputBuffer.slice(0,t)}}},t.prototype.initializeBuffers=function(){try{this.outputBuffer=new Float32Array(this.outputBufferSize),this.lastOutput=new Float32Array(this.channels)}catch(t){this.outputBuffer=[],this.lastOutput=[]}};var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(i){function n(e,r){this.sampleRate=e,this.channels=r,this.refill=o(this.refill,this),this.context=null!=u?u:u=new a,this.deviceSampleRate=this.context.sampleRate,this.bufferSize=Math.ceil(4096/(this.deviceSampleRate/this.sampleRate)*this.channels),this.bufferSize+=this.bufferSize%this.channels,this.deviceSampleRate!==this.sampleRate&&(this.resampler=new t(this.sampleRate,this.deviceSampleRate,this.channels,4096*this.channels)),this.node=this.context[h](4096,this.channels,this.channels),this.node.onaudioprocess=this.refill,this.node.connect(this.context.destination)}var a,h,u;s(n,i),r.AudioDevice.register(n),a=e.AudioContext||e.webkitAudioContext,n.supported=a&&("function"==typeof a.prototype[h="createScriptProcessor"]||"function"==typeof a.prototype[h="createJavaScriptNode"]),u=null,n.prototype.refill=function(t){var e,r,i,s,n,a,o,h,u,f;for(a=t.outputBuffer,e=a.numberOfChannels,r=new Array(e),s=o=0;o<e;s=o+=1)r[s]=a.getChannelData(s);for(i=new Float32Array(this.bufferSize),this.emit("refill",i),this.resampler&&(i=this.resampler.resampler(i)),s=h=0,f=a.length;h<f;s=h+=1)for(n=u=0;u<e;n=u+=1)r[n][s]=i[s*e+n]},n.prototype.destroy=function(){return this.node.disconnect(0)},n.prototype.getDeviceTime=function(){return this.context.currentTime*this.sampleRate}})(r.EventEmitter);var o=function(t,e){return function(){return t.apply(e,arguments)}},i={}.hasOwnProperty,s=function(t,e){function r(){this.constructor=t}for(var s in e)i.call(e,s)&&(t[s]=e[s]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t};(function(t){function e(t,e){this.sampleRate=t,this.channels=e,this.refill=o(this.refill,this),this.audio=new Audio,this.audio.mozSetup(this.channels,this.sampleRate),this.writePosition=0,this.prebufferSize=this.sampleRate/2,this.tail=null,this.timer=i(this.refill,100)}var i,n;return s(e,t),r.AudioDevice.register(e),e.supported="undefined"!=typeof Audio&&null!==Audio&&"mozWriteAudio"in new Audio,e.prototype.refill=function(){var t,e,r,i;this.tail&&(i=this.audio.mozWriteAudio(this.tail),this.writePosition+=i,this.writePosition<this.tail.length?this.tail=this.tail.subarray(i):this.tail=null),r=this.audio.mozCurrentSampleOffset(),(t=r+this.prebufferSize-this.writePosition)>0&&(e=new Float32Array(t),this.emit("refill",e),i=this.audio.mozWriteAudio(e),i<e.length&&(this.tail=e.subarray(i)),this.writePosition+=i)},e.prototype.destroy=function(){return n(this.timer)},e.prototype.getDeviceTime=function(){return this.audio.mozCurrentSampleOffset()/this.channels},i=function(t,e){var i,s;return null==(i=r.Buffer.makeBlobURL("setInterval(function() { postMessage('ping'); }, "+e+");"))?setInterval(t,e):(s=new Worker(i),s.onmessage=t,s.url=i,s)},n=function(t){return t.terminate?(t.terminate(),URL.revokeObjectURL(t.url)):clearInterval(t)},e})(r.EventEmitter),e.AV=r}(),function(){AV.Demuxer.extend(function(){AV.Demuxer.register(this),this.probe=function(t){return"fLaC"===t.peekString(0,4)};this.prototype.readChunk=function(){var t=this.stream;if(!this.readHeader&&t.available(4)){if("fLaC"!==t.readString(4))return this.emit("error","Invalid FLAC file.");this.readHeader=!0}for(;t.available(1)&&!this.last;){if(!this.readBlockHeaders){var e=t.readUInt8();this.last=128==(128&e),this.type=127&e,this.size=t.readUInt24()}if(!this.foundStreamInfo&&0!==this.type)return this.emit("error","STREAMINFO must be the first block");if(!t.available(this.size))return;switch(this.type){case 0:if(this.foundStreamInfo)return this.emit("error","STREAMINFO can only occur once.");if(34!==this.size)return this.emit("error","STREAMINFO size is wrong.");this.foundStreamInfo=!0;var r=new AV.Bitstream(t),i={minBlockSize:r.read(16),maxBlockSize:r.read(16),minFrameSize:r.read(24),maxFrameSize:r.read(24)};this.format={formatID:"flac",sampleRate:r.read(20),channelsPerFrame:r.read(3)+1,bitsPerChannel:r.read(5)+1},this.emit("format",this.format),this.emit("cookie",i);var s=r.read(36);this.emit("duration",s/this.format.sampleRate*1e3|0),t.advance(16),this.readBlockHeaders=!1;break;case 3:for(var n=0;n<this.size/18;n++)if(4294967295==t.peekUInt32(0)&&4294967295==t.peekUInt32(1))t.advance(18);else{t.readUInt32()>0&&this.emit("error","Seek points with sample number >UInt32 not supported");var a=t.readUInt32();t.readUInt32()>0&&this.emit("error","Seek points with stream offset >UInt32 not supported");var o=t.readUInt32();t.advance(2),this.addSeekPoint(o,a)}break;case 4:this.metadata||(this.metadata={});var h=t.readUInt32(!0);this.metadata.vendor=t.readString(h);for(var u=t.readUInt32(!0),f=0;f<u;f++){h=t.readUInt32(!0);var l=t.readString(h,"utf8"),c=l.indexOf("=");this.metadata[l.slice(0,c).toLowerCase()]=l.slice(c+1)}break;case 6:if(3!==t.readUInt32())t.advance(this.size-4);else{var p=t.readUInt32(),d=(t.readString(p),t.readUInt32()),u=(t.readString(d),t.readUInt32(),t.readUInt32(),t.readUInt32(),t.readUInt32(),t.readUInt32()),m=t.readBuffer(u);this.metadata||(this.metadata={}),this.metadata.coverArt=m}break;default:t.advance(this.size),this.readBlockHeaders=!1}this.last&&this.metadata&&this.emit("metadata",this.metadata)}for(;t.available(1)&&this.last;){var v=t.readSingleBuffer(t.remainingBytes());this.emit("data",v)}}}),AV.Decoder.extend(function(){function t(t){for(var e=0,r=0;;){if(r=t>>>24)break;if(e+=8,255&(r=t>>>16))break;if(e+=8,255&(r=t>>>8))break;if(e+=8,255&(r=t))break;return e+=8}return 240&r?r>>>=4:e+=4,8&r?e:4&r?e+1:2&r?e+2:1&r?e+3:e+4}AV.Decoder.register("flac",this),this.prototype.setCookie=function(t){this.cookie=t,this.decoded=[];for(var e=0;e<this.format.channelsPerFrame;e++)this.decoded[e]=new Int32Array(t.maxBlockSize)};const e=new Int16Array([0,192,576,1152,2304,4608,0,0,256,512,1024,2048,4096,8192,16384,32768]),r=new Int32Array([0,88200,176400,192e3,8e3,16e3,22050,24e3,32e3,44100,48e3,96e3,0,0,0,0]),i=new Int8Array([0,8,12,0,16,20,24,0]);this.prototype.readChunk=function(){var t=this.bitstream;if(t.available(32)){if(32764!=(32767&t.read(15)))throw new Error("Invalid sync code");var s=(t.read(1),t.read(4)),n=t.read(4),a=t.read(4),o=t.read(3);t.advance(1),this.chMode=a;var h;if(a<8)h=a+1,this.chMode=0;else{if(!(a<=10))throw new Error("Invalid channel mode");h=2}if(h!==this.format.channelsPerFrame)throw new Error("Switching channel layout mid-stream not supported.");if(3===o||7===o)throw new Error("Invalid sample size code");if(this.bps=i[o],this.bps!==this.format.bitsPerChannel)throw new Error("Switching bits per sample mid-stream not supported.");var u,f;this.bps>16?(u=32-this.bps,f=!0):(u=16-this.bps,f=!1);for(var l=0;1===t.read(1);)l++;for(var c=t.read(7-l);l>1;l--)t.advance(2),c=c<<6|t.read(6);if(0===s)throw new Error("Reserved blocksize code");this.blockSize=6===s?t.read(8)+1:7===s?t.read(16)+1:e[s];if(n<12)r[n];else if(12===n)1e3*t.read(8);else if(13===n)t.read(16);else{if(14!==n)throw new Error("Invalid sample rate code");10*t.read(16)}t.advance(8);for(var p=0;p<h;p++)this.decodeSubframe(p);t.align(),t.advance(16);var d=new ArrayBuffer(this.blockSize*h*this.bps/8),m=f?new Int32Array(d):new Int16Array(d),v=this.blockSize,y=this.decoded,k=0;switch(this.chMode){case 0:for(var b=0;b<v;b++)for(var p=0;p<h;p++)m[k++]=y[p][b]<<u;break;case 8:for(var p=0;p<v;p++){var g=y[0][p],w=y[1][p];m[k++]=g<<u,m[k++]=g-w<<u}break;case 9:for(var p=0;p<v;p++){var g=y[0][p],w=y[1][p];m[k++]=g+w<<u,m[k++]=w<<u}break;case 10:for(var p=0;p<v;p++){var g=y[0][p],w=y[1][p];g-=w>>1,m[k++]=g+w<<u,m[k++]=g<<u}}return m}},this.prototype.decodeSubframe=function(t){var e=0,r=this.bitstream,i=this.blockSize,s=this.decoded;if(this.curr_bps=this.bps,0===t?9===this.chMode&&this.curr_bps++:8!==this.chMode&&10!==this.chMode||this.curr_bps++,r.read(1))throw new Error("Invalid subframe padding");var n=r.read(6);if(r.read(1)){for(e=1;!r.read(1);)e++;this.curr_bps-=e}if(this.curr_bps>32)throw new Error("decorrelated bit depth > 32 ("+this.curr_bps+")");if(0===n)for(var a=r.read(this.curr_bps,!0),o=0;o<i;o++)s[t][o]=a;else if(1===n)for(var h=this.curr_bps,o=0;o<i;o++)s[t][o]=r.read(h,!0);else if(n>=8&&n<=12)this.decode_subframe_fixed(t,-9&n);else{if(!(n>=32))throw new Error("Invalid coding type");this.decode_subframe_lpc(t,1+(-33&n))}if(e)for(var o=0;o<i;o++)s[t][o]<<=e},this.prototype.decode_subframe_fixed=function(t,e){for(var r=this.decoded[t],i=this.bitstream,s=this.curr_bps,n=0;n<e;n++)r[n]=i.read(s,!0);this.decode_residuals(t,e);var a=0,o=0,h=0,u=0;switch(e>0&&(a=r[e-1]),e>1&&(o=a-r[e-2]),e>2&&(h=o-r[e-2]+r[e-3]),e>3&&(u=h-r[e-2]+2*r[e-3]-r[e-4]),e){case 0:break;case 1:case 2:case 3:case 4:for(var f=new Int32Array([a,o,h,u]),l=this.blockSize,n=e;n<l;n++){f[e-1]+=r[n];for(var c=e-2;c>=0;c--)f[c]+=f[c+1];r[n]=f[0]}break;default:throw new Error("Invalid Predictor Order "+e)}},this.prototype.decode_subframe_lpc=function(t,e){for(var r=this.bitstream,i=this.decoded[t],s=this.curr_bps,n=this.blockSize,a=0;a<e;a++)i[a]=r.read(s,!0);var o=r.read(4)+1;if(16===o)throw new Error("Invalid coefficient precision");var h=r.read(5,!0);if(h<0)throw new Error("Negative qlevel, maybe buggy stream");for(var u=new Int32Array(32),a=0;a<e;a++)u[a]=r.read(o,!0);if(this.decode_residuals(t,e),this.bps>16)throw new Error("no 64-bit integers in JS, could probably use doubles though");for(var a=e;a<n-1;a+=2){for(var f,l=i[a-e],c=0,p=0,d=e-1;d>0;d--)f=u[d],c+=f*l,l=i[a-d],p+=f*l;f=u[0],c+=f*l,l=i[a]+=c>>h,p+=f*l,i[a+1]+=p>>h}if(a<n){for(var m=0,d=0;d<e;d++)m+=u[d]*i[a-d-1];i[a]+=m>>h}};this.prototype.decode_residuals=function(t,e){var r=this.bitstream,i=r.read(2);if(i>1)throw new Error("Illegal residual coding method "+i);var s=r.read(4),n=this.blockSize>>>s;if(e>n)throw new Error("Invalid predictor order "+e+" > "+n);for(var a=this.decoded[t],o=e,h=e,u=0;u<1<<s;u++){var f=r.read(0===i?4:5);if(f===(0===i?15:31))for(f=r.read(5);h<n;h++)a[o++]=r.read(f,!0);else for(;h<n;h++)a[o++]=this.golomb(f,32767,0);h=0}};this.prototype.golomb=function(e,r,i){var s=this.bitstream,n=s.bitPosition,a=s.peek(32-n)<<n,o=0,h=31-t(1|a);if(h-e>=7&&32-h<r)a>>>=h-e,a+=30-h<<e,s.advance(32+e-h),o=a;else{for(var u=0;0===s.read(1);u++)a=s.peek(32-n)<<n;u<r-1?(a=e?s.read(e):0,o=a+(u<<e)):u===r-1?(a=s.read(i),o=a+1):o=-1}return o>>1^-(1&o)}})}();
