(function(a){function b(a,c,d,e){var f=b.sinks,g;for(g in f)if(f.hasOwnProperty(g)&&f[g].enabled)try{return new f[g](a,c,d,e)}catch(h){}throw b.Error(2)}function c(){var a;for(a in c.prototype)c.prototype.hasOwnProperty(a)&&(this[a]=c.prototype[a]);this._listeners={}}function d(a){if(!d.hasOwnProperty(a))throw d(1);if(!(this instanceof d))return new d(a);var b;for(b in d[a])d[a].hasOwnProperty(b)&&(this[b]=d[a][b]);this.code=a}function e(a){this.boundTo=a,this.buffers=[],a.activeRecordings.push(this)}function f(){}function g(a,c,d,e){d=d||c.prototype,c.prototype=new b.SinkClass,c.prototype.type=a,c.enabled=!e;for(e in d)d.hasOwnProperty(e)&&(c.prototype[e]=d[e]);g[a]=c}c.prototype={_listeners:null,emit:function(a,b){if(this._listeners[a])for(var c=0;c<this._listeners[a].length;c++)this._listeners[a][c].apply(this,b);return this},on:function(a,b){return this._listeners[a]=this._listeners[a]||[],this._listeners[a].push(b),this},off:function(a,b){if(this._listeners[a]){if(!b)return delete this._listeners[a],this;for(var c=0;c<this._listeners[a].length;c++)this._listeners[a][c]===b&&this._listeners[a].splice(c--,1);this._listeners[a].length||delete this._listeners[a]}return this}},b.EventEmitter=c,d.prototype=new Error,d.prototype.toString=function(){return"SinkError 0x"+this.code.toString(16)+": "+this.message},d[1]={message:"No such error code.",explanation:"The error code does not exist."},d[2]={message:"No audio sink available.",explanation:"The audio device may be busy, or no supported output API is available for this browser."},d[16]={message:"Buffer underflow.",explanation:"Trying to recover..."},d[17]={message:"Critical recovery fail.",explanation:"The buffer underflow has reached a critical point, trying to recover, but will probably fail anyway."},d[18]={message:"Buffer size too large.",explanation:"Unable to allocate the buffer due to excessive length, please try a smaller buffer. Buffer size should probably be smaller than the sample rate."},b.Error=d,e.prototype={add:function(a){this.buffers.push(a)},clear:function(){this.buffers=[]},stop:function(){var a=this.boundTo.activeRecordings,b;for(b=0;b<a.length;b++)a[b]===this&&a.splice(b--,1)},join:function(){var a=0,b=0,c=this.buffers,d,e,f,g=c.length;for(f=0;f<g;f++)a+=c[f].length;d=new Float32Array(a);for(f=0;f<g;f++){for(e=0;e<c[f].length;e++)d[b+e]=c[f][e];b+=c[f].length}return d}},b.SinkClass=f,f.prototype={sampleRate:44100,channelCount:2,bufferSize:4096,writePosition:0,writeMode:"async",channelMode:"interleaved",previousHit:0,ringBuffer:null,ringOffset:0,start:function(a,c,d,e){this.channelCount=isNaN(c)||c===null?this.channelCount:c,this.bufferSize=isNaN(d)||d===null?this.bufferSize:d,this.sampleRate=isNaN(e)||e===null?this.sampleRate:e,this.readFn=a,this.activeRecordings=[],this.previousHit=+(new Date),this.asyncBuffers=[],this.syncBuffers=[],b.EventEmitter.call(this)},process:function(a,c){this.ringBuffer&&(this.channelMode==="interleaved"?this.ringSpin:this.ringSpinInterleaved).apply(this,arguments),this.writeBuffersSync.apply(this,arguments);if(this.channelMode==="interleaved")this.readFn&&this.readFn.apply(this,arguments),this.emit("audioprocess",arguments);else{var d=b.deinterleave(a,this.channelCount),e=[d].concat([].slice.call(arguments,1));this.readFn&&this.readFn.apply(this,e),this.emit("audioprocess",e),b.interleave(d,this.channelCount,a)}this.writeBuffersAsync.apply(this,arguments),this.recordData.apply(this,arguments),this.previousHit=+(new Date),this.writePosition+=a.length/c},record:function(){return new e(this)},recordData:function(a){var b=this.activeRecordings,c,d=b.length;for(c=0;c<d;c++)b[c].add(a)},writeBuffersAsync:function(a){var b=this.asyncBuffers,c=a.length,d,e,f,g,h;if(b)for(f=0;f<b.length;f++){d=b[f],e=d.b.length,h=d.d,d.d-=Math.min(h,c);for(g=0;g+h<c&&g<e;g++)a[g+h]+=d.b[g];d.b=d.b.subarray(g+h),f>=e&&b.splice(f--,1)}},writeBuffersSync:function(a){var b=this.syncBuffers,c=a.length,d=0,e=0;for(;d<c&&b.length;d++){a[d]+=b[0][e];if(b[0].length<=e){b.splice(0,1),e=0;continue}e++}b.length&&(b[0]=b[0].subarray(e))},writeBufferAsync:function(a,c){a=this.mode==="deinterleaved"?b.interleave(a,this.channelCount):a;var d=this.asyncBuffers;return d.push({b:a,d:isNaN(c)?~~((+(new Date)-this.previousHit)/1e3*this.sampleRate):c}),d.length},writeBufferSync:function(a){a=this.mode==="deinterleaved"?b.interleave(a,this.channelCount):a;var c=this.syncBuffers;return c.push(a),c.length},writeBuffer:function(){return this[this.writeMode==="async"?"writeBufferAsync":"writeBufferSync"].apply(this,arguments)},getSyncWriteOffset:function(){var a=this.syncBuffers,b=0,c;for(c=0;c<a.length;c++)b+=a[c].length;return b},getPlaybackTime:function(){return this.writePosition-this.bufferSize},ringSpin:function(a){var b=this.ringBuffer,c=a.length,d=b.length,e=this.ringOffset,f;for(f=0;f<c;f++)a[f]+=b[e],e=(e+1)%d;this.ringOffset=e},ringSpinDeinterleaved:function(a){var b=this.ringBuffer,c=a.length,d=b.length,e=b[0].length,f=d*e,g=this.ringOffset,h,i;for(h=0;h<c;h+=d){for(i=0;i<d;i++)a[h+i]+=b[i][g];g=(g+1)%e}this.ringOffset=i}},g("moz",function(){function l(){if(d){f=e.mozWriteAudio(d),c+=f;if(f<d.length)return d=d.subarray(f),d;d=null}g=e.mozCurrentSampleOffset(),h=Number(g+(j!==g?a.bufferSize:a.preBufferSize)*a.channelCount-c),g===j&&a.emit("error",[b.Error(16)]);if(h>0||j===g){try{i=new Float32Array(j===g?a.preBufferSize*a.channelCount:a.forceBufferSize?h<a.bufferSize*2?a.bufferSize*2:h:h)}catch(k){a.emit("error",[b.Error(18)]),a.kill();return}a.process(i,a.channelCount),f=a._audio.mozWriteAudio(i),f<i.length&&(d=i.subarray(f)),c+=f}j=g}var a=this,c=0,d=null,e=new Audio,f,g,h,i,j,k;a.start.apply(a,arguments),a.preBufferSize=isNaN(arguments[4])||arguments[4]===null?this.preBufferSize:arguments[4],e.mozSetup(a.channelCount,a.sampleRate),this._timers=[],this._timers.push(b.doInterval(function(){+(new Date)-a.previousHit>2e3&&(a._audio=e=new Audio,e.mozSetup(a.channelCount,a.sampleRate),c=0,a.emit("error",[b.Error(17)]))},1e3)),this._timers.push(b.doInterval(l,a.interval)),a._bufferFill=l,a._audio=e},{bufferSize:24576,preBufferSize:24576,forceBufferSize:!1,interval:20,kill:function(){while(this._timers.length)this._timers[0](),this._timers.splice(0,1);this.emit("kill")},getPlaybackTime:function(){return this._audio.mozCurrentSampleOffset()/this.channelCount}});var h=[];g("webkit",function(a,c,d,e){function k(a){var b=a.outputBuffer,c=b.numberOfChannels,d,e,g=b.length,h=b.size,i=new Array(c),j=new Float32Array(g*c),k;for(d=0;d<c;d++)i[d]=b.getChannelData(d);f.process(j,f.channelCount);for(d=0;d<g;d++)for(e=0;e<c;e++)i[e][d]=j[d*f.channelCount+e]}var f=this,i=new(window.AudioContext||webkitAudioContext),j=i.createJavaScriptNode(d,0,c);f.start.apply(f,arguments),g.webkit.forceSampleRate&&f.sampleRate!==i.sampleRate?k=function(c){var d=c.outputBuffer,e=d.numberOfChannels,g,h,j=d.length,k=d.size,l=new Array(e),m=new Float32Array(Math.floor(j*f.sampleRate/i.sampleRate)*e),n;for(g=0;g<e;g++)l[g]=d.getChannelData(g);f.process(m,f.channelCount),m=b.deinterleave(m,f.channelCount);for(h=0;h<e;h++){n=b.resample(m[h],f.sampleRate,i.sampleRate);for(g=0;g<j;g++)l[h][g]=n[g]}}:f.sampleRate=i.sampleRate,j.onaudioprocess=k,j.connect(i.destination),f._context=i,f._node=j,f._callback=k,h.push(j)},{kill:function(){this._node.disconnect(0);for(var a=0;a<h.length;a++)h[a]===this._node&&h.splice(a--,1);this._node=this._context=null,this.kill(),this.emit("kill")},getPlaybackTime:function(){return this._context.currentTime*this.sampleRate}}),g.webkit.fix82795=h,g("dummy",function(){function c(){var b=new Float32Array(a.bufferSize*a.channelCount);a.process(b,a.channelCount)}var a=this;a.start.apply(a,arguments),a._kill=b.doInterval(c,a.bufferSize/a.sampleRate*1e3),a._callback=c},{kill:function(){this._kill(),this.emit("kill")}},!0),b.sinks=b.devices=g,b.Recording=e,function(){function d(b){var e=null,f,g;try{return g=new a,g.append(b),f=c.createObjectURL(g.getBlob()),e=new Worker(f),e._terminate=e.terminate,e._url=f,g=null,e.terminate=function(){this._terminate,c.revokeObjectURL(this._url)},d.type="blob",e}catch(h){}try{return e=new Worker("data:text/javascript;base64,"+btoa(b)),d.type="data",e}catch(h){}return e}var a=typeof window=="undefined"?undefined:window.MozBlobBuilder||window.WebKitBlobBuilder||window.MSBlobBuilder||window.OBlobBuilder||window.BlobBuilder,c=typeof window=="undefined"?undefined:window.MozURL||window.webkitURL||window.MSURL||window.OURL||window.URL;d.ready=d.working=!1,b.EventEmitter.call(d),d.test=function(){function c(b){if(d.ready)return;d.ready=!0,d.working=b,d.emit("ready",[b]),d.off("ready"),b&&a&&a.terminate(),a=null}var a=d("this.onmessage=function(e){postMessage(e.data)}"),b="inlineWorker";d.ready=d.working=!1,a?(a.onmessage=function(a){c(a.data===b)},a.postMessage(b),setTimeout(function(){c(!1)},1e3)):c(!1)},b.inlineWorker=d,d.test()}(),b.doInterval=function(a,c){function f(f){b.inlineWorker.working&&!f?(d=b.inlineWorker('setInterval(function(){ postMessage("tic"); }, '+c+");"),d.onmessage=function(){a()},e=function(){d.terminate()}):(d=setInterval(a,c),e=function(){clearInterval(d)})}var d,e;return b.doInterval.backgroundWork||b.devices.moz.backgroundWork?b.inlineWorker.ready?f():b.inlineWorker.on("ready",function(){f()}):f(!0),function(){e?e():b.inlineWorker.ready||b.inlineWorker.on("ready",function(){e&&e()})}},b.doInterval.backgroundWork=!0,function(){function a(c,d){return c&&d?a[c]=d:c&&a[c]instanceof Function&&(b.interpolate=a[c]),a[c]}b.interpolation=a,a("linear",function(a,b){var c=Math.floor(b),d=c+1,e=b-c;return d=d<a.length?d:0,a[c]*(1-e)+a[d]*e}),a("nearest",function(a,b){return b>=a.length-.5?a[0]:a[Math.round(b)]}),a("linear")}(),b.resample=function(a,c,d,e,f){var g=arguments.length,h=g===2?c:g===3?c/d:e/c*f/d,i=a.length,j=Math.ceil(i/h),k=new Float32Array(j),l,m;for(l=0,m=0;l<i;l+=h)k[m++]=b.interpolate(a,l);return k},b.deinterleave=function(a,b){var c=a.length,d=c/b,e=[],f,g;for(f=0;f<b;f++){e[f]=new Float32Array(d);for(g=0;g<d;g++)e[f][g]=a[g*b+f]}return e},b.interleave=function(a,b,c){b=b||a.length;var d=a[0].length,e=a.length,f,g;c=c||new Float32Array(d*b);for(f=0;f<e;f++)for(g=0;g<d;g++)c[f+g*b]=a[f][g];return c},b.mix=function(a){var b=[].slice.call(arguments,1),c,d,e;for(e=0;e<b.length;e++){c=Math.max(a.length,b[e].length);for(d=0;d<c;d++)a[d]+=b[e][d]}return a},b.resetBuffer=function(a){var b=a.length,c;for(c=0;c<b;c++)a[c]=0;return a},b.clone=function(a,b){var c=a.length,d;b=b||new Float32Array(c);for(d=0;d<c;d++)b[d]=a[d];return b},b.createDeinterleaved=function(a,b){var c=new Array(b),d;for(d=0;d<b;d++)c[d]=new Float32Array(a);return c},a.Sink=b})(function(){return this}());