{"version":3,"file":"audio-processor.mjs","sources":["../src/audio-processor.mjs"],"sourcesContent":["class audioProcessor extends AudioWorkletProcessor {\r\n\tconstructor(...args) {\r\n\t\tsuper(...args);\r\n\t\tthis.audioSample = 0;\n\t\tthis.byteSample = 0;\n\t\tthis.divisorStorage = 0;\n\t\tthis.drawMode = 'Points';\n\t\tthis.errorDisplayed = true;\n\t\tthis.func = null;\n\t\tthis.getValues = null;\n\t\tthis.isFuncbeat = false;\n\t\tthis.isPlaying = false;\n\t\tthis.lastByteValue = [null, null, null];\n\t\tthis.lastFuncValue = [null, null, null];\n\t\tthis.lastOutputChannels = 1;\n\t\tthis.lastTime = -1;\n\t\tthis.outValue = [0, 0];\n\t\tthis.outValueChannels = [0, 0, 0];\n\t\tthis.fftRawOutput = false;\n\t\tthis.playbackSpeed = 1;\r\n\t\tthis.sampleRate = 8000;\r\n\t\tthis.sampleRatio = 1;\r\n\t\tthis.srDivisor = 1;\n\t\tthis.fftBuffer = [];\r\n\t\tthis.fftSize = 256;\r\n\t\tthis.audioFiles = new Map();\r\n\t\tObject.seal(this);\r\n\t\taudioProcessor.deleteGlobals();\r\n\t\taudioProcessor.freezeGlobals();\r\n\t\tthis.port.addEventListener('message', e => this.receiveData(e.data));\r\n\t\tthis.port.start();\r\n\t}\r\n\tstatic deleteGlobals() {\r\n\t\t// Delete single letter variables to prevent persistent variable errors (covers a good enough range)\r\n\t\tfor(let i = 0; i < 26; ++i) {\r\n\t\t\tdelete globalThis[String.fromCharCode(65 + i)];\r\n\t\t\tdelete globalThis[String.fromCharCode(97 + i)];\r\n\t\t}\r\n\t\t// Delete global variables\r\n\t\tfor(const name in globalThis) {\r\n\t\t\tif(Object.prototype.hasOwnProperty.call(globalThis, name)) {\r\n\t\t\t\tdelete globalThis[name];\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\tstatic freezeGlobals() {\r\n\t\tObject.getOwnPropertyNames(globalThis).forEach(name => {\r\n\t\t\tconst prop = globalThis[name];\r\n\t\t\tconst type = typeof prop;\r\n\t\t\tif((type === 'object' || type === 'function') && name !== 'globalThis') {\r\n\t\t\t\tObject.freeze(prop);\r\n\t\t\t}\r\n\t\t\tif(type === 'function' && Object.prototype.hasOwnProperty.call(prop, 'prototype')) {\r\n\t\t\t\tObject.freeze(prop.prototype);\r\n\t\t\t}\r\n\t\t\tObject.defineProperty(globalThis, name, { writable: false, configurable: false });\r\n\t\t});\r\n\t}\r\n\tstatic getErrorMessage(err, time) {\r\n\t\tconst when = time === null ? 'compilation' : 't=' + time;\r\n\t\tif(!(err instanceof Error)) {\r\n\t\t\treturn `${ when } thrown: ${ typeof err === 'string' ? err : JSON.stringify(err) }`;\r\n\t\t}\r\n\t\tconst { message, lineNumber, columnNumber } = err;\r\n\t\treturn `${ when } error: ${ typeof message === 'string' ? message : JSON.stringify(message) }${\r\n\t\t\ttypeof lineNumber === 'number' && typeof columnNumber === 'number' ?\r\n\t\t\t\t` (at line ${ lineNumber - 3 }, character ${ +columnNumber })` : '' }`;\r\n\t}\r\n\tprocess(inputs, [chData]) {\r\n\t\tconst chDataLen = chData[0].length;\r\n\t\tif(!chDataLen || !this.isPlaying) {\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tlet time = this.sampleRatio * this.audioSample;\r\n\t\tlet { byteSample } = this;\n\t\tconst divisor = Math.max(1, this.srDivisor || 1);\n\t\tconst drawBuffer = [];\r\n\t\tconst isDiagram = this.drawMode === 'Combined' || this.drawMode === 'Diagram';\r\n\t\tfor(let i = 0; i < chDataLen; ++i) {\r\n\t\t\ttime += this.sampleRatio;\r\n\t\t\t// make sure you dont modify this because it will mess up the scope\r\n\t\t\tconst currentTime = Math.floor(time);\r\n\t\t\tif(this.lastTime !== currentTime) {\r\n\t\t\t\tlet funcValue;\r\n\t\t\t\tconst currentSample = Math.floor(byteSample);\n\t\t\t\tconst divisorMet = (((currentTime % divisor) + divisor) % divisor) === 0;\n\t\t\t\ttry {\n\t\t\t\t\tif(this.isFuncbeat) {\n\t\t\t\t\t\tfuncValue = this.func(currentSample / this.sampleRate, this.sampleRate);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfuncValue = this.func(currentSample);\n\t\t\t\t\t}\n\t\t\t\t\tif(!divisorMet) {\n\t\t\t\t\t\tfuncValue = this.divisorStorage;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.divisorStorage = funcValue;\n\t\t\t\t\t}\n\t\t\t\t} catch(err) {\n\t\t\t\t\tif(this.errorDisplayed) {\r\n\t\t\t\t\t\tthis.errorDisplayed = false;\r\n\t\t\t\t\t\tthis.sendData({\r\n\t\t\t\t\t\t\terror: {\r\n\t\t\t\t\t\t\t\tmessage: audioProcessor.getErrorMessage(err, currentSample),\r\n\t\t\t\t\t\t\t\tisRuntime: true\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfuncValue = NaN;\r\n\t\t\t\t}\r\n\t\t\t\tconst outputChannels = Array.isArray(funcValue) ? Math.max(0, Math.min(funcValue.length, 3)) : 1;\n\t\t\t\tlet values = Array.isArray(funcValue) ? funcValue.slice() : [funcValue];\n\t\t\t\tlet hasCenter = false;\n\t\t\t\tif(Array.isArray(funcValue)) {\n\t\t\t\t\tif(funcValue.length >= 3) {\n\t\t\t\t\t\tvalues = [funcValue[0], funcValue[1], funcValue[2]];\n\t\t\t\t\t\thasCenter = true;\n\t\t\t\t\t} else if(funcValue.length === 2) {\n\t\t\t\t\t\tvalues = [funcValue[0], NaN, funcValue[1]];\n\t\t\t\t\t} else if(funcValue.length === 1) {\n\t\t\t\t\t\tvalues = [funcValue[0], NaN, funcValue[0]];\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalues = [NaN, NaN, NaN];\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tvalues = [funcValue, NaN, funcValue];\n\t\t\t\t}\n\t\t\t\tif(!hasCenter) {\n\t\t\t\t\tthis.lastFuncValue[1] = NaN;\n\t\t\t\t\tthis.lastByteValue[1] = NaN;\n\t\t\t\t\tthis.outValueChannels[1] = 0;\n\t\t\t\t}\n\t\t\t\tlet hasValue = false;\n\t\t\t\tconst channelIndices = hasCenter ? [0, 1, 2] : [0, 2];\n\t\t\t\tfor(const ch of channelIndices) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tvalues[ch] = +values[ch];\n\t\t\t\t\t} catch(err) {\n\t\t\t\t\t\tvalues[ch] = NaN;\n\t\t\t\t\t}\n\t\t\t\t\tif(isDiagram) {\n\t\t\t\t\t\tif(!isNaN(values[ch])) {\n\t\t\t\t\t\t\tthis.outValueChannels[ch] = this.getValues(values[ch], ch);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.lastByteValue[ch] = NaN;\n\t\t\t\t\t\t}\n\t\t\t\t\t\thasValue = true;\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif(values[ch] === this.lastFuncValue[ch]) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t} else if(!isNaN(values[ch])) {\n\t\t\t\t\t\tthis.outValueChannels[ch] = this.getValues(values[ch], ch);\n\t\t\t\t\t\thasValue = true;\n\t\t\t\t\t} else if(!isNaN(this.lastFuncValue[ch])) {\n\t\t\t\t\t\tthis.lastByteValue[ch] = NaN;\n\t\t\t\t\t\thasValue = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(hasCenter) {\n\t\t\t\t\tconst left = this.outValueChannels[0];\n\t\t\t\t\tconst center = this.outValueChannels[1];\n\t\t\t\t\tconst right = this.outValueChannels[2];\n\t\t\t\t\tthis.outValue[0] = left * (2 / 3) + center / 3;\n\t\t\t\t\tthis.outValue[1] = right * (2 / 3) + center / 3;\n\t\t\t\t} else {\n\t\t\t\t\tthis.outValue[0] = this.outValueChannels[0];\n\t\t\t\t\tthis.outValue[1] = this.outValueChannels[2];\n\t\t\t\t}\n\t\t\t\tif(outputChannels !== this.lastOutputChannels) {\n\t\t\t\t\thasValue = true;\n\t\t\t\t}\n\t\t\t\tif(hasValue) {\n\t\t\t\t\tdrawBuffer.push({ t: byteSample, value: [...this.lastByteValue], channels: outputChannels });\n\t\t\t\t}\n\n\t\t\t\tbyteSample += currentTime - this.lastTime;\n\t\t\t\tthis.lastFuncValue = values;\n\t\t\t\tthis.lastOutputChannels = outputChannels;\n\t\t\t\tthis.lastTime = currentTime;\n\t\t\t}\n\t\t\tif(this.fftRawOutput && chData[2]) {\n\t\t\t\tchData[0][i] = this.outValueChannels[0];\n\t\t\t\tchData[1][i] = this.outValueChannels[1];\n\t\t\t\tchData[2][i] = this.outValueChannels[2];\n\t\t\t} else {\n\t\t\t\tchData[0][i] = this.outValue[0];\n\t\t\t\tchData[1][i] = this.outValue[1];\n\t\t\t\tif(chData[2]) {\n\t\t\t\t\tchData[2][i] = this.outValueChannels[1];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif(Math.abs(byteSample) > Number.MAX_SAFE_INTEGER) {\r\n\t\t\tthis.resetTime();\r\n\t\t\treturn true;\r\n\t\t}\r\n\t\tthis.audioSample += chDataLen;\r\n\t\tlet isSend = false;\r\n\t\tconst data = {};\r\n\t\tif(byteSample !== this.byteSample) {\r\n\t\t\tisSend = true;\r\n\t\t\tdata.byteSample = this.byteSample = byteSample;\r\n\t\t}\r\n\t\tif(drawBuffer.length) {\r\n\t\t\tisSend = true;\r\n\t\t\tdata.drawBuffer = drawBuffer;\r\n\t\t\t// Collect samples for FFT\r\n\t\t\tfor(const sample of drawBuffer) {\n\t\t\t\tconst left = sample.value[0];\n\t\t\t\tconst center = sample.value[1];\n\t\t\t\tconst right = sample.value[2];\n\t\t\t\tconst mix = !isNaN(right) ? (left + right) / 2 :\n\t\t\t\t\t!isNaN(center) ? (left + center) / 2 : left;\n\t\t\t\tthis.fftBuffer.push(mix);\n\t\t\t}\n\t\t\tif(this.fftBuffer.length >= this.fftSize) {\r\n\t\t\t\tdata.fftData = this.fftBuffer.slice(-this.fftSize);\r\n\t\t\t\tthis.fftBuffer = this.fftBuffer.slice(-this.fftSize);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(isSend) {\r\n\t\t\tthis.sendData(data);\r\n\t\t}\r\n\t\treturn true;\r\n\t}\r\n\treceiveData(data) {\r\n\t\tif(data.byteSample !== undefined) {\r\n\t\t\tthis.byteSample = +data.byteSample || 0;\r\n\t\t\tthis.resetValues();\r\n\t\t}\r\n\t\tif(data.errorDisplayed === true) {\r\n\t\t\tthis.errorDisplayed = true;\r\n\t\t}\r\n\t\tif(data.isPlaying !== undefined) {\r\n\t\t\tthis.isPlaying = data.isPlaying;\r\n\t\t}\r\n\r\n\t\tif(data.srDivisor !== undefined) {\r\n\t\t\tthis.srDivisor = data.srDivisor;\r\n\t\t}\r\n\t\tif(data.playbackSpeed !== undefined) {\r\n\t\t\tconst sampleRatio = this.sampleRatio / this.playbackSpeed;\r\n\t\t\tthis.playbackSpeed = data.playbackSpeed;\r\n\t\t\tthis.setSampleRatio(sampleRatio);\r\n\t\t}\r\n\t\tif(data.mode !== undefined) {\r\n\t\t\tthis.isFuncbeat = data.mode === 'Funcbeat';\r\n\t\t\tif (this.isFuncbeat) {\r\n\t\t\t    this.getValues = (funcValue, ch) => {\r\n\t\t\t        const outValue = Math.max(Math.min(funcValue, 1), -1);\r\n\t\t\t        this.lastByteValue[ch] = Math.round((outValue + 1) * 127.5);\r\n\t\t\t        return outValue;\r\n\t\t\t    };\r\n\t\t\t} else {\r\n\t\t\t    this.getValues = (funcValue, ch) => (this.lastByteValue[ch] = NaN);\r\n\t\t\t}\r\n\t\t\tif (this.isFuncbeat) {\r\n\t\t\t    this.getValues = (funcValue, ch) => {\r\n\t\t\t        const outValue = Math.max(Math.min(funcValue, 1), -1);\r\n\t\t\t        this.lastByteValue[ch] = Math.round((outValue + 1) * 127.5);\r\n\t\t\t        return outValue;\r\n\t\t\t    };\r\n\t\t\t} else {\r\n\t\t\t    this.getValues = (funcValue, ch) => (this.lastByteValue[ch] = NaN);\r\n\t\t\t}\r\n\t\t\tswitch(data.mode) {\n\t\t\tcase 'Bytebeat':\n\t\t\t\tthis.getValues = (funcValue, ch) => (this.lastByteValue[ch] = funcValue & 255) / 127.5 - 1;\n\t\t\t\tbreak;\n\t\t\tcase 'Signed Bytebeat':\n\t\t\t\tthis.getValues = (funcValue, ch) =>\n\t\t\t\t\t(this.lastByteValue[ch] = (funcValue + 128) & 255) / 127.5 - 1;\n\t\t\t\tbreak;\n\t\t\tcase 'Bitbeat':\n\t\t\t\tthis.getValues = (funcValue, ch) =>\n\t\t\t\t\t(this.lastByteValue[ch] = funcValue & 1 ? 192 : 64) / 127.5 - 1;\n\t\t\t\tbreak;\n\t\t\tcase '2048':\n\t\t\t\tthis.getValues = (funcValue, ch) =>\n\t\t\t\t\t(this.lastByteValue[ch] = Math.floor(funcValue / 8) & 255) / 127.5 - 1;\n\t\t\t\tbreak;\n\t\t\tcase 'logmode':\n\t\t\t\tthis.getValues = (funcValue, ch) =>\n\t\t\t\t\t(this.lastByteValue[ch] = (Math.log2(funcValue) * 32) & 255) / 127.5 - 1;\n\t\t\t\tbreak;\n\t\t\tcase 'logHack':\n\t\t\t\tthis.getValues = (funcValue, ch) => {\n\t\t\t\t\tconst neg = (funcValue < 0) ? -32 : 32;\n\t\t\t\t\tthis.lastByteValue[ch] = (Math.log2(Math.abs(funcValue)) * neg) & 255;\n\t\t\t\t\treturn this.lastByteValue[ch] / 127.5 - 1;\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase 'logHack2':\n\t\t\t\tthis.getValues = (funcValue, ch) => {\n\t\t\t\t\tconst neg = funcValue < 0;\n\t\t\t\t\tif(funcValue === 0) {\n\t\t\t\t\t\tthis.lastByteValue[ch] = 128;\n\t\t\t\t\t\treturn 0;\n\t\t\t\t\t}\n\t\t\t\t\tthis.lastByteValue[ch] =\n\t\t\t\t\t\t((Math.log2(Math.abs(funcValue)) * (neg ? -16 : 16)) + (neg ? -127 : 128)) & 255;\n\t\t\t\t\treturn this.lastByteValue[ch] / 127.5 - 1;\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase 'Floatbeat':\n\t\t\tcase 'Funcbeat':\n\t\t\t\tthis.getValues = (funcValue, ch) => {\n\t\t\t\t\tconst outValue = Math.max(Math.min(funcValue, 1), -1);\n\t\t\t\t\tthis.lastByteValue[ch] = Math.round((outValue + 1) * 127.5);\r\n\t\t\t\t\treturn outValue;\r\n\t\t\t\t};\r\n\t\t\t\tbreak;\r\n\t\t\tdefault: this.getValues = (funcValue, ch) => (this.lastByteValue[ch] = NaN);\r\n\t\t\t}\r\n\t\t}\r\n\t\tif(data.drawMode !== undefined) {\r\n\t\t\tthis.drawMode = data.drawMode;\r\n\t\t}\r\n\t\tif(data.setFunction !== undefined) {\r\n\t\t\tthis.setFunction(data.setFunction);\r\n\t\t}\r\n\t\tif(data.resetTime === true) {\r\n\t\t\tthis.resetTime();\r\n\t\t}\r\n\t\tif(data.sampleRate !== undefined) {\r\n\t\t\tthis.sampleRate = data.sampleRate;\r\n\t\t}\r\n\t\tif(data.sampleRatio !== undefined) {\r\n\t\t\tthis.setSampleRatio(data.sampleRatio);\r\n\t\t}\r\n\t\tif(data.audioFiles !== undefined) {\n\t\t\tthis.audioFiles = new Map(data.audioFiles);\n\t\t}\n\t\tif(data.fftRawOutput !== undefined) {\n\t\t\tthis.fftRawOutput = !!data.fftRawOutput;\n\t\t}\n\t}\n\tsendData(data) {\r\n\t\tthis.port.postMessage(data);\r\n\t}\r\n\tresetTime() {\r\n\t\tthis.byteSample = 0;\r\n\t\tthis.resetValues();\r\n\t\tthis.sendData({ byteSample: 0 });\r\n\t}\r\n\tresetValues() {\n\t\tthis.audioSample = 0;\n\t\tthis.divisorStorage = 0;\n\t\tthis.lastByteValue = [null, null, null];\n\t\tthis.lastFuncValue = [null, null, null];\n\t\tthis.lastTime = -1;\n\t\tthis.outValue = [0, 0];\n\t\tthis.outValueChannels = [0, 0, 0];\n\t}\n\tsetFunction(codeText) {\r\n\t\t// Create shortened Math functions\r\n\t\tconst params = Object.getOwnPropertyNames(Math);\r\n\t\tconst values = params.map(k => Math[k]);\r\n\t\t\r\n\t\tconst funcs = {\r\n\t\t\t/*bit*/        \"bitC\": function (x, y, z) { return x & y ? z : 0 },\r\n\t\t\t/*bit reverse*/\"br\": function (x, size = 8) {\r\n\t\t\t\tif (size > 32) { throw new Error(\"br() Size cannot be greater than 32\") } else {\r\n\t\t\t\t\tlet result = 0;\r\n\t\t\t\t\tfor (let idx = 0; idx < (size - 0); idx++) {\r\n\t\t\t\t\t\tresult += funcs.bitC(x, 2 ** idx, 2 ** (size - (idx + 1)))\r\n\t\t\t\t\t}\r\n\t\t\t\t\treturn result\r\n\t\t\t\t}\r\n\t\t\t},\r\n\t\t\t/*sin that loops every 128 \"steps\", instead of every pi steps*/\"sinf\": function (x) { return Math.sin(x / (128 / Math.PI)) },\r\n\t\t\t/*cos that loops every 128 \"steps\", instead of every pi steps*/\"cosf\": function (x) { return Math.cos(x / (128 / Math.PI)) },\r\n\t\t\t/*tan that loops every 128 \"steps\", instead of every pi steps*/\"tanf\": function (x) { return Math.tan(x / (128 / Math.PI)) },\r\n\t\t\t/*converts t into a string composed of it's bits, regex's that*/\"regG\": function (t, X) { return X.test(t.toString(2)) },\r\n\r\n\t\t\t\"saw\": t => t % 256,\r\n\t\t\t\"tri\": t => Math.abs((t % 512) - 256),\r\n\t\t\t\"sq\": t => t % 256 < 128 ? 255 : 0,\r\n\t\t\t\"audioIN\": (index, channel = 0, file = 0) => {\r\n\t\t\t\tconst audioFile = this.audioFiles.get(file);\r\n\t\t\t\tif (!audioFile || !audioFile.data) return 0;\r\n\t\t\t\tconst sampleIndex = Math.floor(index) * audioFile.channels + (channel % audioFile.channels);\r\n\t\t\t\treturn audioFile.data[sampleIndex] || 0;\r\n\t\t\t},\r\n\t\t\t\"audioLength\": (file = 0) => {\r\n\t\t\t\tconst audioFile = this.audioFiles.get(file);\r\n\t\t\t\treturn audioFile ? audioFile.data.length/audioFile.channels : 0;\r\n\t\t\t}\r\n\t\t};\r\n\t\t\r\n\t\tparams.push('int', 'window', ...Object.keys(funcs));\r\n\t\tvalues.push(Math.floor, globalThis, ...Object.values(funcs));\r\n\t\taudioProcessor.deleteGlobals();\r\n\t\t// Code testing\r\n\t\tlet isCompiled = false;\r\n\t\tconst oldFunc = this.func;\r\n\t\ttry {\r\n\t\t\tif(this.isFuncbeat) {\r\n\t\t\t\tthis.func = new Function(...params, codeText).bind(globalThis, ...values);\r\n\t\t\t} else {\r\n\t\t\t\t// Optimize code like eval(unescape(escape`XXXX`.replace(/u(..)/g,\"$1%\")))\r\n\t\t\t\tcodeText = codeText.trim().replace(\r\n\t\t\t\t\t/^eval\\(unescape\\(escape(?:`|\\('|\\(\"|\\(`)(.*?)(?:`|'\\)|\"\\)|`\\)).replace\\(\\/u\\(\\.\\.\\)\\/g,[\"'`]\\$1%[\"'`]\\)\\)\\)$/,\r\n\t\t\t\t\t(match, m1) => unescape(escape(m1).replace(/u(..)/g, '$1%')));\r\n\t\t\t\tthis.func = new Function(...params, 't', `return 0,\\n${ codeText || 0 };`)\r\n\t\t\t\t\t.bind(globalThis, ...values);\r\n\t\t\t}\r\n\t\t\tisCompiled = true;\r\n\t\t\tif(this.isFuncbeat) {\r\n\t\t\t\tthis.func = this.func();\r\n\t\t\t\tthis.func(0, this.sampleRate);\r\n\t\t\t} else {\r\n\t\t\t\tthis.func(0);\r\n\t\t\t}\r\n\t\t} catch(err) {\r\n\t\t\tif(!isCompiled) {\r\n\t\t\t\tthis.func = oldFunc;\r\n\t\t\t}\r\n\t\t\tthis.errorDisplayed = false;\r\n\t\t\tthis.sendData({\r\n\t\t\t\terror: { message: audioProcessor.getErrorMessage(err, isCompiled ? 0 : null), isCompiled },\r\n\t\t\t\tupdateUrl: isCompiled\r\n\t\t\t});\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tthis.errorDisplayed = false;\r\n\t\tthis.sendData({ error: { message: '', isCompiled }, updateUrl: true });\r\n\t}\r\n\tsetSampleRatio(sampleRatio) {\r\n\t\tconst timeOffset = Math.floor(this.sampleRatio * this.audioSample) - this.lastTime;\r\n\t\tthis.sampleRatio = sampleRatio * this.playbackSpeed;\r\n\t\tthis.lastTime = Math.floor(this.sampleRatio * this.audioSample) - timeOffset;\r\n\t}\r\n}\r\n\r\nregisterProcessor('audioProcessor', audioProcessor);\r\n"],"names":["audioProcessor","AudioWorkletProcessor","constructor","args","super","this","audioSample","byteSample","divisorStorage","drawMode","errorDisplayed","func","getValues","isFuncbeat","isPlaying","lastByteValue","lastFuncValue","lastOutputChannels","lastTime","outValue","outValueChannels","fftRawOutput","playbackSpeed","sampleRate","sampleRatio","srDivisor","fftBuffer","fftSize","audioFiles","Map","Object","seal","deleteGlobals","freezeGlobals","port","addEventListener","e","receiveData","data","start","i","globalThis","String","fromCharCode","name","prototype","hasOwnProperty","call","getOwnPropertyNames","forEach","prop","type","freeze","defineProperty","writable","configurable","getErrorMessage","err","time","when","Error","JSON","stringify","message","lineNumber","columnNumber","process","inputs","chData","chDataLen","length","divisor","Math","max","drawBuffer","isDiagram","currentTime","floor","funcValue","currentSample","divisorMet","sendData","error","isRuntime","NaN","outputChannels","Array","isArray","min","values","slice","hasCenter","hasValue","channelIndices","ch","isNaN","left","center","right","push","t","value","channels","abs","Number","MAX_SAFE_INTEGER","resetTime","isSend","sample","mix","fftData","undefined","resetValues","setSampleRatio","mode","round","log2","neg","setFunction","postMessage","codeText","params","map","k","funcs","bitC","x","y","z","br","size","result","idx","sinf","sin","PI","cosf","cos","tanf","tan","regG","X","test","toString","saw","tri","sq","audioIN","index","channel","file","audioFile","get","sampleIndex","audioLength","keys","isCompiled","oldFunc","Function","bind","trim","replace","match","m1","unescape","escape","updateUrl","timeOffset","registerProcessor"],"mappings":"AAAA,MAAMA,UAAuBC,sBAC5B,WAAAC,IAAeC,GACdC,SAASD,GACTE,KAAKC,YAAc,EACnBD,KAAKE,WAAa,EAClBF,KAAKG,eAAiB,EACtBH,KAAKI,SAAW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