-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathrecorder-worker.js
3 lines (3 loc) · 1.04 KB
/
recorder-worker.js
1
2
3
//build:2019/11/15 09:05:57
!function(i){"use strict";!function(){"undefined"!=typeof console&&console.log.apply(console,arguments)}("mp3 recorder worker started!"),importScripts("./lame.all.js");var l,u,f,p,n=[];function m(e){n.push(new Int8Array(e))}function t(){n=[]}function d(e){if(f!=p)for(var n=f/p,a=Math.ceil(e.length/n),t=new Float32Array(a),r=0,o=0;r<a;o+=n)t[r++]=e[~~o];else t=new Float32Array(e);a=t.length;var c=new Int16Array(a);for(o=0;o<a;o++){var s=Math.max(-1,Math.min(1,t[o]));c[o]=s<0?32768*s:32767*s}return c}function r(){m(l.flush()),function(e,n){self.postMessage({cmd:e,data:n})}("complete",n),t()}self.onmessage=function(e){var n=e.data,a=n.data;switch(n.cmd){case"init":!function(e){u=e.numChannels||1,f=e.inputSampleRate,p=Math.min(e.outputSampleRate||f,f),t(),l=new lamejs.Mp3Encoder(u,p,e.bitRate||128)}(a);break;case"encode":!function(e){for(var n=d(e[0]),a=1<u?d(e[1]):i,t=1152,r=n.length,o=0;t<=r;o+=t){var c=n.subarray(o,o+t),s=a?a.subarray(o,o+t):i;m(l.encodeBuffer(c,s)),r-=t}}(a);break;case"stop":r()}}}();