telegram-tt/dist/8ccc0b555efcec3616377aea078dda16.js

2 lines
26 KiB
JavaScript
Raw Normal View History

2021-04-09 13:17:49 +02:00
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.EncoderWorker=t():e.EncoderWorker=t()}("undefined"!=typeof self?self:this,function(){return function(e){var t={};function n(s){if(t[s])return t[s].exports;var r=t[s]={i:s,l:!1,exports:{}};return e[s].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,s){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:s})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var s=Object.create(null);if(n.r(s),Object.defineProperty(s,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(s,r,function(t){return e[t]}.bind(null,r));return s},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){"use strict";(function(t){var n,s,r=new Promise(function(e){s=e});t.onmessage=function(e){r.then(function(){switch(e.data.command){case"encode":n&&n.encode(e.data.buffers);break;case"getHeaderPages":n&&(n.generateIdPage(),n.generateCommentPage());break;case"done":n&&(n.encodeFinalFrame(),t.postMessage({message:"done"}));break;case"close":t.close();break;case"flush":n&&n.flush();break;case"init":n&&n.destroy(),n=new i(e.data,Module),t.postMessage({message:"ready"})}})};var i=function(e,t){if(!t)throw new Error("Module with exports required to initialize an encoder instance");this.config=Object.assign({bufferLength:4096,encoderApplication:2049,encoderFrameSize:20,encoderSampleRate:48e3,maxFramesPerPage:40,numberOfChannels:1,originalSampleRate:44100,resampleQuality:3,serial:Math.floor(4294967296*Math.random())},e),this._opus_encoder_create=t._opus_encoder_create,this._opus_encoder_destroy=t._opus_encoder_destroy,this._opus_encoder_ctl=t._opus_encoder_ctl,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_encode_float=t._opus_encode_float,this._free=t._free,this._malloc=t._malloc,this.HEAPU8=t.HEAPU8,this.HEAP32=t.HEAP32,this.HEAPF32=t.HEAPF32,this.pageIndex=0,this.granulePosition=0,this.segmentData=new Uint8Array(65025),this.segmentDataIndex=0,this.segmentTable=new Uint8Array(255),this.segmentTableIndex=0,this.framesInPage=0,this.initChecksumTable(),this.initCodec(),this.initResampler(),1===this.config.numberOfChannels?this.interleave=function(e){return e[0]}:this.interleavedBuffers=new Float32Array(this.config.bufferLength*this.config.numberOfChannels)};i.prototype.encode=function(e){for(var t=this.interleave(e),n=0;n<t.length;){var s=Math.min(this.resampleBufferLength-this.resampleBufferIndex,t.length-n);if(this.resampleBuffer.set(t.subarray(n,n+s),this.resampleBufferIndex),n+=s,this.resampleBufferIndex+=s,this.resampleBufferIndex===this.resampleBufferLength){this._speex_resampler_process_interleaved_float(this.resampler,this.resampleBufferPointer,this.resampleSamplesPerChannelPointer,this.encoderBufferPointer,this.encoderSamplesPerChannelPointer);var r=this._opus_encode_float(this.encoder,this.encoderBufferPointer,this.encoderSamplesPerChannel,this.encoderOutputPointer,this.encoderOutputMaxLength);this.segmentPacket(r),this.resampleBufferIndex=0,this.framesInPage++,this.framesInPage>=this.config.maxFramesPerPage&&this.generatePage()}}},i.prototype.destroy=function(){this.encoder&&(this._free(this.encoderSamplesPerChannelPointer),delete this.encoderSamplesPerChannelPointer,this._free(this.encoderBufferPointer),delete this.encoderBufferPointer,this._free(this.encoderOutputPointer),delete this.encoderOutputPointer,this._free(this.resampleSamplesP