UNPKG

mosfez-synth

Version:

A microtonal-aware synth engine library for web.

1,466 lines (1,462 loc) 396 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); function validateParamDefinition(name, paramDef) { if (!isConstant(paramDef) && !isVariable(paramDef)) { throw new Error(`param "${name}" must be a constant number or a string referring to a param name, but got ${paramDef}`); } return paramDef; } function validateParamDefinitionObject(paramDefs) { for (const name in paramDefs) { validateParamDefinition(name, paramDefs[name]); } return paramDefs; } function isConstant(paramDef) { return typeof paramDef === "number"; } function isVariable(paramDef) { return typeof paramDef === "string"; } function resolveParam(params, paramDef) { if (isConstant(paramDef)) { return paramDef; } else if (isVariable(paramDef)) { return params[paramDef]; } return void 0; } class DspNode { type; constructor(config) { this.type = config.type; } static isFaustDspNode(DspNode2) { return DspNode2.type === "faust"; } static isPolyDspNode(DspNode2) { return DspNode2.type === "poly"; } static isFaustDspNodeSerialized(serialized) { return serialized.type === "faust"; } static isPolyDspNodeSerialized(serialized) { return serialized.type === "poly"; } serialize() { throw new Error(".serialize() can only be called on subclasses"); } } class DspNodeFaust extends DspNode { dsp; inputs; paramDefs; dependencies; constructor(config) { super({ type: "faust" }); this.dsp = config.dsp; this.inputs = config.inputs ?? []; this.paramDefs = validateParamDefinitionObject(config.paramDefs); this.dependencies = config.dependencies; } serialize() { const { dsp, paramDefs } = this; const inputs = this.inputs.map((input) => input.serialize()); return { type: "faust", dsp, inputs, paramDefs }; } } class DspNodePoly extends DspNode { input; polyphony; paramCacheSize; release; gate; dependencies; constructor(config) { super({ type: "poly" }); this.input = config.input; this.polyphony = config.polyphony; this.paramCacheSize = config.paramCacheSize; this.release = validateParamDefinition("release", config.release); this.gate = validateParamDefinition("gate", config.gate); this.dependencies = config.dependencies; } serialize() { const { polyphony, paramCacheSize, release, gate } = this; const input = this.input.serialize(); return { type: "poly", input, polyphony, paramCacheSize, release, gate }; } } Object.defineProperty(exports, "__esModule", { value: true }); var FaustModule = function() { var _scriptDir = typeof document !== "undefined" && document.currentScript ? document.currentScript.src : void 0; if (typeof __filename !== "undefined") _scriptDir = _scriptDir || __filename; return function(FaustModule2) { FaustModule2 = FaustModule2 || {}; var Module = typeof FaustModule2 !== "undefined" ? FaustModule2 : {}; if (!Module.expectedDataFileDownloads) { Module.expectedDataFileDownloads = 0; Module.finishedDataFileDownloads = 0; } Module.expectedDataFileDownloads++; (function() { var loadPackage = function(metadata) { if (typeof window === "object") { window["encodeURIComponent"](window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf("/")) + "/"); } else if (typeof location !== "undefined") { encodeURIComponent(location.pathname.toString().substring(0, location.pathname.toString().lastIndexOf("/")) + "/"); } else { throw "using preloaded data can only be done on a web page or in a web worker"; } var PACKAGE_NAME = "../../lib/libfaust-wasm.data"; var REMOTE_PACKAGE_BASE = "libfaust-wasm.data"; if (typeof Module["locateFilePackage"] === "function" && !Module["locateFile"]) { Module["locateFile"] = Module["locateFilePackage"]; err("warning: you defined Module.locateFilePackage, that has been renamed to Module.locateFile (using your locateFilePackage for now)"); } var REMOTE_PACKAGE_NAME = Module["locateFile"] ? Module["locateFile"](REMOTE_PACKAGE_BASE, "") : REMOTE_PACKAGE_BASE; var REMOTE_PACKAGE_SIZE = metadata["remote_package_size"]; metadata["package_uuid"]; function fetchRemotePackage(packageName, packageSize, callback2, errback) { var xhr = new XMLHttpRequest(); xhr.open("GET", packageName, true); xhr.responseType = "arraybuffer"; xhr.onprogress = function(event) { var url = packageName; var size = packageSize; if (event.total) size = event.total; if (event.loaded) { if (!xhr.addedTotal) { xhr.addedTotal = true; if (!Module.dataFileDownloads) Module.dataFileDownloads = {}; Module.dataFileDownloads[url] = { loaded: event.loaded, total: size }; } else { Module.dataFileDownloads[url].loaded = event.loaded; } var total = 0; var loaded = 0; var num = 0; for (var download in Module.dataFileDownloads) { var data = Module.dataFileDownloads[download]; total += data.total; loaded += data.loaded; num++; } total = Math.ceil(total * Module.expectedDataFileDownloads / num); if (Module["setStatus"]) Module["setStatus"]("Downloading data... (" + loaded + "/" + total + ")"); } else if (!Module.dataFileDownloads) { if (Module["setStatus"]) Module["setStatus"]("Downloading data..."); } }; xhr.onerror = function(event) { throw new Error("NetworkError for: " + packageName); }; xhr.onload = function(event) { if (xhr.status == 200 || xhr.status == 304 || xhr.status == 206 || xhr.status == 0 && xhr.response) { var packageData = xhr.response; callback2(packageData); } else { throw new Error(xhr.statusText + " : " + xhr.responseURL); } }; xhr.send(null); } var fetchedCallback = null; var fetched = Module["getPreloadedPackage"] ? Module["getPreloadedPackage"](REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE) : null; if (!fetched) fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, function(data) { if (fetchedCallback) { fetchedCallback(data); fetchedCallback = null; } else { fetched = data; } }); function runWithFS() { function assert2(check, msg) { if (!check) throw msg + new Error().stack; } Module["FS_createPath"]("/", "libraries", true, true); function DataRequest(start, end, audio) { this.start = start; this.end = end; this.audio = audio; } DataRequest.prototype = { requests: {}, open: function(mode, name) { this.name = name; this.requests[name] = this; Module["addRunDependency"]("fp " + this.name); }, send: function() { }, onload: function() { var byteArray = this.byteArray.subarray(this.start, this.end); this.finish(byteArray); }, finish: function(byteArray) { var that = this; Module["FS_createDataFile"](this.name, null, byteArray, true, true, true); Module["removeRunDependency"]("fp " + that.name); this.requests[this.name] = null; } }; var files = metadata["files"]; for (var i = 0; i < files.length; ++i) { new DataRequest(files[i]["start"], files[i]["end"], files[i]["audio"]).open("GET", files[i]["filename"]); } function processPackageData(arrayBuffer) { Module.finishedDataFileDownloads++; assert2(arrayBuffer, "Loading data file failed."); assert2(arrayBuffer instanceof ArrayBuffer, "bad input to processPackageData"); var byteArray = new Uint8Array(arrayBuffer); DataRequest.prototype.byteArray = byteArray; var files2 = metadata["files"]; for (var i2 = 0; i2 < files2.length; ++i2) { DataRequest.prototype.requests[files2[i2].filename].onload(); } Module["removeRunDependency"]("datafile_../../lib/libfaust-wasm.data"); } Module["addRunDependency"]("datafile_../../lib/libfaust-wasm.data"); if (!Module.preloadResults) Module.preloadResults = {}; Module.preloadResults[PACKAGE_NAME] = { fromCache: false }; if (fetched) { processPackageData(fetched); fetched = null; } else { fetchedCallback = processPackageData; } } if (Module["calledRun"]) { runWithFS(); } else { if (!Module["preRun"]) Module["preRun"] = []; Module["preRun"].push(runWithFS); } }; loadPackage({ files: [ { filename: "/libraries/hoa.lib", start: 0, end: 13105, audio: 0 }, { filename: "/libraries/compressors.lib", start: 13105, end: 58859, audio: 0 }, { filename: "/libraries/basics.lib", start: 58859, end: 110385, audio: 0 }, { filename: "/libraries/dx7.lib", start: 110385, end: 179488, audio: 0 }, { filename: "/libraries/analyzers.lib", start: 179488, end: 212357, audio: 0 }, { filename: "/libraries/spats.lib", start: 212357, end: 217531, audio: 0 }, { filename: "/libraries/envelopes.lib", start: 217531, end: 228127, audio: 0 }, { filename: "/libraries/oscillators.lib", start: 228127, end: 275738, audio: 0 }, { filename: "/libraries/mi.lib", start: 275738, end: 293026, audio: 0 }, { filename: "/libraries/misceffects.lib", start: 293026, end: 314755, audio: 0 }, { filename: "/libraries/version.lib", start: 314755, end: 315662, audio: 0 }, { filename: "/libraries/webaudio.lib", start: 315662, end: 327785, audio: 0 }, { filename: "/libraries/math.lib", start: 327785, end: 349263, audio: 0 }, { filename: "/libraries/stdfaust.lib", start: 349263, end: 350533, audio: 0 }, { filename: "/libraries/filter.lib", start: 350533, end: 415919, audio: 0 }, { filename: "/libraries/delays.lib", start: 415919, end: 430403, audio: 0 }, { filename: "/libraries/routes.lib", start: 430403, end: 437029, audio: 0 }, { filename: "/libraries/soundfiles.lib", start: 437029, end: 446390, audio: 0 }, { filename: "/libraries/tonestacks.lib", start: 446390, end: 458744, audio: 0 }, { filename: "/libraries/aanl.lib", start: 458744, end: 484841, audio: 0 }, { filename: "/libraries/wdmodels.lib", start: 484841, end: 574662, audio: 0 }, { filename: "/libraries/all.lib", start: 574662, end: 575678, audio: 0 }, { filename: "/libraries/music.lib", start: 575678, end: 594112, audio: 0 }, { filename: "/libraries/tubes.lib", start: 594112, end: 943901, audio: 0 }, { filename: "/libraries/effect.lib", start: 943901, end: 1012931, audio: 0 }, { filename: "/libraries/vaeffects.lib", start: 1012931, end: 1048800, audio: 0 }, { filename: "/libraries/maxmsp.lib", start: 1048800, end: 1056659, audio: 0 }, { filename: "/libraries/platform.lib", start: 1056659, end: 1059739, audio: 0 }, { filename: "/libraries/synths.lib", start: 1059739, end: 1070990, audio: 0 }, { filename: "/libraries/sf.lib", start: 1070990, end: 1072056, audio: 0 }, { filename: "/libraries/fds.lib", start: 1072056, end: 1092602, audio: 0 }, { filename: "/libraries/reducemaps.lib", start: 1092602, end: 1097438, audio: 0 }, { filename: "/libraries/phaflangers.lib", start: 1097438, end: 1107359, audio: 0 }, { filename: "/libraries/filters.lib", start: 1107359, end: 1212987, audio: 0 }, { filename: "/libraries/signals.lib", start: 1212987, end: 1224932, audio: 0 }, { filename: "/libraries/instruments.lib", start: 1224932, end: 1234327, audio: 0 }, { filename: "/libraries/quantizers.lib", start: 1234327, end: 1244180, audio: 0 }, { filename: "/libraries/noises.lib", start: 1244180, end: 1258842, audio: 0 }, { filename: "/libraries/oscillator.lib", start: 1258842, end: 1278693, audio: 0 }, { filename: "/libraries/interpolators.lib", start: 1278693, end: 1301737, audio: 0 }, { filename: "/libraries/demos.lib", start: 1301737, end: 1364872, audio: 0 }, { filename: "/libraries/reverbs.lib", start: 1364872, end: 1402697, audio: 0 }, { filename: "/libraries/physmodels.lib", start: 1402697, end: 1573680, audio: 0 }, { filename: "/libraries/maths.lib", start: 1573680, end: 1595081, audio: 0 } ], remote_package_size: 1595081, package_uuid: "04ea3dc2-3649-4af3-b126-173b06afc41a" }); })(); var moduleOverrides = {}; var key; for (key in Module) { if (Module.hasOwnProperty(key)) { moduleOverrides[key] = Module[key]; } } var thisProgram = "./this.program"; var ENVIRONMENT_IS_WEB = false; var ENVIRONMENT_IS_WORKER = false; var ENVIRONMENT_IS_NODE = false; var ENVIRONMENT_IS_SHELL = false; ENVIRONMENT_IS_WEB = typeof window === "object"; ENVIRONMENT_IS_WORKER = typeof importScripts === "function"; ENVIRONMENT_IS_NODE = typeof process === "object" && typeof process.versions === "object" && typeof process.versions.node === "string"; ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER; if (Module["ENVIRONMENT"]) { throw new Error("Module.ENVIRONMENT has been deprecated. To force the environment, use the ENVIRONMENT compile-time option (for example, -s ENVIRONMENT=web or -s ENVIRONMENT=node)"); } var scriptDirectory = ""; function locateFile(path) { if (Module["locateFile"]) { return Module["locateFile"](path, scriptDirectory); } return scriptDirectory + path; } var read_, readBinary; var nodeFS; var nodePath; if (ENVIRONMENT_IS_NODE) { if (ENVIRONMENT_IS_WORKER) { scriptDirectory = require("path").dirname(scriptDirectory) + "/"; } else { scriptDirectory = __dirname + "/"; } read_ = function shell_read(filename, binary) { if (!nodeFS) nodeFS = require("fs"); if (!nodePath) nodePath = require("path"); filename = nodePath["normalize"](filename); return nodeFS["readFileSync"](filename, binary ? null : "utf8"); }; readBinary = function readBinary2(filename) { var ret = read_(filename, true); if (!ret.buffer) { ret = new Uint8Array(ret); } assert(ret.buffer); return ret; }; if (process["argv"].length > 1) { thisProgram = process["argv"][1].replace(/\\/g, "/"); } process["argv"].slice(2); process["on"]("uncaughtException", function(ex) { if (!(ex instanceof ExitStatus)) { throw ex; } }); process["on"]("unhandledRejection", abort); Module["inspect"] = function() { return "[Emscripten Module object]"; }; } else if (ENVIRONMENT_IS_SHELL) { if (typeof read != "undefined") { read_ = function shell_read(f) { return read(f); }; } readBinary = function readBinary2(f) { var data; if (typeof readbuffer === "function") { return new Uint8Array(readbuffer(f)); } data = read(f, "binary"); assert(typeof data === "object"); return data; }; if (typeof scriptArgs != "undefined") { scriptArgs; } if (typeof print !== "undefined") { if (typeof console === "undefined") console = {}; console.log = print; console.warn = console.error = typeof printErr !== "undefined" ? printErr : print; } } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) { if (ENVIRONMENT_IS_WORKER) { scriptDirectory = self.location.href; } else if (document.currentScript) { scriptDirectory = document.currentScript.src; } if (_scriptDir) { scriptDirectory = _scriptDir; } if (scriptDirectory.indexOf("blob:") !== 0) { scriptDirectory = scriptDirectory.substr(0, scriptDirectory.lastIndexOf("/") + 1); } else { scriptDirectory = ""; } { read_ = function shell_read(url) { var xhr = new XMLHttpRequest(); xhr.open("GET", url, false); xhr.send(null); return xhr.responseText; }; if (ENVIRONMENT_IS_WORKER) { readBinary = function readBinary2(url) { var xhr = new XMLHttpRequest(); xhr.open("GET", url, false); xhr.responseType = "arraybuffer"; xhr.send(null); return new Uint8Array(xhr.response); }; } } } else { throw new Error("environment detection error"); } var out = Module["print"] || console.log.bind(console); var err = Module["printErr"] || console.warn.bind(console); for (key in moduleOverrides) { if (moduleOverrides.hasOwnProperty(key)) { Module[key] = moduleOverrides[key]; } } moduleOverrides = null; if (Module["arguments"]) Module["arguments"]; if (!Object.getOwnPropertyDescriptor(Module, "arguments")) Object.defineProperty(Module, "arguments", { configurable: true, get: function() { abort("Module.arguments has been replaced with plain arguments_"); } }); if (Module["thisProgram"]) thisProgram = Module["thisProgram"]; if (!Object.getOwnPropertyDescriptor(Module, "thisProgram")) Object.defineProperty(Module, "thisProgram", { configurable: true, get: function() { abort("Module.thisProgram has been replaced with plain thisProgram"); } }); if (Module["quit"]) Module["quit"]; if (!Object.getOwnPropertyDescriptor(Module, "quit")) Object.defineProperty(Module, "quit", { configurable: true, get: function() { abort("Module.quit has been replaced with plain quit_"); } }); assert(typeof Module["memoryInitializerPrefixURL"] === "undefined", "Module.memoryInitializerPrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["pthreadMainPrefixURL"] === "undefined", "Module.pthreadMainPrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["cdInitializerPrefixURL"] === "undefined", "Module.cdInitializerPrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["filePackagePrefixURL"] === "undefined", "Module.filePackagePrefixURL option was removed, use Module.locateFile instead"); assert(typeof Module["read"] === "undefined", "Module.read option was removed (modify read_ in JS)"); assert(typeof Module["readAsync"] === "undefined", "Module.readAsync option was removed (modify readAsync in JS)"); assert(typeof Module["readBinary"] === "undefined", "Module.readBinary option was removed (modify readBinary in JS)"); assert(typeof Module["setWindowTitle"] === "undefined", "Module.setWindowTitle option was removed (modify setWindowTitle in JS)"); assert(typeof Module["TOTAL_MEMORY"] === "undefined", "Module.TOTAL_MEMORY has been renamed Module.INITIAL_MEMORY"); if (!Object.getOwnPropertyDescriptor(Module, "read")) Object.defineProperty(Module, "read", { configurable: true, get: function() { abort("Module.read has been replaced with plain read_"); } }); if (!Object.getOwnPropertyDescriptor(Module, "readAsync")) Object.defineProperty(Module, "readAsync", { configurable: true, get: function() { abort("Module.readAsync has been replaced with plain readAsync"); } }); if (!Object.getOwnPropertyDescriptor(Module, "readBinary")) Object.defineProperty(Module, "readBinary", { configurable: true, get: function() { abort("Module.readBinary has been replaced with plain readBinary"); } }); var stackSave; var stackRestore; var stackAlloc; stackSave = stackRestore = stackAlloc = function() { abort("cannot use the stack before compiled code is ready to run, and has provided stack access"); }; function dynamicAlloc(size) { assert(DYNAMICTOP_PTR); var ret = HEAP32[DYNAMICTOP_PTR >> 2]; var end = ret + size + 15 & -16; assert(end <= HEAP8.length, "failure to dynamicAlloc - memory growth etc. is not supported there, call malloc/sbrk directly"); HEAP32[DYNAMICTOP_PTR >> 2] = end; return ret; } function getNativeTypeSize(type) { switch (type) { case "i1": case "i8": return 1; case "i16": return 2; case "i32": return 4; case "i64": return 8; case "float": return 4; case "double": return 8; default: { if (type[type.length - 1] === "*") { return 4; } else if (type[0] === "i") { var bits = Number(type.substr(1)); assert(bits % 8 === 0, "getNativeTypeSize invalid bits " + bits + ", type " + type); return bits / 8; } else { return 0; } } } } function warnOnce(text) { if (!warnOnce.shown) warnOnce.shown = {}; if (!warnOnce.shown[text]) { warnOnce.shown[text] = 1; err(text); } } var wasmBinary; if (Module["wasmBinary"]) wasmBinary = Module["wasmBinary"]; if (!Object.getOwnPropertyDescriptor(Module, "wasmBinary")) Object.defineProperty(Module, "wasmBinary", { configurable: true, get: function() { abort("Module.wasmBinary has been replaced with plain wasmBinary"); } }); if (Module["noExitRuntime"]) Module["noExitRuntime"]; if (!Object.getOwnPropertyDescriptor(Module, "noExitRuntime")) Object.defineProperty(Module, "noExitRuntime", { configurable: true, get: function() { abort("Module.noExitRuntime has been replaced with plain noExitRuntime"); } }); if (typeof WebAssembly !== "object") { abort("No WebAssembly support found. Build with -s WASM=0 to target JavaScript instead."); } function setValue(ptr, value, type, noSafe) { type = type || "i8"; if (type.charAt(type.length - 1) === "*") type = "i32"; switch (type) { case "i1": HEAP8[ptr >> 0] = value; break; case "i8": HEAP8[ptr >> 0] = value; break; case "i16": HEAP16[ptr >> 1] = value; break; case "i32": HEAP32[ptr >> 2] = value; break; case "i64": tempI64 = [ value >>> 0, (tempDouble = value, +Math_abs(tempDouble) >= 1 ? tempDouble > 0 ? (Math_min(+Math_floor(tempDouble / 4294967296), 4294967295) | 0) >>> 0 : ~~+Math_ceil((tempDouble - +(~~tempDouble >>> 0)) / 4294967296) >>> 0 : 0) ], HEAP32[ptr >> 2] = tempI64[0], HEAP32[ptr + 4 >> 2] = tempI64[1]; break; case "float": HEAPF32[ptr >> 2] = value; break; case "double": HEAPF64[ptr >> 3] = value; break; default: abort("invalid type for setValue: " + type); } } var wasmMemory; var wasmTable = new WebAssembly.Table({ initial: 2176, maximum: 2176 + 0, element: "anyfunc" }); var ABORT = false; function assert(condition, text) { if (!condition) { abort("Assertion failed: " + text); } } function getCFunc(ident) { var func = Module["_" + ident]; assert(func, "Cannot call unknown function " + ident + ", make sure it is exported"); return func; } function ccall(ident, returnType, argTypes, args, opts) { var toC = { string: function(str) { var ret2 = 0; if (str !== null && str !== void 0 && str !== 0) { var len = (str.length << 2) + 1; ret2 = stackAlloc(len); stringToUTF8(str, ret2, len); } return ret2; }, array: function(arr) { var ret2 = stackAlloc(arr.length); writeArrayToMemory(arr, ret2); return ret2; } }; function convertReturnValue(ret2) { if (returnType === "string") return UTF8ToString(ret2); if (returnType === "boolean") return Boolean(ret2); return ret2; } var func = getCFunc(ident); var cArgs = []; var stack = 0; assert(returnType !== "array", 'Return type should not be "array".'); if (args) { for (var i = 0; i < args.length; i++) { var converter = toC[argTypes[i]]; if (converter) { if (stack === 0) stack = stackSave(); cArgs[i] = converter(args[i]); } else { cArgs[i] = args[i]; } } } var ret = func.apply(null, cArgs); ret = convertReturnValue(ret); if (stack !== 0) stackRestore(stack); return ret; } function cwrap(ident, returnType, argTypes, opts) { return function() { return ccall(ident, returnType, argTypes, arguments); }; } var ALLOC_STACK = 1; var ALLOC_NONE = 3; function allocate(slab, types, allocator, ptr) { var zeroinit, size; if (typeof slab === "number") { zeroinit = true; size = slab; } else { zeroinit = false; size = slab.length; } var singleType = typeof types === "string" ? types : null; var ret; if (allocator == ALLOC_NONE) { ret = ptr; } else { ret = [_malloc, stackAlloc, dynamicAlloc][allocator](Math.max(size, singleType ? 1 : types.length)); } if (zeroinit) { var stop; ptr = ret; assert((ret & 3) == 0); stop = ret + (size & ~3); for (; ptr < stop; ptr += 4) { HEAP32[ptr >> 2] = 0; } stop = ret + size; while (ptr < stop) { HEAP8[ptr++ >> 0] = 0; } return ret; } if (singleType === "i8") { if (slab.subarray || slab.slice) { HEAPU8.set(slab, ret); } else { HEAPU8.set(new Uint8Array(slab), ret); } return ret; } var i = 0, type, typeSize, previousType; while (i < size) { var curr = slab[i]; type = singleType || types[i]; if (type === 0) { i++; continue; } assert(type, "Must know what type to store in allocate!"); if (type == "i64") type = "i32"; setValue(ret + i, curr, type); if (previousType !== type) { typeSize = getNativeTypeSize(type); previousType = type; } i += typeSize; } return ret; } function getMemory(size) { if (!runtimeInitialized) return dynamicAlloc(size); return _malloc(size); } var UTF8Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf8") : void 0; function UTF8ArrayToString(u8Array, idx, maxBytesToRead) { var endIdx = idx + maxBytesToRead; var endPtr = idx; while (u8Array[endPtr] && !(endPtr >= endIdx)) ++endPtr; if (endPtr - idx > 16 && u8Array.subarray && UTF8Decoder) { return UTF8Decoder.decode(u8Array.subarray(idx, endPtr)); } else { var str = ""; while (idx < endPtr) { var u0 = u8Array[idx++]; if (!(u0 & 128)) { str += String.fromCharCode(u0); continue; } var u1 = u8Array[idx++] & 63; if ((u0 & 224) == 192) { str += String.fromCharCode((u0 & 31) << 6 | u1); continue; } var u2 = u8Array[idx++] & 63; if ((u0 & 240) == 224) { u0 = (u0 & 15) << 12 | u1 << 6 | u2; } else { if ((u0 & 248) != 240) warnOnce("Invalid UTF-8 leading byte 0x" + u0.toString(16) + " encountered when deserializing a UTF-8 string on the asm.js/wasm heap to a JS string!"); u0 = (u0 & 7) << 18 | u1 << 12 | u2 << 6 | u8Array[idx++] & 63; } if (u0 < 65536) { str += String.fromCharCode(u0); } else { var ch = u0 - 65536; str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023); } } } return str; } function UTF8ToString(ptr, maxBytesToRead) { return ptr ? UTF8ArrayToString(HEAPU8, ptr, maxBytesToRead) : ""; } function stringToUTF8Array(str, outU8Array, outIdx, maxBytesToWrite) { if (!(maxBytesToWrite > 0)) return 0; var startIdx = outIdx; var endIdx = outIdx + maxBytesToWrite - 1; for (var i = 0; i < str.length; ++i) { var u = str.charCodeAt(i); if (u >= 55296 && u <= 57343) { var u1 = str.charCodeAt(++i); u = 65536 + ((u & 1023) << 10) | u1 & 1023; } if (u <= 127) { if (outIdx >= endIdx) break; outU8Array[outIdx++] = u; } else if (u <= 2047) { if (outIdx + 1 >= endIdx) break; outU8Array[outIdx++] = 192 | u >> 6; outU8Array[outIdx++] = 128 | u & 63; } else if (u <= 65535) { if (outIdx + 2 >= endIdx) break; outU8Array[outIdx++] = 224 | u >> 12; outU8Array[outIdx++] = 128 | u >> 6 & 63; outU8Array[outIdx++] = 128 | u & 63; } else { if (outIdx + 3 >= endIdx) break; if (u >= 2097152) warnOnce("Invalid Unicode code point 0x" + u.toString(16) + " encountered when serializing a JS string to an UTF-8 string on the asm.js/wasm heap! (Valid unicode code points should be in range 0-0x1FFFFF)."); outU8Array[outIdx++] = 240 | u >> 18; outU8Array[outIdx++] = 128 | u >> 12 & 63; outU8Array[outIdx++] = 128 | u >> 6 & 63; outU8Array[outIdx++] = 128 | u & 63; } } outU8Array[outIdx] = 0; return outIdx - startIdx; } function stringToUTF8(str, outPtr, maxBytesToWrite) { assert(typeof maxBytesToWrite == "number", "stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!"); return stringToUTF8Array(str, HEAPU8, outPtr, maxBytesToWrite); } function lengthBytesUTF8(str) { var len = 0; for (var i = 0; i < str.length; ++i) { var u = str.charCodeAt(i); if (u >= 55296 && u <= 57343) u = 65536 + ((u & 1023) << 10) | str.charCodeAt(++i) & 1023; if (u <= 127) ++len; else if (u <= 2047) len += 2; else if (u <= 65535) len += 3; else len += 4; } return len; } var UTF16Decoder = typeof TextDecoder !== "undefined" ? new TextDecoder("utf-16le") : void 0; function UTF16ToString(ptr) { assert(ptr % 2 == 0, "Pointer passed to UTF16ToString must be aligned to two bytes!"); var endPtr = ptr; var idx = endPtr >> 1; while (HEAP16[idx]) ++idx; endPtr = idx << 1; if (endPtr - ptr > 32 && UTF16Decoder) { return UTF16Decoder.decode(HEAPU8.subarray(ptr, endPtr)); } else { var i = 0; var str = ""; while (1) { var codeUnit = HEAP16[ptr + i * 2 >> 1]; if (codeUnit == 0) return str; ++i; str += String.fromCharCode(codeUnit); } } } function stringToUTF16(str, outPtr, maxBytesToWrite) { assert(outPtr % 2 == 0, "Pointer passed to stringToUTF16 must be aligned to two bytes!"); assert(typeof maxBytesToWrite == "number", "stringToUTF16(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!"); if (maxBytesToWrite === void 0) { maxBytesToWrite = 2147483647; } if (maxBytesToWrite < 2) return 0; maxBytesToWrite -= 2; var startPtr = outPtr; var numCharsToWrite = maxBytesToWrite < str.length * 2 ? maxBytesToWrite / 2 : str.length; for (var i = 0; i < numCharsToWrite; ++i) { var codeUnit = str.charCodeAt(i); HEAP16[outPtr >> 1] = codeUnit; outPtr += 2; } HEAP16[outPtr >> 1] = 0; return outPtr - startPtr; } function lengthBytesUTF16(str) { return str.length * 2; } function UTF32ToString(ptr) { assert(ptr % 4 == 0, "Pointer passed to UTF32ToString must be aligned to four bytes!"); var i = 0; var str = ""; while (1) { var utf32 = HEAP32[ptr + i * 4 >> 2]; if (utf32 == 0) return str; ++i; if (utf32 >= 65536) { var ch = utf32 - 65536; str += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023); } else { str += String.fromCharCode(utf32); } } } function stringToUTF32(str, outPtr, maxBytesToWrite) { assert(outPtr % 4 == 0, "Pointer passed to stringToUTF32 must be aligned to four bytes!"); assert(typeof maxBytesToWrite == "number", "stringToUTF32(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!"); if (maxBytesToWrite === void 0) { maxBytesToWrite = 2147483647; } if (maxBytesToWrite < 4) return 0; var startPtr = outPtr; var endPtr = startPtr + maxBytesToWrite - 4; for (var i = 0; i < str.length; ++i) { var codeUnit = str.charCodeAt(i); if (codeUnit >= 55296 && codeUnit <= 57343) { var trailSurrogate = str.charCodeAt(++i); codeUnit = 65536 + ((codeUnit & 1023) << 10) | trailSurrogate & 1023; } HEAP32[outPtr >> 2] = codeUnit; outPtr += 4; if (outPtr + 4 > endPtr) break; } HEAP32[outPtr >> 2] = 0; return outPtr - startPtr; } function lengthBytesUTF32(str) { var len = 0; for (var i = 0; i < str.length; ++i) { var codeUnit = str.charCodeAt(i); if (codeUnit >= 55296 && codeUnit <= 57343) ++i; len += 4; } return len; } function allocateUTF8(str) { var size = lengthBytesUTF8(str) + 1; var ret = _malloc(size); if (ret) stringToUTF8Array(str, HEAP8, ret, size); return ret; } function writeArrayToMemory(array, buffer2) { assert(array.length >= 0, "writeArrayToMemory array must have a length (should be an array or typed array)"); HEAP8.set(array, buffer2); } function writeAsciiToMemory(str, buffer2, dontAddNull) { for (var i = 0; i < str.length; ++i) { assert(str.charCodeAt(i) === str.charCodeAt(i) & 255); HEAP8[buffer2++ >> 0] = str.charCodeAt(i); } if (!dontAddNull) HEAP8[buffer2 >> 0] = 0; } var WASM_PAGE_SIZE = 65536; function alignUp(x, multiple) { if (x % multiple > 0) { x += multiple - x % multiple; } return x; } var buffer, HEAP8, HEAPU8, HEAP16, HEAPU16, HEAP32, HEAPU32, HEAPF32, HEAPF64; function updateGlobalBufferAndViews(buf) { buffer = buf; Module["HEAP8"] = HEAP8 = new Int8Array(buf); Module["HEAP16"] = HEAP16 = new Int16Array(buf); Module["HEAP32"] = HEAP32 = new Int32Array(buf); Module["HEAPU8"] = HEAPU8 = new Uint8Array(buf); Module["HEAPU16"] = HEAPU16 = new Uint16Array(buf); Module["HEAPU32"] = HEAPU32 = new Uint32Array(buf); Module["HEAPF32"] = HEAPF32 = new Float32Array(buf); Module["HEAPF64"] = HEAPF64 = new Float64Array(buf); } var STACK_BASE = 7643408, STACK_MAX = 2400528, DYNAMIC_BASE = 7643408, DYNAMICTOP_PTR = 2400368; assert(STACK_BASE % 16 === 0, "stack must start aligned"); assert(DYNAMIC_BASE % 16 === 0, "heap must start aligned"); var TOTAL_STACK = 5242880; if (Module["TOTAL_STACK"]) assert(TOTAL_STACK === Module["TOTAL_STACK"], "the stack size can no longer be determined at runtime"); var INITIAL_INITIAL_MEMORY = Module["INITIAL_MEMORY"] || 16777216; if (!Object.getOwnPropertyDescriptor(Module, "INITIAL_MEMORY")) Object.defineProperty(Module, "INITIAL_MEMORY", { configurable: true, get: function() { abort("Module.INITIAL_MEMORY has been replaced with plain INITIAL_INITIAL_MEMORY"); } }); assert(INITIAL_INITIAL_MEMORY >= TOTAL_STACK, "INITIAL_MEMORY should be larger than TOTAL_STACK, was " + INITIAL_INITIAL_MEMORY + "! (TOTAL_STACK=" + TOTAL_STACK + ")"); assert(typeof Int32Array !== "undefined" && typeof Float64Array !== "undefined" && Int32Array.prototype.subarray !== void 0 && Int32Array.prototype.set !== void 0, "JS engine does not provide full typed array support"); if (Module["wasmMemory"]) { wasmMemory = Module["wasmMemory"]; } else { wasmMemory = new WebAssembly.Memory({ initial: INITIAL_INITIAL_MEMORY / WASM_PAGE_SIZE }); } if (wasmMemory) { buffer = wasmMemory.buffer; } INITIAL_INITIAL_MEMORY = buffer.byteLength; assert(INITIAL_INITIAL_MEMORY % WASM_PAGE_SIZE === 0); updateGlobalBufferAndViews(buffer); HEAP32[DYNAMICTOP_PTR >> 2] = DYNAMIC_BASE; function writeStackCookie() { assert((STACK_MAX & 3) == 0); HEAPU32[(STACK_MAX >> 2) + 1] = 34821223; HEAPU32[(STACK_MAX >> 2) + 2] = 2310721022; HEAP32[0] = 1668509029; } function checkStackCookie() { var cookie1 = HEAPU32[(STACK_MAX >> 2) + 1]; var cookie2 = HEAPU32[(STACK_MAX >> 2) + 2]; if (cookie1 != 34821223 || cookie2 != 2310721022) { abort("Stack overflow! Stack cookie has been overwritten, expected hex dwords 0x89BACDFE and 0x2135467, but received 0x" + cookie2.toString(16) + " " + cookie1.toString(16)); } if (HEAP32[0] !== 1668509029) abort("Runtime error: The application has corrupted its heap memory area (address zero)!"); } function abortStackOverflow(allocSize) { abort("Stack overflow! Attempted to allocate " + allocSize + " bytes on the stack, but stack has only " + (STACK_MAX - stackSave() + allocSize) + " bytes available!"); } (function() { var h16 = new Int16Array(1); var h8 = new Int8Array(h16.buffer); h16[0] = 25459; if (h8[0] !== 115 || h8[1] !== 99) throw "Runtime error: expected the system to be little-endian!"; })(); function callRuntimeCallbacks(callbacks) { while (callbacks.length > 0) { var callback2 = callbacks.shift(); if (typeof callback2 == "function") { callback2(); continue; } var func = callback2.func; if (typeof func === "number") { if (callback2.arg === void 0) { Module["dynCall_v"](func); } else { Module["dynCall_vi"](func, callback2.arg); } } else { func(callback2.arg === void 0 ? null : callback2.arg); } } } var __ATPRERUN__ = []; var __ATINIT__ = []; var __ATMAIN__ = []; var __ATPOSTRUN__ = []; var runtimeInitialized = false; var runtimeExited = false; function preRun() { if (Module["preRun"]) { if (typeof Module["preRun"] == "function") Module["preRun"] = [Module["preRun"]]; while (Module["preRun"].length) { addOnPreRun(Module["preRun"].shift()); } } callRuntimeCallbacks(__ATPRERUN__); } function initRuntime() { checkStackCookie(); assert(!runtimeInitialized); runtimeInitialized = true; SOCKFS.root = FS.mount(SOCKFS, {}, null); if (!Module["noFSInit"] && !FS.init.initialized) FS.init(); callRuntimeCallbacks(__ATINIT__); } function preMain() { checkStackCookie(); FS.ignorePermissions = false; callRuntimeCallbacks(__ATMAIN__); } function postRun() { checkStackCookie(); if (Module["postRun"]) { if (typeof Module["postRun"] == "function") Module["postRun"] = [Module["postRun"]]; while (Module["postRun"].length) { addOnPostRun(Module["postRun"].shift()); } } callRuntimeCallbacks(__ATPOSTRUN__); } function addOnPreRun(cb) { __ATPRERUN__.unshift(cb); } function addOnPostRun(cb) { __ATPOSTRUN__.unshift(cb); } assert(Math.imul, "This browser does not support Math.imul(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"); assert(Math.fround, "This browser does not support Math.fround(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"); assert(Math.clz32, "This browser does not support Math.clz32(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"); assert(Math.trunc, "This browser does not support Math.trunc(), build with LEGACY_VM_SUPPORT or POLYFILL_OLD_MATH_FUNCTIONS to add in a polyfill"); var Math_abs = Math.abs; var Math_ceil = Math.ceil; var Math_floor = Math.floor; var Math_min = Math.min; var runDependencies = 0; var runDependencyWatcher = null; var dependenciesFulfilled = null; var runDependencyTracking = {}; function getUniqueRunDependency(id) { var orig = id; while (1) { if (!runDependencyTracking[id]) return id; id = orig + Math.random(); } } function addRunDependency(id) { runDependencies++; if (Module["monitorRunDependencies"]) { Module["monitorRunDependencies"](runDependencies); } if (id) { assert(!runDependencyTracking[id]); runDependencyTracking[id] = 1; if (runDependencyWatcher === null && typeof setInterval !== "undefined") { runDependencyWatcher = setInterval(function() { if (ABORT) { clearInterval(runDependencyWatcher); runDependencyWatcher = null; return; } var shown = false; for (var dep in runDependencyTracking) { if (!shown) { shown = true; err("still waiting on run dependencies:"); } err("dependency: " + dep); } if (shown) { err("(end of list)"); } }, 1e4); } } else { err("warning: run dependency added without ID"); } } function removeRunDependency(id) { runDependencies--; if (Module["monitorRunDependencies"]) { Module["monitorRunDependencies"](runDependencies); } if (id) { assert(runDependencyTracking[id]); delete runDependencyTracking[id]; } else { err("warning: run dependency removed without ID"); } if (runDependencies == 0) { if (runDependencyWatcher !== null) { clearInterval(runDependencyWatcher); runDependencyWatcher = null; } if (dependenciesFulfilled) { var callback2 = dependenciesFulfilled; dependenciesFulfilled = null; callback2(); } } } Module["preloadedImages"] = {}; Module["preloadedAudios"] = {}; function abort(what) { if (Module["onAbort"]) { Module["onAbort"](what); } what += ""; out(what); err(what); ABORT = true; var output = "abort(" + what + ") at " + stackTrace(); what = output; throw new WebAssembly.RuntimeError(what); } var dataURIPrefix = "data:application/octet-stream;base64,"; function isDataURI(filename) { return String.prototype.startsWith ? filename.startsWith(dataURIPrefix) : filename.indexOf(dataURIPrefix) === 0; } var wasmBinaryFile = "libfaust-wasm.wasm"; if (!isDataURI(wasmBinaryFile)) { wasmBinaryFile = locateFile(wasmBinaryFile); } function getBinary() { try { if (wasmBinary) { return new Uint8Array(wasmBinary); } if (readBinary) { return readBinary(wasmBinaryFile); } else { throw "both async and sync fetching of the wasm failed"; } } catch (err2) { abort(err2); } } function getBinaryPromise() { if (!wasmBinary && (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) && typeof fetch === "function") { return fetch(wasmBinaryFile, { credentials: "same-origin" }).then(function(response) { if (!response["ok"]) { throw "failed to load wasm binary file at '" + wasmBinaryFile + "'"; } return response["arrayBuffer"](); }).catch(function() { return getBinary(); }); } return new Promise(function(resolve, reject) { resolve(getBinary()); }); } function createWasm() { var info = { env: asmLibraryArg, wasi_snapshot_preview1: asmLibraryArg }; function receiveInstance(instance, module2) { var exports22 = instance.exports; Module["asm"] = exports22; removeRunDependency("wasm-instantiate"); } addRunDependency("wasm-instantiate"); var trueModule = Module; function receiveInstantiatedSource(output) { assert(Module === trueModule, "the Module object should not be replaced during async compilation - perhaps the order of HTML elements is wrong?"); trueModule = null; receiveInstance(output["instance"]); } function instantiateArrayBuffer(receiver) { return getBinaryPromise().then(function(binary) { return WebAssembly.instantiate(binary, info); }).then(receiver, function(reason) { err("failed to asynchronously prepare wasm: " + reason); abort(reason); }); } function instantiateAsync() { if (!wasmBinary && typeof WebAssembly.instantiateStream