Comparing version 0.2.20 to 0.2.21
328
dist/apu.js
@@ -1,175 +0,165 @@ | ||
var APU; | ||
(function (APU) { | ||
var workletSource = "\"use strict\";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,\"value\"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||\"object\"!=typeof e&&\"function\"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");return t}function _inherits(t,e){if(\"function\"!=typeof e&&null!==e)throw new TypeError(\"Super expression must either be null or a function\");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e=\"function\"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if(\"function\"!=typeof t)throw new TypeError(\"Super expression must either be null or a function\");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if(\"undefined\"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if(\"function\"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf(\"[native code]\")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if(\"write\"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if(\"play\"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if(\"module\"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage(\"ready\")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:\"process\",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error(\"What is op \"+n.toString(16)+\" at \"+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor(\"gameboy-processor\",GameboyProcessor);\n"; | ||
var wasmEncoded = 'AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaGFuAwAFcmNoYW4DAQqhOglTAAJAIAFBH00EQCAAQcCRAmwhACABQRZHBEAgAEGUoQJqLQAAR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I8CaiAAIABBmJECai0AAEEPcUEKdCAAQZeRAmotAABBAnRyakHEAGooAgA2AgAPCyAAQaiPAmogAkEGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEECcjoAAA8LIAAgAkEHdjoA5I8CDwsgAEHojwJqIAAgAkECdGpBxIYCaigCADYCAA8LIABBpJACaiACQQV2QQNxOgAADwsgAEHwjwJqIAAgAEGdkQJqLQAAQQ9xQQp0IABBnJECai0AAEECdHJqQcSAAWooAgA2AgAPCyAAQfiPAmogAkEGdkEBcToAACAAQfCPAmogACAAQZ2RAmotAABBD3FBCnQgAEGckQJqLQAAQQJ0cmpBxIABaigCADYCACACQRh0QRh1QX9KDQcgAC0A5I8CRQRAIABBpZACakEAOgAAIABB7I8CakEANgIAIABB+Y8CakEAOgAACyAAQQE6AOSPAiAAQaiQAmpBADYCACAAQfmPAmpBAToAACAAQfSPAmpBADYCACAAQaWRAmoiACAALQAAQQRyOgAADwsgAEG4kAJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB0JACaiACQQN2QQFxIgE6AAACQCABBEAgAEHMkAJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHMkAJqIAJBBHY2AgALIAAgAUF/aiABcjoA0JACIABB1JACaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgACACQQdxQQZ0aiACQQJ2QTxxakHEgAJqKAIAIQEgAEH8kAJqIAJBA3ZBAXE2AgAgAEHAkAJqIAE2AgAPCyAAQciQAmogAkEGdkEBcToAACACQRh0QRh1QX9KDQMgAC0AtJACRQRAIABBvJACakEANgIACyAAQQE6ALSQAiAAQcSQAmpBADYCACAAQYCRAmpB//8BOwEAIABB3JACakE+OgAAIABB2JACakEANgIAIABBzJACaiAAQaCRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEIcjoAAA8LIABBhZECaiACQQdxOgAAIABBhpECaiACQQR2QQdxOgAADwsgAEGIkQJqIAJBAXE6AAAgAEGNkQJqIAJBB3Y6AAAgAEGKkQJqIAJBAXZBAXE6AAAgAEGHkQJqIAJBBHZBAXE6AAAgAEGMkQJqIAJBAnZBAXE6AAAgAEGJkQJqIAJBBXZBAXE6AAAgAEGOkQJqIAJBA3ZBAXE6AAAgAEGLkQJqIAJBBnZBAXE6AAAPCyAAIAJBB3Y6AISRAiACQRh0QRh1QQBIDQAgAEGA/wA7AI+RAiAAQfiOAmpBfzYCACAAQfyOAmogACgCJDYCACAAQZGRAmpBADoAACAAQeCOAmpB/wE6AAAgAEHcjgJqQQA2AgAgAEGSkQJqQf7/AjsAACAAQeSOAmogACgCBCIBNgIAIABB8I4CakL+HzcCACAAQdiOAmpBADsBACAAQciOAmogAEHAhgJqKAIAIgI2AgAgAEHQjgJqIABBvIABaigCADYCACAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBADYC3I4CIABBAToAxI4CIABBgI8CakEANgIAIABB6I4CakEANgIAIABB1I4CakEANgIAIABB7I4CakEBOgAAIABBmI8CaiACNgIAIABBlZECakG/gPz/ezYAACAAQbSPAmogATYCACAAQbCPAmpB/wE6AAAgAEGsjwJqQQA2AgAgAEGojwJqQQA7AQAgAEGgjwJqIABBwIABaigCADYCACAAQaWRAmoiBCAELQAAIgRBAXI6AAAgAC0AlI8CRQRAIABBnI8CakEANgIACyAAQQA2AqyPAiAAQQE6AJSPAiAAQQE6AOSPAiAAQZmRAmpB//4DOwAAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBpI8CakEANgIAIABBm5ECakGfAToAACAAQZyRAmpB//8COwAAIABBpJACakEAOwEAIABB7I8CakEANgIAIAAgBEEHcjoApZECIABBqJACakEANgIAIABB+I8CakGAAjsBACA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AEGDCAsNQQAAgEAAAABAj6qqPwBBkAgLB5AZAQCQHwEAQZAMCweQGwEAkCEBAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBBWNsYW5nDzEwLjAuMC00dWJ1bnR1MQ=='; | ||
APU.C3 = 44, APU.Cs3 = 156, APU.D3 = 263, APU.Ds3 = 363, APU.E3 = 457, APU.F3 = 547, APU.Fs3 = 631, APU.G3 = 710, APU.Gs3 = 786, APU.A3 = 856, APU.As3 = 923, APU.B3 = 986, APU.C4 = 1046, APU.Cs4 = 1102, APU.D4 = 1155, APU.Ds4 = 1205, APU.E4 = 1253, APU.F4 = 1297, APU.Fs4 = 1339, APU.G4 = 1379, APU.Gs4 = 1417, APU.A4 = 1452, APU.As4 = 1486, APU.B4 = 1517, APU.C5 = 1547, APU.Cs5 = 1575, APU.D5 = 1602, APU.Ds5 = 1627, APU.E5 = 1650, APU.F5 = 1673, APU.Fs5 = 1694, APU.G5 = 1714, APU.Gs5 = 1732, APU.A5 = 1750, APU.As5 = 1767, APU.B5 = 1783, APU.C6 = 1798, APU.Cs6 = 1812, APU.D6 = 1825, APU.Ds6 = 1837, APU.E6 = 1849, APU.F6 = 1860, APU.Fs6 = 1871, APU.G6 = 1881, APU.Gs6 = 1890, APU.A6 = 1899, APU.As6 = 1907, APU.B6 = 1915, APU.C7 = 1923, APU.Cs7 = 1930, APU.D7 = 1936, APU.Ds7 = 1943, APU.E7 = 1949, APU.F7 = 1954, APU.Fs7 = 1959, APU.G7 = 1964, APU.Gs7 = 1969, APU.A7 = 1974, APU.As7 = 1978, APU.B7 = 1982, APU.C8 = 1985, APU.Cs8 = 1989, APU.D8 = 1992, APU.Ds8 = 1995, APU.E8 = 1998, APU.F8 = 2001, APU.Fs8 = 2004, APU.G8 = 2006, APU.Gs8 = 2009, APU.A8 = 2011, APU.As8 = 2013, APU.B8 = 2015; | ||
if ('webkitAudioContext' in window) { | ||
window.AudioContext = webkitAudioContext; | ||
var workletSource = "\"use strict\";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,\"value\"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||\"object\"!=typeof e&&\"function\"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");return t}function _inherits(t,e){if(\"function\"!=typeof e&&null!==e)throw new TypeError(\"Super expression must either be null or a function\");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e=\"function\"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if(\"function\"!=typeof t)throw new TypeError(\"Super expression must either be null or a function\");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if(\"undefined\"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if(\"function\"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf(\"[native code]\")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if(\"write\"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if(\"play\"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if(\"module\"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage(\"ready\")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:\"process\",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error(\"What is op \"+n.toString(16)+\" at \"+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor(\"gameboy-processor\",GameboyProcessor);\n"; | ||
var wasmEncoded = 'AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaGFuAwAFcmNoYW4DAQqhOglTAAJAIAFBH00EQCAAQcCRAmwhACABQRZHBEAgAEGUoQJqLQAARQ0CCyAAQZAQaiABIAIQAQ8LIAFBL0sNACAAQcCRAmwgAWpBn6ECaiACOgAACwuBFgECfyAAIAFqQY+RAmoiAyACOgAAAkAgAUEWSw0AAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAIAFBAWsOFgECAwQVBQYHCAkKCwwNFQ4PEBESExQACyAAQfSOAmogAkEHcTYCACAAQfiOAmogAkEDdkEBcSIBQX9qIAFyNgIAIABB/I4CaiAAIAJBAnZBHHFqQSRqKAIANgIADwsgAEHZjgJqIAJBBnY6AAAgAEHIjgJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB4I4CaiACQQN2QQFxIgE6AAACQCABBEAgAEHcjgJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHcjgJqIAJBBHY2AgALIAAgAUF/aiABcjoA4I4CIABB5I4CaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHYjgJqIAJBBnZBAXE6AAAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIAIAJBGHRBGHVBf0oNECAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBAToAxI4CIABB1I4CakEANgIAIABBgI8CakEANgIAIABB6I4CakEANgIAIABB7I4CakEBOgAAIABB3I4CaiAAQZGRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEBcjoAAA8LIABBqY8CaiACQQZ2OgAAIABBmI8CaiAAIAJBP3FBAnRqQcSEAmooAgA2AgAPCyAAQbCPAmogAkEDdkEBcSIBOgAAAkAgAQRAIABBrI8CaiIDQQAgAygCACIDQQFqIANBDkobNgIADAELIABBrI8CaiACQQR2NgIACyAAIAFBf2ogAXI6ALCPAiAAQbSPAmogACACQQdxQQJ0akEEaigCADYCAA8LIABBoI8CaiAAIABBmJECai0AAEEPcUEKdCAAQZeRAmotAABBAnRyakHEAGooAgA2AgAPCyAAQaiPAmogAkEGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEECcjoAAA8LIAAgAkEHdjoA5I8CDwsgAEHojwJqIAAgAkECdGpBxIYCaigCADYCAA8LIABBpJACaiACQQV2QQNxOgAADwsgAEHwjwJqIAAgAEGdkQJqLQAAQQ9xQQp0IABBnJECai0AAEECdHJqQcSAAWooAgA2AgAPCyAAQfiPAmogAkEGdkEBcToAACAAQfCPAmogACAAQZ2RAmotAABBD3FBCnQgAEGckQJqLQAAQQJ0cmpBxIABaigCADYCACACQRh0QRh1QX9KDQcgAC0A5I8CRQRAIABBpZACakEAOgAAIABB7I8CakEANgIAIABB+Y8CakEAOgAACyAAQQE6AOSPAiAAQaiQAmpBADYCACAAQfmPAmpBAToAACAAQfSPAmpBADYCACAAQaWRAmoiACAALQAAQQRyOgAADwsgAEG4kAJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB0JACaiACQQN2QQFxIgE6AAACQCABBEAgAEHMkAJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHMkAJqIAJBBHY2AgALIAAgAUF/aiABcjoA0JACIABB1JACaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgACACQQdxQQZ0aiACQQJ2QTxxakHEgAJqKAIAIQEgAEH8kAJqIAJBA3ZBAXE2AgAgAEHAkAJqIAE2AgAPCyAAQciQAmogAkEGdkEBcToAACACQRh0QRh1QX9KDQMgAC0AtJACRQRAIABBvJACakEANgIACyAAQQE6ALSQAiAAQcSQAmpBADYCACAAQYCRAmpB//8BOwEAIABB3JACakE+OgAAIABB2JACakEANgIAIABBzJACaiAAQaCRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEIcjoAA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QtYnkBBWNsYW5nDzEwLjAuMC00dWJ1bnR1MQ=='; | ||
export var C3 = 44, Cs3 = 156, D3 = 263, Ds3 = 363, E3 = 457, F3 = 547, Fs3 = 631, G3 = 710, Gs3 = 786, A3 = 856, As3 = 923, B3 = 986, C4 = 1046, Cs4 = 1102, D4 = 1155, Ds4 = 1205, E4 = 1253, F4 = 1297, Fs4 = 1339, G4 = 1379, Gs4 = 1417, A4 = 1452, As4 = 1486, B4 = 1517, C5 = 1547, Cs5 = 1575, D5 = 1602, Ds5 = 1627, E5 = 1650, F5 = 1673, Fs5 = 1694, G5 = 1714, Gs5 = 1732, A5 = 1750, As5 = 1767, B5 = 1783, C6 = 1798, Cs6 = 1812, D6 = 1825, Ds6 = 1837, E6 = 1849, F6 = 1860, Fs6 = 1871, G6 = 1881, Gs6 = 1890, A6 = 1899, As6 = 1907, B6 = 1915, C7 = 1923, Cs7 = 1930, D7 = 1936, Ds7 = 1943, E7 = 1949, F7 = 1954, Fs7 = 1959, G7 = 1964, Gs7 = 1969, A7 = 1974, As7 = 1978, B7 = 1982, C8 = 1985, Cs8 = 1989, D8 = 1992, Ds8 = 1995, E8 = 1998, F8 = 2001, Fs8 = 2004, G8 = 2006, Gs8 = 2009, A8 = 2011, As8 = 2013, B8 = 2015; | ||
if ('webkitAudioContext' in window) { | ||
window.AudioContext = webkitAudioContext; | ||
} | ||
/** | ||
* Audio Context that all APU stuff runs on | ||
*/ | ||
export var audioContext = new AudioContext({ latencyHint: 'interactive' }); | ||
/** | ||
* Resumes the audio context. Should be called as a result of some user event, like a click. | ||
* Until this is called, the browser won't allow any sound to play. | ||
*/ | ||
export function allow() { | ||
audioContext.resume(); | ||
} | ||
var lastVolume = 1; | ||
var userVolumeNode = audioContext.createGain(); | ||
userVolumeNode.gain.setValueAtTime(lastVolume, audioContext.currentTime); | ||
userVolumeNode.connect(audioContext.destination); | ||
/** | ||
* Volume multiplier intended to be changed by a user-facing volume control | ||
* @param newVolume Value between 0 and 1 | ||
*/ | ||
export function changeUserVolume(newVolume) { | ||
if (newVolume >= 0 && newVolume <= 1) { | ||
userVolumeNode.gain.setValueAtTime(lastVolume, audioContext.currentTime); | ||
userVolumeNode.gain.linearRampToValueAtTime(newVolume, audioContext.currentTime + 0.05); | ||
lastVolume = newVolume; | ||
} | ||
/** | ||
* Audio Context that all APU stuff runs on | ||
*/ | ||
APU.audioContext = new AudioContext({ latencyHint: 'interactive' }); | ||
/** | ||
* Resumes the audio context. Should be called as a result of some user event, like a click. | ||
* Until this is called, the browser won't allow any sound to play. | ||
*/ | ||
function allow() { | ||
APU.audioContext.resume(); | ||
} | ||
APU.allow = allow; | ||
var lastVolume = 1; | ||
var userVolumeNode = APU.audioContext.createGain(); | ||
userVolumeNode.gain.setValueAtTime(lastVolume, APU.audioContext.currentTime); | ||
userVolumeNode.connect(APU.audioContext.destination); | ||
/** | ||
* Volume multiplier intended to be changed by a user-facing volume control | ||
* @param newVolume Value between 0 and 1 | ||
*/ | ||
function changeUserVolume(newVolume) { | ||
if (newVolume >= 0 && newVolume <= 1) { | ||
userVolumeNode.gain.setValueAtTime(lastVolume, APU.audioContext.currentTime); | ||
userVolumeNode.gain.linearRampToValueAtTime(newVolume, APU.audioContext.currentTime + 0.05); | ||
lastVolume = newVolume; | ||
} | ||
/** | ||
* The last audio node, which is connected to the AudioContext's destination | ||
*/ | ||
export var audioNode = userVolumeNode; | ||
var workletBlob = new Blob([workletSource], { type: 'application/javascript' }); | ||
var workletURL = URL.createObjectURL(workletBlob); | ||
var wasmBuffer = new Uint8Array(atob(wasmEncoded).split('').map(function (s) { return s.charCodeAt(0); })).buffer; | ||
var nodePromise = audioContext.audioWorklet.addModule(workletURL).then(function () { | ||
var node = new AudioWorkletNode(audioContext, 'gameboy-processor', { outputChannelCount: [2] }); | ||
node.connect(userVolumeNode); | ||
return new Promise(function (resolve) { | ||
node.port.onmessage = function (_a) { | ||
var e = _a.data; | ||
return (e === 'ready') && resolve(node); | ||
}; | ||
node.port.postMessage({ type: 'module', data: wasmBuffer }); | ||
}); | ||
}); | ||
var nextInstanceId = 0; | ||
var allowSFX = true; | ||
function track(data, loop, mask) { | ||
if (mask === void 0) { mask = null; } | ||
return { | ||
play: function () { | ||
if (mask && !allowSFX) | ||
return null; | ||
var id = ++nextInstanceId; | ||
nodePromise.then(function (node) { | ||
node.port.postMessage({ id: id, type: 'play', data: data, loop: loop, mask: mask }); | ||
}); | ||
return { | ||
pause: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'pause' }); }); | ||
}, | ||
resume: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'resume' }); }); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
/** | ||
* Create a BGM object | ||
* | ||
* When a BGM is played, it will immediately stop any previous BGM and SFX | ||
* | ||
* TODO: resume paused BGM | ||
* @param data Data block of a VGM file | ||
* @param loop Byte offset of the data block to loop back to upon completion. (-1 if no loop) | ||
*/ | ||
export function bgm(data, loop) { | ||
if (loop === void 0) { loop = 0; } | ||
return track(data, loop); | ||
} | ||
/** | ||
* Create an SFX object | ||
* | ||
* When a SFX is played, it will immediately stop any previous SFX | ||
* | ||
* It will also immediately take control away from the BGM for playing on channels, | ||
* and should silence those channels. When the SFX completes, it will give control | ||
* back to the BGM for all channels. | ||
* | ||
* Right now a channel mask is used for an SFX to declare which channels it intends | ||
* to use. A smarter mechanism may be used in the future, such as scanning the data. | ||
* @param data Data block of a VGM file | ||
* @param mask Array of four 0's or 1's that indicates which channels this SFX will be using | ||
*/ | ||
export function sfx(data, mask) { | ||
if (mask === void 0) { mask = [1, 1, 1, 1]; } | ||
return track(data, -1, mask); | ||
} | ||
/** | ||
* Creates a BGM object from an entire .vgm file contents, as an ArrayBuffer | ||
* @param arrayBuffer | ||
*/ | ||
export function fromFile(arrayBuffer) { | ||
// make sure the 4-byte header is correct. | ||
// It should be "Vgm " (space at the end) | ||
var header = new Uint8Array(arrayBuffer, 0, 4); | ||
for (var i = 0; i < 4; ++i) { | ||
if (header[i] !== 'Vgm '.charCodeAt(i)) { | ||
throw new Error('Invalid header'); | ||
} | ||
} | ||
APU.changeUserVolume = changeUserVolume; | ||
/** | ||
* The last audio node, which is connected to the AudioContext's destination | ||
*/ | ||
APU.audioNode = userVolumeNode; | ||
var workletBlob = new Blob([workletSource], { type: 'application/javascript' }); | ||
var workletURL = URL.createObjectURL(workletBlob); | ||
var wasmBuffer = new Uint8Array(atob(wasmEncoded).split('').map(function (s) { return s.charCodeAt(0); })).buffer; | ||
var nodePromise = APU.audioContext.audioWorklet.addModule(workletURL).then(function () { | ||
var node = new AudioWorkletNode(APU.audioContext, 'gameboy-processor', { outputChannelCount: [2] }); | ||
node.connect(userVolumeNode); | ||
return new Promise(function (resolve) { | ||
node.port.onmessage = function (_a) { | ||
var e = _a.data; | ||
return (e === 'ready') && resolve(node); | ||
// get where vgm data starts. this is | ||
// (address of where vgm offset is stored, always 0x34) | ||
// + (value of vgm offset.) | ||
var data0 = 0x34 + new Uint32Array(arrayBuffer, 0x34, 1)[0]; | ||
// the loop point works similarly | ||
var loopPoint = 0x1c + new Uint32Array(arrayBuffer, 0x1c, 1)[0] - data0; | ||
// finally, the rest of the file is the data | ||
var data = arrayBuffer.slice(data0); | ||
return bgm(data, loopPoint); | ||
} | ||
/** | ||
* Slowly fade out the BGM. This also immediately stops current | ||
* SFX, and prevents any new SFX from playing until completion. | ||
* @param millis Number of milliseconds for the fade to complete | ||
* @returns A promise that resolves when the fade has completed | ||
*/ | ||
export function fade(millis) { | ||
if (millis === void 0) { millis = 2000; } | ||
// TODO: should be no-op if already fading | ||
return nodePromise.then(function (node) { | ||
// halt any currently-playing SFX | ||
sfx(new ArrayBuffer(0), [0, 0, 0, 0]).play(); | ||
if (millis > 0) { | ||
// disallow sfx until fade completes | ||
allowSFX = false; | ||
var _loop_1 = function (i) { | ||
var vol = 6 - i; | ||
setTimeout(function () { return node.port.postMessage({ type: 'write', layer: 0, register: 0x14, value: (vol << 4) + (vol) }); }, millis * i / 7); | ||
}; | ||
node.port.postMessage({ type: 'module', data: wasmBuffer }); | ||
}); | ||
}); | ||
var nextInstanceId = 0; | ||
var allowSFX = true; | ||
function track(data, loop, mask) { | ||
if (mask === void 0) { mask = null; } | ||
return { | ||
play: function () { | ||
if (mask && !allowSFX) | ||
return null; | ||
var id = ++nextInstanceId; | ||
nodePromise.then(function (node) { | ||
node.port.postMessage({ id: id, type: 'play', data: data, loop: loop, mask: mask }); | ||
}); | ||
return { | ||
pause: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'pause' }); }); | ||
}, | ||
resume: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'resume' }); }); | ||
} | ||
}; | ||
// use NR50 to fade out | ||
for (var i = 0; i <= 5; ++i) { | ||
_loop_1(i); | ||
} | ||
}; | ||
} | ||
/** | ||
* Create a BGM object | ||
* | ||
* When a BGM is played, it will immediately stop any previous BGM and SFX | ||
* | ||
* TODO: resume paused BGM | ||
* @param data Data block of a VGM file | ||
* @param loop Byte offset of the data block to loop back to upon completion. (-1 if no loop) | ||
*/ | ||
function bgm(data, loop) { | ||
if (loop === void 0) { loop = 0; } | ||
return track(data, loop); | ||
} | ||
APU.bgm = bgm; | ||
/** | ||
* Create an SFX object | ||
* | ||
* When a SFX is played, it will immediately stop any previous SFX | ||
* | ||
* It will also immediately take control away from the BGM for playing on channels, | ||
* and should silence those channels. When the SFX completes, it will give control | ||
* back to the BGM for all channels. | ||
* | ||
* Right now a channel mask is used for an SFX to declare which channels it intends | ||
* to use. A smarter mechanism may be used in the future, such as scanning the data. | ||
* @param data Data block of a VGM file | ||
* @param mask Array of four 0's or 1's that indicates which channels this SFX will be using | ||
*/ | ||
function sfx(data, mask) { | ||
if (mask === void 0) { mask = [1, 1, 1, 1]; } | ||
return track(data, -1, mask); | ||
} | ||
APU.sfx = sfx; | ||
/** | ||
* Creates a BGM object from an entire .vgm file contents, as an ArrayBuffer | ||
* @param arrayBuffer | ||
*/ | ||
function fromFile(arrayBuffer) { | ||
// make sure the 4-byte header is correct. | ||
// It should be "Vgm " (space at the end) | ||
var header = new Uint8Array(arrayBuffer, 0, 4); | ||
for (var i = 0; i < 4; ++i) { | ||
if (header[i] !== 'Vgm '.charCodeAt(i)) { | ||
throw new Error('Invalid header'); | ||
} | ||
// stop sound with NR52 | ||
setTimeout(function () { | ||
node.port.postMessage({ type: 'write', layer: 0, register: 0x16, value: 0 }); | ||
// and clear song | ||
bgm(new ArrayBuffer(0), -1).play(); | ||
}, millis * 6 / 7); | ||
} | ||
// get where vgm data starts. this is | ||
// (address of where vgm offset is stored, always 0x34) | ||
// + (value of vgm offset.) | ||
var data0 = 0x34 + new Uint32Array(arrayBuffer, 0x34, 1)[0]; | ||
// the loop point works similarly | ||
var loopPoint = 0x1c + new Uint32Array(arrayBuffer, 0x1c, 1)[0] - data0; | ||
// finally, the rest of the file is the data | ||
var data = arrayBuffer.slice(data0); | ||
return bgm(data, loopPoint); | ||
} | ||
APU.fromFile = fromFile; | ||
/** | ||
* Slowly fade out the BGM. This also immediately stops current | ||
* SFX, and prevents any new SFX from playing until completion. | ||
* @param millis Number of milliseconds for the fade to complete | ||
* @returns A promise that resolves when the fade has completed | ||
*/ | ||
function fade(millis) { | ||
if (millis === void 0) { millis = 2000; } | ||
// TODO: should be no-op if already fading | ||
return nodePromise.then(function (node) { | ||
// halt any currently-playing SFX | ||
sfx(new ArrayBuffer(0), [0, 0, 0, 0]).play(); | ||
if (millis > 0) { | ||
// disallow sfx until fade completes | ||
allowSFX = false; | ||
var _loop_1 = function (i) { | ||
var vol = 6 - i; | ||
setTimeout(function () { return node.port.postMessage({ type: 'write', layer: 0, register: 0x14, value: (vol << 4) + (vol) }); }, millis * i / 7); | ||
}; | ||
// use NR50 to fade out | ||
for (var i = 0; i <= 5; ++i) { | ||
_loop_1(i); | ||
} | ||
// stop sound with NR52 | ||
setTimeout(function () { | ||
node.port.postMessage({ type: 'write', layer: 0, register: 0x16, value: 0 }); | ||
// and clear song | ||
bgm(new ArrayBuffer(0), -1).play(); | ||
}, millis * 6 / 7); | ||
} | ||
// resolve | ||
return new Promise(function (resolve) { return setTimeout(resolve, millis); }) | ||
// ... and allow sfx once again | ||
.then(function () { allowSFX = true; }); | ||
}); | ||
} | ||
APU.fade = fade; | ||
function compile(commands) { | ||
} | ||
APU.compile = compile; | ||
})(APU || (APU = {})); | ||
// resolve | ||
return new Promise(function (resolve) { return setTimeout(resolve, millis); }) | ||
// ... and allow sfx once again | ||
.then(function () { allowSFX = true; }); | ||
}); | ||
} | ||
export function compile(commands) { | ||
} |
@@ -1,1 +0,1 @@ | ||
var APU;!function(A){A.C3=44,A.Cs3=156,A.D3=263,A.Ds3=363,A.E3=457,A.F3=547,A.Fs3=631,A.G3=710,A.Gs3=786,A.A3=856,A.As3=923,A.B3=986,A.C4=1046,A.Cs4=1102,A.D4=1155,A.Ds4=1205,A.E4=1253,A.F4=1297,A.Fs4=1339,A.G4=1379,A.Gs4=1417,A.A4=1452,A.As4=1486,A.B4=1517,A.C5=1547,A.Cs5=1575,A.D5=1602,A.Ds5=1627,A.E5=1650,A.F5=1673,A.Fs5=1694,A.G5=1714,A.Gs5=1732,A.A5=1750,A.As5=1767,A.B5=1783,A.C6=1798,A.Cs6=1812,A.D6=1825,A.Ds6=1837,A.E6=1849,A.F6=1860,A.Fs6=1871,A.G6=1881,A.Gs6=1890,A.A6=1899,A.As6=1907,A.B6=1915,A.C7=1923,A.Cs7=1930,A.D7=1936,A.Ds7=1943,A.E7=1949,A.F7=1954,A.Fs7=1959,A.G7=1964,A.Gs7=1969,A.A7=1974,A.As7=1978,A.B7=1982,A.C8=1985,A.Cs8=1989,A.D8=1992,A.Ds8=1995,A.E8=1998,A.F8=2001,A.Fs8=2004,A.G8=2006,A.Gs8=2009,A.A8=2011,A.As8=2013,A.B8=2015,"webkitAudioContext"in window&&(window.AudioContext=webkitAudioContext),A.audioContext=new AudioContext({latencyHint:"interactive"}),A.allow=function(){A.audioContext.resume()};var B=1,C=A.audioContext.createGain();C.gain.setValueAtTime(B,A.audioContext.currentTime),C.connect(A.audioContext.destination),A.changeUserVolume=function(g){g>=0&&g<=1&&(C.gain.setValueAtTime(B,A.audioContext.currentTime),C.gain.linearRampToValueAtTime(g,A.audioContext.currentTime+.05),B=g)},A.audioNode=C;var g=new Blob(['"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return t}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if("write"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if("play"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if("module"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage("ready")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:"process",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error("What is op "+n.toString(16)+" at "+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor("gameboy-processor",GameboyProcessor);\n'],{type:"application/javascript"}),t=URL.createObjectURL(g),I=new Uint8Array(atob("AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaG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QQR2NgIACyAAIAFBf2ogAXI6ALCPAiAAQbSPAmogACACQQdxQQJ0akEEaigCADYCAA8LIABBoI8CaiAAIABBmJECai0AAEEPcUEKdCAAQZeRAmotAABBAnRyakHEAGooAgA2AgAPCyAAQaiPAmogAkEGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEECcjoAAA8LIAAgAkEHdjoA5I8CDwsgAEHojwJqIAAgAkECdGpBxIYCaigCADYCAA8LIABBpJACaiACQQV2QQNxOgAADwsgAEHwjwJqIAAgAEGdkQJqLQAAQQ9xQQp0IABBnJECai0AAEECdHJqQcSAAWooAgA2AgAPCyAAQfiPAmogAkEGdkEBcToAACAAQfCPAmogACAAQZ2RAmotAABBD3FBCnQgAEGckQJqLQAAQQJ0cmpBxIABaigCADYCACACQRh0QRh1QX9KDQcgAC0A5I8CRQRAIABBpZACakEAOgAAIABB7I8CakEANgIAIABB+Y8CakEAOgAACyAAQQE6AOSPAiAAQaiQAmpBADYCACAAQfmPAmpBAToAACAAQfSPAmpBADYCACAAQaWRAmoiACAALQAAQQRyOgAADwsgAEG4kAJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB0JACaiACQQN2QQFxIgE6AAACQCABBEAgAEHMkAJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHMkAJqIAJBBHY2AgALIAAgAUF/aiABcjoA0JACIABB1JACaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgACACQQdxQQZ0aiACQQJ2QTxxakHEgAJqKAIAIQEgAEH8kAJqIAJBA3ZBAXE2AgAgAEHAkAJqIAE2AgAPCyAAQciQAmogAkEGdkEBcToAACACQRh0QRh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qAgCSOAIAIABBkMsEaiAAQZDDBGoqAgAgAEGQxwRqKgIAkjgCACAAQQRqIgANAAsLCy4DAEGDCAsNQQAAgEAAAABAj6qqPwBBkAgLB5AZAQCQHwEAQZAMCweQGwEAkCEBAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBBWNsYW5nDzEwLjAuMC00dWJ1bnR1MQ==").split("").map((function(A){return A.charCodeAt(0)}))).buffer,Q=A.audioContext.audioWorklet.addModule(t).then((function(){var B=new AudioWorkletNode(A.audioContext,"gameboy-processor",{outputChannelCount:[2]});return B.connect(C),new Promise((function(A){B.port.onmessage=function(C){return"ready"===C.data&&A(B)},B.port.postMessage({type:"module",data:I})}))})),e=0,i=!0;function E(A,B,C){return void 0===C&&(C=null),{play:function(){if(C&&!i)return null;var g=++e;return Q.then((function(t){t.port.postMessage({id:g,type:"play",data:A,loop:B,mask:C})})),{pause:function(){Q.then((function(A){return A.port.postMessage({id:g,type:"pause"})}))},resume:function(){Q.then((function(A){return A.port.postMessage({id:g,type:"resume"})}))}}}}}function o(A,B){return void 0===B&&(B=0),E(A,B)}function n(A,B){return void 0===B&&(B=[1,1,1,1]),E(A,-1,B)}A.bgm=o,A.sfx=n,A.fromFile=function(A){for(var B=new Uint8Array(A,0,4),C=0;C<4;++C)if(B[C]!=="Vgm ".charCodeAt(C))throw new Error("Invalid header");var g=52+new Uint32Array(A,52,1)[0],t=28+new Uint32Array(A,28,1)[0]-g;return o(A.slice(g),t)},A.fade=function(A){return void 0===A&&(A=2e3),Q.then((function(B){if(n(new ArrayBuffer(0),[0,0,0,0]).play(),A>0){i=!1;for(var C=function(C){var g=6-C;setTimeout((function(){return B.port.postMessage({type:"write",layer:0,register:20,value:(g<<4)+g})}),A*C/7)},g=0;g<=5;++g)C(g);setTimeout((function(){B.port.postMessage({type:"write",layer:0,register:22,value:0}),o(new ArrayBuffer(0),-1).play()}),6*A/7)}return new Promise((function(B){return setTimeout(B,A)})).then((function(){i=!0}))}))},A.compile=function(A){}}(APU||(APU={})); | ||
var workletSource='"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return t}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if("write"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if("play"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if("module"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage("ready")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:"process",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error("What is op "+n.toString(16)+" at "+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor("gameboy-processor",GameboyProcessor);\n',wasmEncoded="AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaGFuAwAFcmNoYW4DAQqhOglTAAJAIAFBH00EQCAAQcCRAmwhACABQRZHBEAgAEGUoQJqLQAARQ0CCyAAQZAQaiABIAIQAQ8LIAFBL0sNACAAQcCRAmwgAWpBn6ECaiACOgAACwuBFgECfyAAIAFqQY+RAmoiAyACOgAAAkAgAUEWSw0AAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAIAFBAWsOFgECAwQVBQYHCAkKCwwNFQ4PEBESExQACyAAQfSOAmogAkEHcTYCACAAQfiOAmogAkEDdkEBcSIBQX9qIAFyNgIAIABB/I4CaiAAIAJBAnZBHHFqQSRqKAIANgIADwsgAEHZjgJqIAJBBnY6AAAgAEHIjgJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB4I4CaiACQQN2QQFxIgE6AAACQCABBEAgAEHcjgJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHcjgJqIAJBBHY2AgALIAAgAUF/aiABcjoA4I4CIABB5I4CaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHYjgJqIAJBBnZBAXE6AAAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIAIAJBGHRBGHVBf0oNECAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBAToAxI4CIABB1I4CakEANgIAIABBgI8CakEANgIAIABB6I4CakEANgIAIABB7I4CakEBOgAAIABB3I4CaiAAQZGRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEBcjoAAA8LIABBqY8CaiACQQZ2OgAAIABBmI8CaiAAIAJBP3FBAnRqQcSEAmooAgA2AgAPCyAAQbCPAmogAkEDdkEBcSIBOgAAAkAgAQRAIABBrI8CaiIDQQAgAygCACIDQQFqIANBDkobNgIADAELIABBrI8CaiACQQR2NgIACyAAIAFBf2ogAXI6ALCPAiAAQbSPAmogACACQQdxQQJ0akEEaigCADYCAA8LIABBoI8CaiAAIABBmJECai0AAEEPcUEKdCAAQZeRAmotAABBAnRyakHEAGooAgA2AgAPCyAAQaiPAmogAkEGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEECcjoAAA8LIAAgAkEHdjoA5I8CDwsgAEHojwJqIAAgAkECdGpBxIYCaigCADYCAA8LIABBpJACaiACQQV2QQNxOgAADwsgAEHwjwJqIAAgAEGdkQJqLQAAQQ9xQQp0IABBnJECai0AAEECdHJqQcSAAWooAgA2AgAPCyAAQfiPAmogAkEGdkEBcToAACAAQfCPAmogACAAQZ2RAmotAABBD3FBCnQgAEGckQJqLQAAQQJ0cmpBxIABaigCADYCACACQRh0QRh1QX9KDQcgAC0A5I8CRQRAIABBpZACakEAOgAAIABB7I8CakEANgIAIABB+Y8CakEAOgAACyAAQQE6AOSPAiAAQaiQAmpBADYCACAAQfmPAmpBAToAACAAQfSPAmpBADYCACAAQaWRAmoiACAALQAAQQRyOgAADwsgAEG4kAJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB0JACaiACQQN2QQFxIgE6AAACQCABBEAgAEHMkAJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHMkAJqIAJBBHY2AgALIAAgAUF/aiABcjoA0JACIABB1JACaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgACACQQdxQQZ0aiACQQJ2QTxxakHEgAJqKAIAIQEgAEH8kAJqIAJBA3ZBAXE2AgAgAEHAkAJqIAE2AgAPCyAAQciQAmogAkEGdkEBcToAACACQRh0QRh1QX9KDQMgAC0AtJACRQRAIABBvJACakEANgIACyAAQQE6ALSQAiAAQcSQAmpBADYCACAAQYCRAmpB//8BOwEAIABB3JACakE+OgAAIABB2JACakEANgIAIABBzJACaiAAQaCRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEIcjoAAA8LIABBhZECaiACQQdxOgAAIABBhpECaiAC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1bnR1MQ==";export var C3=44,Cs3=156,D3=263,Ds3=363,E3=457,F3=547,Fs3=631,G3=710,Gs3=786,A3=856,As3=923,B3=986,C4=1046,Cs4=1102,D4=1155,Ds4=1205,E4=1253,F4=1297,Fs4=1339,G4=1379,Gs4=1417,A4=1452,As4=1486,B4=1517,C5=1547,Cs5=1575,D5=1602,Ds5=1627,E5=1650,F5=1673,Fs5=1694,G5=1714,Gs5=1732,A5=1750,As5=1767,B5=1783,C6=1798,Cs6=1812,D6=1825,Ds6=1837,E6=1849,F6=1860,Fs6=1871,G6=1881,Gs6=1890,A6=1899,As6=1907,B6=1915,C7=1923,Cs7=1930,D7=1936,Ds7=1943,E7=1949,F7=1954,Fs7=1959,G7=1964,Gs7=1969,A7=1974,As7=1978,B7=1982,C8=1985,Cs8=1989,D8=1992,Ds8=1995,E8=1998,F8=2001,Fs8=2004,G8=2006,Gs8=2009,A8=2011,As8=2013,B8=2015;"webkitAudioContext"in window&&(window.AudioContext=webkitAudioContext);export var audioContext=new AudioContext({latencyHint:"interactive"});export function allow(){audioContext.resume()}var lastVolume=1,userVolumeNode=audioContext.createGain();userVolumeNode.gain.setValueAtTime(lastVolume,audioContext.currentTime),userVolumeNode.connect(audioContext.destination);export function changeUserVolume(A){A>=0&&A<=1&&(userVolumeNode.gain.setValueAtTime(lastVolume,audioContext.currentTime),userVolumeNode.gain.linearRampToValueAtTime(A,audioContext.currentTime+.05),lastVolume=A)}export var audioNode=userVolumeNode;var workletBlob=new Blob([workletSource],{type:"application/javascript"}),workletURL=URL.createObjectURL(workletBlob),wasmBuffer=new Uint8Array(atob(wasmEncoded).split("").map((function(A){return A.charCodeAt(0)}))).buffer,nodePromise=audioContext.audioWorklet.addModule(workletURL).then((function(){var A=new AudioWorkletNode(audioContext,"gameboy-processor",{outputChannelCount:[2]});return A.connect(userVolumeNode),new Promise((function(B){A.port.onmessage=function(t){return"ready"===t.data&&B(A)},A.port.postMessage({type:"module",data:wasmBuffer})}))})),nextInstanceId=0,allowSFX=!0;function track(A,B,t){return void 0===t&&(t=null),{play:function(){if(t&&!allowSFX)return null;var C=++nextInstanceId;return nodePromise.then((function(g){g.port.postMessage({id:C,type:"play",data:A,loop:B,mask:t})})),{pause:function(){nodePromise.then((function(A){return A.port.postMessage({id:C,type:"pause"})}))},resume:function(){nodePromise.then((function(A){return A.port.postMessage({id:C,type:"resume"})}))}}}}}export function bgm(A,B){return void 0===B&&(B=0),track(A,B)}export function sfx(A,B){return void 0===B&&(B=[1,1,1,1]),track(A,-1,B)}export function fromFile(A){for(var B=new Uint8Array(A,0,4),t=0;t<4;++t)if(B[t]!=="Vgm ".charCodeAt(t))throw new Error("Invalid header");var C=52+new Uint32Array(A,52,1)[0],g=28+new Uint32Array(A,28,1)[0]-C;return bgm(A.slice(C),g)}export function fade(A){return void 0===A&&(A=2e3),nodePromise.then((function(B){if(sfx(new ArrayBuffer(0),[0,0,0,0]).play(),A>0){allowSFX=!1;for(var t=function(t){var C=6-t;setTimeout((function(){return B.port.postMessage({type:"write",layer:0,register:20,value:(C<<4)+C})}),A*t/7)},C=0;C<=5;++C)t(C);setTimeout((function(){B.port.postMessage({type:"write",layer:0,register:22,value:0}),bgm(new ArrayBuffer(0),-1).play()}),6*A/7)}return new Promise((function(B){return setTimeout(B,A)})).then((function(){allowSFX=!0}))}))}export function compile(A){} |
!function(){function e(e,t){var r=document.createElement("iframe");r.style.cssText="position:absolute;left:0;top:-999px;width:1px;height:1px;",t.appendChild(r);var o=r.contentWindow,n=o.document,i="var window,$hook";for(var a in o)a in e||"eval"===a||(i+=",",i+=a);for(var s in e)i+=",",i+=s,i+="=self.",i+=s;var u=n.createElement("script");u.appendChild(n.createTextNode('function $hook(self,console) {"use strict";\n '+i+";return function() {return eval(arguments[0])}}")),n.body.appendChild(u),this.exec=o.$hook.call(e,e,console)}var t,r=[];function o(e){var t=this,o={},i=-1;this.parameters.forEach(function(e,n){var a=r[++i]||(r[i]=new Float32Array(t.bufferSize));a.fill(e.value),o[n]=a}),this.processor.realm.exec("self.sampleRate=sampleRate="+this.context.sampleRate+";self.currentTime=currentTime="+this.context.currentTime);var a=n(e.inputBuffer),s=n(e.outputBuffer);this.instance.process([a],[s],o)}function n(e){for(var t=[],r=0;r<e.numberOfChannels;r++)t[r]=e.getChannelData(r);return t}function i(e){return e.$$processors||(e.$$processors={})}"function"==typeof AudioWorkletNode&&"audioWorklet"in AudioContext.prototype||(self.AudioWorkletNode=function(e,r,n){var a=i(e)[r],s=e.createScriptProcessor(2048,2,n&&n.outputChannelCount?n.outputChannelCount[0]:2);if(s.parameters=new Map,a.properties)for(var u=0;u<a.properties.length;u++){var c=a.properties[u],l=e.createGain().gain;l.value=c.defaultValue,s.parameters.set(c.name,l)}var p=new MessageChannel;t=p.port2;var f=new a.Processor(n||{});return t=null,s.port=p.port1,s.processor=a,s.instance=f,s.onaudioprocess=o,s},Object.defineProperty((self.AudioContext||self.webkitAudioContext).prototype,"audioWorklet",{get:function(){return this.$$audioWorklet||(this.$$audioWorklet=new self.AudioWorklet(this))}}),self.AudioWorklet=function(){function r(e){this.$$context=e}return r.prototype.addModule=function(r,o){var n=this;return fetch(r).then(function(e){if(!e.ok)throw Error(e.status);return e.text()}).then(function(r){var a={sampleRate:n.$$context.sampleRate,currentTime:n.$$context.currentTime,AudioWorkletProcessor:function(){this.port=t},registerProcessor:function(e,t){i(n.$$context)[e]={realm:s,context:a,Processor:t,properties:t.parameterDescriptors||[]}}};a.self=a;var s=new e(a,document.documentElement);return s.exec((o&&o.transpile||String)(r)),null})},r}())}(); | ||
//# sourceMappingURL=audioworklet-polyfill.js.map | ||
var APU; | ||
(function (APU) { | ||
var workletSource = "\"use strict\";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,\"value\"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||\"object\"!=typeof e&&\"function\"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");return t}function _inherits(t,e){if(\"function\"!=typeof e&&null!==e)throw new TypeError(\"Super expression must either be null or a function\");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e=\"function\"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if(\"function\"!=typeof t)throw new TypeError(\"Super expression must either be null or a function\");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if(\"undefined\"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if(\"function\"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf(\"[native code]\")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if(\"write\"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if(\"play\"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if(\"module\"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage(\"ready\")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:\"process\",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error(\"What is op \"+n.toString(16)+\" at \"+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor(\"gameboy-processor\",GameboyProcessor);\n"; | ||
var wasmEncoded = 'AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaGFuAwAFcmNoYW4DAQqhOglTAAJAIAFBH00EQCAAQcCRAmwhACABQRZHBEAgAEGUoQJqLQAARQ0CCyAAQZAQaiABIAIQAQ8LIAFBL0sNACAAQcCRAmwgAWpBn6ECaiACOgAACwuBFgECfyAAIAFqQY+RAmoiAyACOgAAAkAgAUEWSw0AAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAIAFBAWsOFgECAwQVBQYHCAkKCwwNFQ4PEBESExQACyAAQfSOAmogAkEHcTYCACAAQfiOAmogAkEDdkEBcSIBQX9qIAFyNgIAIABB/I4CaiAAIAJBAnZBHHFqQSRqKAIANgIADwsgAEHZjgJqIAJBBnY6AAAgAEHIjgJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB4I4CaiACQQN2QQFxIgE6AAACQCABBEAgAEHcjgJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHcjgJqIAJBBHY2AgALIAAgAUF/aiABcjoA4I4CIABB5I4CaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHYjgJqIAJBBnZBAXE6AAAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIAIAJBGHRBGHVBf0oNECAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBAToAxI4CIABB1I4CakEANgIAIABBgI8CakEANgIAIABB6I4CakEANgIAIABB7I4CakEBOgAAIABB3I4CaiAAQZGRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEBcjoAAA8LIABBqY8CaiACQQZ2OgAAIABBmI8CaiAAIAJBP3FBAnRqQcSEAmooAgA2AgAPCyAAQbCPAmogAkEDdkEBcSIBOgAAAkAgAQRAIABBrI8CaiIDQQAgAygCACIDQQFqIANBDkobNgIADAELIABBrI8CaiACQQR2NgIACyAAIAFBf2ogAXI6ALCPAiAAQbSPAmogACACQQdxQQJ0akEEaigCADYCAA8LIABBoI8CaiAAIABBmJECai0AAEEPcUEKdCAAQZeRAmotAABBAnRyakHEAGooAgA2AgAPCyAAQaiPAmogAkEGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaR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JqIAJBBXZBAXE6AAAgAEGOkQJqIAJBA3ZBAXE6AAAgAEGLkQJqIAJBBnZBAXE6AAAPCyAAIAJBB3Y6AISRAiACQRh0QRh1QQBIDQAgAEGA/wA7AI+RAiAAQfiOAmpBfzYCACAAQfyOAmogACgCJDYCACAAQZGRAmpBADoAACAAQeCOAmpB/wE6AAAgAEHcjgJqQQA2AgAgAEGSkQJqQf7/AjsAACAAQeSOAmogACgCBCIBNgIAIABB8I4CakL+HzcCACAAQdiOAmpBADsBACAAQciOAmogAEHAhgJqKAIAIgI2AgAgAEHQjgJqIABBvIABaigCADYCACAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBADYC3I4CIABBAToAxI4CIABBgI8CakEANgIAIABB6I4CakEANgIAIABB1I4CakEANgIAIABB7I4CakEBOgAAIABBmI8CaiACNgIAIABBlZECakG/gPz/ezYAACAAQbSPAmogATYCACAAQbCPAmpB/wE6AAAgAEGsjwJqQQA2AgAgAEGojwJqQQA7AQAgAEGgjwJqIABBwIABaigCADYCACAAQaWRAmoiBCAELQAAIgRBAXI6AAAgAC0AlI8CRQRAIABBnI8CakEANgIACyAAQQA2AqyPAiAAQQE6AJSPAiAAQQE6AOSPAiAAQZmRAmpB//4DOwAAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBpI8CakEANgIAIABBm5ECakGfAToAACAAQZyRAmpB//8COwAAIABBpJACakEAOwEAIABB7I8CakEANgIAIAAgBEEHcjoApZECIABBqJACakEANgIAIABB+I8CakGAAjsBACAAQfSPAmpBADYCACAAQeiPAmogAEHAjgJqKAIANgIAIABB8I8CaiAAQcCAAmooAgA2AgAgAEHMkAJqQQA2AgAgAEG4kAJqIAI2AgAgAEGfkQJqQf+BgPh7NgAAIABB1JACaiABNgIAIABB0JACakH/AToAACAAQfyQAmpBADYCACAAQciQAmpBADoAACAAQcCQAmogACgCxIACNgIAIAAtALSQAkUEQCAAQbyQAmpBADYCAAsgAEEANgLMkAIgAEEAOgC0kAIgAEEAOgDkjwI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U.B3 = 986, APU.C4 = 1046, APU.Cs4 = 1102, APU.D4 = 1155, APU.Ds4 = 1205, APU.E4 = 1253, APU.F4 = 1297, APU.Fs4 = 1339, APU.G4 = 1379, APU.Gs4 = 1417, APU.A4 = 1452, APU.As4 = 1486, APU.B4 = 1517, APU.C5 = 1547, APU.Cs5 = 1575, APU.D5 = 1602, APU.Ds5 = 1627, APU.E5 = 1650, APU.F5 = 1673, APU.Fs5 = 1694, APU.G5 = 1714, APU.Gs5 = 1732, APU.A5 = 1750, APU.As5 = 1767, APU.B5 = 1783, APU.C6 = 1798, APU.Cs6 = 1812, APU.D6 = 1825, APU.Ds6 = 1837, APU.E6 = 1849, APU.F6 = 1860, APU.Fs6 = 1871, APU.G6 = 1881, APU.Gs6 = 1890, APU.A6 = 1899, APU.As6 = 1907, APU.B6 = 1915, APU.C7 = 1923, APU.Cs7 = 1930, APU.D7 = 1936, APU.Ds7 = 1943, APU.E7 = 1949, APU.F7 = 1954, APU.Fs7 = 1959, APU.G7 = 1964, APU.Gs7 = 1969, APU.A7 = 1974, APU.As7 = 1978, APU.B7 = 1982, APU.C8 = 1985, APU.Cs8 = 1989, APU.D8 = 1992, APU.Ds8 = 1995, APU.E8 = 1998, APU.F8 = 2001, APU.Fs8 = 2004, APU.G8 = 2006, APU.Gs8 = 2009, APU.A8 = 2011, APU.As8 = 2013, APU.B8 = 2015; | ||
if ('webkitAudioContext' in window) { | ||
window.AudioContext = webkitAudioContext; | ||
var workletSource = "\"use strict\";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError(\"Cannot call a class as a function\")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,\"value\"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||\"object\"!=typeof e&&\"function\"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\");return t}function _inherits(t,e){if(\"function\"!=typeof e&&null!==e)throw new TypeError(\"Super expression must either be null or a function\");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e=\"function\"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if(\"function\"!=typeof t)throw new TypeError(\"Super expression must either be null or a function\");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if(\"undefined\"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if(\"function\"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf(\"[native code]\")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if(\"write\"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if(\"play\"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if(\"module\"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage(\"ready\")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:\"process\",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error(\"What is op \"+n.toString(16)+\" at \"+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor(\"gameboy-processor\",GameboyProcessor);\n"; | ||
var wasmEncoded = 'AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaGFuAwAFcmNoYW4DAQqhOglTAAJAIAFBH00EQCAAQcCRAmwhACABQRZHBEAgAEGUoQJqLQAARQ0CCyAAQZAQaiABIAIQAQ8LIAFBL0sNACAAQcCRAmwgAWpBn6ECaiACOgAACwuBFgECfyAAIAFqQY+RAmoiAyACOgAAAkAgAUEWSw0AAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAIAFBAWsOFgECAwQVBQYHCAkKCwwNFQ4PEBESExQACyAAQfSOAmogAkEHcTYCACAAQfiOAmogAkEDdkEBcSIBQX9qIAFyNgIAIABB/I4CaiAAIAJBAnZBHHFqQSRqKAIANgIADwsgAEHZjgJqIAJBBnY6AAAgAEHIjgJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB4I4CaiACQQN2QQFxIgE6AAACQCABBEAgAEHcjgJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHcjgJqIAJBBHY2AgALIAAgAUF/aiABcjoA4I4CIABB5I4CaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHYjgJqIAJBBnZBAXE6AAAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIAIAJBGHRBGHVBf0oNECAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBAToAxI4CIABB1I4CakEANgIAIABBgI8CakEANgIAIABB6I4CakEANgIAIABB7I4CakEBOgAAIABB3I4CaiAAQZGRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEBcjoAAA8LIABBqY8CaiACQQZ2OgAAIABBmI8CaiAAIAJBP3FBAnRqQcSEAmooAgA2AgAPCyAAQbCPAmogAkEDdkEBcSIBOgAAAkAgAQRAIABBrI8CaiIDQQAgAygCACIDQQFqIANBDkobNgIADAELIABBrI8CaiACQQR2NgIACyAAIAFBf2ogAXI6ALCPAiAAQbSPAmogACACQQdxQQJ0akEEaigCADYCAA8LIABBoI8CaiAAIABBmJECai0AAEEPcUEKdCAAQZeRAmotAABBAnRyakHEAGooAgA2AgAPCyAAQaiPAmogAkEGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEECcjoAAA8LIAAgAkEHdjoA5I8CDwsgAEHojwJqIAAgAkECdGpBxIYCaigCADY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h0QRh1QQBIDQAgAEGA/wA7AI+RAiAAQfiOAmpBfzYCACAAQfyOAmogACgCJDYCACAAQZGRAmpBADoAACAAQeCOAmpB/wE6AAAgAEHcjgJqQQA2AgAgAEGSkQJqQf7/AjsAACAAQeSOAmogACgCBCIBNgIAIABB8I4CakL+HzcCACAAQdiOAmpBADsBACAAQciOAmogAEHAhgJqKAIAIgI2AgAgAEHQjgJqIABBvIABaigCADYCACAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBADYC3I4CIABBAToAxI4CIABBgI8CakEANgIAIABB6I4CakEANgIAIABB1I4CakEANgIAIABB7I4CakEBOgAAIABBmI8CaiACNgIAIABBlZECakG/gPz/ezYAACAAQbSPAmogATYCACAAQbCPAmpB/wE6AAAgAEGsjwJqQQA2AgAgAEGojwJqQQA7AQAgAEGgjwJqIABBwIABaigCADYCACAAQaWRAmoiBCAELQAAIgRBAXI6AAAgAC0AlI8CRQRAIABBnI8CakEANgIACyAAQQA2AqyPAiAAQQE6AJSPAiAAQQE6AOSPAiAAQZmRAmpB//4DOwAAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBpI8CakEANgIAIABBm5ECakGfAToAACAAQZyRAmpB//8COwAAIABBpJACakEAOwEAIABB7I8CakEANgIAIAAgBEEHcjoApZECIABBqJACakEANgIAIABB+I8CakGAAjsBACAAQfSPAmpBADYCACAAQeiPAmogAEHAjgJqKAIANgIAIABB8I8CaiAAQcCAAmooAgA2AgAgAEHMkAJqQQA2AgAgAEG4kAJqIAI2AgAgAEGfkQJqQf+BgPh7NgAAIABB1JACaiABNgIAIABB0JACakH/AToAACAAQfyQAmpBADYCACAAQciQAmpBADoAACAAQcCQAmogACgCxIACNgIAIAAtALSQAkUEQCAAQbyQAmpBADYCAAsgAEEANgLMkAIgAEEAOgC0kAIgAEEAOgDkjwIgAEEAOgCUjwIgAEEAOgDEjgIgACAEQQ9yOgClkQIgAEGAkQJqQf//ATsBACAAQdyQAmpBPjoAACAAQdiQAmpBADYCACAAQ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IgA0EEaiIDQYAIRw0ACyAAQcCRAmwiAkGSoQJqQQA6AAAgAkHCoAJqQQA6AAAgAkHynwJqQQA6AAAgAkGinwJqQQA6AAAgAQUgAgsLPgAgAEHAkQJsIgBBkBBqQRZBABABIABBx6ECakKsiJTnwrW37cgANwAAIABBv6ECakKsu+vG5MbA5xY3AAALaQBBACAAEAMaQQEgABADGkGQEEEWQQAQAUHHoQJCrIiU58K1t+3IADcAAEG/oQJCrLvrxuTGwOcWNwAAQdChAkEWQQAQAUGHswRCrIiU58K1t+3IADcAAEH/sgRCrLvrxuTGwOcWNwAAC18AIAFBA00EQAJ/AkACQAJAAkAgAUEBaw4DAQIDAAsgAEHAkQJsQaKfAmoMAwsgAEHAkQJsQfKfAmoMAgsgAEHAkQJsQcKgAmoMAQsgAEHAkQJsQZKhAmoLQQE6AAALC18AIAFBA00EQAJ/AkACQAJAAkAgAUEBaw4DAQIDAAsgAEHAkQJsQaKfAmoMAwsgAEHAkQJsQfKfAmoMAgsgAEHAkQJsQcKgAmoMAQsgAEHAkQJsQZKhAmoLQQA6AAALC2EBAX9BAEGQCBACQQFBkAwQAkGAfCEAA0AgAEGQvwRqIABBkLcEaioCACAAQZC7BGoqAgCSOAIAIABBkMsEaiAAQZDDBGoqAgAgAEGQxwRqKgIAkjgCACAAQQRqIgANAAsLCy4DAEGDCAsNQQAAgEAAAABAj6qqPwBBkAgLB5AZAQCQHwEAQZAMCweQGwEAkCEBAC8JcHJvZHVjZXJzAQxwcm9jZXNzZWQtYnkBBWNsYW5nDzEwLjAuMC00dWJ1bnR1MQ=='; | ||
export var C3 = 44, Cs3 = 156, D3 = 263, Ds3 = 363, E3 = 457, F3 = 547, Fs3 = 631, G3 = 710, Gs3 = 786, A3 = 856, As3 = 923, B3 = 986, C4 = 1046, Cs4 = 1102, D4 = 1155, Ds4 = 1205, E4 = 1253, F4 = 1297, Fs4 = 1339, G4 = 1379, Gs4 = 1417, A4 = 1452, As4 = 1486, B4 = 1517, C5 = 1547, Cs5 = 1575, D5 = 1602, Ds5 = 1627, E5 = 1650, F5 = 1673, Fs5 = 1694, G5 = 1714, Gs5 = 1732, A5 = 1750, As5 = 1767, B5 = 1783, C6 = 1798, Cs6 = 1812, D6 = 1825, Ds6 = 1837, E6 = 1849, F6 = 1860, Fs6 = 1871, G6 = 1881, Gs6 = 1890, A6 = 1899, As6 = 1907, B6 = 1915, C7 = 1923, Cs7 = 1930, D7 = 1936, Ds7 = 1943, E7 = 1949, F7 = 1954, Fs7 = 1959, G7 = 1964, Gs7 = 1969, A7 = 1974, As7 = 1978, B7 = 1982, C8 = 1985, Cs8 = 1989, D8 = 1992, Ds8 = 1995, E8 = 1998, F8 = 2001, Fs8 = 2004, G8 = 2006, Gs8 = 2009, A8 = 2011, As8 = 2013, B8 = 2015; | ||
if ('webkitAudioContext' in window) { | ||
window.AudioContext = webkitAudioContext; | ||
} | ||
/** | ||
* Audio Context that all APU stuff runs on | ||
*/ | ||
export var audioContext = new AudioContext({ latencyHint: 'interactive' }); | ||
/** | ||
* Resumes the audio context. Should be called as a result of some user event, like a click. | ||
* Until this is called, the browser won't allow any sound to play. | ||
*/ | ||
export function allow() { | ||
audioContext.resume(); | ||
} | ||
var lastVolume = 1; | ||
var userVolumeNode = audioContext.createGain(); | ||
userVolumeNode.gain.setValueAtTime(lastVolume, audioContext.currentTime); | ||
userVolumeNode.connect(audioContext.destination); | ||
/** | ||
* Volume multiplier intended to be changed by a user-facing volume control | ||
* @param newVolume Value between 0 and 1 | ||
*/ | ||
export function changeUserVolume(newVolume) { | ||
if (newVolume >= 0 && newVolume <= 1) { | ||
userVolumeNode.gain.setValueAtTime(lastVolume, audioContext.currentTime); | ||
userVolumeNode.gain.linearRampToValueAtTime(newVolume, audioContext.currentTime + 0.05); | ||
lastVolume = newVolume; | ||
} | ||
/** | ||
* Audio Context that all APU stuff runs on | ||
*/ | ||
APU.audioContext = new AudioContext({ latencyHint: 'interactive' }); | ||
/** | ||
* Resumes the audio context. Should be called as a result of some user event, like a click. | ||
* Until this is called, the browser won't allow any sound to play. | ||
*/ | ||
function allow() { | ||
APU.audioContext.resume(); | ||
} | ||
APU.allow = allow; | ||
var lastVolume = 1; | ||
var userVolumeNode = APU.audioContext.createGain(); | ||
userVolumeNode.gain.setValueAtTime(lastVolume, APU.audioContext.currentTime); | ||
userVolumeNode.connect(APU.audioContext.destination); | ||
/** | ||
* Volume multiplier intended to be changed by a user-facing volume control | ||
* @param newVolume Value between 0 and 1 | ||
*/ | ||
function changeUserVolume(newVolume) { | ||
if (newVolume >= 0 && newVolume <= 1) { | ||
userVolumeNode.gain.setValueAtTime(lastVolume, APU.audioContext.currentTime); | ||
userVolumeNode.gain.linearRampToValueAtTime(newVolume, APU.audioContext.currentTime + 0.05); | ||
lastVolume = newVolume; | ||
} | ||
/** | ||
* The last audio node, which is connected to the AudioContext's destination | ||
*/ | ||
export var audioNode = userVolumeNode; | ||
var workletBlob = new Blob([workletSource], { type: 'application/javascript' }); | ||
var workletURL = URL.createObjectURL(workletBlob); | ||
var wasmBuffer = new Uint8Array(atob(wasmEncoded).split('').map(function (s) { return s.charCodeAt(0); })).buffer; | ||
var nodePromise = audioContext.audioWorklet.addModule(workletURL).then(function () { | ||
var node = new AudioWorkletNode(audioContext, 'gameboy-processor', { outputChannelCount: [2] }); | ||
node.connect(userVolumeNode); | ||
return new Promise(function (resolve) { | ||
node.port.onmessage = function (_a) { | ||
var e = _a.data; | ||
return (e === 'ready') && resolve(node); | ||
}; | ||
node.port.postMessage({ type: 'module', data: wasmBuffer }); | ||
}); | ||
}); | ||
var nextInstanceId = 0; | ||
var allowSFX = true; | ||
function track(data, loop, mask) { | ||
if (mask === void 0) { mask = null; } | ||
return { | ||
play: function () { | ||
if (mask && !allowSFX) | ||
return null; | ||
var id = ++nextInstanceId; | ||
nodePromise.then(function (node) { | ||
node.port.postMessage({ id: id, type: 'play', data: data, loop: loop, mask: mask }); | ||
}); | ||
return { | ||
pause: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'pause' }); }); | ||
}, | ||
resume: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'resume' }); }); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
/** | ||
* Create a BGM object | ||
* | ||
* When a BGM is played, it will immediately stop any previous BGM and SFX | ||
* | ||
* TODO: resume paused BGM | ||
* @param data Data block of a VGM file | ||
* @param loop Byte offset of the data block to loop back to upon completion. (-1 if no loop) | ||
*/ | ||
export function bgm(data, loop) { | ||
if (loop === void 0) { loop = 0; } | ||
return track(data, loop); | ||
} | ||
/** | ||
* Create an SFX object | ||
* | ||
* When a SFX is played, it will immediately stop any previous SFX | ||
* | ||
* It will also immediately take control away from the BGM for playing on channels, | ||
* and should silence those channels. When the SFX completes, it will give control | ||
* back to the BGM for all channels. | ||
* | ||
* Right now a channel mask is used for an SFX to declare which channels it intends | ||
* to use. A smarter mechanism may be used in the future, such as scanning the data. | ||
* @param data Data block of a VGM file | ||
* @param mask Array of four 0's or 1's that indicates which channels this SFX will be using | ||
*/ | ||
export function sfx(data, mask) { | ||
if (mask === void 0) { mask = [1, 1, 1, 1]; } | ||
return track(data, -1, mask); | ||
} | ||
/** | ||
* Creates a BGM object from an entire .vgm file contents, as an ArrayBuffer | ||
* @param arrayBuffer | ||
*/ | ||
export function fromFile(arrayBuffer) { | ||
// make sure the 4-byte header is correct. | ||
// It should be "Vgm " (space at the end) | ||
var header = new Uint8Array(arrayBuffer, 0, 4); | ||
for (var i = 0; i < 4; ++i) { | ||
if (header[i] !== 'Vgm '.charCodeAt(i)) { | ||
throw new Error('Invalid header'); | ||
} | ||
} | ||
APU.changeUserVolume = changeUserVolume; | ||
/** | ||
* The last audio node, which is connected to the AudioContext's destination | ||
*/ | ||
APU.audioNode = userVolumeNode; | ||
var workletBlob = new Blob([workletSource], { type: 'application/javascript' }); | ||
var workletURL = URL.createObjectURL(workletBlob); | ||
var wasmBuffer = new Uint8Array(atob(wasmEncoded).split('').map(function (s) { return s.charCodeAt(0); })).buffer; | ||
var nodePromise = APU.audioContext.audioWorklet.addModule(workletURL).then(function () { | ||
var node = new AudioWorkletNode(APU.audioContext, 'gameboy-processor', { outputChannelCount: [2] }); | ||
node.connect(userVolumeNode); | ||
return new Promise(function (resolve) { | ||
node.port.onmessage = function (_a) { | ||
var e = _a.data; | ||
return (e === 'ready') && resolve(node); | ||
// get where vgm data starts. this is | ||
// (address of where vgm offset is stored, always 0x34) | ||
// + (value of vgm offset.) | ||
var data0 = 0x34 + new Uint32Array(arrayBuffer, 0x34, 1)[0]; | ||
// the loop point works similarly | ||
var loopPoint = 0x1c + new Uint32Array(arrayBuffer, 0x1c, 1)[0] - data0; | ||
// finally, the rest of the file is the data | ||
var data = arrayBuffer.slice(data0); | ||
return bgm(data, loopPoint); | ||
} | ||
/** | ||
* Slowly fade out the BGM. This also immediately stops current | ||
* SFX, and prevents any new SFX from playing until completion. | ||
* @param millis Number of milliseconds for the fade to complete | ||
* @returns A promise that resolves when the fade has completed | ||
*/ | ||
export function fade(millis) { | ||
if (millis === void 0) { millis = 2000; } | ||
// TODO: should be no-op if already fading | ||
return nodePromise.then(function (node) { | ||
// halt any currently-playing SFX | ||
sfx(new ArrayBuffer(0), [0, 0, 0, 0]).play(); | ||
if (millis > 0) { | ||
// disallow sfx until fade completes | ||
allowSFX = false; | ||
var _loop_1 = function (i) { | ||
var vol = 6 - i; | ||
setTimeout(function () { return node.port.postMessage({ type: 'write', layer: 0, register: 0x14, value: (vol << 4) + (vol) }); }, millis * i / 7); | ||
}; | ||
node.port.postMessage({ type: 'module', data: wasmBuffer }); | ||
}); | ||
}); | ||
var nextInstanceId = 0; | ||
var allowSFX = true; | ||
function track(data, loop, mask) { | ||
if (mask === void 0) { mask = null; } | ||
return { | ||
play: function () { | ||
if (mask && !allowSFX) | ||
return null; | ||
var id = ++nextInstanceId; | ||
nodePromise.then(function (node) { | ||
node.port.postMessage({ id: id, type: 'play', data: data, loop: loop, mask: mask }); | ||
}); | ||
return { | ||
pause: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'pause' }); }); | ||
}, | ||
resume: function () { | ||
nodePromise.then(function (node) { return node.port.postMessage({ id: id, type: 'resume' }); }); | ||
} | ||
}; | ||
// use NR50 to fade out | ||
for (var i = 0; i <= 5; ++i) { | ||
_loop_1(i); | ||
} | ||
}; | ||
} | ||
/** | ||
* Create a BGM object | ||
* | ||
* When a BGM is played, it will immediately stop any previous BGM and SFX | ||
* | ||
* TODO: resume paused BGM | ||
* @param data Data block of a VGM file | ||
* @param loop Byte offset of the data block to loop back to upon completion. (-1 if no loop) | ||
*/ | ||
function bgm(data, loop) { | ||
if (loop === void 0) { loop = 0; } | ||
return track(data, loop); | ||
} | ||
APU.bgm = bgm; | ||
/** | ||
* Create an SFX object | ||
* | ||
* When a SFX is played, it will immediately stop any previous SFX | ||
* | ||
* It will also immediately take control away from the BGM for playing on channels, | ||
* and should silence those channels. When the SFX completes, it will give control | ||
* back to the BGM for all channels. | ||
* | ||
* Right now a channel mask is used for an SFX to declare which channels it intends | ||
* to use. A smarter mechanism may be used in the future, such as scanning the data. | ||
* @param data Data block of a VGM file | ||
* @param mask Array of four 0's or 1's that indicates which channels this SFX will be using | ||
*/ | ||
function sfx(data, mask) { | ||
if (mask === void 0) { mask = [1, 1, 1, 1]; } | ||
return track(data, -1, mask); | ||
} | ||
APU.sfx = sfx; | ||
/** | ||
* Creates a BGM object from an entire .vgm file contents, as an ArrayBuffer | ||
* @param arrayBuffer | ||
*/ | ||
function fromFile(arrayBuffer) { | ||
// make sure the 4-byte header is correct. | ||
// It should be "Vgm " (space at the end) | ||
var header = new Uint8Array(arrayBuffer, 0, 4); | ||
for (var i = 0; i < 4; ++i) { | ||
if (header[i] !== 'Vgm '.charCodeAt(i)) { | ||
throw new Error('Invalid header'); | ||
} | ||
// stop sound with NR52 | ||
setTimeout(function () { | ||
node.port.postMessage({ type: 'write', layer: 0, register: 0x16, value: 0 }); | ||
// and clear song | ||
bgm(new ArrayBuffer(0), -1).play(); | ||
}, millis * 6 / 7); | ||
} | ||
// get where vgm data starts. this is | ||
// (address of where vgm offset is stored, always 0x34) | ||
// + (value of vgm offset.) | ||
var data0 = 0x34 + new Uint32Array(arrayBuffer, 0x34, 1)[0]; | ||
// the loop point works similarly | ||
var loopPoint = 0x1c + new Uint32Array(arrayBuffer, 0x1c, 1)[0] - data0; | ||
// finally, the rest of the file is the data | ||
var data = arrayBuffer.slice(data0); | ||
return bgm(data, loopPoint); | ||
} | ||
APU.fromFile = fromFile; | ||
/** | ||
* Slowly fade out the BGM. This also immediately stops current | ||
* SFX, and prevents any new SFX from playing until completion. | ||
* @param millis Number of milliseconds for the fade to complete | ||
* @returns A promise that resolves when the fade has completed | ||
*/ | ||
function fade(millis) { | ||
if (millis === void 0) { millis = 2000; } | ||
// TODO: should be no-op if already fading | ||
return nodePromise.then(function (node) { | ||
// halt any currently-playing SFX | ||
sfx(new ArrayBuffer(0), [0, 0, 0, 0]).play(); | ||
if (millis > 0) { | ||
// disallow sfx until fade completes | ||
allowSFX = false; | ||
var _loop_1 = function (i) { | ||
var vol = 6 - i; | ||
setTimeout(function () { return node.port.postMessage({ type: 'write', layer: 0, register: 0x14, value: (vol << 4) + (vol) }); }, millis * i / 7); | ||
}; | ||
// use NR50 to fade out | ||
for (var i = 0; i <= 5; ++i) { | ||
_loop_1(i); | ||
} | ||
// stop sound with NR52 | ||
setTimeout(function () { | ||
node.port.postMessage({ type: 'write', layer: 0, register: 0x16, value: 0 }); | ||
// and clear song | ||
bgm(new ArrayBuffer(0), -1).play(); | ||
}, millis * 6 / 7); | ||
} | ||
// resolve | ||
return new Promise(function (resolve) { return setTimeout(resolve, millis); }) | ||
// ... and allow sfx once again | ||
.then(function () { allowSFX = true; }); | ||
}); | ||
} | ||
APU.fade = fade; | ||
function compile(commands) { | ||
} | ||
APU.compile = compile; | ||
})(APU || (APU = {})); | ||
// resolve | ||
return new Promise(function (resolve) { return setTimeout(resolve, millis); }) | ||
// ... and allow sfx once again | ||
.then(function () { allowSFX = true; }); | ||
}); | ||
} | ||
export function compile(commands) { | ||
} |
!function(){function e(e,t){var r=document.createElement("iframe");r.style.cssText="position:absolute;left:0;top:-999px;width:1px;height:1px;",t.appendChild(r);var o=r.contentWindow,n=o.document,i="var window,$hook";for(var a in o)a in e||"eval"===a||(i+=",",i+=a);for(var s in e)i+=",",i+=s,i+="=self.",i+=s;var u=n.createElement("script");u.appendChild(n.createTextNode('function $hook(self,console) {"use strict";\n '+i+";return function() {return eval(arguments[0])}}")),n.body.appendChild(u),this.exec=o.$hook.call(e,e,console)}var t,r=[];function o(e){var t=this,o={},i=-1;this.parameters.forEach(function(e,n){var a=r[++i]||(r[i]=new Float32Array(t.bufferSize));a.fill(e.value),o[n]=a}),this.processor.realm.exec("self.sampleRate=sampleRate="+this.context.sampleRate+";self.currentTime=currentTime="+this.context.currentTime);var a=n(e.inputBuffer),s=n(e.outputBuffer);this.instance.process([a],[s],o)}function n(e){for(var t=[],r=0;r<e.numberOfChannels;r++)t[r]=e.getChannelData(r);return t}function i(e){return e.$$processors||(e.$$processors={})}"function"==typeof AudioWorkletNode&&"audioWorklet"in AudioContext.prototype||(self.AudioWorkletNode=function(e,r,n){var a=i(e)[r],s=e.createScriptProcessor(2048,2,n&&n.outputChannelCount?n.outputChannelCount[0]:2);if(s.parameters=new Map,a.properties)for(var u=0;u<a.properties.length;u++){var c=a.properties[u],l=e.createGain().gain;l.value=c.defaultValue,s.parameters.set(c.name,l)}var p=new MessageChannel;t=p.port2;var f=new a.Processor(n||{});return t=null,s.port=p.port1,s.processor=a,s.instance=f,s.onaudioprocess=o,s},Object.defineProperty((self.AudioContext||self.webkitAudioContext).prototype,"audioWorklet",{get:function(){return this.$$audioWorklet||(this.$$audioWorklet=new self.AudioWorklet(this))}}),self.AudioWorklet=function(){function r(e){this.$$context=e}return r.prototype.addModule=function(r,o){var n=this;return fetch(r).then(function(e){if(!e.ok)throw Error(e.status);return e.text()}).then(function(r){var a={sampleRate:n.$$context.sampleRate,currentTime:n.$$context.currentTime,AudioWorkletProcessor:function(){this.port=t},registerProcessor:function(e,t){i(n.$$context)[e]={realm:s,context:a,Processor:t,properties:t.parameterDescriptors||[]}}};a.self=a;var s=new e(a,document.documentElement);return s.exec((o&&o.transpile||String)(r)),null})},r}())}(); | ||
//# sourceMappingURL=audioworklet-polyfill.js.map | ||
var APU;!function(A){A.C3=44,A.Cs3=156,A.D3=263,A.Ds3=363,A.E3=457,A.F3=547,A.Fs3=631,A.G3=710,A.Gs3=786,A.A3=856,A.As3=923,A.B3=986,A.C4=1046,A.Cs4=1102,A.D4=1155,A.Ds4=1205,A.E4=1253,A.F4=1297,A.Fs4=1339,A.G4=1379,A.Gs4=1417,A.A4=1452,A.As4=1486,A.B4=1517,A.C5=1547,A.Cs5=1575,A.D5=1602,A.Ds5=1627,A.E5=1650,A.F5=1673,A.Fs5=1694,A.G5=1714,A.Gs5=1732,A.A5=1750,A.As5=1767,A.B5=1783,A.C6=1798,A.Cs6=1812,A.D6=1825,A.Ds6=1837,A.E6=1849,A.F6=1860,A.Fs6=1871,A.G6=1881,A.Gs6=1890,A.A6=1899,A.As6=1907,A.B6=1915,A.C7=1923,A.Cs7=1930,A.D7=1936,A.Ds7=1943,A.E7=1949,A.F7=1954,A.Fs7=1959,A.G7=1964,A.Gs7=1969,A.A7=1974,A.As7=1978,A.B7=1982,A.C8=1985,A.Cs8=1989,A.D8=1992,A.Ds8=1995,A.E8=1998,A.F8=2001,A.Fs8=2004,A.G8=2006,A.Gs8=2009,A.A8=2011,A.As8=2013,A.B8=2015,"webkitAudioContext"in window&&(window.AudioContext=webkitAudioContext),A.audioContext=new AudioContext({latencyHint:"interactive"}),A.allow=function(){A.audioContext.resume()};var B=1,C=A.audioContext.createGain();C.gain.setValueAtTime(B,A.audioContext.currentTime),C.connect(A.audioContext.destination),A.changeUserVolume=function(g){g>=0&&g<=1&&(C.gain.setValueAtTime(B,A.audioContext.currentTime),C.gain.linearRampToValueAtTime(g,A.audioContext.currentTime+.05),B=g)},A.audioNode=C;var g=new Blob(['"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return t}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if("write"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if("play"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if("module"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage("ready")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:"process",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error("What is op "+n.toString(16)+" at "+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor("gameboy-processor",GameboyProcessor);\n'],{type:"application/javascript"}),t=URL.createObjectURL(g),I=new Uint8Array(atob("AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaGFuAwAFcmNoYW4DAQqhOglTAAJAIAFBH00EQCAAQcCRAmwhACABQRZHBEAgAEGUoQJqLQAARQ0CCyAAQZAQaiABIAIQAQ8LIAFBL0sNACAAQcCRAmwgAWpBn6ECaiACOgAACwuBFgECfyAAI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EGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEECcjoAAA8LIAAgAkEHdjoA5I8CDwsgAEHojwJqIAAgAkECdGpBxIYCaigCADYCAA8LIABBpJACaiACQQV2QQNxOgAADwsgAEHwjwJqIAAgAEGdkQJqLQAAQQ9xQQp0IABBnJECai0AAEECdHJqQcSAAWooAgA2AgAPCyAAQfiPAmogAkEGdkEBcToAACAAQfCPAmogACAAQZ2RAmotAABBD3FBCnQgAEGckQJqLQAAQQJ0cmpBxIABaigCADYCACACQRh0QRh1QX9KDQcgAC0A5I8CRQRAIABBpZACakEAOgAAIABB7I8CakEANgIAIABB+Y8CakEAOgAACyAAQQE6AOSPAiAAQaiQAmpBADYCACAAQfmPAmpBAToAACAAQfSPAmpBADYCACAAQaWRAmoiACAALQAAQQRyOgAADwsgAEG4kAJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB0JACaiACQQN2QQFxIgE6AAACQCABBEAgAEHMkAJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHMkAJqIAJBBHY2AgALIAAgAUF/aiABcjoA0JACIABB1JACaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgACACQQdxQQZ0aiACQQJ2QTxxakHEgAJqKAIAIQEgAEH8kAJqIAJBA3ZBAXE2AgAgAEHAkAJqIAE2AgAPCyAAQciQAmogAkEGdkEBcToAACACQRh0QRh1QX9KDQMgAC0AtJACRQRAIABBvJACakEANgIACyAAQQE6ALSQAiAAQcSQAmpBADYCACAAQYCRAmpB//8BOwEAIABB3JACakE+OgAAIABB2JACakEANgIAIABBzJACaiAAQaCRAmotAABBBHY2AgAgAEGlkQ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jZXJzAQxwcm9jZXNzZWQtYnkBBWNsYW5nDzEwLjAuMC00dWJ1bnR1MQ==").split("").map((function(A){return A.charCodeAt(0)}))).buffer,Q=A.audioContext.audioWorklet.addModule(t).then((function(){var B=new AudioWorkletNode(A.audioContext,"gameboy-processor",{outputChannelCount:[2]});return B.connect(C),new Promise((function(A){B.port.onmessage=function(C){return"ready"===C.data&&A(B)},B.port.postMessage({type:"module",data:I})}))})),e=0,i=!0;function E(A,B,C){return void 0===C&&(C=null),{play:function(){if(C&&!i)return null;var g=++e;return Q.then((function(t){t.port.postMessage({id:g,type:"play",data:A,loop:B,mask:C})})),{pause:function(){Q.then((function(A){return A.port.postMessage({id:g,type:"pause"})}))},resume:function(){Q.then((function(A){return A.port.postMessage({id:g,type:"resume"})}))}}}}}function o(A,B){return void 0===B&&(B=0),E(A,B)}function n(A,B){return void 0===B&&(B=[1,1,1,1]),E(A,-1,B)}A.bgm=o,A.sfx=n,A.fromFile=function(A){for(var B=new Uint8Array(A,0,4),C=0;C<4;++C)if(B[C]!=="Vgm ".charCodeAt(C))throw new Error("Invalid header");var g=52+new Uint32Array(A,52,1)[0],t=28+new Uint32Array(A,28,1)[0]-g;return o(A.slice(g),t)},A.fade=function(A){return void 0===A&&(A=2e3),Q.then((function(B){if(n(new ArrayBuffer(0),[0,0,0,0]).play(),A>0){i=!1;for(var C=function(C){var g=6-C;setTimeout((function(){return B.port.postMessage({type:"write",layer:0,register:20,value:(g<<4)+g})}),A*C/7)},g=0;g<=5;++g)C(g);setTimeout((function(){B.port.postMessage({type:"write",layer:0,register:22,value:0}),o(new ArrayBuffer(0),-1).play()}),6*A/7)}return new Promise((function(B){return setTimeout(B,A)})).then((function(){i=!0}))}))},A.compile=function(A){}}(APU||(APU={})); | ||
var workletSource='"use strict";function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),t}function _possibleConstructorReturn(t,e){return!e||"object"!=typeof e&&"function"!=typeof e?_assertThisInitialized(t):e}function _assertThisInitialized(t){if(void 0===t)throw new ReferenceError("this hasn\'t been initialised - super() hasn\'t been called");return t}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&_setPrototypeOf(t,e)}function _wrapNativeSuper(t){var e="function"==typeof Map?new Map:void 0;return(_wrapNativeSuper=function(t){if(null===t||!_isNativeFunction(t))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return _construct(t,arguments,_getPrototypeOf(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),_setPrototypeOf(r,t)})(t)}function isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function _construct(t,e,r){return(_construct=isNativeReflectConstruct()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var o=new(Function.bind.apply(t,n));return r&&_setPrototypeOf(o,r.prototype),o}).apply(null,arguments)}function _isNativeFunction(t){return-1!==Function.toString.call(t).indexOf("[native code]")}function _setPrototypeOf(t,e){return(_setPrototypeOf=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _getPrototypeOf(t){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var GameboyProcessor=function(t){function e(){var t,r;_classCallCheck(this,e);for(var n=arguments.length,o=new Array(n),i=0;i<n;i++)o[i]=arguments[i];return(r=_possibleConstructorReturn(this,(t=_getPrototypeOf(e)).call.apply(t,[this].concat(o)))).port.onmessage=function(t){var e=t.data;if("write"===e.type)r.s.registerWrite(e.layer,e.register,e.value);else if("play"===e.type){var n=new Uint8Array(e.data);r.ready.then((function(){e.mask?r.s.playSFX(n,e.mask):r.s.playSong(n,e.loop)}))}else if("module"===e.type){var o=WebAssembly.instantiate(e.data).then((function(t){return t.instance.exports}));o.then((function(t){t.init(sampleRate),r.lchan=new Float32Array(t.memory.buffer,t.lchan,128),r.rchan=new Float32Array(t.memory.buffer,t.rchan,128),r.updateGB=t.update,r.s=songContext(t.gb_sound_w,t.enable_channel,t.disable_channel),r.port.postMessage("ready")})),r.ready=o.then((function(){return!0}))}},r}return _inherits(e,_wrapNativeSuper(AudioWorkletProcessor)),_createClass(e,[{key:"process",value:function(t,e){if(this.updateGB)for(var r=e[0][0],n=e[0][1],o=0;o<r.length;o+=128){for(var i=0;i<128;++i)this.s.tick();this.updateGB(),r.set(this.lchan,o),n.set(this.rchan,o)}return!0}}]),e}();function songContext(t,e,r){var n=[0,1].map((function(r){return chip(t.bind(null,r),e.bind(null,r))}));return{playSong:function(e,o){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;n[0].track=e,n[0].idx=i,n[0].timer=0,n[0].loopPoint=o,n[0].mask=[1,1,1,1],n[0].doneCallback=null,n[1].track=null,n[1].idx=-1,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=[0,0,0,0],n[1].doneCallback=null;for(var a=0;a<4;++a)r(1,a);t(0,22,0)},playSFX:function(t,e){n[0].mask=e.map((function(t){return 1-t})),n[1].track=t,n[1].idx=0,n[1].timer=0,n[1].loopPoint=-1,n[1].mask=e,n[1].doneCallback=function(){n[0].mask=[1,1,1,1],n[1].mask=[0,0,0,0]};for(var o=0;o<4;++o)e[o]&&r(0,o)},tick:function(){n.forEach((function(t){return t.tick()}))},registerWrite:t}}function chip(t,e){var r={track:null,idx:-1,timer:0,loopPoint:-1,mask:[0,0,0,0],doneCallback:null,tick:function(){for(;r.timer<=0&&r.idx>=0;){if(r.idx>=r.track.length&&(r.idx=r.loopPoint,-1===r.idx)){r.doneCallback&&r.doneCallback();break}var n=r.track[r.idx++];if(179===n){var o=r.track[r.idx++],i=r.track[r.idx++];t(o,i),128&i&&(4===o&&r.mask[0]?e(0):9===o&&r.mask[1]?e(1):14===o&&r.mask[2]?e(2):19===o&&r.mask[3]&&e(3))}else if(97===n){var a=r.track[r.idx++]+(r.track[r.idx++]<<8);r.timer+=a}else if(98===n){r.timer+=735}else if(112==(240&n)){var c=1+(15&n);r.timer+=c}else{if(102!==n)throw new Error("What is op "+n.toString(16)+" at "+(r.idx-1));r.idx=r.track.length}}var u=44100/sampleRate;r.timer-=u}};return r}registerProcessor("gameboy-processor",GameboyProcessor);\n',wasmEncoded="AGFzbQEAAAABGQVgAn9/AGABfwBgA39/fwBgAABgAn9/AX8DCgkCAgAEAQEAAAMFAwEAAwYPAn8AQZC7BAt/AEGQxwQLB5QBCgZtZW1vcnkCAApnYl9zb3VuZF93AAAaZGV2aWNlX3N0YXJ0X2dhbWVib3lfc291bmQAAxpkZXZpY2VfcmVzZXRfZ2FtZWJveV9zb3VuZAAEBGluaXQABQ9kaXNhYmxlX2NoYW5uZWwABg5lbmFibGVfY2hhbm5lbAAHBnVwZGF0ZQAIBWxjaGFuAwAFcmNoYW4DAQqhOglTAAJAIAFBH00EQCAAQcCRAmwhACABQRZHBEAgAEGUoQJqLQAARQ0CCyAAQZAQaiABIAIQAQ8LIAFBL0sNACAAQcCRAmwgAWpBn6ECaiACOgAACwuBFgECfyAAIAFqQY+RAmoiAyACOgAAAkAgAUEWSw0AAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAAkACQAJAIAFBAWsOFgECAwQVBQYHCAkKCwwNFQ4PEBESExQACyAAQfSOAmogAkEHcTYCACAAQfiOAmogAkEDdkEBcSIBQX9qIAFyNgIAIABB/I4CaiAAIAJBAnZBHHFqQSRqKAIANgIADwsgAEHZjgJqIAJBBnY6AAAgAEHIjgJqIAAgAkE/cUECdGpBxIQCaigCADYCAA8LIABB4I4CaiACQQN2QQFxIgE6AAACQCABBEAgAEHcjgJqIgNBACADKAIAIgNBAWogA0EOShs2AgAMAQsgAEHcjgJqIAJBBHY2AgALIAAgAUF/aiABcjoA4I4CIABB5I4CaiAAIAJBB3FBAnRqQQRqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIADwsgAEHwjgJqIABBkpECai0AACAAQZORAmotAABBD3FBCHRyIgE2AgAgAEHYjgJqIAJBBnZBAXE6AAAgAEHQjgJqIAAgAUECdGpBxABqKAIANgIAIAJBGHRBGHVBf0oNECAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBAToAxI4CIABB1I4CakEANgIAIABBgI8CakEANgIAIABB6I4CakEANgIAIABB7I4CakEBOgAAIABB3I4CaiAAQZGRAmotAABBBHY2AgAgAEGlkQJqIgAgAC0AAEEBcjoAAA8LIABBqY8CaiACQQZ2OgAAIABBmI8CaiAAIAJBP3FBAnRqQcSEAmooAgA2AgAPCyAAQbCPAmogAkEDdkEBcSIBOgAAAkAgAQRAIABBrI8CaiIDQQAgAygCACIDQQFqIANBDkobNgIADAELIABBrI8CaiACQQR2NgIACyAAIAFBf2ogAXI6ALCPAiAAQbSPAmogACACQQdxQQJ0akEEaigCADYCAA8LIABBoI8CaiAAIABBmJECai0AAEEPcUEKdCAAQZeRAmotAABBAnRyakHEAGooAgA2AgAPCyAAQaiPAmogAkEGdkEBcToAACAAQaCPAmogACAAQZiRAmotAABBD3FBCnQgAEGXkQJqLQAAQQJ0cmpBxABqKAIANgIAIAJBGHRBGHVBf0oNDCAALQCUjwJFBEAgAEGcjwJqQQA2AgALIABBAToAlI8CIABBpI8CakEANgIAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBrI8CaiAAQZaRA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qIAJBBXZBAXE6AAAgAEGOkQJqIAJBA3ZBAXE6AAAgAEGLkQJqIAJBBnZBAXE6AAAPCyAAIAJBB3Y6AISRAiACQRh0QRh1QQBIDQAgAEGA/wA7AI+RAiAAQfiOAmpBfzYCACAAQfyOAmogACgCJDYCACAAQZGRAmpBADoAACAAQeCOAmpB/wE6AAAgAEHcjgJqQQA2AgAgAEGSkQJqQf7/AjsAACAAQeSOAmogACgCBCIBNgIAIABB8I4CakL+HzcCACAAQdiOAmpBADsBACAAQciOAmogAEHAhgJqKAIAIgI2AgAgAEHQjgJqIABBvIABaigCADYCACAALQDEjgJFBEAgAEHMjgJqQQA2AgALIABBADYC3I4CIABBAToAxI4CIABBgI8CakEANgIAIABB6I4CakEANgIAIABB1I4CakEANgIAIABB7I4CakEBOgAAIABBmI8CaiACNgIAIABBlZECakG/gPz/ezYAACAAQbSPAmogATYCACAAQbCPAmpB/wE6AAAgAEGsjwJqQQA2AgAgAEGojwJqQQA7AQAgAEGgjwJqIABBwIABaigCADYCACAAQaWRAmoiBCAELQAAIgRBAXI6AAAgAC0AlI8CRQRAIABBnI8CakEANgIACyAAQQA2AqyPAiAAQQE6AJSPAiAAQQE6AOSPAiAAQZmRAmpB//4DOwAAIABBvI8CakEBOgAAIABBuI8CakEANgIAIABBpI8CakEANgIAIABBm5ECakGfAToAACAAQZyRAmpB//8COwAAIABBpJACakEAOwEAIABB7I8CakEANgIAIAAgBEEHcjoApZECIABBqJACakEANgIAIABB+I8CakGAAjsBACAAQfSPAmpBADYCACAAQeiPAmogAEHAjgJqKAIANgIAIABB8I8CaiAAQcCAAmooAgA2AgAgAEHMkAJqQQA2AgAgAEG4kAJqIAI2AgAgAEGfkQJqQf+BgPh7NgAAIABB1JACaiABNgIAIABB0JACakH/AToAACAAQfyQAmpBADYCACAAQciQAmpBADoAACAAQcCQAmogACgCxIACNgIAIAAtALSQAkUEQCAAQbyQAmpBADYCAAsgAEEANgLMkAIgAEEAOgC0kAIgAEEAOgDkjwIg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gs4=1417,A4=1452,As4=1486,B4=1517,C5=1547,Cs5=1575,D5=1602,Ds5=1627,E5=1650,F5=1673,Fs5=1694,G5=1714,Gs5=1732,A5=1750,As5=1767,B5=1783,C6=1798,Cs6=1812,D6=1825,Ds6=1837,E6=1849,F6=1860,Fs6=1871,G6=1881,Gs6=1890,A6=1899,As6=1907,B6=1915,C7=1923,Cs7=1930,D7=1936,Ds7=1943,E7=1949,F7=1954,Fs7=1959,G7=1964,Gs7=1969,A7=1974,As7=1978,B7=1982,C8=1985,Cs8=1989,D8=1992,Ds8=1995,E8=1998,F8=2001,Fs8=2004,G8=2006,Gs8=2009,A8=2011,As8=2013,B8=2015;"webkitAudioContext"in window&&(window.AudioContext=webkitAudioContext);export var audioContext=new AudioContext({latencyHint:"interactive"});export function allow(){audioContext.resume()}var lastVolume=1,userVolumeNode=audioContext.createGain();userVolumeNode.gain.setValueAtTime(lastVolume,audioContext.currentTime),userVolumeNode.connect(audioContext.destination);export function changeUserVolume(A){A>=0&&A<=1&&(userVolumeNode.gain.setValueAtTime(lastVolume,audioContext.currentTime),userVolumeNode.gain.linearRampToValueAtTime(A,audioContext.currentTime+.05),lastVolume=A)}export var audioNode=userVolumeNode;var workletBlob=new Blob([workletSource],{type:"application/javascript"}),workletURL=URL.createObjectURL(workletBlob),wasmBuffer=new Uint8Array(atob(wasmEncoded).split("").map((function(A){return A.charCodeAt(0)}))).buffer,nodePromise=audioContext.audioWorklet.addModule(workletURL).then((function(){var A=new AudioWorkletNode(audioContext,"gameboy-processor",{outputChannelCount:[2]});return A.connect(userVolumeNode),new Promise((function(B){A.port.onmessage=function(t){return"ready"===t.data&&B(A)},A.port.postMessage({type:"module",data:wasmBuffer})}))})),nextInstanceId=0,allowSFX=!0;function track(A,B,t){return void 0===t&&(t=null),{play:function(){if(t&&!allowSFX)return null;var C=++nextInstanceId;return nodePromise.then((function(g){g.port.postMessage({id:C,type:"play",data:A,loop:B,mask:t})})),{pause:function(){nodePromise.then((function(A){return A.port.postMessage({id:C,type:"pause"})}))},resume:function(){nodePromise.then((function(A){return A.port.postMessage({id:C,type:"resume"})}))}}}}}export function bgm(A,B){return void 0===B&&(B=0),track(A,B)}export function sfx(A,B){return void 0===B&&(B=[1,1,1,1]),track(A,-1,B)}export function fromFile(A){for(var B=new Uint8Array(A,0,4),t=0;t<4;++t)if(B[t]!=="Vgm ".charCodeAt(t))throw new Error("Invalid header");var C=52+new Uint32Array(A,52,1)[0],g=28+new Uint32Array(A,28,1)[0]-C;return bgm(A.slice(C),g)}export function fade(A){return void 0===A&&(A=2e3),nodePromise.then((function(B){if(sfx(new ArrayBuffer(0),[0,0,0,0]).play(),A>0){allowSFX=!1;for(var t=function(t){var C=6-t;setTimeout((function(){return B.port.postMessage({type:"write",layer:0,register:20,value:(C<<4)+C})}),A*t/7)},C=0;C<=5;++C)t(C);setTimeout((function(){B.port.postMessage({type:"write",layer:0,register:22,value:0}),bgm(new ArrayBuffer(0),-1).play()}),6*A/7)}return new Promise((function(B){return setTimeout(B,A)})).then((function(){allowSFX=!0}))}))}export function compile(A){} |
154
index.d.ts
@@ -1,81 +0,79 @@ | ||
declare namespace APU { | ||
type APUTrackMask = [0 | 1, 0 | 1, 0 | 1, 0 | 1]; | ||
export const C3 = 44, Cs3 = 156, D3 = 263, Ds3 = 363, E3 = 457, F3 = 547, Fs3 = 631, G3 = 710, Gs3 = 786, A3 = 856, As3 = 923, B3 = 986, C4 = 1046, Cs4 = 1102, D4 = 1155, Ds4 = 1205, E4 = 1253, F4 = 1297, Fs4 = 1339, G4 = 1379, Gs4 = 1417, A4 = 1452, As4 = 1486, B4 = 1517, C5 = 1547, Cs5 = 1575, D5 = 1602, Ds5 = 1627, E5 = 1650, F5 = 1673, Fs5 = 1694, G5 = 1714, Gs5 = 1732, A5 = 1750, As5 = 1767, B5 = 1783, C6 = 1798, Cs6 = 1812, D6 = 1825, Ds6 = 1837, E6 = 1849, F6 = 1860, Fs6 = 1871, G6 = 1881, Gs6 = 1890, A6 = 1899, As6 = 1907, B6 = 1915, C7 = 1923, Cs7 = 1930, D7 = 1936, Ds7 = 1943, E7 = 1949, F7 = 1954, Fs7 = 1959, G7 = 1964, Gs7 = 1969, A7 = 1974, As7 = 1978, B7 = 1982, C8 = 1985, Cs8 = 1989, D8 = 1992, Ds8 = 1995, E8 = 1998, F8 = 2001, Fs8 = 2004, G8 = 2006, Gs8 = 2009, A8 = 2011, As8 = 2013, B8 = 2015; | ||
/** | ||
* Audio Context that all APU stuff runs on | ||
*/ | ||
export const audioContext: AudioContext; | ||
/** | ||
* Resumes the audio context. Should be called as a result of some user event, like a click. | ||
* Until this is called, the browser won't allow any sound to play. | ||
*/ | ||
export function allow(): void; | ||
/** | ||
* Volume multiplier intended to be changed by a user-facing volume control | ||
* @param newVolume Value between 0 and 1 | ||
*/ | ||
export function changeUserVolume(newVolume: number): void; | ||
/** | ||
* The last audio node, which is connected to the AudioContext's destination | ||
*/ | ||
export const audioNode: AudioNode; | ||
/** | ||
* Create a BGM object | ||
* | ||
* When a BGM is played, it will immediately stop any previous BGM and SFX | ||
* | ||
* TODO: resume paused BGM | ||
* @param data Data block of a VGM file | ||
* @param loop Byte offset of the data block to loop back to upon completion. (-1 if no loop) | ||
*/ | ||
export function bgm(data: ArrayBuffer, loop?: number): { | ||
play(): { | ||
pause(): void; | ||
resume(): void; | ||
}; | ||
declare type APUTrackMask = [0 | 1, 0 | 1, 0 | 1, 0 | 1]; | ||
export declare const C3 = 44, Cs3 = 156, D3 = 263, Ds3 = 363, E3 = 457, F3 = 547, Fs3 = 631, G3 = 710, Gs3 = 786, A3 = 856, As3 = 923, B3 = 986, C4 = 1046, Cs4 = 1102, D4 = 1155, Ds4 = 1205, E4 = 1253, F4 = 1297, Fs4 = 1339, G4 = 1379, Gs4 = 1417, A4 = 1452, As4 = 1486, B4 = 1517, C5 = 1547, Cs5 = 1575, D5 = 1602, Ds5 = 1627, E5 = 1650, F5 = 1673, Fs5 = 1694, G5 = 1714, Gs5 = 1732, A5 = 1750, As5 = 1767, B5 = 1783, C6 = 1798, Cs6 = 1812, D6 = 1825, Ds6 = 1837, E6 = 1849, F6 = 1860, Fs6 = 1871, G6 = 1881, Gs6 = 1890, A6 = 1899, As6 = 1907, B6 = 1915, C7 = 1923, Cs7 = 1930, D7 = 1936, Ds7 = 1943, E7 = 1949, F7 = 1954, Fs7 = 1959, G7 = 1964, Gs7 = 1969, A7 = 1974, As7 = 1978, B7 = 1982, C8 = 1985, Cs8 = 1989, D8 = 1992, Ds8 = 1995, E8 = 1998, F8 = 2001, Fs8 = 2004, G8 = 2006, Gs8 = 2009, A8 = 2011, As8 = 2013, B8 = 2015; | ||
/** | ||
* Audio Context that all APU stuff runs on | ||
*/ | ||
export declare const audioContext: AudioContext; | ||
/** | ||
* Resumes the audio context. Should be called as a result of some user event, like a click. | ||
* Until this is called, the browser won't allow any sound to play. | ||
*/ | ||
export declare function allow(): void; | ||
/** | ||
* Volume multiplier intended to be changed by a user-facing volume control | ||
* @param newVolume Value between 0 and 1 | ||
*/ | ||
export declare function changeUserVolume(newVolume: number): void; | ||
/** | ||
* The last audio node, which is connected to the AudioContext's destination | ||
*/ | ||
export declare const audioNode: AudioNode; | ||
/** | ||
* Create a BGM object | ||
* | ||
* When a BGM is played, it will immediately stop any previous BGM and SFX | ||
* | ||
* TODO: resume paused BGM | ||
* @param data Data block of a VGM file | ||
* @param loop Byte offset of the data block to loop back to upon completion. (-1 if no loop) | ||
*/ | ||
export declare function bgm(data: ArrayBuffer, loop?: number): { | ||
play(): { | ||
pause(): void; | ||
resume(): void; | ||
}; | ||
/** | ||
* Create an SFX object | ||
* | ||
* When a SFX is played, it will immediately stop any previous SFX | ||
* | ||
* It will also immediately take control away from the BGM for playing on channels, | ||
* and should silence those channels. When the SFX completes, it will give control | ||
* back to the BGM for all channels. | ||
* | ||
* Right now a channel mask is used for an SFX to declare which channels it intends | ||
* to use. A smarter mechanism may be used in the future, such as scanning the data. | ||
* @param data Data block of a VGM file | ||
* @param mask Array of four 0's or 1's that indicates which channels this SFX will be using | ||
*/ | ||
export function sfx(data: ArrayBuffer, mask?: APUTrackMask): { | ||
play(): { | ||
pause(): void; | ||
resume(): void; | ||
}; | ||
}; | ||
/** | ||
* Create an SFX object | ||
* | ||
* When a SFX is played, it will immediately stop any previous SFX | ||
* | ||
* It will also immediately take control away from the BGM for playing on channels, | ||
* and should silence those channels. When the SFX completes, it will give control | ||
* back to the BGM for all channels. | ||
* | ||
* Right now a channel mask is used for an SFX to declare which channels it intends | ||
* to use. A smarter mechanism may be used in the future, such as scanning the data. | ||
* @param data Data block of a VGM file | ||
* @param mask Array of four 0's or 1's that indicates which channels this SFX will be using | ||
*/ | ||
export declare function sfx(data: ArrayBuffer, mask?: APUTrackMask): { | ||
play(): { | ||
pause(): void; | ||
resume(): void; | ||
}; | ||
/** | ||
* Creates a BGM object from an entire .vgm file contents, as an ArrayBuffer | ||
* @param arrayBuffer | ||
*/ | ||
export function fromFile(arrayBuffer: ArrayBuffer): { | ||
play(): { | ||
pause(): void; | ||
resume(): void; | ||
}; | ||
}; | ||
/** | ||
* Creates a BGM object from an entire .vgm file contents, as an ArrayBuffer | ||
* @param arrayBuffer | ||
*/ | ||
export declare function fromFile(arrayBuffer: ArrayBuffer): { | ||
play(): { | ||
pause(): void; | ||
resume(): void; | ||
}; | ||
/** | ||
* Slowly fade out the BGM. This also immediately stops current | ||
* SFX, and prevents any new SFX from playing until completion. | ||
* @param millis Number of milliseconds for the fade to complete | ||
* @returns A promise that resolves when the fade has completed | ||
*/ | ||
export function fade(millis?: number): Promise<void>; | ||
type APUWait = number; | ||
type APUCommand = APUPulseCommand | APUWaveCommand | APUNoiseCommand; | ||
type APUPulseCommand = {}; | ||
type APUWaveCommand = {}; | ||
type APUNoiseCommand = {}; | ||
export function compile(commands: (APUCommand | APUWait)[]): void; | ||
export {}; | ||
} | ||
}; | ||
/** | ||
* Slowly fade out the BGM. This also immediately stops current | ||
* SFX, and prevents any new SFX from playing until completion. | ||
* @param millis Number of milliseconds for the fade to complete | ||
* @returns A promise that resolves when the fade has completed | ||
*/ | ||
export declare function fade(millis?: number): Promise<void>; | ||
declare type APUWait = number; | ||
declare type APUCommand = APUPulseCommand | APUWaveCommand | APUNoiseCommand; | ||
declare type APUPulseCommand = {}; | ||
declare type APUWaveCommand = {}; | ||
declare type APUNoiseCommand = {}; | ||
export declare function compile(commands: (APUCommand | APUWait)[]): void; | ||
export {}; |
{ | ||
"name": "apu", | ||
"version": "0.2.20", | ||
"version": "0.2.21", | ||
"description": "Easy 3 kB library for 98% accurate Gameboy audio", | ||
@@ -5,0 +5,0 @@ "browser": "dist/apu.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
95339
697