diff --git a/public/src/js/lib/oggmented-wasm.js b/public/src/js/lib/oggmented-wasm.js new file mode 100644 index 0000000..f10dc7b --- /dev/null +++ b/public/src/js/lib/oggmented-wasm.js @@ -0,0 +1,46 @@ + +var Oggmented = (function() { + var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined; + + return ( +function(Oggmented) { + Oggmented = Oggmented || {}; + +(function(b,c){function m(h){delete k[h]}function l(h){if(e)setTimeout(l,0,h);else{var t=k[h];if(t){e=!0;try{var p=t.A,y=t.v;switch(y.length){case 0:p();break;case 1:p(y[0]);break;case 2:p(y[0],y[1]);break;case 3:p(y[0],y[1],y[2]);break;default:p.apply(c,y)}}finally{m(h),e=!1}}}}function q(){r=function(h){process.C(function(){l(h)})}}function u(){if(b.postMessage&&!b.importScripts){var h=!0,t=b.onmessage;b.onmessage=function(){h=!1};b.postMessage("","*");b.onmessage=t;return h}}function w(){function h(p){p.source=== +b&&"string"===typeof p.data&&0===p.data.indexOf(t)&&l(+p.data.slice(t.length))}var t="setImmediate$"+Math.random()+"$";b.addEventListener?b.addEventListener("message",h,!1):b.attachEvent("onmessage",h);r=function(p){b.postMessage(t+p,"*")}}function v(){var h=new MessageChannel;h.port1.onmessage=function(t){l(t.data)};r=function(t){h.port2.postMessage(t)}}function A(){var h=f.documentElement;r=function(t){var p=f.createElement("script");p.onreadystatechange=function(){l(t);p.onreadystatechange=null; +h.removeChild(p);p=null};h.appendChild(p)}}function d(){r=function(h){setTimeout(l,0,h)}}if(!b.setImmediate){var g=1,k={},e=!1,f=b.document,r,n=Object.getPrototypeOf&&Object.getPrototypeOf(b);n=n&&n.setTimeout?n:b;"[object process]"==={}.toString.call(b.process)?q():u()?w():b.MessageChannel?v():f&&"onreadystatechange"in f.createElement("script")?A():d();n.setImmediate=function(h){"function"!==typeof h&&(h=new Function(""+h));for(var t=Array(arguments.length-1),p=0;p{try{var {channels:l,length:q,rate:u}=(g=>{const k=g.byteLength,e=B(k);g=new Int8Array(g);C.set(g,e);D("open_buffer","number",["number","number"],[e,k]);return{channels:ba(),length:ca(),rate:da()}})(b),w=aa.createBuffer(l,q,u),v=B(Uint32Array.BYTES_PER_ELEMENT),A=0}catch(g){return m&&m(g)}const d=()=>{try{const g=Date.now();let k;for(;k=ea(v);){const e=fa(v,"*"),f=new Uint32Array(ha.buffer,e,l);for(let r=0;r>0];case "i8":return C[b>>0];case "i16":return ka[b>>1];case "i32":return M[b>>2];case "i64":return M[b>>2];case "float":return E[b>>2];case "double":return la[b>>3];default:L("invalid type for getValue: "+c)}return null}var N,O=!1;function ma(b){var c=a["_"+b];c||L("Assertion failed: Cannot call unknown function "+(b+", make sure it is exported"));return c} +function D(b,c,m,l){var q={string:function(d){var g=0;if(null!==d&&void 0!==d&&0!==d){var k=(d.length<<2)+1;g=P(k);var e=g,f=Q;if(0=n){var h=d.charCodeAt(++r);n=65536+((n&1023)<<10)|h&1023}if(127>=n){if(e>=k)break;f[e++]=n}else{if(2047>=n){if(e+1>=k)break;f[e++]=192|n>>6}else{if(65535>=n){if(e+2>=k)break;f[e++]=224|n>>12}else{if(e+3>=k)break;f[e++]=240|n>>18;f[e++]=128|n>>12&63}f[e++]=128|n>>6&63}f[e++]=128|n&63}}f[e]= +0}}return g},array:function(d){var g=P(d.length);C.set(d,g);return g}},u=ma(b),w=[];b=0;if(l)for(var v=0;v=k);)++e;if(16f?k+=String.fromCharCode(f):(f-=65536,k+=String.fromCharCode(55296|f>>10,56320|f&1023))}}else k+=String.fromCharCode(f)}d=k}}else d="";else d="boolean"===c?!!d:d;return d}(m);0!==b&&pa(b);return m}var oa="undefined"!==typeof TextDecoder?new TextDecoder("utf8"):void 0,R,C,Q,ka,M,ha,E,la; +function qa(b){R=b;a.HEAP8=C=new Int8Array(b);a.HEAP16=ka=new Int16Array(b);a.HEAP32=M=new Int32Array(b);a.HEAPU8=Q=new Uint8Array(b);a.HEAPU16=new Uint16Array(b);a.HEAPU32=ha=new Uint32Array(b);a.HEAPF32=E=new Float32Array(b);a.HEAPF64=la=new Float64Array(b)}var ra=a.INITIAL_MEMORY||16777216;a.wasmMemory?N=a.wasmMemory:N=new WebAssembly.Memory({initial:ra/65536,maximum:32768});N&&(R=N.buffer);ra=R.byteLength;qa(R);var S,sa=[],ta=[],ua=[],va=[];function wa(){var b=a.preRun.shift();sa.unshift(b)} +var T=0,U=null,V=null;a.preloadedImages={};a.preloadedAudios={};function L(b){if(a.onAbort)a.onAbort(b);J(b);O=!0;b=new WebAssembly.RuntimeError("abort("+b+"). Build with -s ASSERTIONS=1 for more info.");z(b);throw b;}function xa(){var b=W;return String.prototype.startsWith?b.startsWith("data:application/octet-stream;base64,"):0===b.indexOf("data:application/octet-stream;base64,")}var W="oggmented-wasm.wasm";if(!xa()){var ya=W;W=a.locateFile?a.locateFile(ya,I):I+ya} +function za(){try{if(K)return new Uint8Array(K);throw"both async and sync fetching of the wasm failed";}catch(b){L(b)}}function Aa(){return K||"function"!==typeof fetch?Promise.resolve().then(za):fetch(W,{credentials:"same-origin"}).then(function(b){if(!b.ok)throw"failed to load wasm binary file at '"+W+"'";return b.arrayBuffer()}).catch(function(){return za()})} +function X(b){for(;0>>=0;var c=Q.length;if(2147483648=m;m*=2){var l=c*(1+.2/m);l=Math.min(l,b+100663296);l=Math.max(16777216,b,l);0>>16);qa(N.buffer);var q=1;break a}catch(u){}q=void 0}if(q)return!0}return!1},d:function(b){if(!noExitRuntime){if(a.onExit)a.onExit(b);O=!0}ja(b,new Ca(b))},a:N}; +(function(){function b(q){a.asm=q.exports;S=a.asm.e;T--;a.monitorRunDependencies&&a.monitorRunDependencies(T);0==T&&(null!==U&&(clearInterval(U),U=null),V&&(q=V,V=null,q()))}function c(q){b(q.instance)}function m(q){return Aa().then(function(u){return WebAssembly.instantiate(u,l)}).then(q,function(u){J("failed to asynchronously prepare wasm: "+u);L(u)})}var l={a:Da};T++;a.monitorRunDependencies&&a.monitorRunDependencies(T);if(a.instantiateWasm)try{return a.instantiateWasm(l,b)}catch(q){return J("Module.instantiateWasm callback failed with error: "+ +q),!1}(function(){return K||"function"!==typeof WebAssembly.instantiateStreaming||xa()||"function"!==typeof fetch?m(c):fetch(W,{credentials:"same-origin"}).then(function(q){return WebAssembly.instantiateStreaming(q,l).then(c,function(u){J("wasm streaming compile failed: "+u);J("falling back to ArrayBuffer instantiation");return m(c)})})})().catch(z);return{}})();var Ba=a.___wasm_call_ctors=function(){return(Ba=a.___wasm_call_ctors=a.asm.f).apply(null,arguments)}; +a._open_buffer=function(){return(a._open_buffer=a.asm.g).apply(null,arguments)};var ia=a._close_buffer=function(){return(ia=a._close_buffer=a.asm.h).apply(null,arguments)},ca=a._get_length=function(){return(ca=a._get_length=a.asm.i).apply(null,arguments)},ba=a._get_channels=function(){return(ba=a._get_channels=a.asm.j).apply(null,arguments)},da=a._get_rate=function(){return(da=a._get_rate=a.asm.k).apply(null,arguments)};a._get_time=function(){return(a._get_time=a.asm.l).apply(null,arguments)}; +a._get_streams=function(){return(a._get_streams=a.asm.m).apply(null,arguments)}; +var ea=a._read_float=function(){return(ea=a._read_float=a.asm.n).apply(null,arguments)},F=a._free=function(){return(F=a._free=a.asm.o).apply(null,arguments)},B=a._malloc=function(){return(B=a._malloc=a.asm.p).apply(null,arguments)},na=a.stackSave=function(){return(na=a.stackSave=a.asm.q).apply(null,arguments)},pa=a.stackRestore=function(){return(pa=a.stackRestore=a.asm.r).apply(null,arguments)},P=a.stackAlloc=function(){return(P=a.stackAlloc=a.asm.s).apply(null,arguments)};a.ccall=D;a.getValue=fa; +var Y;function Ca(b){this.name="ExitStatus";this.message="Program terminated with exit("+b+")";this.status=b}V=function Ea(){Y||Z();Y||(V=Ea)}; +function Z(){function b(){if(!Y&&(Y=!0,a.calledRun=!0,!O)){X(ta);X(ua);x(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();va.unshift(c)}X(va)}}if(!(01)for(var g=1;g>0];case"i16":return k[A>>1];case"i32":case"i64":return f[A>>2];case"float":return x[A>>2];case"double":return U[A>>3];default:O("invalid type for getValue: "+I)}return null}n=null,w.quit&&(c=w.quit),w.wasmBinary&&(H=w.wasmBinary),w.noExitRuntime&&(s=w.noExitRuntime),"object"!==("undefined"==typeof WebAssembly?"undefined":E(WebAssembly))&&h("no native wasm support detected");var t,K=new WebAssembly.Table({initial:44,maximum:44,element:"anyfunc"}),y=!1;function R(A,I,g,C){var Q={string:function(A){var I=0;if(null!=A&&0!==A){var g=1+(A.length<<2),C=I=iA(g),Q=J;if(0=E&&(E=65536+((1023&E)<<10)|1023&A.charCodeAt(++B)),127>=E){if(C>=g)break;Q[C++]=E}else{if(2047>=E){if(C+1>=g)break;Q[C++]=192|E>>6}else{if(65535>=E){if(C+2>=g)break;Q[C++]=224|E>>12}else{if(C+3>=g)break;Q[C++]=240|E>>18,Q[C++]=128|E>>12&63}Q[C++]=128|E>>6&63}Q[C++]=128|63&E}}Q[C]=0}}return I},array:function(A){var I=iA(A.length);return G.set(A,I),I}},B=function(A){var I=w["_"+A];return I||O("Assertion failed: Cannot call unknown function "+A+", make sure it is exported"),I}(A),E=[];if(A=0,C)for(var D=0;D=C);)++Q;if(16(B=224==(240&B)?(15&B)<<12|E<<6|D:(7&B)<<18|E<<12|D<<6|63&g[A++])?C+=String.fromCharCode(B):(B-=65536,C+=String.fromCharCode(55296|B>>10,56320|1023&B))}}else C+=String.fromCharCode(B)}A=C}}else A="";else A="boolean"===I?!!A:A;return A}(g=B.apply(null,E)),0!==A&&oA(A),g}var N,G,J,k,f,S,x,U,z="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function q(A){N=A,w.HEAP8=G=new Int8Array(A),w.HEAP16=k=new Int16Array(A),w.HEAP32=f=new Int32Array(A),w.HEAPU8=J=new Uint8Array(A),w.HEAPU16=new Uint16Array(A),w.HEAPU32=S=new Uint32Array(A),w.HEAPF32=x=new Float32Array(A),w.HEAPF64=U=new Float64Array(A)}"undefined"!=typeof TextDecoder&&new TextDecoder("utf-16le");var T=w.INITIAL_MEMORY||16777216;function r(A){for(;0>4,Q=(15&Q)<<4|B>>2;var D=(3&B)<<6|E;I+=String.fromCharCode(C),64!==B&&(I+=String.fromCharCode(Q)),64!==E&&(I+=String.fromCharCode(D))}while(g=g;g*=2){var C=I*(1+.2/g);C=Math.min(C,A+100663296),0<(C=Math.max(16777216,A,C))%65536&&(C+=65536-C%65536);A:{try{t.grow(Math.min(2147418112,C)-N.byteLength+65535>>16),q(t.buffer);var Q=1;break A}catch(A){}Q=void 0}if(Q)return!0}return!1},c:function(A){!s&&(y=!0,w.onExit)&&w.onExit(A),c(A,new MA(A))},memory:t,table:K},_=function(){function A(A){w.asm=A.exports,p--,w.monitorRunDependencies&&w.monitorRunDependencies(p),0==p&&(null!==u&&(clearInterval(u),u=null),V&&(A=V,V=null,A()))}function I(I){A(I.instance)}function g(A){return(H||"function"!=typeof fetch?new Promise((function(A){A(b())})):fetch(X,{credentials:"same-origin"}).then((function(A){if(!A.ok)throw"failed to load wasm binary file at '"+X+"'";return A.arrayBuffer()})).catch((function(){return b()}))).then((function(A){return WebAssembly.instantiate(A,C)})).then(A,(function(A){h("failed to asynchronously prepare wasm: "+A),O(A)}))}var C={a:v};if(p++,w.monitorRunDependencies&&w.monitorRunDependencies(p),w.instantiateWasm)try{return w.instantiateWasm(C,A)}catch(A){return h("Module.instantiateWasm callback failed with error: "+A),!1}return function(){if(H||"function"!=typeof WebAssembly.instantiateStreaming||m(X)||"function"!=typeof fetch)return g(I);fetch(X,{credentials:"same-origin"}).then((function(A){return WebAssembly.instantiateStreaming(A,C).then(I,(function(A){h("wasm streaming compile failed: "+A),h("falling back to ArrayBuffer instantiation"),g(I)}))}))}(),{}}();w.asm=_;var $=w.___wasm_call_ctors=function(){return($=w.___wasm_call_ctors=w.asm.d).apply(null,arguments)};w._open_buffer=function(){return(w._open_buffer=w.asm.e).apply(null,arguments)};var AA=w._close_buffer=function(){return(AA=w._close_buffer=w.asm.f).apply(null,arguments)},IA=w._get_length=function(){return(IA=w._get_length=w.asm.g).apply(null,arguments)},gA=w._get_channels=function(){return(gA=w._get_channels=w.asm.h).apply(null,arguments)},CA=w._get_rate=function(){return(CA=w._get_rate=w.asm.i).apply(null,arguments)};w._get_time=function(){return(w._get_time=w.asm.j).apply(null,arguments)},w._get_streams=function(){return(w._get_streams=w.asm.k).apply(null,arguments)};var QA,BA=w._read_float=function(){return(BA=w._read_float=w.asm.l).apply(null,arguments)},EA=w._free=function(){return(EA=w._free=w.asm.m).apply(null,arguments)},DA=w._malloc=function(){return(DA=w._malloc=w.asm.n).apply(null,arguments)},wA=w.stackSave=function(){return(wA=w.stackSave=w.asm.o).apply(null,arguments)},iA=w.stackAlloc=function(){return(iA=w.stackAlloc=w.asm.p).apply(null,arguments)},oA=w.stackRestore=function(){return(oA=w.stackRestore=w.asm.q).apply(null,arguments)};function MA(A){this.name="ExitStatus",this.message="Program terminated with exit("+A+")",this.status=A}function PA(){function A(){if(!QA&&(QA=!0,w.calledRun=!0,!y)){if(r(Y),r(L),w.onRuntimeInitialized&&w.onRuntimeInitialized(),w.postRun)for("function"==typeof w.postRun&&(w.postRun=[w.postRun]);w.postRun.length;){var A=w.postRun.shift();d.unshift(A)}r(d)}}if(!(0=0&&(A._idleTimeoutId=setTimeout((function(){A._onTimeout&&A._onTimeout()}),I))},g(4),I.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==A&&A.setImmediate||this&&this.setImmediate,I.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==A&&A.clearImmediate||this&&this.clearImmediate}).call(this,g(0))},function(A,I,g){(function(A,I){!function(A,g){"use strict";if(!A.setImmediate){var C,Q,B,E,D,w=1,i={},o=!1,M=A.document,P=Object.getPrototypeOf&&Object.getPrototypeOf(A);P=P&&P.setTimeout?P:A,"[object process]"==={}.toString.call(A.process)?C=function(A){I.nextTick((function(){c(A)}))}:!function(){if(A.postMessage&&!A.importScripts){var I=!0,g=A.onmessage;return A.onmessage=function(){I=!1},A.postMessage("","*"),A.onmessage=g,I}}()?A.MessageChannel?((B=new MessageChannel).port1.onmessage=function(A){c(A.data)},C=function(A){B.port2.postMessage(A)}):M&&"onreadystatechange"in M.createElement("script")?(Q=M.documentElement,C=function(A){var I=M.createElement("script");I.onreadystatechange=function(){c(A),I.onreadystatechange=null,Q.removeChild(I),I=null},Q.appendChild(I)}):C=function(A){setTimeout(c,0,A)}:(E="setImmediate$"+Math.random()+"$",D=function(I){I.source===A&&"string"==typeof I.data&&0===I.data.indexOf(E)&&c(+I.data.slice(E.length))},A.addEventListener?A.addEventListener("message",D,!1):A.attachEvent("onmessage",D),C=function(I){A.postMessage(E+I,"*")}),P.setImmediate=function(A){"function"!=typeof A&&(A=new Function(""+A));for(var I=new Array(arguments.length-1),g=0;g { this.addPromise(this.loadScript("/src/js/" + name), "/src/js/" + name) @@ -191,8 +191,7 @@ class Loader{ snd.buffer = new SoundBuffer() if(!oggSupport){ - var oggmentedCtx = new oggmented.default() - snd.buffer.oggDecoder = oggmentedCtx.decodeAudioData.bind(oggmentedCtx) + snd.buffer.oggDecoder = snd.buffer.fallbackDecoder } snd.musicGain = snd.buffer.createGain() snd.sfxGain = snd.buffer.createGain() diff --git a/public/src/js/soundbuffer.js b/public/src/js/soundbuffer.js index f4c13e2..b4d2e07 100644 --- a/public/src/js/soundbuffer.js +++ b/public/src/js/soundbuffer.js @@ -65,6 +65,9 @@ gain.setVolume(gain.defaultVol) } } + fallbackDecoder(buffer, resolve, reject){ + Oggmented().then(oggmented => oggmented.decodeOggData(buffer, resolve, reject), reject) + } } class SoundGain{ constructor(soundBuffer, channel){