18 lines
2.0 MiB
JavaScript
18 lines
2.0 MiB
JavaScript
|
|
||
|
var Module = (() => {
|
||
|
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
|
||
|
|
||
|
return (
|
||
|
function(Module) {
|
||
|
Module = Module || {};
|
||
|
|
||
|
var Module=typeof Module!="undefined"?Module:{};var readyPromiseResolve,readyPromiseReject;Module["ready"]=new Promise(function(resolve,reject){readyPromiseResolve=resolve;readyPromiseReject=reject});if(!Module.expectedDataFileDownloads){Module.expectedDataFileDownloads=0}Module.expectedDataFileDownloads++;(function(){if(Module["ENVIRONMENT_IS_PTHREAD"])return;var loadPackage=function(metadata){function runWithFS(){Module["FS_createPath"]("/","audio_3a",true,true);Module["FS_createPath"]("/audio_3a","model_file",true,true);var start32=Module["___emscripten_embedded_file_data"]>>2;do{var name_addr=HEAPU32[start32++];var len=HEAPU32[start32++];var content=HEAPU32[start32++];var name=UTF8ToString(name_addr);Module["FS_createDataFile"](name,null,HEAP8.subarray(content,content+len),true,true,true)}while(HEAPU32[start32])}if(Module["calledRun"]){runWithFS()}else{if(!Module["preRun"])Module["preRun"]=[];Module["preRun"].push(runWithFS)}};loadPackage({"files":[]})})();var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof importScripts=="function";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var read_,readAsync,readBinary,setWindowTitle;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(_scriptDir){scriptDirectory=_scriptDir}if(scriptDirectory.indexOf("blob:")!==0){scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}else{scriptDirectory=""}{read_=(url=>{try{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText}catch(err){var data=tryParseAsDataURI(url);if(data){return intArrayToString(data)}throw err}});if(ENVIRONMENT_IS_WORKER){readBinary=(url=>{try{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}catch(err){var data=tryParseAsDataURI(url);if(data){return data}throw err}})}readAsync=((url,onload,onerror)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=(()=>{if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response);return}var data=tryParseAsDataURI(url);if(data){onload(data.buffer);return}onerror()});xhr.onerror=onerror;xhr.send(null)})}setWindowTitle=(title=>document.title=title)}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.warn.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];if(Module["quit"])quit_=Module["quit"];var tempRet0=0;var setTempRet0=value=>{tempRet0=value};var wasmBinary;if(Module["wasmBinary"])wasmBinary=Module["wasmBinary"];var noExitRuntime=Module["noExitRuntime"]||true;if(typeof WebAssembly!="object"){abort("no native wasm support detected")}var wasmMemory;var ABORT=false;var EXITSTATUS;function assert(condition,text){if(!condition){abort(text)}}var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):undefined;function UTF8ArrayToString(heapOrArray,idx,maxBytesToRead){var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}else{var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&1
|
||
|
|
||
|
|
||
|
return Module.ready
|
||
|
}
|
||
|
);
|
||
|
})();
|
||
|
|
||
|
const t=Float32Array.BYTES_PER_ELEMENT,e=Uint16Array.BYTES_PER_ELEMENT;class s{constructor(t,e,s,i){this._isInitialized=!1,this._module=t,this._length=e,this._maxChannelCount=i?Math.min(i,32):s,this._channelCount=s,this._allocateHeap(),this._isInitialized=!0}_allocateHeap(){const s=this._length*t,i=this._channelCount*s;this._dataPtr=this._module._malloc(i),this._channelData=[];for(let t=0;t<this._channelCount;++t){const i=this._dataPtr+t*s,n=i+s;this._channelData[t]=this._module.HEAPF32.subarray(i>>e,n>>e)}}adaptChannel(t){t<this._maxChannelCount&&(this._channelCount=t)}get length(){return this._isInitialized?this._length:null}get numberOfChannels(){return this._isInitialized?this._channelCount:null}get maxChannelCount(){return this._isInitialized?this._maxChannelCount:null}getChannelData(t){return t>=this._channelCount?null:void 0===t?this._channelData:this._channelData[t]}getHeapAddress(){return this._dataPtr}getPointer(){return this._dataPtr}free(){this._isInitialized=!1,this._module._free(this._dataPtr),this._module._free(this._pointerArrayPtr),this._channelData=null}}class i extends AudioWorkletProcessor{constructor(t){super(),this.authStatus=!1,this.enableDenoise=!0,this.flag=!0,this._channelCount=2,this._kernelBufferSize=128,this._channelCount=2,this.initStatus=!1,this.isDumping=!1,this.dumpNum=103359375,this.dumpNumCount=0,this.port.onmessage=t=>{const{type:e,data:s}=t.data;switch(e){case"init":const{sdkAppId:t,userId:e,timestamp:i,sign:n,status:a}=s;return this.sdkAppId=t,this.userId=e,this.timestamp=i,this.sign=n,void(this.status=a);case"disable":return void(this.enableDenoise=!1);case"enable":return void(this.enableDenoise=!0);case"startDump":return this.isDumping=!0,void(this.dumpNumCount=0);case"stopDump":return this.isDumping=!1,void this.port.postMessage({type:"dumped"})}},this.init()}async init(){this.module=await Module(),this._heapInputBuffer=new s(this.module,this._kernelBufferSize,2),this._heapOutputBuffer=new s(this.module,this._kernelBufferSize,2),this.initStatus=!0;const t=new this.module.WebAiDenoise;let e=t.Auth(this.sdkAppId,this.userId,this.timestamp,this.status,this.sign);if(this.authStatus=e,!e)throw new Error("RTCAIDenoiser auth failed. Your sdkAppId is not allowed to open ai denoiser.");this._kernel=t}process(t,e){if(this.initStatus){const s=t[0],i=e[0],n=s.length;for(let t=0;t<n;++t)this._heapInputBuffer.getChannelData(t).set(s[t]);if(this.authStatus&&this.enableDenoise){this._kernel.Process(this._heapInputBuffer.getHeapAddress(),this._heapOutputBuffer.getHeapAddress(),n,128);for(let t=0;t<n;++t)i[t].set(this._heapOutputBuffer.getChannelData(t))}else for(let t=0;t<n;++t)i[t].set(this._heapInputBuffer.getChannelData(t))}return this.isDumping&&(this.dumpNumCount<this.dumpNum?(this.dumpNumCount+=1,this.dump(t,e,this.dumpNumCount)):(this.isDumping=!1,this.port.postMessage({type:"dumped"}))),!0}dump(t,e){this.port.postMessage({type:"ondump",data:{inputPCM:t[0],outputPCM:e[0]}})}}registerProcessor("trtc-denoiser-processor",i)
|