@mimium/mimium-webaudio 4.0.3 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@ var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
4
  import "./textencoder-B0AgIAQT.js";
5
- import { initSync as g, Config as f, Context as w } from "./mimium_web-45qAhlDr.js";
6
- const d = [
5
+ import { initSync as f, Config as w, Context as y } from "./mimium_web-45qAhlDr.js";
6
+ const _ = [
7
7
  "core.mmm",
8
8
  "delay.mmm",
9
9
  "env.mmm",
@@ -14,14 +14,14 @@ const d = [
14
14
  "reactive.mmm",
15
15
  "reverb.mmm"
16
16
  ];
17
- function _(l) {
18
- return l.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\//, "");
17
+ function g(m) {
18
+ return m.replace(/\\/g, "/").replace(/^\.\//, "").replace(/^\//, "");
19
19
  }
20
- function y(l) {
21
- const s = _(l).replace(/^lib\//, "");
22
- return [.../* @__PURE__ */ new Set([l, s, `./${s}`, `lib/${s}`, `/lib/${s}`])];
20
+ function b(m) {
21
+ const s = g(m).replace(/^lib\//, "");
22
+ return [.../* @__PURE__ */ new Set([m, s, `./${s}`, `lib/${s}`, `/lib/${s}`])];
23
23
  }
24
- class b extends AudioWorkletProcessor {
24
+ class v extends AudioWorkletProcessor {
25
25
  constructor() {
26
26
  super();
27
27
  __publicField(this, "context");
@@ -38,7 +38,7 @@ class b extends AudioWorkletProcessor {
38
38
  console.log("start_loading");
39
39
  const s = e.data;
40
40
  WebAssembly.compile(s).then((r) => {
41
- g({ module: r }), console.log("wasm module loaded,sending message"), this.port.postMessage({ type: "wasm-module-loaded" });
41
+ f({ module: r }), console.log("wasm module loaded,sending message"), this.port.postMessage({ type: "wasm-module-loaded" });
42
42
  }).catch((r) => {
43
43
  console.error("wasm module load error, ", r), this.port.postMessage({ type: "error_wasm_load", data: r });
44
44
  });
@@ -56,35 +56,35 @@ class b extends AudioWorkletProcessor {
56
56
  break;
57
57
  }
58
58
  }
59
- async compile(e, s, r, m = "", p = "https://raw.githubusercontent.com/mimium-org/mimium-rs/main/lib/", c = []) {
59
+ async compile(e, s, r, c = "", n = "https://raw.githubusercontent.com/mimium-org/mimium-rs/main/lib/", p = []) {
60
60
  this.isCompiled = false, this.context = null, this.interleaved_input = new Float32Array(), this.interleaved_output = new Float32Array();
61
- let n = f.new();
62
- n.sample_rate = e, n.buffer_size = s;
63
- const t = new w(n);
61
+ let l = w.new();
62
+ l.sample_rate = e, l.buffer_size = s;
63
+ const t = new y(l);
64
64
  let a = {
65
65
  type: "compile_error",
66
66
  data: { message: "compile did not complete." }
67
67
  };
68
68
  try {
69
- m && t.set_module_base_url(m);
69
+ c && t.set_module_base_url(c);
70
70
  const i = new Set(
71
- c.map((o) => _(o.path).replace(/^lib\//, ""))
71
+ p.map((o) => g(o.path).replace(/^lib\//, ""))
72
72
  );
73
- if (!d.every(
73
+ if (!_.every(
74
74
  (o) => i.has(o)
75
75
  )) {
76
- const o = d.filter((u) => !i.has(u));
76
+ const o = _.filter((d) => !i.has(d));
77
77
  throw new Error(
78
- `virtual lib cache is incomplete. missing=[${o.join(", ")}]. worklet does not fetch libs; preload on main thread is required. baseUrl=${p}`
78
+ `virtual lib cache is incomplete. missing=[${o.join(", ")}]. worklet does not fetch libs; preload on main thread is required. baseUrl=${n}`
79
79
  );
80
80
  }
81
- c.forEach((o) => {
82
- y(o.path).forEach((u) => {
83
- t.put_virtual_file_cache(u, o.content);
81
+ p.forEach((o) => {
82
+ b(o.path).forEach((d) => {
83
+ t.put_virtual_file_cache(d, o.content);
84
84
  });
85
85
  }), await t.compile(r);
86
- const h = t.get_output_channels() || 0;
87
- if (h <= 0) {
86
+ const u = t.get_output_channels() || 0;
87
+ if (u <= 0) {
88
88
  this.context = null, this.isCompiled = false, this.interleaved_input = new Float32Array(), this.interleaved_output = new Float32Array(), a = {
89
89
  type: "compile_error",
90
90
  data: { message: "compile failed: compile finished with zero output channels." }
@@ -94,10 +94,10 @@ class b extends AudioWorkletProcessor {
94
94
  this.interleaved_input = new Float32Array(
95
95
  s * t.get_input_channels()
96
96
  ), this.interleaved_output = new Float32Array(
97
- s * h
97
+ s * u
98
98
  ), this.context = t, this.isCompiled = true, a = {
99
99
  type: "compile_finished",
100
- data: { output_channels: h }
100
+ data: { output_channels: u }
101
101
  };
102
102
  } catch (i) {
103
103
  this.context = null, this.isCompiled = false, this.interleaved_input = new Float32Array(), this.interleaved_output = new Float32Array(), a = {
@@ -111,14 +111,14 @@ class b extends AudioWorkletProcessor {
111
111
  }
112
112
  }
113
113
  process(e, s, r) {
114
- var _a, _b2;
114
+ var _a, _b;
115
115
  if (this.context && this.isCompiled) {
116
- const m = this.context.get_input_channels(), p = this.context.get_output_channels(), c = e[0], n = s[0];
117
- if (this.interleaved_input.length !== (((_a = c == null ? void 0 : c[0]) == null ? void 0 : _a.length) ?? 0) * m || this.interleaved_output.length !== (((_b2 = n == null ? void 0 : n[0]) == null ? void 0 : _b2.length) ?? 0) * p)
116
+ const c = this.context.get_input_channels(), n = this.context.get_output_channels(), p = e[0], l = s[0];
117
+ if (this.interleaved_input.length !== (((_a = p == null ? void 0 : p[0]) == null ? void 0 : _a.length) ?? 0) * c || this.interleaved_output.length !== (((_b = l == null ? void 0 : l[0]) == null ? void 0 : _b.length) ?? 0) * n)
118
118
  return true;
119
- c.forEach((t, a) => {
119
+ p.forEach((t, a) => {
120
120
  for (let i = 0; i < t.length; i++)
121
- this.interleaved_input[m * i + a] = t[i];
121
+ this.interleaved_input[c * i + a] = t[i];
122
122
  }), this.interleaved_output.fill(0);
123
123
  try {
124
124
  this.context.process(this.interleaved_input, this.interleaved_output);
@@ -128,15 +128,16 @@ class b extends AudioWorkletProcessor {
128
128
  data: { message: t instanceof Error ? t.message : String(t) }
129
129
  }), true;
130
130
  }
131
- n.forEach((t, a) => {
132
- for (let i = 0; i < t.length; i++)
133
- t[i] = this.interleaved_output[p * i + a];
131
+ l.forEach((t, a) => {
132
+ const i = n <= 1 ? 0 : Math.min(a, n - 1);
133
+ for (let h = 0; h < t.length; h++)
134
+ t[h] = this.interleaved_output[n * h + i] ?? 0;
134
135
  });
135
136
  }
136
137
  return true;
137
138
  }
138
139
  }
139
- registerProcessor("MimiumProcessor", b);
140
+ registerProcessor("MimiumProcessor", v);
140
141
  export {
141
- b as MimiumProcessor
142
+ v as MimiumProcessor
142
143
  };
@@ -1 +1 @@
1
- {"version":3,"file":"audioprocessor.mjs","sources":["../src/audioprocessor.mts"],"sourcesContent":["import \"./textencoder.mjs\";\nimport { initSync, Context, Config } from \"mimium-web\";\n\nconst STANDARD_LIB_FILES = [\n \"core.mmm\",\n \"delay.mmm\",\n \"env.mmm\",\n \"filter.mmm\",\n \"math.mmm\",\n \"noise.mmm\",\n \"osc.mmm\",\n \"reactive.mmm\",\n \"reverb.mmm\",\n];\n\nfunction normalizeVirtualPath(path: string): string {\n return path.replace(/\\\\/g, \"/\").replace(/^\\.\\//, \"\").replace(/^\\//, \"\");\n}\n\nfunction expandVirtualPathAliases(path: string): string[] {\n const normalized = normalizeVirtualPath(path);\n const strippedLib = normalized.replace(/^lib\\//, \"\");\n return [...new Set([path, strippedLib, `./${strippedLib}`, `lib/${strippedLib}`, `/lib/${strippedLib}`])];\n}\n\nexport class MimiumProcessor extends AudioWorkletProcessor {\n context: Context | null;\n isCompiled: boolean;\n interleaved_input: Float32Array = new Float32Array();\n interleaved_output: Float32Array = new Float32Array();\n\n constructor() {\n super();\n this.context = null;\n this.isCompiled = false;\n this.port.onmessage = (event) => {\n this.onmessage(event.data);\n };\n }\n onmessage(event: MessageEvent<any>) {\n console.log(\"onmessage \", event);\n switch (event.type) {\n case \"send-wasm-module\": {\n console.log(\"start_loading\");\n const wasmBinary = event.data as ArrayBuffer; //this is invalid conversion for workaround.\n WebAssembly.compile(wasmBinary)\n .then((wasm) => {\n initSync({ module: wasm });\n console.log(\"wasm module loaded,sending message\");\n this.port.postMessage({ type: \"wasm-module-loaded\" });\n })\n .catch((e) => {\n console.error(\"wasm module load error, \", e);\n this.port.postMessage({ type: \"error_wasm_load\", data: e });\n });\n\n break;\n }\n case \"compile\":\n void this.compile(\n event.data.samplerate,\n event.data.buffersize,\n event.data.src,\n event.data.moduleBaseUrl,\n event.data.libBaseUrl,\n event.data.virtualFiles\n );\n break;\n }\n }\n public async compile(\n samplerate: number,\n buffersize: number,\n src: string,\n moduleBaseUrl: string = \"\",\n libBaseUrl: string = \"https://raw.githubusercontent.com/mimium-org/mimium-rs/main/lib/\",\n virtualFiles: Array<{ path: string; content: string }> = []\n ) {\n this.isCompiled = false;\n this.context = null;\n this.interleaved_input = new Float32Array();\n this.interleaved_output = new Float32Array();\n\n let config = Config.new();\n config.sample_rate = samplerate;\n config.buffer_size = buffersize;\n const nextContext = new Context(config); //io channel is written in context.vonfig\n\n let compileMessage: {\n type: \"compile_finished\" | \"compile_error\";\n data: { output_channels?: number; message?: string };\n } = {\n type: \"compile_error\",\n data: { message: \"compile did not complete.\" },\n };\n\n try {\n if (moduleBaseUrl) {\n nextContext.set_module_base_url(moduleBaseUrl);\n }\n const virtualFileNames = new Set(\n virtualFiles.map((file) => normalizeVirtualPath(file.path).replace(/^lib\\//, \"\"))\n );\n const hasStdLibVirtualFiles = STANDARD_LIB_FILES.every((libFile) =>\n virtualFileNames.has(libFile)\n );\n\n if (!hasStdLibVirtualFiles) {\n const missing = STANDARD_LIB_FILES.filter((libFile) => !virtualFileNames.has(libFile));\n throw new Error(\n `virtual lib cache is incomplete. missing=[${missing.join(\", \")}]. worklet does not fetch libs; preload on main thread is required. baseUrl=${libBaseUrl}`\n );\n }\n\n virtualFiles.forEach((file) => {\n expandVirtualPathAliases(file.path).forEach((alias) => {\n nextContext.put_virtual_file_cache(alias, file.content);\n });\n });\n await nextContext.compile(src);\n\n const outputChannels = nextContext.get_output_channels() || 0;\n if (outputChannels <= 0) {\n this.context = null;\n this.isCompiled = false;\n this.interleaved_input = new Float32Array();\n this.interleaved_output = new Float32Array();\n compileMessage = {\n type: \"compile_error\",\n data: { message: \"compile failed: compile finished with zero output channels.\" },\n };\n return;\n }\n\n this.interleaved_input = new Float32Array(\n buffersize * nextContext.get_input_channels()\n );\n this.interleaved_output = new Float32Array(\n buffersize * outputChannels\n );\n this.context = nextContext;\n this.isCompiled = true;\n\n compileMessage = {\n type: \"compile_finished\",\n data: { output_channels: outputChannels },\n };\n } catch (e) {\n this.context = null;\n this.isCompiled = false;\n this.interleaved_input = new Float32Array();\n this.interleaved_output = new Float32Array();\n\n compileMessage = {\n type: \"compile_error\",\n data: {\n message: `compile failed: ${e instanceof Error ? e.message : String(e)}`,\n },\n };\n } finally {\n this.port.postMessage(compileMessage);\n }\n }\n public process(\n inputs: Float32Array[][],\n outputs: Float32Array[][],\n parameter: Record<string, Float32Array>\n ) {\n if (this.context && this.isCompiled) {\n const ichannels = this.context.get_input_channels();\n const ochannels = this.context.get_output_channels();\n const input = inputs[0];\n const output = outputs[0];\n if (\n this.interleaved_input.length !== (input?.[0]?.length ?? 0) * ichannels ||\n this.interleaved_output.length !== (output?.[0]?.length ?? 0) * ochannels\n ) {\n return true;\n }\n input.forEach((input, ich) => {\n for (let i = 0; i < input.length; i++) {\n this.interleaved_input[ichannels * i + ich] = input[i];\n }\n });\n this.interleaved_output.fill(0);\n try {\n this.context.process(this.interleaved_input, this.interleaved_output);\n } catch (e) {\n this.context = null;\n this.isCompiled = false;\n this.port.postMessage({\n type: \"runtime_error\",\n data: { message: e instanceof Error ? e.message : String(e) },\n });\n return true;\n }\n output.forEach((output, och) => {\n for (let i = 0; i < output.length; i++) {\n output[i] = this.interleaved_output[ochannels * i + och];\n }\n });\n }\n return true;\n }\n}\n\nregisterProcessor(\"MimiumProcessor\", MimiumProcessor);\n"],"names":["STANDARD_LIB_FILES","normalizeVirtualPath","path","expandVirtualPathAliases","strippedLib","MimiumProcessor","event","wasmBinary","wasm","initSync","e","samplerate","buffersize","src","moduleBaseUrl","libBaseUrl","virtualFiles","config","Config","nextContext","Context","compileMessage","virtualFileNames","file","libFile","missing","alias","outputChannels","inputs","outputs","parameter","ichannels","ochannels","input","output","ich","och"],"mappings":";;AAGA,MAAMA,IAAqB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAASC,EAAqBC,GAAsB;AAClD,SAAOA,EAAK,QAAQ,OAAO,GAAG,EAAE,QAAQ,SAAS,EAAE,EAAE,QAAQ,OAAO,EAAE;AACxE;AAEA,SAASC,EAAyBD,GAAwB;AAExD,QAAME,IADaH,EAAqBC,CAAI,EACb,QAAQ,UAAU,EAAE;AACnD,SAAO,CAAC,GAAG,oBAAI,IAAI,CAACA,GAAME,GAAa,KAAKA,CAAW,IAAI,OAAOA,CAAW,IAAI,QAAQA,CAAW,EAAE,CAAC,CAAC;AAC1G;AAEO,MAAMC,UAAwB,sBAAsB;AAAA,EACzD;AAAA,EACA;AAAA,EACA,oBAAkC,IAAI,aAAA;AAAA,EACtC,qBAAmC,IAAI,aAAA;AAAA,EAEvC,cAAc;AACZ,UAAA,GACA,KAAK,UAAU,MACf,KAAK,aAAa,IAClB,KAAK,KAAK,YAAY,CAACC,MAAU;AAC/B,WAAK,UAAUA,EAAM,IAAI;AAAA,IAC3B;AAAA,EACF;AAAA,EACA,UAAUA,GAA0B;AAElC,YADA,QAAQ,IAAI,cAAcA,CAAK,GACvBA,EAAM,MAAA;AAAA,MACZ,KAAK,oBAAoB;AACvB,gBAAQ,IAAI,eAAe;AAC3B,cAAMC,IAAaD,EAAM;AACzB,oBAAY,QAAQC,CAAU,EAC3B,KAAK,CAACC,MAAS;AACd,UAAAC,EAAS,EAAE,QAAQD,GAAM,GACzB,QAAQ,IAAI,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YAAMC,IAAY,KAAK,QAAQ,mBAAA,GACzBC,IAAY,KAAK,QAAQ,oBAAA,GACzBC,IAAQL,EAAO,CAAC,GAChBM,IAASL,EAAQ,CAAC;AACxB,UACE,KAAK,kBAAkB,YAAYI,IAAQ,CAAC,GAAG,UAAU,KAAKF,KAC9D,KAAK,mBAAmB,YAAYG,IAAS,CAAC,GAAG,UAAU,KAAKF;AAEhE,eAAO;AAET,MAAAC,EAAM,QAAQ,CAACA,GAAOE,MAAQ;AAC5B,iBAAS,IAAI,GAAG,IAAIF,EAAM,QAAQ;AAChC,eAAK,kBAAkBF,IAAY,IAAII,CAAG,IAAIF,EAAM,CAAC;AAAA,MAEzD,CAAC,GACD,KAAK,mBAAmB,KAAK,CAAC;AAC9B,UAAI;AACF,aAAK,QAAQ,QAAQ,KAAK,mBAAmB,KAAK,kBAAkB;AAAA,MACtE,SAASvB,GAAG;AACV,oBAAK,UAAU,MACf,KAAK,aAAa,IAClB,KAAK,KAAK,YAAY;AAAA,UACpB,MAAM;AAAA,UACN,MAAM,EAAE,SAASA,aAAa,QAAQA,EAAE,UAAU,OAAOA,CAAC,EAAA;AAAA,QAAE,CAC7D,GACM;AAAA,MACT;AACA,MAAAwB,EAAO,QAAQ,CAACA,GAAQE,MAAQ;AAC9B,iBAAS,IAAI,GAAG,IAAIF,EAAO,QAAQ;AACjCA,UAAAA,EAAO,CAAC,IAAI,KAAK,mBAAmBF,IAAY,IAAII,CAAG;AAAA,MAE3D,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;AAEA,kBAAkB,mBAAmB/B,CAAe;"}
1
+ {"version":3,"file":"audioprocessor.mjs","sources":["../src/audioprocessor.mts"],"sourcesContent":["import \"./textencoder.mjs\";\nimport { initSync, Context, Config } from \"mimium-web\";\n\nconst STANDARD_LIB_FILES = [\n \"core.mmm\",\n \"delay.mmm\",\n \"env.mmm\",\n \"filter.mmm\",\n \"math.mmm\",\n \"noise.mmm\",\n \"osc.mmm\",\n \"reactive.mmm\",\n \"reverb.mmm\",\n];\n\nfunction normalizeVirtualPath(path: string): string {\n return path.replace(/\\\\/g, \"/\").replace(/^\\.\\//, \"\").replace(/^\\//, \"\");\n}\n\nfunction expandVirtualPathAliases(path: string): string[] {\n const normalized = normalizeVirtualPath(path);\n const strippedLib = normalized.replace(/^lib\\//, \"\");\n return [...new Set([path, strippedLib, `./${strippedLib}`, `lib/${strippedLib}`, `/lib/${strippedLib}`])];\n}\n\nexport class MimiumProcessor extends AudioWorkletProcessor {\n context: Context | null;\n isCompiled: boolean;\n interleaved_input: Float32Array = new Float32Array();\n interleaved_output: Float32Array = new Float32Array();\n\n constructor() {\n super();\n this.context = null;\n this.isCompiled = false;\n this.port.onmessage = (event) => {\n this.onmessage(event.data);\n };\n }\n onmessage(event: MessageEvent<any>) {\n console.log(\"onmessage \", event);\n switch (event.type) {\n case \"send-wasm-module\": {\n console.log(\"start_loading\");\n const wasmBinary = event.data as ArrayBuffer; //this is invalid conversion for workaround.\n WebAssembly.compile(wasmBinary)\n .then((wasm) => {\n initSync({ module: wasm });\n console.log(\"wasm module loaded,sending message\");\n this.port.postMessage({ type: \"wasm-module-loaded\" });\n })\n .catch((e) => {\n console.error(\"wasm module load error, \", e);\n this.port.postMessage({ type: \"error_wasm_load\", data: e });\n });\n\n break;\n }\n case \"compile\":\n void this.compile(\n event.data.samplerate,\n event.data.buffersize,\n event.data.src,\n event.data.moduleBaseUrl,\n event.data.libBaseUrl,\n event.data.virtualFiles\n );\n break;\n }\n }\n public async compile(\n samplerate: number,\n buffersize: number,\n src: string,\n moduleBaseUrl: string = \"\",\n libBaseUrl: string = \"https://raw.githubusercontent.com/mimium-org/mimium-rs/main/lib/\",\n virtualFiles: Array<{ path: string; content: string }> = []\n ) {\n this.isCompiled = false;\n this.context = null;\n this.interleaved_input = new Float32Array();\n this.interleaved_output = new Float32Array();\n\n let config = Config.new();\n config.sample_rate = samplerate;\n config.buffer_size = buffersize;\n const nextContext = new Context(config); //io channel is written in context.vonfig\n\n let compileMessage: {\n type: \"compile_finished\" | \"compile_error\";\n data: { output_channels?: number; message?: string };\n } = {\n type: \"compile_error\",\n data: { message: \"compile did not complete.\" },\n };\n\n try {\n if (moduleBaseUrl) {\n nextContext.set_module_base_url(moduleBaseUrl);\n }\n const virtualFileNames = new Set(\n virtualFiles.map((file) => normalizeVirtualPath(file.path).replace(/^lib\\//, \"\"))\n );\n const hasStdLibVirtualFiles = STANDARD_LIB_FILES.every((libFile) =>\n virtualFileNames.has(libFile)\n );\n\n if (!hasStdLibVirtualFiles) {\n const missing = STANDARD_LIB_FILES.filter((libFile) => !virtualFileNames.has(libFile));\n throw new Error(\n `virtual lib cache is incomplete. missing=[${missing.join(\", \")}]. worklet does not fetch libs; preload on main thread is required. baseUrl=${libBaseUrl}`\n );\n }\n\n virtualFiles.forEach((file) => {\n expandVirtualPathAliases(file.path).forEach((alias) => {\n nextContext.put_virtual_file_cache(alias, file.content);\n });\n });\n await nextContext.compile(src);\n\n const outputChannels = nextContext.get_output_channels() || 0;\n if (outputChannels <= 0) {\n this.context = null;\n this.isCompiled = false;\n this.interleaved_input = new Float32Array();\n this.interleaved_output = new Float32Array();\n compileMessage = {\n type: \"compile_error\",\n data: { message: \"compile failed: compile finished with zero output channels.\" },\n };\n return;\n }\n\n this.interleaved_input = new Float32Array(\n buffersize * nextContext.get_input_channels()\n );\n this.interleaved_output = new Float32Array(\n buffersize * outputChannels\n );\n this.context = nextContext;\n this.isCompiled = true;\n\n compileMessage = {\n type: \"compile_finished\",\n data: { output_channels: outputChannels },\n };\n } catch (e) {\n this.context = null;\n this.isCompiled = false;\n this.interleaved_input = new Float32Array();\n this.interleaved_output = new Float32Array();\n\n compileMessage = {\n type: \"compile_error\",\n data: {\n message: `compile failed: ${e instanceof Error ? e.message : String(e)}`,\n },\n };\n } finally {\n this.port.postMessage(compileMessage);\n }\n }\n public process(\n inputs: Float32Array[][],\n outputs: Float32Array[][],\n parameter: Record<string, Float32Array>\n ) {\n if (this.context && this.isCompiled) {\n const ichannels = this.context.get_input_channels();\n const ochannels = this.context.get_output_channels();\n const input = inputs[0];\n const output = outputs[0];\n if (\n this.interleaved_input.length !== (input?.[0]?.length ?? 0) * ichannels ||\n this.interleaved_output.length !== (output?.[0]?.length ?? 0) * ochannels\n ) {\n return true;\n }\n input.forEach((input, ich) => {\n for (let i = 0; i < input.length; i++) {\n this.interleaved_input[ichannels * i + ich] = input[i];\n }\n });\n this.interleaved_output.fill(0);\n try {\n this.context.process(this.interleaved_input, this.interleaved_output);\n } catch (e) {\n this.context = null;\n this.isCompiled = false;\n this.port.postMessage({\n type: \"runtime_error\",\n data: { message: e instanceof Error ? e.message : String(e) },\n });\n return true;\n }\n output.forEach((output, och) => {\n const sourceChannel = ochannels <= 1 ? 0 : Math.min(och, ochannels - 1);\n for (let i = 0; i < output.length; i++) {\n output[i] = this.interleaved_output[ochannels * i + sourceChannel] ?? 0;\n }\n });\n }\n return true;\n }\n}\n\nregisterProcessor(\"MimiumProcessor\", MimiumProcessor);\n"],"names":["STANDARD_LIB_FILES","normalizeVirtualPath","path","expandVirtualPathAliases","strippedLib","MimiumProcessor","event","wasmBinary","wasm","initSync","e","samplerate","buffersize","src","moduleBaseUrl","libBaseUrl","virtualFiles","config","Config","nextContext","Context","compileMessage","virtualFileNames","file","libFile","missing","alias","outputChannels","inputs","outputs","parameter","ichannels","ochannels","input","output","ich","och","sourceChannel","i"],"mappings":";;AAGA,MAAMA,IAAqB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAASC,EAAqBC,GAAsB;AAClD,SAAOA,EAAK,QAAQ,OAAO,GAAG,EAAE,QAAQ,SAAS,EAAE,EAAE,QAAQ,OAAO,EAAE;AACxE;AAEA,SAASC,EAAyBD,GAAwB;AAExD,QAAME,IADaH,EAAqBC,CAAI,EACb,QAAQ,UAAU,EAAE;AACnD,SAAO,CAAC,GAA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AAK,aAAa,IAClB,KAAK,KAAK,YAAY;AAAA,UACpB,MAAM;AAAA,UACN,MAAM,EAAE,SAASA,aAAa,QAAQA,EAAE,UAAU,OAAOA,CAAC,EAAA;AAAA,QAAE,CAC7D,GACM;AAAA,MACT;AACA,MAAAwB,EAAO,QAAQ,CAACA,GAAQE,MAAQ;AAC9B,cAAMC,IAAgBL,KAAa,IAAI,IAAI,KAAK,IAAII,GAAKJ,IAAY,CAAC;AACtE,iBAASM,IAAI,GAAGA,IAAIJ,EAAO,QAAQI;AACjCJ,UAAAA,EAAOI,CAAC,IAAI,KAAK,mBAAmBN,IAAYM,IAAID,CAAa,KAAK;AAAA,MAE1E,CAAC;AAAA,IACH;AACA,WAAO;AAAA,EACT;AACF;AAEA,kBAAkB,mBAAmBhC,CAAe;"}
package/dist/index.mjs CHANGED
@@ -243,7 +243,13 @@ let __tla = (async () => {
243
243
  throw new Error(`Failed to load audio analyzer worklet at url: ${g}. Further info: ${y(K)}`);
244
244
  }
245
245
  let N = new a(A, "MimiumProcessor", {
246
- channelCountMode: "clamped-max"
246
+ numberOfOutputs: 1,
247
+ outputChannelCount: [
248
+ 2
249
+ ],
250
+ channelCount: 2,
251
+ channelCountMode: "explicit",
252
+ channelInterpretation: "discrete"
247
253
  });
248
254
  if (N.init(D, i), await N.waitForCompile(), N.channelCount <= 0) throw new Error("compile succeeded but output channel count is zero");
249
255
  return N;