You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
21 KiB
2 lines
21 KiB
4 years ago
|
var Module=typeof Module!=="undefined"?Module:{};!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.DecoderWorker=t():e.DecoderWorker=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function r(s){if(t[s])return t[s].exports;var i=t[s]={i:s,l:!1,exports:{}};return e[s].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,s){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(r.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(s,i,function(t){return e[t]}.bind(null,i));return s},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){null;(function(t){var r,s,i=new Promise(function(e){s=e});t.onmessage=function(e){i.then(function(){switch(e.data.command){case"decode":r&&r.decode(e.data.pages);break;case"done":r&&(r.sendLastBuffer(),t.close());break;case"init":r=new o(e.data,Module)}})};var o=function(e,t){if(!t)throw new Error("Module with exports required to initialize a decoder instance");this.mainReady=i,this.config=Object.assign({bufferLength:4096,decoderSampleRate:48e3,outputBufferSampleRate:48e3,resampleQuality:3},e),this._opus_decoder_create=t._opus_decoder_create,this._opus_decoder_destroy=t._opus_decoder_destroy,this._speex_resampler_process_interleaved_float=t._speex_resampler_process_interleaved_float,this._speex_resampler_init=t._speex_resampler_init,this._speex_resampler_destroy=t._speex_resampler_destroy,this._opus_decode_float=t._opus_decode_float,this._free=t._free,this._malloc=t._malloc,this.HEAPU8=t.HEAPU8,this.HEAP32=t.HEAP32,this.HEAPF32=t.HEAPF32,this.outputBuffers=[]};o.prototype.decode=function(e){var t=new DataView(e.buffer);this.getPageBoundaries(t).map(function(r){var s=t.getUint8(r+5,!0),i=t.getUint32(r+18,!0);if(2&s&&(this.numberOfChannels=t.getUint8(r+37,!0),this.init()),i>1){for(var o=t.getUint8(r+26,!0),u=r+27+o,n=0;n<o;n++){var f=t.getUint8(r+27+n,!0);if(this.decoderBuffer.set(e.subarray(u,u+=f),this.decoderBufferIndex),this.decoderBufferIndex+=f,f<255){var h=this._opus_decode_float(this.decoder,this.decoderBufferPointer,this.decoderBufferIndex,this.decoderOutputPointer,this.decoderOutputMaxLength,0),a=Math.ceil(h*this.config.outputBufferSampleRate/this.config.decoderSampleRate);this.HEAP32[this.decoderOutputLengthPointer>>2]=h,this.HEAP32[this.resampleOutputLengthPointer>>2]=a,this._speex_resampler_process_interleaved_float(this.resampler,this.decoderOutputPointer,this.decoderOutputLengthPointer,this.resampleOutputBufferPointer,this.resampleOutputLengthPointer),this.sendToOutputBuffers(this.HEAPF32.subarray(this.resampleOutputBufferPointer>>2,(this.resampleOutputBufferPointer>>2)+a*this.numberOfChannels)),this.decoderBufferIndex=0}}4&s&&this.sendLastBuffer()}},this)},o.prototype.getPageBoundaries=function(e){for(var t=[],r=0;r<e.byteLength-32;r++)1399285583==e.getUint32(r,!0)&&t.push(r);return t},o.prototype.init=function(){this.resetOutputBuffers(),this.initCodec(),this.initResampler()},o.prototype.initCodec=function(){this.decoder&&(this._opus_decoder_destroy(this.decoder),this._free(this.decoderBufferPointer),this._free(this.decoderOutputLengthPointer),this._free(this.decoderOutputPointer));var e=this._malloc(4);this.decoder=this._opus_decoder_create(this.config.decoderSampleRate,this.numberOfChannels,e),this._free(e),this.decoderBufferMaxLength=4e3,this.decoderBufferPointer=this._malloc(this.decoderBufferMaxLength),this.decoderBuffer=this.HEAPU8.subarray(this.decoderBufferPointer,this.decoderBu
|