function QBAudioRecorderWorker(){var e=this;e.bufferChunks=[],e.bufferSize=0,e.sampleRate=0,e.mimeType="",onmessage=function(t){e.onMessage(t.data)}}importScripts("https://cdn.rawgit.com/zhuker/lamejs/c318d57d/lame.min.js");var MP3encoder=new lamejs.Mp3Encoder(1,48e3,256);QBAudioRecorderWorker.prototype={postMessage:function(e){postMessage(e)},onMessage:function(e){switch(e.cmd){case"init":this.mimeType=e.mimeType,this.sampleRate=e.sampleRate,this.bufferChunks=[],this.bufferSize=0;break;case"record":this.bufferChunks.push(new Float32Array(e.bufferChunk)),this.bufferSize+=e.bufferSize;break;case"finish":this.postMessage(this.getBlobData())}},encodeWAV:function(e){function t(e,t,n){for(var r=0;r<n.length;r++)e.setUint8(t+r,n.charCodeAt(r))}var n=new ArrayBuffer(44+2*e.length),r=new DataView(n);return t(r,0,"RIFF"),r.setUint32(4,32+2*e.length,!0),t(r,8,"WAVE"),t(r,12,"fmt "),r.setUint32(16,16,!0),r.setUint16(20,1,!0),r.setUint16(22,1,!0),r.setUint32(24,this.sampleRate,!0),r.setUint32(28,2*this.sampleRate,!0),r.setUint16(32,2,!0),r.setUint16(34,16,!0),t(r,36,"data"),r.setUint32(40,2*e.length,!0),function(e,t,n){for(var r=0;r<n.length;r++,t+=2){var s=Math.max(-1,Math.min(1,n[r]));e.setInt16(t,s<0?32768*s:32767*s,!0)}}(r,44,e),r},encodeMP3:function(e){var t=new Int16Array(e),n=MP3encoder.encodeBuffer(t),r=MP3encoder.flush(),s=[];return s.push(n),s.push(new Int8Array(r)),s},getBlobData:function(){for(var e,t,n,r=new Float32Array(this.bufferSize),s=this.bufferChunks.length,a=0,i=0;i<s;i++)e=this.bufferChunks[i],r.set(e,a),a+=e.length;switch(t=this.encodeWAV(r),this.mimeType){case"audio/wav":n=[t];break;case"audio/mp3":n=this.encodeMP3(t.buffer);break;default:throw new Error}return n}},new QBAudioRecorderWorker;