(function(){let e=[`wasmdoom_music_init`,`wasmdoom_music_alloc`,`wasmdoom_music_set_genmidi`,`wasmdoom_music_register`,`wasmdoom_music_play`,`wasmdoom_music_pause`,`wasmdoom_music_resume`,`wasmdoom_music_stop`,`wasmdoom_music_unregister`,`wasmdoom_music_set_volume`,`wasmdoom_music_render`,`wasmdoom_music_active`];function t(t){if(!(t.memory instanceof WebAssembly.Memory))throw Error("music wasm: missing `memory` export");for(let n of e)if(typeof t[n]!=`function`)throw Error(`music wasm: missing export \`${n}\``)}var n=class extends AudioWorkletProcessor{wasmDoomMusic=null;pending=[];constructor(){super(),this.port.onmessage=e=>{try{this.onMessage(e.data)}catch(t){this.port.postMessage({debug:`onmessage-threw`,type:e.data?.type,err:String(t),stack:t?.stack??null})}},this.port.start()}onMessage(e){if(e.type===`init`){let n=new WebAssembly.Module(e.wasm),r=new WebAssembly.Instance(n,{});t(r.exports),this.wasmDoomMusic=r.exports,this.wasmDoomMusic.wasmdoom_music_init(sampleRate);for(let e of this.pending)this.dispatch(e);this.pending=[];return}if(!this.wasmDoomMusic){this.pending.push(e);return}this.dispatch(e)}dispatch(e){let t=this.wasmDoomMusic;switch(e.type){case`setGenmidi`:{let n=this.stage(e.data);n!==0&&t.wasmdoom_music_set_genmidi(n,e.data.byteLength);break}case`register`:{let n=this.stage(e.data);n!==0&&t.wasmdoom_music_register(e.handle,n,e.data.byteLength);break}case`play`:t.wasmdoom_music_play(e.handle,+!!e.looping);break;case`pause`:t.wasmdoom_music_pause(e.handle);break;case`resume`:t.wasmdoom_music_resume(e.handle);break;case`stop`:t.wasmdoom_music_stop(e.handle);break;case`unregister`:t.wasmdoom_music_unregister(e.handle);break;case`setVolume`:t.wasmdoom_music_set_volume(e.volume);break}}stage(e){let t=this.wasmDoomMusic,n=t.wasmdoom_music_alloc(e.byteLength);return n===0?0:(new Uint8Array(t.memory.buffer,n,e.byteLength).set(new Uint8Array(e)),n)}process(e,t){let n=t[0];if(!n||n.length===0)return!0;let r=n[0],i=r.length,a=n.length>=2?n[1]:null;if(!this.wasmDoomMusic)return r.fill(0),a&&a.fill(0),!0;let o=this.wasmDoomMusic.wasmdoom_music_render(i),s=new Float32Array(this.wasmDoomMusic.memory.buffer,o,2*i);for(let e=0;e<i;e++)r[e]=s[2*e],a&&(a[e]=s[2*e+1]);return!0}};registerProcessor(`wasmdoom.music`,n)})();