libopusutils
Version:
fork of johni0702/libopus.js. contains libopus compiled to JavaScript using emscripten
39 lines (33 loc) • 7.34 kB
JavaScript
var Module = (function() {
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
if (typeof __filename !== 'undefined') _scriptDir = _scriptDir || __filename;
return (
function(Module) {
Module = Module || {};
var a;a||(a=typeof Module !== 'undefined' ? Module : {});var d,f;a.ready=new Promise(function(b,c){d=b;f=c});var h={},k;for(k in a)a.hasOwnProperty(k)&&(h[k]=a[k]);var l=!1,m=!1,n=!1,q=!1;l="object"===typeof window;m="function"===typeof importScripts;n="object"===typeof process&&"object"===typeof process.versions&&"string"===typeof process.versions.node;q=!l&&!n&&!m;var r="",t,u,v,w;
if(n)r=m?require("path").dirname(r)+"/":__dirname+"/",t=function(b,c){v||(v=null);w||(w=require("path"));b=w.normalize(b);return v.readFileSync(b,c?null:"utf8")},u=function(b){b=t(b,!0);b.buffer||(b=new Uint8Array(b));b.buffer||x("Assertion failed: undefined");return b},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),process.on("uncaughtException",function(b){throw b;}),process.on("unhandledRejection",x),a.inspect=function(){return"[Emscripten Module object]"};
else if(q)"undefined"!=typeof read&&(t=function(b){return read(b)}),u=function(b){if("function"===typeof readbuffer)return new Uint8Array(readbuffer(b));b=read(b,"binary");"object"===typeof b||x("Assertion failed: undefined");return b},"undefined"!==typeof print&&("undefined"===typeof console&&(console={}),console.log=print,console.warn=console.error="undefined"!==typeof printErr?printErr:print);else if(l||m)m?r=self.location.href:"undefined"!==typeof document&&document.currentScript&&(r=document.currentScript.src),
_scriptDir&&(r=_scriptDir),0!==r.indexOf("blob:")?r=r.substr(0,r.lastIndexOf("/")+1):r="",t=function(b){var c=new XMLHttpRequest;c.open("GET",b,!1);c.send(null);return c.responseText},m&&(u=function(b){var c=new XMLHttpRequest;c.open("GET",b,!1);c.responseType="arraybuffer";c.send(null);return new Uint8Array(c.response)});a.print||console.log.bind(console);var y=a.printErr||console.warn.bind(console);for(k in h)h.hasOwnProperty(k)&&(a[k]=h[k]);h=null;var z;a.wasmBinary&&(z=a.wasmBinary);var noExitRuntime;
a.noExitRuntime&&(noExitRuntime=a.noExitRuntime);"object"!==typeof WebAssembly&&x("no native wasm support detected");var A,B=!1,C,D,E=a.INITIAL_MEMORY||16777216;a.wasmMemory?A=a.wasmMemory:A=new WebAssembly.Memory({initial:E/65536,maximum:E/65536});A&&(C=A.buffer);E=C.byteLength;var F=C;C=F;a.HEAP8=new Int8Array(F);a.HEAP16=new Int16Array(F);a.HEAP32=new Int32Array(F);a.HEAPU8=D=new Uint8Array(F);a.HEAPU16=new Uint16Array(F);a.HEAPU32=new Uint32Array(F);a.HEAPF32=new Float32Array(F);a.HEAPF64=new Float64Array(F);
var G,H=[],I=[],J=[],L=[];function M(){var b=a.preRun.shift();H.unshift(b)}var N=0,O=null,P=null;a.preloadedImages={};a.preloadedAudios={};function x(b){if(a.onAbort)a.onAbort(b);y(b);B=!0;b=new WebAssembly.RuntimeError("abort("+b+"). Build with -s ASSERTIONS=1 for more info.");f(b);throw b;}function Q(b){var c=R;return String.prototype.startsWith?c.startsWith(b):0===c.indexOf(b)}function S(){return Q("data:application/octet-stream;base64,")}var R="libopus.wasm";
if(!S()){var T=R;R=a.locateFile?a.locateFile(T,r):r+T}function U(){try{if(z)return new Uint8Array(z);if(u)return u(R);throw"both async and sync fetching of the wasm failed";}catch(b){x(b)}}function V(){return z||!l&&!m||"function"!==typeof fetch||Q("file://")?Promise.resolve().then(U):fetch(R,{credentials:"same-origin"}).then(function(b){if(!b.ok)throw"failed to load wasm binary file at '"+R+"'";return b.arrayBuffer()}).catch(function(){return U()})}
function W(b){for(;0<b.length;){var c=b.shift();if("function"==typeof c)c(a);else{var g=c.v;"number"===typeof g?void 0===c.u?G.get(g)():G.get(g)(c.u):g(void 0===c.u?null:c.u)}}}I.push({v:function(){X()}});var aa={b:function(b,c,g){D.copyWithin(b,c,c+g)},c:function(){x("OOM")},a:A};
(function(){function b(e){a.asm=e.exports;G=a.asm.d;N--;a.monitorRunDependencies&&a.monitorRunDependencies(N);0==N&&(null!==O&&(clearInterval(O),O=null),P&&(e=P,P=null,e()))}function c(e){b(e.instance)}function g(e){return V().then(function(p){return WebAssembly.instantiate(p,K)}).then(e,function(p){y("failed to asynchronously prepare wasm: "+p);x(p)})}var K={a:aa};N++;a.monitorRunDependencies&&a.monitorRunDependencies(N);if(a.instantiateWasm)try{return a.instantiateWasm(K,b)}catch(e){return y("Module.instantiateWasm callback failed with error: "+
e),!1}(function(){return z||"function"!==typeof WebAssembly.instantiateStreaming||S()||Q("file://")||"function"!==typeof fetch?g(c):fetch(R,{credentials:"same-origin"}).then(function(e){return WebAssembly.instantiateStreaming(e,K).then(c,function(p){y("wasm streaming compile failed: "+p);y("falling back to ArrayBuffer instantiation");return g(c)})})})().catch(f);return{}})();var X=a.___wasm_call_ctors=function(){return(X=a.___wasm_call_ctors=a.asm.e).apply(null,arguments)};
a._opus_strerror=function(){return(a._opus_strerror=a.asm.f).apply(null,arguments)};a._opus_get_version_string=function(){return(a._opus_get_version_string=a.asm.g).apply(null,arguments)};a._opus_decoder_get_size=function(){return(a._opus_decoder_get_size=a.asm.h).apply(null,arguments)};a._opus_decoder_init=function(){return(a._opus_decoder_init=a.asm.i).apply(null,arguments)};a._opus_decode=function(){return(a._opus_decode=a.asm.j).apply(null,arguments)};
a._opus_decode_float=function(){return(a._opus_decode_float=a.asm.k).apply(null,arguments)};a._opus_decoder_ctl=function(){return(a._opus_decoder_ctl=a.asm.l).apply(null,arguments)};a._opus_packet_get_nb_samples=function(){return(a._opus_packet_get_nb_samples=a.asm.m).apply(null,arguments)};a._opus_encoder_get_size=function(){return(a._opus_encoder_get_size=a.asm.n).apply(null,arguments)};a._opus_encoder_init=function(){return(a._opus_encoder_init=a.asm.o).apply(null,arguments)};
a._opus_encode=function(){return(a._opus_encode=a.asm.p).apply(null,arguments)};a._opus_encode_float=function(){return(a._opus_encode_float=a.asm.q).apply(null,arguments)};a._opus_encoder_ctl=function(){return(a._opus_encoder_ctl=a.asm.r).apply(null,arguments)};a._malloc=function(){return(a._malloc=a.asm.s).apply(null,arguments)};a._free=function(){return(a._free=a.asm.t).apply(null,arguments)};var Y;P=function ba(){Y||Z();Y||(P=ba)};
function Z(){function b(){if(!Y&&(Y=!0,a.calledRun=!0,!B)){W(I);W(J);d(a);if(a.onRuntimeInitialized)a.onRuntimeInitialized();if(a.postRun)for("function"==typeof a.postRun&&(a.postRun=[a.postRun]);a.postRun.length;){var c=a.postRun.shift();L.unshift(c)}W(L)}}if(!(0<N)){if(a.preRun)for("function"==typeof a.preRun&&(a.preRun=[a.preRun]);a.preRun.length;)M();W(H);0<N||(a.setStatus?(a.setStatus("Running..."),setTimeout(function(){setTimeout(function(){a.setStatus("")},1);b()},1)):b())}}a.run=Z;
if(a.preInit)for("function"==typeof a.preInit&&(a.preInit=[a.preInit]);0<a.preInit.length;)a.preInit.pop()();noExitRuntime=!0;Z();
return Module.ready
}
);
})();
if (typeof exports === 'object' && typeof module === 'object')
module.exports = Module;
else if (typeof define === 'function' && define['amd'])
define([], function() { return Module; });
else if (typeof exports === 'object')
exports["Module"] = Module;
Module.instance = Module();
module.exports = Module;