@grame/faustwasm 0.0.25

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.
Files changed (111) hide show
  1. package/README.md +181 -0
  2. package/assets/standalone/faust-ui/index.css +414 -0
  3. package/assets/standalone/faust-ui/index.css.map +1 -0
  4. package/assets/standalone/faust-ui/index.d.ts +1 -0
  5. package/assets/standalone/faust-ui/index.js +3478 -0
  6. package/assets/standalone/faust-ui/index.js.map +1 -0
  7. package/assets/standalone/faustwasm/index.d.ts +1252 -0
  8. package/assets/standalone/faustwasm/index.js +3772 -0
  9. package/assets/standalone/faustwasm/index.js.map +7 -0
  10. package/assets/standalone/index.html +73 -0
  11. package/assets/standalone/index.js +198 -0
  12. package/assets/standalone/types.d.ts +9 -0
  13. package/dist/cjs/index.d.ts +1252 -0
  14. package/dist/cjs/index.js +3752 -0
  15. package/dist/cjs/index.js.map +7 -0
  16. package/dist/cjs-bundle/index.d.ts +1259 -0
  17. package/dist/cjs-bundle/index.js +11507 -0
  18. package/dist/cjs-bundle/index.js.map +7 -0
  19. package/dist/esm/index.d.ts +1252 -0
  20. package/dist/esm/index.js +3772 -0
  21. package/dist/esm/index.js.map +7 -0
  22. package/dist/esm-bundle/index.d.ts +1259 -0
  23. package/dist/esm-bundle/index.js +11495 -0
  24. package/dist/esm-bundle/index.js.map +7 -0
  25. package/fileutils.js +40 -0
  26. package/libfaust-wasm/libfaust-wasm.d.cts +3 -0
  27. package/libfaust-wasm/libfaust-wasm.d.ts +3 -0
  28. package/libfaust-wasm/libfaust-wasm.data +0 -0
  29. package/libfaust-wasm/libfaust-wasm.data.d.ts +2 -0
  30. package/libfaust-wasm/libfaust-wasm.js +21 -0
  31. package/libfaust-wasm/libfaust-wasm.wasm +0 -0
  32. package/libfaust-wasm/libfaust-wasm.wasm.d.ts +2 -0
  33. package/library.md +91 -0
  34. package/package.json +43 -0
  35. package/postbuild-bundled.js +11 -0
  36. package/postbuild.js +63 -0
  37. package/prebuild-bundled.js +11 -0
  38. package/rsrc/overview.png +0 -0
  39. package/rsrc/overview.xlsx +0 -0
  40. package/scripts/faust2sndfile.js +43 -0
  41. package/scripts/faust2svg.js +17 -0
  42. package/scripts/faust2wasm.js +29 -0
  43. package/src/FaustAudioWorkletNode.ts +264 -0
  44. package/src/FaustAudioWorkletProcessor.ts +273 -0
  45. package/src/FaustCompiler.ts +252 -0
  46. package/src/FaustDspGenerator.ts +498 -0
  47. package/src/FaustDspInstance.ts +141 -0
  48. package/src/FaustFFTAudioWorkletProcessor.ts +554 -0
  49. package/src/FaustOfflineProcessor.ts +141 -0
  50. package/src/FaustScriptProcessorNode.ts +80 -0
  51. package/src/FaustSvgDiagrams.ts +37 -0
  52. package/src/FaustWasmInstantiator.ts +202 -0
  53. package/src/FaustWebAudioDsp.ts +1060 -0
  54. package/src/LibFaust.ts +57 -0
  55. package/src/WavDecoder.ts +207 -0
  56. package/src/WavEncoder.ts +204 -0
  57. package/src/copyWebStandaloneAssets.d.ts +3 -0
  58. package/src/copyWebStandaloneAssets.js +20 -0
  59. package/src/exports-bundle.ts +5 -0
  60. package/src/exports.ts +24 -0
  61. package/src/faust2svgFiles.d.ts +3 -0
  62. package/src/faust2svgFiles.js +43 -0
  63. package/src/faust2wasmFiles.d.ts +5 -0
  64. package/src/faust2wasmFiles.js +93 -0
  65. package/src/faust2wavFiles.d.ts +3 -0
  66. package/src/faust2wavFiles.js +58 -0
  67. package/src/index-bundle-iife.ts +7 -0
  68. package/src/index-bundle.ts +5 -0
  69. package/src/index.ts +5 -0
  70. package/src/instantiateFaustModule.ts +32 -0
  71. package/src/instantiateFaustModuleFromFile.ts +57 -0
  72. package/src/types.ts +234 -0
  73. package/test/clarinet.dsp +1 -0
  74. package/test/faustlive-wasm/faust-ui/index.css +414 -0
  75. package/test/faustlive-wasm/faust-ui/index.css.map +1 -0
  76. package/test/faustlive-wasm/faust-ui/index.d.ts +1 -0
  77. package/test/faustlive-wasm/faust-ui/index.js +3478 -0
  78. package/test/faustlive-wasm/faust-ui/index.js.map +1 -0
  79. package/test/faustlive-wasm/faustwasm/index.d.ts +1252 -0
  80. package/test/faustlive-wasm/faustwasm/index.js +3772 -0
  81. package/test/faustlive-wasm/faustwasm/index.js.map +7 -0
  82. package/test/faustlive-wasm/index.css +97 -0
  83. package/test/faustlive-wasm/index.html +130 -0
  84. package/test/faustlive-wasm/index.js +638 -0
  85. package/test/guitar.dsp +1 -0
  86. package/test/guitar1.dsp +2 -0
  87. package/test/libfaust-in-worklet/index.html +13 -0
  88. package/test/libfaust-in-worklet/index.js +40 -0
  89. package/test/mono.dsp +8 -0
  90. package/test/node/test.js +17 -0
  91. package/test/noise.dsp +3 -0
  92. package/test/organ.dsp +5 -0
  93. package/test/organ1.dsp +6 -0
  94. package/test/osc.dsp +4 -0
  95. package/test/osc2.dsp +5 -0
  96. package/test/osc3.dsp +4 -0
  97. package/test/p-dj.dsp +4 -0
  98. package/test/poly.dsp +13 -0
  99. package/test/rev.dsp +2 -0
  100. package/test/t1.dsp +1 -0
  101. package/test/web/fft.html +87 -0
  102. package/test/web/fft1.html +88 -0
  103. package/test/web/fft2.html +114 -0
  104. package/test/web/fftw.js +1907 -0
  105. package/test/web/index.html +12 -0
  106. package/test/web/index.js +235 -0
  107. package/test/web/kissfft.js +904 -0
  108. package/test/web/mono.html +46 -0
  109. package/test/web/poly-key.html +62 -0
  110. package/test/web/poly.html +59 -0
  111. package/tsconfig.json +22 -0
@@ -0,0 +1,3772 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __commonJS = (cb, mod) => function __require() {
8
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
19
+
20
+ // node_modules/tslib/tslib.js
21
+ var require_tslib = __commonJS({
22
+ "node_modules/tslib/tslib.js"(exports, module) {
23
+ var __extends;
24
+ var __assign;
25
+ var __rest;
26
+ var __decorate;
27
+ var __param;
28
+ var __metadata;
29
+ var __awaiter;
30
+ var __generator;
31
+ var __exportStar;
32
+ var __values;
33
+ var __read;
34
+ var __spread;
35
+ var __spreadArrays;
36
+ var __await;
37
+ var __asyncGenerator;
38
+ var __asyncDelegator;
39
+ var __asyncValues;
40
+ var __makeTemplateObject;
41
+ var __importStar;
42
+ var __importDefault;
43
+ var __classPrivateFieldGet;
44
+ var __classPrivateFieldSet;
45
+ var __createBinding;
46
+ (function(factory) {
47
+ var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : {};
48
+ if (typeof define === "function" && define.amd) {
49
+ define("tslib", ["exports"], function(exports2) {
50
+ factory(createExporter(root, createExporter(exports2)));
51
+ });
52
+ } else if (typeof module === "object" && typeof module.exports === "object") {
53
+ factory(createExporter(root, createExporter(module.exports)));
54
+ } else {
55
+ factory(createExporter(root));
56
+ }
57
+ function createExporter(exports2, previous) {
58
+ if (exports2 !== root) {
59
+ if (typeof Object.create === "function") {
60
+ Object.defineProperty(exports2, "__esModule", { value: true });
61
+ } else {
62
+ exports2.__esModule = true;
63
+ }
64
+ }
65
+ return function(id, v) {
66
+ return exports2[id] = previous ? previous(id, v) : v;
67
+ };
68
+ }
69
+ })(function(exporter) {
70
+ var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d, b) {
71
+ d.__proto__ = b;
72
+ } || function(d, b) {
73
+ for (var p in b)
74
+ if (b.hasOwnProperty(p))
75
+ d[p] = b[p];
76
+ };
77
+ __extends = function(d, b) {
78
+ extendStatics(d, b);
79
+ function __() {
80
+ this.constructor = d;
81
+ }
82
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
83
+ };
84
+ __assign = Object.assign || function(t) {
85
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
86
+ s = arguments[i];
87
+ for (var p in s)
88
+ if (Object.prototype.hasOwnProperty.call(s, p))
89
+ t[p] = s[p];
90
+ }
91
+ return t;
92
+ };
93
+ __rest = function(s, e) {
94
+ var t = {};
95
+ for (var p in s)
96
+ if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
97
+ t[p] = s[p];
98
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
99
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
100
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
101
+ t[p[i]] = s[p[i]];
102
+ }
103
+ return t;
104
+ };
105
+ __decorate = function(decorators, target, key, desc) {
106
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
107
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
108
+ r = Reflect.decorate(decorators, target, key, desc);
109
+ else
110
+ for (var i = decorators.length - 1; i >= 0; i--)
111
+ if (d = decorators[i])
112
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
113
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
114
+ };
115
+ __param = function(paramIndex, decorator) {
116
+ return function(target, key) {
117
+ decorator(target, key, paramIndex);
118
+ };
119
+ };
120
+ __metadata = function(metadataKey, metadataValue) {
121
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
122
+ return Reflect.metadata(metadataKey, metadataValue);
123
+ };
124
+ __awaiter = function(thisArg, _arguments, P, generator) {
125
+ function adopt(value) {
126
+ return value instanceof P ? value : new P(function(resolve) {
127
+ resolve(value);
128
+ });
129
+ }
130
+ return new (P || (P = Promise))(function(resolve, reject) {
131
+ function fulfilled(value) {
132
+ try {
133
+ step(generator.next(value));
134
+ } catch (e) {
135
+ reject(e);
136
+ }
137
+ }
138
+ function rejected(value) {
139
+ try {
140
+ step(generator["throw"](value));
141
+ } catch (e) {
142
+ reject(e);
143
+ }
144
+ }
145
+ function step(result) {
146
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
147
+ }
148
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
149
+ });
150
+ };
151
+ __generator = function(thisArg, body) {
152
+ var _ = { label: 0, sent: function() {
153
+ if (t[0] & 1)
154
+ throw t[1];
155
+ return t[1];
156
+ }, trys: [], ops: [] }, f, y, t, g;
157
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
158
+ return this;
159
+ }), g;
160
+ function verb(n) {
161
+ return function(v) {
162
+ return step([n, v]);
163
+ };
164
+ }
165
+ function step(op) {
166
+ if (f)
167
+ throw new TypeError("Generator is already executing.");
168
+ while (_)
169
+ try {
170
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
171
+ return t;
172
+ if (y = 0, t)
173
+ op = [op[0] & 2, t.value];
174
+ switch (op[0]) {
175
+ case 0:
176
+ case 1:
177
+ t = op;
178
+ break;
179
+ case 4:
180
+ _.label++;
181
+ return { value: op[1], done: false };
182
+ case 5:
183
+ _.label++;
184
+ y = op[1];
185
+ op = [0];
186
+ continue;
187
+ case 7:
188
+ op = _.ops.pop();
189
+ _.trys.pop();
190
+ continue;
191
+ default:
192
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
193
+ _ = 0;
194
+ continue;
195
+ }
196
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
197
+ _.label = op[1];
198
+ break;
199
+ }
200
+ if (op[0] === 6 && _.label < t[1]) {
201
+ _.label = t[1];
202
+ t = op;
203
+ break;
204
+ }
205
+ if (t && _.label < t[2]) {
206
+ _.label = t[2];
207
+ _.ops.push(op);
208
+ break;
209
+ }
210
+ if (t[2])
211
+ _.ops.pop();
212
+ _.trys.pop();
213
+ continue;
214
+ }
215
+ op = body.call(thisArg, _);
216
+ } catch (e) {
217
+ op = [6, e];
218
+ y = 0;
219
+ } finally {
220
+ f = t = 0;
221
+ }
222
+ if (op[0] & 5)
223
+ throw op[1];
224
+ return { value: op[0] ? op[1] : void 0, done: true };
225
+ }
226
+ };
227
+ __createBinding = function(o, m, k, k2) {
228
+ if (k2 === void 0)
229
+ k2 = k;
230
+ o[k2] = m[k];
231
+ };
232
+ __exportStar = function(m, exports2) {
233
+ for (var p in m)
234
+ if (p !== "default" && !exports2.hasOwnProperty(p))
235
+ exports2[p] = m[p];
236
+ };
237
+ __values = function(o) {
238
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
239
+ if (m)
240
+ return m.call(o);
241
+ if (o && typeof o.length === "number")
242
+ return {
243
+ next: function() {
244
+ if (o && i >= o.length)
245
+ o = void 0;
246
+ return { value: o && o[i++], done: !o };
247
+ }
248
+ };
249
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
250
+ };
251
+ __read = function(o, n) {
252
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
253
+ if (!m)
254
+ return o;
255
+ var i = m.call(o), r, ar = [], e;
256
+ try {
257
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
258
+ ar.push(r.value);
259
+ } catch (error) {
260
+ e = { error };
261
+ } finally {
262
+ try {
263
+ if (r && !r.done && (m = i["return"]))
264
+ m.call(i);
265
+ } finally {
266
+ if (e)
267
+ throw e.error;
268
+ }
269
+ }
270
+ return ar;
271
+ };
272
+ __spread = function() {
273
+ for (var ar = [], i = 0; i < arguments.length; i++)
274
+ ar = ar.concat(__read(arguments[i]));
275
+ return ar;
276
+ };
277
+ __spreadArrays = function() {
278
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++)
279
+ s += arguments[i].length;
280
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
281
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
282
+ r[k] = a[j];
283
+ return r;
284
+ };
285
+ __await = function(v) {
286
+ return this instanceof __await ? (this.v = v, this) : new __await(v);
287
+ };
288
+ __asyncGenerator = function(thisArg, _arguments, generator) {
289
+ if (!Symbol.asyncIterator)
290
+ throw new TypeError("Symbol.asyncIterator is not defined.");
291
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
292
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
293
+ return this;
294
+ }, i;
295
+ function verb(n) {
296
+ if (g[n])
297
+ i[n] = function(v) {
298
+ return new Promise(function(a, b) {
299
+ q.push([n, v, a, b]) > 1 || resume(n, v);
300
+ });
301
+ };
302
+ }
303
+ function resume(n, v) {
304
+ try {
305
+ step(g[n](v));
306
+ } catch (e) {
307
+ settle(q[0][3], e);
308
+ }
309
+ }
310
+ function step(r) {
311
+ r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
312
+ }
313
+ function fulfill(value) {
314
+ resume("next", value);
315
+ }
316
+ function reject(value) {
317
+ resume("throw", value);
318
+ }
319
+ function settle(f, v) {
320
+ if (f(v), q.shift(), q.length)
321
+ resume(q[0][0], q[0][1]);
322
+ }
323
+ };
324
+ __asyncDelegator = function(o) {
325
+ var i, p;
326
+ return i = {}, verb("next"), verb("throw", function(e) {
327
+ throw e;
328
+ }), verb("return"), i[Symbol.iterator] = function() {
329
+ return this;
330
+ }, i;
331
+ function verb(n, f) {
332
+ i[n] = o[n] ? function(v) {
333
+ return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
334
+ } : f;
335
+ }
336
+ };
337
+ __asyncValues = function(o) {
338
+ if (!Symbol.asyncIterator)
339
+ throw new TypeError("Symbol.asyncIterator is not defined.");
340
+ var m = o[Symbol.asyncIterator], i;
341
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
342
+ return this;
343
+ }, i);
344
+ function verb(n) {
345
+ i[n] = o[n] && function(v) {
346
+ return new Promise(function(resolve, reject) {
347
+ v = o[n](v), settle(resolve, reject, v.done, v.value);
348
+ });
349
+ };
350
+ }
351
+ function settle(resolve, reject, d, v) {
352
+ Promise.resolve(v).then(function(v2) {
353
+ resolve({ value: v2, done: d });
354
+ }, reject);
355
+ }
356
+ };
357
+ __makeTemplateObject = function(cooked, raw) {
358
+ if (Object.defineProperty) {
359
+ Object.defineProperty(cooked, "raw", { value: raw });
360
+ } else {
361
+ cooked.raw = raw;
362
+ }
363
+ return cooked;
364
+ };
365
+ __importStar = function(mod) {
366
+ if (mod && mod.__esModule)
367
+ return mod;
368
+ var result = {};
369
+ if (mod != null) {
370
+ for (var k in mod)
371
+ if (Object.hasOwnProperty.call(mod, k))
372
+ result[k] = mod[k];
373
+ }
374
+ result["default"] = mod;
375
+ return result;
376
+ };
377
+ __importDefault = function(mod) {
378
+ return mod && mod.__esModule ? mod : { "default": mod };
379
+ };
380
+ __classPrivateFieldGet = function(receiver, privateMap) {
381
+ if (!privateMap.has(receiver)) {
382
+ throw new TypeError("attempted to get private field on non-instance");
383
+ }
384
+ return privateMap.get(receiver);
385
+ };
386
+ __classPrivateFieldSet = function(receiver, privateMap, value) {
387
+ if (!privateMap.has(receiver)) {
388
+ throw new TypeError("attempted to set private field on non-instance");
389
+ }
390
+ privateMap.set(receiver, value);
391
+ return value;
392
+ };
393
+ exporter("__extends", __extends);
394
+ exporter("__assign", __assign);
395
+ exporter("__rest", __rest);
396
+ exporter("__decorate", __decorate);
397
+ exporter("__param", __param);
398
+ exporter("__metadata", __metadata);
399
+ exporter("__awaiter", __awaiter);
400
+ exporter("__generator", __generator);
401
+ exporter("__exportStar", __exportStar);
402
+ exporter("__createBinding", __createBinding);
403
+ exporter("__values", __values);
404
+ exporter("__read", __read);
405
+ exporter("__spread", __spread);
406
+ exporter("__spreadArrays", __spreadArrays);
407
+ exporter("__await", __await);
408
+ exporter("__asyncGenerator", __asyncGenerator);
409
+ exporter("__asyncDelegator", __asyncDelegator);
410
+ exporter("__asyncValues", __asyncValues);
411
+ exporter("__makeTemplateObject", __makeTemplateObject);
412
+ exporter("__importStar", __importStar);
413
+ exporter("__importDefault", __importDefault);
414
+ exporter("__classPrivateFieldGet", __classPrivateFieldGet);
415
+ exporter("__classPrivateFieldSet", __classPrivateFieldSet);
416
+ });
417
+ }
418
+ });
419
+
420
+ // node_modules/@aws-crypto/sha256-js/build/constants.js
421
+ var require_constants = __commonJS({
422
+ "node_modules/@aws-crypto/sha256-js/build/constants.js"(exports) {
423
+ "use strict";
424
+ Object.defineProperty(exports, "__esModule", { value: true });
425
+ exports.MAX_HASHABLE_LENGTH = exports.INIT = exports.KEY = exports.DIGEST_LENGTH = exports.BLOCK_SIZE = void 0;
426
+ exports.BLOCK_SIZE = 64;
427
+ exports.DIGEST_LENGTH = 32;
428
+ exports.KEY = new Uint32Array([
429
+ 1116352408,
430
+ 1899447441,
431
+ 3049323471,
432
+ 3921009573,
433
+ 961987163,
434
+ 1508970993,
435
+ 2453635748,
436
+ 2870763221,
437
+ 3624381080,
438
+ 310598401,
439
+ 607225278,
440
+ 1426881987,
441
+ 1925078388,
442
+ 2162078206,
443
+ 2614888103,
444
+ 3248222580,
445
+ 3835390401,
446
+ 4022224774,
447
+ 264347078,
448
+ 604807628,
449
+ 770255983,
450
+ 1249150122,
451
+ 1555081692,
452
+ 1996064986,
453
+ 2554220882,
454
+ 2821834349,
455
+ 2952996808,
456
+ 3210313671,
457
+ 3336571891,
458
+ 3584528711,
459
+ 113926993,
460
+ 338241895,
461
+ 666307205,
462
+ 773529912,
463
+ 1294757372,
464
+ 1396182291,
465
+ 1695183700,
466
+ 1986661051,
467
+ 2177026350,
468
+ 2456956037,
469
+ 2730485921,
470
+ 2820302411,
471
+ 3259730800,
472
+ 3345764771,
473
+ 3516065817,
474
+ 3600352804,
475
+ 4094571909,
476
+ 275423344,
477
+ 430227734,
478
+ 506948616,
479
+ 659060556,
480
+ 883997877,
481
+ 958139571,
482
+ 1322822218,
483
+ 1537002063,
484
+ 1747873779,
485
+ 1955562222,
486
+ 2024104815,
487
+ 2227730452,
488
+ 2361852424,
489
+ 2428436474,
490
+ 2756734187,
491
+ 3204031479,
492
+ 3329325298
493
+ ]);
494
+ exports.INIT = [
495
+ 1779033703,
496
+ 3144134277,
497
+ 1013904242,
498
+ 2773480762,
499
+ 1359893119,
500
+ 2600822924,
501
+ 528734635,
502
+ 1541459225
503
+ ];
504
+ exports.MAX_HASHABLE_LENGTH = Math.pow(2, 53) - 1;
505
+ }
506
+ });
507
+
508
+ // node_modules/@aws-crypto/sha256-js/build/RawSha256.js
509
+ var require_RawSha256 = __commonJS({
510
+ "node_modules/@aws-crypto/sha256-js/build/RawSha256.js"(exports) {
511
+ "use strict";
512
+ Object.defineProperty(exports, "__esModule", { value: true });
513
+ exports.RawSha256 = void 0;
514
+ var constants_1 = require_constants();
515
+ var RawSha256 = function() {
516
+ function RawSha2562() {
517
+ this.state = Int32Array.from(constants_1.INIT);
518
+ this.temp = new Int32Array(64);
519
+ this.buffer = new Uint8Array(64);
520
+ this.bufferLength = 0;
521
+ this.bytesHashed = 0;
522
+ this.finished = false;
523
+ }
524
+ RawSha2562.prototype.update = function(data) {
525
+ if (this.finished) {
526
+ throw new Error("Attempted to update an already finished hash.");
527
+ }
528
+ var position = 0;
529
+ var byteLength = data.byteLength;
530
+ this.bytesHashed += byteLength;
531
+ if (this.bytesHashed * 8 > constants_1.MAX_HASHABLE_LENGTH) {
532
+ throw new Error("Cannot hash more than 2^53 - 1 bits");
533
+ }
534
+ while (byteLength > 0) {
535
+ this.buffer[this.bufferLength++] = data[position++];
536
+ byteLength--;
537
+ if (this.bufferLength === constants_1.BLOCK_SIZE) {
538
+ this.hashBuffer();
539
+ this.bufferLength = 0;
540
+ }
541
+ }
542
+ };
543
+ RawSha2562.prototype.digest = function() {
544
+ if (!this.finished) {
545
+ var bitsHashed = this.bytesHashed * 8;
546
+ var bufferView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
547
+ var undecoratedLength = this.bufferLength;
548
+ bufferView.setUint8(this.bufferLength++, 128);
549
+ if (undecoratedLength % constants_1.BLOCK_SIZE >= constants_1.BLOCK_SIZE - 8) {
550
+ for (var i = this.bufferLength; i < constants_1.BLOCK_SIZE; i++) {
551
+ bufferView.setUint8(i, 0);
552
+ }
553
+ this.hashBuffer();
554
+ this.bufferLength = 0;
555
+ }
556
+ for (var i = this.bufferLength; i < constants_1.BLOCK_SIZE - 8; i++) {
557
+ bufferView.setUint8(i, 0);
558
+ }
559
+ bufferView.setUint32(constants_1.BLOCK_SIZE - 8, Math.floor(bitsHashed / 4294967296), true);
560
+ bufferView.setUint32(constants_1.BLOCK_SIZE - 4, bitsHashed);
561
+ this.hashBuffer();
562
+ this.finished = true;
563
+ }
564
+ var out = new Uint8Array(constants_1.DIGEST_LENGTH);
565
+ for (var i = 0; i < 8; i++) {
566
+ out[i * 4] = this.state[i] >>> 24 & 255;
567
+ out[i * 4 + 1] = this.state[i] >>> 16 & 255;
568
+ out[i * 4 + 2] = this.state[i] >>> 8 & 255;
569
+ out[i * 4 + 3] = this.state[i] >>> 0 & 255;
570
+ }
571
+ return out;
572
+ };
573
+ RawSha2562.prototype.hashBuffer = function() {
574
+ var _a = this, buffer = _a.buffer, state = _a.state;
575
+ var state0 = state[0], state1 = state[1], state2 = state[2], state3 = state[3], state4 = state[4], state5 = state[5], state6 = state[6], state7 = state[7];
576
+ for (var i = 0; i < constants_1.BLOCK_SIZE; i++) {
577
+ if (i < 16) {
578
+ this.temp[i] = (buffer[i * 4] & 255) << 24 | (buffer[i * 4 + 1] & 255) << 16 | (buffer[i * 4 + 2] & 255) << 8 | buffer[i * 4 + 3] & 255;
579
+ } else {
580
+ var u = this.temp[i - 2];
581
+ var t1_1 = (u >>> 17 | u << 15) ^ (u >>> 19 | u << 13) ^ u >>> 10;
582
+ u = this.temp[i - 15];
583
+ var t2_1 = (u >>> 7 | u << 25) ^ (u >>> 18 | u << 14) ^ u >>> 3;
584
+ this.temp[i] = (t1_1 + this.temp[i - 7] | 0) + (t2_1 + this.temp[i - 16] | 0);
585
+ }
586
+ var t1 = (((state4 >>> 6 | state4 << 26) ^ (state4 >>> 11 | state4 << 21) ^ (state4 >>> 25 | state4 << 7)) + (state4 & state5 ^ ~state4 & state6) | 0) + (state7 + (constants_1.KEY[i] + this.temp[i] | 0) | 0) | 0;
587
+ var t2 = ((state0 >>> 2 | state0 << 30) ^ (state0 >>> 13 | state0 << 19) ^ (state0 >>> 22 | state0 << 10)) + (state0 & state1 ^ state0 & state2 ^ state1 & state2) | 0;
588
+ state7 = state6;
589
+ state6 = state5;
590
+ state5 = state4;
591
+ state4 = state3 + t1 | 0;
592
+ state3 = state2;
593
+ state2 = state1;
594
+ state1 = state0;
595
+ state0 = t1 + t2 | 0;
596
+ }
597
+ state[0] += state0;
598
+ state[1] += state1;
599
+ state[2] += state2;
600
+ state[3] += state3;
601
+ state[4] += state4;
602
+ state[5] += state5;
603
+ state[6] += state6;
604
+ state[7] += state7;
605
+ };
606
+ return RawSha2562;
607
+ }();
608
+ exports.RawSha256 = RawSha256;
609
+ }
610
+ });
611
+
612
+ // node_modules/@aws-sdk/util-utf8-browser/dist-cjs/pureJs.js
613
+ var require_pureJs = __commonJS({
614
+ "node_modules/@aws-sdk/util-utf8-browser/dist-cjs/pureJs.js"(exports) {
615
+ "use strict";
616
+ Object.defineProperty(exports, "__esModule", { value: true });
617
+ exports.toUtf8 = exports.fromUtf8 = void 0;
618
+ var fromUtf8 = (input) => {
619
+ const bytes = [];
620
+ for (let i = 0, len = input.length; i < len; i++) {
621
+ const value = input.charCodeAt(i);
622
+ if (value < 128) {
623
+ bytes.push(value);
624
+ } else if (value < 2048) {
625
+ bytes.push(value >> 6 | 192, value & 63 | 128);
626
+ } else if (i + 1 < input.length && (value & 64512) === 55296 && (input.charCodeAt(i + 1) & 64512) === 56320) {
627
+ const surrogatePair = 65536 + ((value & 1023) << 10) + (input.charCodeAt(++i) & 1023);
628
+ bytes.push(surrogatePair >> 18 | 240, surrogatePair >> 12 & 63 | 128, surrogatePair >> 6 & 63 | 128, surrogatePair & 63 | 128);
629
+ } else {
630
+ bytes.push(value >> 12 | 224, value >> 6 & 63 | 128, value & 63 | 128);
631
+ }
632
+ }
633
+ return Uint8Array.from(bytes);
634
+ };
635
+ exports.fromUtf8 = fromUtf8;
636
+ var toUtf8 = (input) => {
637
+ let decoded = "";
638
+ for (let i = 0, len = input.length; i < len; i++) {
639
+ const byte = input[i];
640
+ if (byte < 128) {
641
+ decoded += String.fromCharCode(byte);
642
+ } else if (192 <= byte && byte < 224) {
643
+ const nextByte = input[++i];
644
+ decoded += String.fromCharCode((byte & 31) << 6 | nextByte & 63);
645
+ } else if (240 <= byte && byte < 365) {
646
+ const surrogatePair = [byte, input[++i], input[++i], input[++i]];
647
+ const encoded = "%" + surrogatePair.map((byteValue) => byteValue.toString(16)).join("%");
648
+ decoded += decodeURIComponent(encoded);
649
+ } else {
650
+ decoded += String.fromCharCode((byte & 15) << 12 | (input[++i] & 63) << 6 | input[++i] & 63);
651
+ }
652
+ }
653
+ return decoded;
654
+ };
655
+ exports.toUtf8 = toUtf8;
656
+ }
657
+ });
658
+
659
+ // node_modules/@aws-sdk/util-utf8-browser/dist-cjs/whatwgEncodingApi.js
660
+ var require_whatwgEncodingApi = __commonJS({
661
+ "node_modules/@aws-sdk/util-utf8-browser/dist-cjs/whatwgEncodingApi.js"(exports) {
662
+ "use strict";
663
+ Object.defineProperty(exports, "__esModule", { value: true });
664
+ exports.toUtf8 = exports.fromUtf8 = void 0;
665
+ function fromUtf8(input) {
666
+ return new TextEncoder().encode(input);
667
+ }
668
+ exports.fromUtf8 = fromUtf8;
669
+ function toUtf8(input) {
670
+ return new TextDecoder("utf-8").decode(input);
671
+ }
672
+ exports.toUtf8 = toUtf8;
673
+ }
674
+ });
675
+
676
+ // node_modules/@aws-sdk/util-utf8-browser/dist-cjs/index.js
677
+ var require_dist_cjs = __commonJS({
678
+ "node_modules/@aws-sdk/util-utf8-browser/dist-cjs/index.js"(exports) {
679
+ "use strict";
680
+ Object.defineProperty(exports, "__esModule", { value: true });
681
+ exports.toUtf8 = exports.fromUtf8 = void 0;
682
+ var pureJs_1 = require_pureJs();
683
+ var whatwgEncodingApi_1 = require_whatwgEncodingApi();
684
+ var fromUtf8 = (input) => typeof TextEncoder === "function" ? (0, whatwgEncodingApi_1.fromUtf8)(input) : (0, pureJs_1.fromUtf8)(input);
685
+ exports.fromUtf8 = fromUtf8;
686
+ var toUtf8 = (input) => typeof TextDecoder === "function" ? (0, whatwgEncodingApi_1.toUtf8)(input) : (0, pureJs_1.toUtf8)(input);
687
+ exports.toUtf8 = toUtf8;
688
+ }
689
+ });
690
+
691
+ // node_modules/@aws-crypto/util/build/convertToBuffer.js
692
+ var require_convertToBuffer = __commonJS({
693
+ "node_modules/@aws-crypto/util/build/convertToBuffer.js"(exports) {
694
+ "use strict";
695
+ Object.defineProperty(exports, "__esModule", { value: true });
696
+ exports.convertToBuffer = void 0;
697
+ var util_utf8_browser_1 = require_dist_cjs();
698
+ var fromUtf8 = typeof Buffer !== "undefined" && Buffer.from ? function(input) {
699
+ return Buffer.from(input, "utf8");
700
+ } : util_utf8_browser_1.fromUtf8;
701
+ function convertToBuffer(data) {
702
+ if (data instanceof Uint8Array)
703
+ return data;
704
+ if (typeof data === "string") {
705
+ return fromUtf8(data);
706
+ }
707
+ if (ArrayBuffer.isView(data)) {
708
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
709
+ }
710
+ return new Uint8Array(data);
711
+ }
712
+ exports.convertToBuffer = convertToBuffer;
713
+ }
714
+ });
715
+
716
+ // node_modules/@aws-crypto/util/build/isEmptyData.js
717
+ var require_isEmptyData = __commonJS({
718
+ "node_modules/@aws-crypto/util/build/isEmptyData.js"(exports) {
719
+ "use strict";
720
+ Object.defineProperty(exports, "__esModule", { value: true });
721
+ exports.isEmptyData = void 0;
722
+ function isEmptyData(data) {
723
+ if (typeof data === "string") {
724
+ return data.length === 0;
725
+ }
726
+ return data.byteLength === 0;
727
+ }
728
+ exports.isEmptyData = isEmptyData;
729
+ }
730
+ });
731
+
732
+ // node_modules/@aws-crypto/util/build/numToUint8.js
733
+ var require_numToUint8 = __commonJS({
734
+ "node_modules/@aws-crypto/util/build/numToUint8.js"(exports) {
735
+ "use strict";
736
+ Object.defineProperty(exports, "__esModule", { value: true });
737
+ exports.numToUint8 = void 0;
738
+ function numToUint8(num) {
739
+ return new Uint8Array([
740
+ (num & 4278190080) >> 24,
741
+ (num & 16711680) >> 16,
742
+ (num & 65280) >> 8,
743
+ num & 255
744
+ ]);
745
+ }
746
+ exports.numToUint8 = numToUint8;
747
+ }
748
+ });
749
+
750
+ // node_modules/@aws-crypto/util/build/uint32ArrayFrom.js
751
+ var require_uint32ArrayFrom = __commonJS({
752
+ "node_modules/@aws-crypto/util/build/uint32ArrayFrom.js"(exports) {
753
+ "use strict";
754
+ Object.defineProperty(exports, "__esModule", { value: true });
755
+ exports.uint32ArrayFrom = void 0;
756
+ function uint32ArrayFrom(a_lookUpTable) {
757
+ if (!Uint32Array.from) {
758
+ var return_array = new Uint32Array(a_lookUpTable.length);
759
+ var a_index = 0;
760
+ while (a_index < a_lookUpTable.length) {
761
+ return_array[a_index] = a_lookUpTable[a_index];
762
+ a_index += 1;
763
+ }
764
+ return return_array;
765
+ }
766
+ return Uint32Array.from(a_lookUpTable);
767
+ }
768
+ exports.uint32ArrayFrom = uint32ArrayFrom;
769
+ }
770
+ });
771
+
772
+ // node_modules/@aws-crypto/util/build/index.js
773
+ var require_build = __commonJS({
774
+ "node_modules/@aws-crypto/util/build/index.js"(exports) {
775
+ "use strict";
776
+ Object.defineProperty(exports, "__esModule", { value: true });
777
+ exports.uint32ArrayFrom = exports.numToUint8 = exports.isEmptyData = exports.convertToBuffer = void 0;
778
+ var convertToBuffer_1 = require_convertToBuffer();
779
+ Object.defineProperty(exports, "convertToBuffer", { enumerable: true, get: function() {
780
+ return convertToBuffer_1.convertToBuffer;
781
+ } });
782
+ var isEmptyData_1 = require_isEmptyData();
783
+ Object.defineProperty(exports, "isEmptyData", { enumerable: true, get: function() {
784
+ return isEmptyData_1.isEmptyData;
785
+ } });
786
+ var numToUint8_1 = require_numToUint8();
787
+ Object.defineProperty(exports, "numToUint8", { enumerable: true, get: function() {
788
+ return numToUint8_1.numToUint8;
789
+ } });
790
+ var uint32ArrayFrom_1 = require_uint32ArrayFrom();
791
+ Object.defineProperty(exports, "uint32ArrayFrom", { enumerable: true, get: function() {
792
+ return uint32ArrayFrom_1.uint32ArrayFrom;
793
+ } });
794
+ }
795
+ });
796
+
797
+ // node_modules/@aws-crypto/sha256-js/build/jsSha256.js
798
+ var require_jsSha256 = __commonJS({
799
+ "node_modules/@aws-crypto/sha256-js/build/jsSha256.js"(exports) {
800
+ "use strict";
801
+ Object.defineProperty(exports, "__esModule", { value: true });
802
+ exports.Sha256 = void 0;
803
+ var tslib_1 = require_tslib();
804
+ var constants_1 = require_constants();
805
+ var RawSha256_1 = require_RawSha256();
806
+ var util_1 = require_build();
807
+ var Sha2562 = function() {
808
+ function Sha2563(secret) {
809
+ this.hash = new RawSha256_1.RawSha256();
810
+ if (secret) {
811
+ this.outer = new RawSha256_1.RawSha256();
812
+ var inner = bufferFromSecret(secret);
813
+ var outer = new Uint8Array(constants_1.BLOCK_SIZE);
814
+ outer.set(inner);
815
+ for (var i = 0; i < constants_1.BLOCK_SIZE; i++) {
816
+ inner[i] ^= 54;
817
+ outer[i] ^= 92;
818
+ }
819
+ this.hash.update(inner);
820
+ this.outer.update(outer);
821
+ for (var i = 0; i < inner.byteLength; i++) {
822
+ inner[i] = 0;
823
+ }
824
+ }
825
+ }
826
+ Sha2563.prototype.update = function(toHash) {
827
+ if ((0, util_1.isEmptyData)(toHash) || this.error) {
828
+ return;
829
+ }
830
+ try {
831
+ this.hash.update((0, util_1.convertToBuffer)(toHash));
832
+ } catch (e) {
833
+ this.error = e;
834
+ }
835
+ };
836
+ Sha2563.prototype.digestSync = function() {
837
+ if (this.error) {
838
+ throw this.error;
839
+ }
840
+ if (this.outer) {
841
+ if (!this.outer.finished) {
842
+ this.outer.update(this.hash.digest());
843
+ }
844
+ return this.outer.digest();
845
+ }
846
+ return this.hash.digest();
847
+ };
848
+ Sha2563.prototype.digest = function() {
849
+ return (0, tslib_1.__awaiter)(this, void 0, void 0, function() {
850
+ return (0, tslib_1.__generator)(this, function(_a) {
851
+ return [2, this.digestSync()];
852
+ });
853
+ });
854
+ };
855
+ return Sha2563;
856
+ }();
857
+ exports.Sha256 = Sha2562;
858
+ function bufferFromSecret(secret) {
859
+ var input = (0, util_1.convertToBuffer)(secret);
860
+ if (input.byteLength > constants_1.BLOCK_SIZE) {
861
+ var bufferHash = new RawSha256_1.RawSha256();
862
+ bufferHash.update(input);
863
+ input = bufferHash.digest();
864
+ }
865
+ var buffer = new Uint8Array(constants_1.BLOCK_SIZE);
866
+ buffer.set(input);
867
+ return buffer;
868
+ }
869
+ }
870
+ });
871
+
872
+ // node_modules/@aws-crypto/sha256-js/build/index.js
873
+ var require_build2 = __commonJS({
874
+ "node_modules/@aws-crypto/sha256-js/build/index.js"(exports) {
875
+ "use strict";
876
+ Object.defineProperty(exports, "__esModule", { value: true });
877
+ var tslib_1 = require_tslib();
878
+ (0, tslib_1.__exportStar)(require_jsSha256(), exports);
879
+ }
880
+ });
881
+
882
+ // src/instantiateFaustModuleFromFile.ts
883
+ var instantiateFaustModuleFromFile = async (jsFile, dataFile = jsFile.replace(/c?js$/, "data"), wasmFile = jsFile.replace(/c?js$/, "wasm")) => {
884
+ var _a, _b;
885
+ let FaustModule;
886
+ let dataBinary;
887
+ let wasmBinary;
888
+ const jsCodeHead = /var (.+) = \(/;
889
+ if (typeof window === "object") {
890
+ let jsCode = await (await fetch(jsFile)).text();
891
+ jsCode = `${jsCode}
892
+ export default ${(_a = jsCode.match(jsCodeHead)) == null ? void 0 : _a[1]};
893
+ `;
894
+ const jsFileMod = URL.createObjectURL(new Blob([jsCode], { type: "text/javascript" }));
895
+ FaustModule = (await import(
896
+ /* webpackIgnore: true */
897
+ jsFileMod
898
+ )).default;
899
+ dataBinary = await (await fetch(dataFile)).arrayBuffer();
900
+ wasmBinary = new Uint8Array(await (await fetch(wasmFile)).arrayBuffer());
901
+ } else {
902
+ const { promises: fs } = await import("fs");
903
+ const { pathToFileURL } = await import("url");
904
+ let jsCode = await fs.readFile(jsFile, { encoding: "utf-8" });
905
+ jsCode = `
906
+ import process from "process";
907
+ import * as path from "path";
908
+ import { createRequire } from "module";
909
+ import { fileURLToPath } from "url";
910
+
911
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
912
+ const __filename = fileURLToPath(import.meta.url);
913
+ const require = createRequire(import.meta.url);
914
+
915
+ ${jsCode}
916
+
917
+ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
918
+ `;
919
+ const jsFileMod = jsFile.replace(/c?js$/, "mjs");
920
+ await fs.writeFile(jsFileMod, jsCode);
921
+ FaustModule = (await import(
922
+ /* webpackIgnore: true */
923
+ pathToFileURL(jsFileMod).href
924
+ )).default;
925
+ await fs.unlink(jsFileMod);
926
+ dataBinary = (await fs.readFile(dataFile)).buffer;
927
+ wasmBinary = (await fs.readFile(wasmFile)).buffer;
928
+ }
929
+ const faustModule = await FaustModule({
930
+ wasmBinary,
931
+ getPreloadedPackage: (remotePackageName, remotePackageSize) => {
932
+ if (remotePackageName === "libfaust-wasm.data")
933
+ return dataBinary;
934
+ return new ArrayBuffer(0);
935
+ }
936
+ });
937
+ return faustModule;
938
+ };
939
+ var instantiateFaustModuleFromFile_default = instantiateFaustModuleFromFile;
940
+
941
+ // src/FaustAudioWorkletProcessor.ts
942
+ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) => {
943
+ const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
944
+ const {
945
+ FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
946
+ FaustWasmInstantiator: FaustWasmInstantiator2
947
+ } = dependencies;
948
+ const {
949
+ processorName,
950
+ dspName,
951
+ dspMeta,
952
+ effectMeta,
953
+ poly
954
+ } = faustData;
955
+ const analysePolyParameters = (item) => {
956
+ const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
957
+ const isPolyReserved = "address" in item && !!polyKeywords.find((k) => item.address.endsWith(k));
958
+ if (poly && isPolyReserved)
959
+ return null;
960
+ if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
961
+ return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
962
+ } else if (item.type === "button" || item.type === "checkbox") {
963
+ return { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
964
+ }
965
+ return null;
966
+ };
967
+ class FaustAudioWorkletProcessor extends AudioWorkletProcessor {
968
+ constructor(options) {
969
+ super(options);
970
+ this.paramValuesCache = {};
971
+ this.port.onmessage = (e) => this.handleMessageAux(e);
972
+ const { parameterDescriptors } = this.constructor;
973
+ parameterDescriptors.forEach((pd) => {
974
+ this.paramValuesCache[pd.name] = pd.defaultValue || 0;
975
+ });
976
+ }
977
+ static get parameterDescriptors() {
978
+ const params = [];
979
+ const callback = (item) => {
980
+ const param = analysePolyParameters(item);
981
+ if (param)
982
+ params.push(param);
983
+ };
984
+ FaustBaseWebAudioDsp2.parseUI(dspMeta.ui, callback);
985
+ if (effectMeta)
986
+ FaustBaseWebAudioDsp2.parseUI(effectMeta.ui, callback);
987
+ return params;
988
+ }
989
+ process(inputs, outputs, parameters) {
990
+ for (const path in parameters) {
991
+ const [paramValue] = parameters[path];
992
+ if (paramValue !== this.paramValuesCache[path]) {
993
+ this.fDSPCode.setParamValue(path, paramValue);
994
+ this.paramValuesCache[path] = paramValue;
995
+ }
996
+ }
997
+ return this.fDSPCode.compute(inputs[0], outputs[0]);
998
+ }
999
+ handleMessageAux(e) {
1000
+ const msg = e.data;
1001
+ switch (msg.type) {
1002
+ case "midi":
1003
+ this.midiMessage(msg.data);
1004
+ break;
1005
+ case "ctrlChange":
1006
+ this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
1007
+ break;
1008
+ case "pitchWheel":
1009
+ this.pitchWheel(msg.data[0], msg.data[1]);
1010
+ break;
1011
+ case "param":
1012
+ this.setParamValue(msg.data.path, msg.data.value);
1013
+ break;
1014
+ case "setPlotHandler": {
1015
+ if (msg.data) {
1016
+ this.fDSPCode.setPlotHandler((output, index, events) => this.port.postMessage({ type: "plot", value: output, index, events }));
1017
+ } else {
1018
+ this.fDSPCode.setPlotHandler(null);
1019
+ }
1020
+ break;
1021
+ }
1022
+ case "start": {
1023
+ this.fDSPCode.start();
1024
+ break;
1025
+ }
1026
+ case "stop": {
1027
+ this.fDSPCode.stop();
1028
+ break;
1029
+ }
1030
+ case "destroy": {
1031
+ this.port.close();
1032
+ this.fDSPCode.destroy();
1033
+ break;
1034
+ }
1035
+ default:
1036
+ break;
1037
+ }
1038
+ }
1039
+ setParamValue(path, value) {
1040
+ this.fDSPCode.setParamValue(path, value);
1041
+ this.paramValuesCache[path] = value;
1042
+ }
1043
+ midiMessage(data) {
1044
+ this.fDSPCode.midiMessage(data);
1045
+ }
1046
+ ctrlChange(channel, ctrl, value) {
1047
+ this.fDSPCode.ctrlChange(channel, ctrl, value);
1048
+ }
1049
+ pitchWheel(channel, wheel) {
1050
+ this.fDSPCode.pitchWheel(channel, wheel);
1051
+ }
1052
+ }
1053
+ class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
1054
+ constructor(options) {
1055
+ super(options);
1056
+ const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
1057
+ const { factory, sampleSize } = options.processorOptions;
1058
+ const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
1059
+ this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128);
1060
+ this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
1061
+ this.fDSPCode.start();
1062
+ }
1063
+ }
1064
+ class FaustPolyAudioWorkletProcessor extends FaustAudioWorkletProcessor {
1065
+ constructor(options) {
1066
+ super(options);
1067
+ this.handleMessageAux = (e) => {
1068
+ const msg = e.data;
1069
+ switch (msg.type) {
1070
+ case "keyOn":
1071
+ this.keyOn(msg.data[0], msg.data[1], msg.data[2]);
1072
+ break;
1073
+ case "keyOff":
1074
+ this.keyOff(msg.data[0], msg.data[1], msg.data[2]);
1075
+ break;
1076
+ default:
1077
+ super.handleMessageAux(e);
1078
+ break;
1079
+ }
1080
+ };
1081
+ const { FaustPolyWebAudioDsp: FaustPolyWebAudioDsp3 } = dependencies;
1082
+ const { voiceFactory, mixerModule, voices, effectFactory, sampleSize } = options.processorOptions;
1083
+ const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
1084
+ this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128);
1085
+ this.port.onmessage = (e) => this.handleMessageAux(e);
1086
+ this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
1087
+ this.fDSPCode.start();
1088
+ }
1089
+ midiMessage(data) {
1090
+ const cmd = data[0] >> 4;
1091
+ const channel = data[0] & 15;
1092
+ const data1 = data[1];
1093
+ const data2 = data[2];
1094
+ if (cmd === 8 || cmd === 9 && data2 === 0)
1095
+ this.keyOff(channel, data1, data2);
1096
+ else if (cmd === 9)
1097
+ this.keyOn(channel, data1, data2);
1098
+ else
1099
+ super.midiMessage(data);
1100
+ }
1101
+ keyOn(channel, pitch, velocity) {
1102
+ this.fDSPCode.keyOn(channel, pitch, velocity);
1103
+ }
1104
+ keyOff(channel, pitch, velocity) {
1105
+ this.fDSPCode.keyOff(channel, pitch, velocity);
1106
+ }
1107
+ allNotesOff(hard) {
1108
+ this.fDSPCode.allNotesOff(hard);
1109
+ }
1110
+ }
1111
+ const Processor = poly ? FaustPolyAudioWorkletProcessor : FaustMonoAudioWorkletProcessor;
1112
+ if (register) {
1113
+ try {
1114
+ registerProcessor(processorName || dspName || (poly ? "mydsp_poly" : "mydsp"), Processor);
1115
+ } catch (error) {
1116
+ console.warn(error);
1117
+ }
1118
+ }
1119
+ return poly ? FaustPolyAudioWorkletProcessor : FaustMonoAudioWorkletProcessor;
1120
+ };
1121
+ var FaustAudioWorkletProcessor_default = getFaustAudioWorkletProcessor;
1122
+
1123
+ // src/FaustFFTAudioWorkletProcessor.ts
1124
+ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true) => {
1125
+ const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
1126
+ const {
1127
+ FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
1128
+ FaustWasmInstantiator: FaustWasmInstantiator2,
1129
+ FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2,
1130
+ FFTUtils
1131
+ } = dependencies;
1132
+ const {
1133
+ processorName,
1134
+ dspName,
1135
+ dspMeta,
1136
+ fftOptions
1137
+ } = faustData;
1138
+ const {
1139
+ windowFunctions,
1140
+ getFFT,
1141
+ fftToSignal,
1142
+ signalToFFT,
1143
+ signalToNoFFT
1144
+ } = FFTUtils;
1145
+ const ceil = (x, to) => Math.abs(to) < 1 ? Math.ceil(x * (1 / to)) / (1 / to) : Math.ceil(x / to) * to;
1146
+ const mod = (x, y) => (x % y + y) % y;
1147
+ const apply = (array, windowFunction) => {
1148
+ for (let i = 0; i < array.length; i++) {
1149
+ array[i] *= windowFunction(i, array.length);
1150
+ }
1151
+ };
1152
+ const fftParamKeywords = ["/fftSize", "/fftHopSize", "/fftOverlap", "/windowFunction", "/noIFFT"];
1153
+ const setTypedArray = (to, from, offsetTo = 0, offsetFrom = 0) => {
1154
+ const toLength = to.length;
1155
+ const fromLength = from.length;
1156
+ const spillLength = Math.min(toLength, fromLength);
1157
+ let spilled = 0;
1158
+ let $to = mod(offsetTo, toLength) || 0;
1159
+ let $from = mod(offsetFrom, fromLength) || 0;
1160
+ while (spilled < spillLength) {
1161
+ const $spillLength = Math.min(spillLength - spilled, toLength - $to, fromLength - $from);
1162
+ const $fromEnd = $from + $spillLength;
1163
+ if ($from === 0 && $fromEnd === fromLength)
1164
+ to.set(from, $to);
1165
+ else
1166
+ to.set(from.subarray($from, $fromEnd), $to);
1167
+ $to = ($to + $spillLength) % toLength;
1168
+ $from = $fromEnd % fromLength;
1169
+ spilled += $spillLength;
1170
+ }
1171
+ return $to;
1172
+ };
1173
+ const analyseParameters = (item) => {
1174
+ const isFFTReserved = "address" in item && !!fftParamKeywords.find((k) => item.address.endsWith(k));
1175
+ if (isFFTReserved)
1176
+ return null;
1177
+ if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
1178
+ return { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
1179
+ } else if (item.type === "button" || item.type === "checkbox") {
1180
+ return { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
1181
+ }
1182
+ return null;
1183
+ };
1184
+ class FaustFFTAudioWorkletProcessor extends AudioWorkletProcessor {
1185
+ constructor(options) {
1186
+ super(options);
1187
+ this.paramValuesCache = {};
1188
+ this.destroyed = false;
1189
+ this.$inputWrite = 0;
1190
+ this.$inputRead = 0;
1191
+ this.$outputWrite = 0;
1192
+ this.$outputRead = 0;
1193
+ this.noIFFT = false;
1194
+ this.fftInput = [];
1195
+ this.fftOutput = [];
1196
+ this.fftOverlap = 0;
1197
+ this.fftHopSize = 0;
1198
+ this.fftSize = 0;
1199
+ this.fftBufferSize = 0;
1200
+ this.fPlotHandler = null;
1201
+ this.fCachedEvents = [];
1202
+ this.fBufferNum = 0;
1203
+ this.windowFunction = null;
1204
+ this.port.onmessage = (e) => this.handleMessageAux(e);
1205
+ const { parameterDescriptors } = this.constructor;
1206
+ parameterDescriptors.forEach((pd) => {
1207
+ this.paramValuesCache[pd.name] = pd.defaultValue || 0;
1208
+ });
1209
+ const { factory, sampleSize } = options.processorOptions;
1210
+ this.dspInstance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
1211
+ this.sampleSize = sampleSize;
1212
+ this.initFFT();
1213
+ }
1214
+ get fftProcessorBufferSize() {
1215
+ return this.fftSize / 2 + 1;
1216
+ }
1217
+ async initFFT() {
1218
+ this.FFT = await getFFT();
1219
+ await this.createFFTProcessor();
1220
+ return true;
1221
+ }
1222
+ static get parameterDescriptors() {
1223
+ const params = [];
1224
+ const callback = (item) => {
1225
+ const param = analyseParameters(item);
1226
+ if (param)
1227
+ params.push(param);
1228
+ };
1229
+ FaustBaseWebAudioDsp2.parseUI(dspMeta.ui, callback);
1230
+ return [
1231
+ ...params,
1232
+ {
1233
+ defaultValue: (fftOptions == null ? void 0 : fftOptions.fftSize) || 1024,
1234
+ maxValue: 2 ** 32,
1235
+ minValue: 2,
1236
+ name: "fftSize"
1237
+ },
1238
+ {
1239
+ defaultValue: (fftOptions == null ? void 0 : fftOptions.fftOverlap) || 2,
1240
+ maxValue: 32,
1241
+ minValue: 1,
1242
+ name: "fftOverlap"
1243
+ },
1244
+ {
1245
+ defaultValue: typeof (fftOptions == null ? void 0 : fftOptions.defaultWindowFunction) === "number" ? fftOptions.defaultWindowFunction + 1 : 0,
1246
+ maxValue: (windowFunctions == null ? void 0 : windowFunctions.length) || 0,
1247
+ minValue: 0,
1248
+ name: "windowFunction"
1249
+ },
1250
+ {
1251
+ defaultValue: +!!(fftOptions == null ? void 0 : fftOptions.noIFFT) || 0,
1252
+ maxValue: 1,
1253
+ minValue: 0,
1254
+ name: "noIFFT"
1255
+ }
1256
+ ];
1257
+ }
1258
+ processFFT() {
1259
+ let samplesForFFT = mod(this.$inputWrite - this.$inputRead, this.fftBufferSize) || this.fftBufferSize;
1260
+ while (samplesForFFT >= this.fftSize) {
1261
+ let fftProcessorOutputs = [];
1262
+ this.fDSPCode.compute((inputs) => {
1263
+ for (let i = 0; i < Math.min(this.fftInput.length, Math.ceil(inputs.length / 3)); i++) {
1264
+ const ffted = this.rfft.forward((fftBuffer) => {
1265
+ setTypedArray(fftBuffer, this.fftInput[i], 0, this.$inputRead);
1266
+ for (let j = 0; j < fftBuffer.length; j++) {
1267
+ fftBuffer[j] *= this.window[j];
1268
+ }
1269
+ });
1270
+ fftToSignal(ffted, inputs[i * 3], inputs[i * 3 + 1], inputs[i * 3 + 2]);
1271
+ }
1272
+ for (let i = this.fftInput.length * 3; i < inputs.length; i++) {
1273
+ if (i % 3 === 2)
1274
+ inputs[i].forEach((v, j) => inputs[i][j] = j);
1275
+ else
1276
+ inputs[i].fill(0);
1277
+ }
1278
+ }, (outputs) => {
1279
+ fftProcessorOutputs = outputs;
1280
+ });
1281
+ this.$inputRead += this.fftHopSize;
1282
+ this.$inputRead %= this.fftBufferSize;
1283
+ samplesForFFT -= this.fftHopSize;
1284
+ for (let i = 0; i < this.fftOutput.length; i++) {
1285
+ let iffted;
1286
+ if (this.noIFFT) {
1287
+ iffted = this.noIFFTBuffer;
1288
+ signalToNoFFT(fftProcessorOutputs[i * 2] || this.fftProcessorZeros, fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros, iffted);
1289
+ } else {
1290
+ iffted = this.rfft.inverse((ifftBuffer) => {
1291
+ signalToFFT(fftProcessorOutputs[i * 2] || this.fftProcessorZeros, fftProcessorOutputs[i * 2 + 1] || this.fftProcessorZeros, ifftBuffer);
1292
+ });
1293
+ }
1294
+ for (let j = 0; j < iffted.length; j++) {
1295
+ iffted[j] *= this.window[j];
1296
+ }
1297
+ let $;
1298
+ for (let j = 0; j < iffted.length - this.fftHopSize; j++) {
1299
+ $ = mod(this.$outputWrite + j, this.fftBufferSize);
1300
+ this.fftOutput[i][$] += iffted[j];
1301
+ if (i === 0)
1302
+ this.windowSumSquare[$] += this.noIFFT ? this.window[j] : this.window[j] ** 2;
1303
+ }
1304
+ for (let j = iffted.length - this.fftHopSize; j < iffted.length; j++) {
1305
+ $ = mod(this.$outputWrite + j, this.fftBufferSize);
1306
+ this.fftOutput[i][$] = iffted[j];
1307
+ if (i === 0)
1308
+ this.windowSumSquare[$] = this.noIFFT ? this.window[j] : this.window[j] ** 2;
1309
+ }
1310
+ }
1311
+ this.$outputWrite += this.fftHopSize;
1312
+ this.$outputWrite %= this.fftBufferSize;
1313
+ }
1314
+ }
1315
+ process(inputs, outputs, parameters) {
1316
+ if (this.destroyed)
1317
+ return false;
1318
+ if (!this.FFT)
1319
+ return true;
1320
+ const input = inputs[0];
1321
+ const output = outputs[0];
1322
+ const inputChannels = (input == null ? void 0 : input.length) || 0;
1323
+ const outputChannels = (output == null ? void 0 : output.length) || 0;
1324
+ const bufferSize = (input == null ? void 0 : input.length) ? Math.max(...input.map((c) => c.length)) || 128 : 128;
1325
+ this.noIFFT = !!parameters.noIFFT[0];
1326
+ this.resetFFT(~~parameters.fftSize[0], ~~parameters.fftOverlap[0], ~~parameters.windowFunction[0], inputChannels, outputChannels, bufferSize);
1327
+ if (!this.fDSPCode)
1328
+ return true;
1329
+ for (const path in parameters) {
1330
+ if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
1331
+ continue;
1332
+ const [paramValue] = parameters[path];
1333
+ if (paramValue !== this.paramValuesCache[path]) {
1334
+ this.fDSPCode.setParamValue(path, paramValue);
1335
+ this.paramValuesCache[path] = paramValue;
1336
+ }
1337
+ }
1338
+ if (input == null ? void 0 : input.length) {
1339
+ let $inputWrite = 0;
1340
+ for (let i = 0; i < input.length; i++) {
1341
+ const inputWindow = this.fftInput[i];
1342
+ const channel = input[i].length ? input[i] : new Float32Array(bufferSize);
1343
+ $inputWrite = setTypedArray(inputWindow, channel, this.$inputWrite);
1344
+ }
1345
+ this.$inputWrite = $inputWrite;
1346
+ } else {
1347
+ this.$inputWrite += bufferSize;
1348
+ this.$inputWrite %= this.fftBufferSize;
1349
+ }
1350
+ this.processFFT();
1351
+ for (let i = 0; i < output.length; i++) {
1352
+ setTypedArray(output[i], this.fftOutput[i], 0, this.$outputRead);
1353
+ let div = 0;
1354
+ for (let j = 0; j < bufferSize; j++) {
1355
+ div = this.windowSumSquare[mod(this.$outputRead + j, this.fftBufferSize)];
1356
+ output[i][j] /= div < 1e-8 ? 1 : div;
1357
+ }
1358
+ }
1359
+ this.$outputRead += bufferSize;
1360
+ this.$outputRead %= this.fftBufferSize;
1361
+ if (this.fPlotHandler) {
1362
+ this.port.postMessage({ type: "plot", value: output, index: this.fBufferNum++, events: this.fCachedEvents });
1363
+ this.fCachedEvents = [];
1364
+ }
1365
+ return true;
1366
+ }
1367
+ handleMessageAux(e) {
1368
+ var _a, _b, _c;
1369
+ const msg = e.data;
1370
+ switch (msg.type) {
1371
+ case "midi":
1372
+ this.midiMessage(msg.data);
1373
+ break;
1374
+ case "ctrlChange":
1375
+ this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
1376
+ break;
1377
+ case "pitchWheel":
1378
+ this.pitchWheel(msg.data[0], msg.data[1]);
1379
+ break;
1380
+ case "param":
1381
+ this.setParamValue(msg.data.path, msg.data.value);
1382
+ break;
1383
+ case "setPlotHandler": {
1384
+ if (msg.data) {
1385
+ this.fPlotHandler = (output, index, events) => {
1386
+ if (events)
1387
+ this.fCachedEvents.push(...events);
1388
+ };
1389
+ } else {
1390
+ this.fPlotHandler = null;
1391
+ }
1392
+ (_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
1393
+ break;
1394
+ }
1395
+ case "start": {
1396
+ (_b = this.fDSPCode) == null ? void 0 : _b.start();
1397
+ break;
1398
+ }
1399
+ case "stop": {
1400
+ (_c = this.fDSPCode) == null ? void 0 : _c.stop();
1401
+ break;
1402
+ }
1403
+ case "destroy": {
1404
+ this.port.close();
1405
+ this.destroy();
1406
+ break;
1407
+ }
1408
+ default:
1409
+ break;
1410
+ }
1411
+ }
1412
+ setParamValue(path, value) {
1413
+ var _a;
1414
+ (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(path, value);
1415
+ this.paramValuesCache[path] = value;
1416
+ }
1417
+ midiMessage(data) {
1418
+ var _a;
1419
+ (_a = this.fDSPCode) == null ? void 0 : _a.midiMessage(data);
1420
+ }
1421
+ ctrlChange(channel, ctrl, value) {
1422
+ var _a;
1423
+ (_a = this.fDSPCode) == null ? void 0 : _a.ctrlChange(channel, ctrl, value);
1424
+ }
1425
+ pitchWheel(channel, wheel) {
1426
+ var _a;
1427
+ (_a = this.fDSPCode) == null ? void 0 : _a.pitchWheel(channel, wheel);
1428
+ }
1429
+ resetFFT(sizeIn, overlapIn, windowFunctionIn, inputChannels, outputChannels, bufferSize) {
1430
+ var _a, _b;
1431
+ const fftSize = ~~ceil(Math.max(2, sizeIn || 1024), 2);
1432
+ const fftOverlap = ~~Math.min(fftSize, Math.max(1, overlapIn));
1433
+ const fftHopSize = ~~Math.max(1, fftSize / fftOverlap);
1434
+ const latency = fftSize - Math.min(fftHopSize, bufferSize);
1435
+ let windowFunction = null;
1436
+ if (windowFunctionIn !== 0) {
1437
+ windowFunction = typeof windowFunctions === "object" ? windowFunctions[~~windowFunctionIn - 1] || null : null;
1438
+ }
1439
+ const fftSizeChanged = fftSize !== this.fftSize;
1440
+ const fftOverlapChanged = fftOverlap !== this.fftOverlap;
1441
+ if (fftSizeChanged || fftOverlapChanged) {
1442
+ this.fftSize = fftSize;
1443
+ this.fftOverlap = fftOverlap;
1444
+ this.fftHopSize = fftHopSize;
1445
+ this.$inputWrite = 0;
1446
+ this.$inputRead = 0;
1447
+ this.$outputWrite = 0;
1448
+ this.$outputRead = -latency;
1449
+ this.fftBufferSize = Math.max(fftSize * 2 - this.fftHopSize, bufferSize * 2);
1450
+ if (!fftSizeChanged && this.fftHopSizeParam)
1451
+ (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(this.fftHopSizeParam, this.fftHopSize);
1452
+ }
1453
+ if (fftSizeChanged) {
1454
+ (_b = this.rfft) == null ? void 0 : _b.dispose();
1455
+ this.rfft = new this.FFT(fftSize);
1456
+ this.noIFFTBuffer = new Float32Array(this.fftSize);
1457
+ this.createFFTProcessor();
1458
+ }
1459
+ if (fftSizeChanged || fftOverlapChanged || windowFunction !== this.windowFunction) {
1460
+ this.windowFunction = windowFunction;
1461
+ this.window = new Float32Array(fftSize);
1462
+ this.window.fill(1);
1463
+ if (windowFunction)
1464
+ apply(this.window, windowFunction);
1465
+ this.windowSumSquare = new Float32Array(this.fftBufferSize);
1466
+ }
1467
+ if (this.fftInput.length > inputChannels) {
1468
+ this.fftInput.splice(inputChannels);
1469
+ }
1470
+ if (this.fftOutput.length > outputChannels) {
1471
+ this.fftOutput.splice(outputChannels);
1472
+ }
1473
+ if (fftSizeChanged || fftOverlapChanged) {
1474
+ for (let i = 0; i < inputChannels; i++) {
1475
+ this.fftInput[i] = new Float32Array(this.fftBufferSize);
1476
+ }
1477
+ for (let i = 0; i < outputChannels; i++) {
1478
+ this.fftOutput[i] = new Float32Array(this.fftBufferSize);
1479
+ }
1480
+ } else {
1481
+ if (this.fftInput.length < inputChannels) {
1482
+ for (let i = this.fftInput.length; i < inputChannels; i++) {
1483
+ this.fftInput[i] = new Float32Array(this.fftBufferSize);
1484
+ }
1485
+ }
1486
+ if (this.fftOutput.length < outputChannels) {
1487
+ for (let i = this.fftOutput.length; i < outputChannels; i++) {
1488
+ this.fftOutput[i] = new Float32Array(this.fftBufferSize);
1489
+ }
1490
+ }
1491
+ }
1492
+ }
1493
+ async createFFTProcessor() {
1494
+ var _a, _b;
1495
+ (_a = this.fDSPCode) == null ? void 0 : _a.stop();
1496
+ (_b = this.fDSPCode) == null ? void 0 : _b.destroy();
1497
+ this.fDSPCode = new FaustMonoWebAudioDsp2(this.dspInstance, sampleRate, this.sampleSize, this.fftProcessorBufferSize);
1498
+ this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
1499
+ this.fDSPCode.setPlotHandler(this.fPlotHandler);
1500
+ const params = this.fDSPCode.getParams();
1501
+ this.fDSPCode.start();
1502
+ for (const path in this.paramValuesCache) {
1503
+ if (!!fftParamKeywords.find((k) => `/${path}`.endsWith(k)))
1504
+ continue;
1505
+ this.fDSPCode.setParamValue(path, this.paramValuesCache[path]);
1506
+ }
1507
+ const fftSizeParam = params.find((s) => s.endsWith("/fftSize"));
1508
+ if (fftSizeParam)
1509
+ this.fDSPCode.setParamValue(fftSizeParam, this.fftSize);
1510
+ this.fftHopSizeParam = params.find((s) => s.endsWith("/fftHopSize"));
1511
+ if (this.fftHopSizeParam)
1512
+ this.fDSPCode.setParamValue(this.fftHopSizeParam, this.fftHopSize);
1513
+ this.fftProcessorZeros = new Float32Array(this.fftProcessorBufferSize);
1514
+ }
1515
+ destroy() {
1516
+ var _a, _b, _c;
1517
+ (_a = this.fDSPCode) == null ? void 0 : _a.stop();
1518
+ (_b = this.fDSPCode) == null ? void 0 : _b.destroy();
1519
+ (_c = this.rfft) == null ? void 0 : _c.dispose();
1520
+ this.destroyed = true;
1521
+ }
1522
+ }
1523
+ const Processor = FaustFFTAudioWorkletProcessor;
1524
+ if (register) {
1525
+ try {
1526
+ registerProcessor(processorName || dspName || "myfftdsp", Processor);
1527
+ } catch (error) {
1528
+ console.warn(error);
1529
+ }
1530
+ }
1531
+ return FaustFFTAudioWorkletProcessor;
1532
+ };
1533
+ var FaustFFTAudioWorkletProcessor_default = getFaustFFTAudioWorkletProcessor;
1534
+
1535
+ // src/FaustCompiler.ts
1536
+ var import_sha256_js = __toESM(require_build2(), 1);
1537
+ var ab2str = (buf) => String.fromCharCode.apply(null, buf);
1538
+ var str2ab = (str) => {
1539
+ const buf = new ArrayBuffer(str.length);
1540
+ const bufView = new Uint8Array(buf);
1541
+ for (let i = 0, strLen = str.length; i < strLen; i++) {
1542
+ bufView[i] = str.charCodeAt(i);
1543
+ }
1544
+ return bufView;
1545
+ };
1546
+ var sha256 = async (str) => {
1547
+ const sha2562 = new import_sha256_js.Sha256();
1548
+ sha2562.update(str);
1549
+ const hashArray = Array.from(await sha2562.digest());
1550
+ const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
1551
+ return hashHex;
1552
+ };
1553
+ var _FaustCompiler = class {
1554
+ static serializeDSPFactories() {
1555
+ const table = {};
1556
+ this.gFactories.forEach((factory, shaKey) => {
1557
+ const { code, json, poly } = factory;
1558
+ table[shaKey] = { code: btoa(ab2str(code)), json: JSON.parse(json), poly };
1559
+ });
1560
+ return table;
1561
+ }
1562
+ static stringifyDSPFactories() {
1563
+ return JSON.stringify(this.serializeDSPFactories());
1564
+ }
1565
+ static deserializeDSPFactories(table) {
1566
+ const awaited = [];
1567
+ for (const shaKey in table) {
1568
+ const factory = table[shaKey];
1569
+ const { code, json, poly } = factory;
1570
+ const ab = str2ab(atob(code));
1571
+ awaited.push(WebAssembly.compile(ab).then((module) => this.gFactories.set(shaKey, { shaKey, cfactory: 0, code: ab, module, json: JSON.stringify(json), poly })));
1572
+ }
1573
+ return Promise.all(awaited);
1574
+ }
1575
+ static importDSPFactories(tableStr) {
1576
+ const table = JSON.parse(tableStr);
1577
+ return this.deserializeDSPFactories(table);
1578
+ }
1579
+ constructor(libFaust) {
1580
+ this.fLibFaust = libFaust;
1581
+ this.fErrorMessage = "";
1582
+ }
1583
+ intVec2intArray(vec) {
1584
+ const size = vec.size();
1585
+ const ui8Code = new Uint8Array(size);
1586
+ for (let i = 0; i < size; i++) {
1587
+ ui8Code[i] = vec.get(i);
1588
+ }
1589
+ return ui8Code;
1590
+ }
1591
+ async createDSPFactory(name, code, args, poly) {
1592
+ if (_FaustCompiler.gFactories.size > 10) {
1593
+ _FaustCompiler.gFactories.clear();
1594
+ }
1595
+ let shaKey = await sha256(name + code + args + (poly ? "poly" : "mono"));
1596
+ if (_FaustCompiler.gFactories.has(shaKey)) {
1597
+ return _FaustCompiler.gFactories.get(shaKey) || null;
1598
+ } else {
1599
+ try {
1600
+ const faustDspWasm = this.fLibFaust.createDSPFactory(name, code, args, !poly);
1601
+ const ui8Code = this.intVec2intArray(faustDspWasm.data);
1602
+ faustDspWasm.data.delete();
1603
+ const module = await WebAssembly.compile(ui8Code);
1604
+ const factory = { shaKey, cfactory: faustDspWasm.cfactory, code: ui8Code, module, json: faustDspWasm.json, poly };
1605
+ this.deleteDSPFactory(factory);
1606
+ _FaustCompiler.gFactories.set(shaKey, factory);
1607
+ return factory;
1608
+ } catch (e) {
1609
+ this.fErrorMessage = this.fLibFaust.getErrorAfterException();
1610
+ this.fLibFaust.cleanupAfterException();
1611
+ throw this.fErrorMessage ? new Error(this.fErrorMessage) : e;
1612
+ }
1613
+ }
1614
+ }
1615
+ version() {
1616
+ return this.fLibFaust.version();
1617
+ }
1618
+ getErrorMessage() {
1619
+ return this.fErrorMessage;
1620
+ }
1621
+ async createMonoDSPFactory(name, code, args) {
1622
+ return this.createDSPFactory(name, code, args, false);
1623
+ }
1624
+ async createPolyDSPFactory(name, code, args) {
1625
+ return this.createDSPFactory(name, code, args, true);
1626
+ }
1627
+ deleteDSPFactory(factory) {
1628
+ this.fLibFaust.deleteDSPFactory(factory.cfactory);
1629
+ factory.cfactory = 0;
1630
+ }
1631
+ expandDSP(code, args) {
1632
+ try {
1633
+ return this.fLibFaust.expandDSP("FaustDSP", code, args);
1634
+ } catch (e) {
1635
+ this.fErrorMessage = this.fLibFaust.getErrorAfterException();
1636
+ this.fLibFaust.cleanupAfterException();
1637
+ throw this.fErrorMessage ? new Error(this.fErrorMessage) : e;
1638
+ }
1639
+ }
1640
+ generateAuxFiles(name, code, args) {
1641
+ try {
1642
+ return this.fLibFaust.generateAuxFiles(name, code, args);
1643
+ } catch (e) {
1644
+ this.fErrorMessage = this.fLibFaust.getErrorAfterException();
1645
+ this.fLibFaust.cleanupAfterException();
1646
+ throw this.fErrorMessage ? new Error(this.fErrorMessage) : e;
1647
+ }
1648
+ }
1649
+ deleteAllDSPFactories() {
1650
+ this.fLibFaust.deleteAllDSPFactories();
1651
+ }
1652
+ fs() {
1653
+ return this.fLibFaust.fs();
1654
+ }
1655
+ async getAsyncInternalMixerModule(isDouble = false) {
1656
+ const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
1657
+ const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
1658
+ if (this[moduleKey])
1659
+ return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1660
+ const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
1661
+ const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
1662
+ this[bufferKey] = mixerBuffer;
1663
+ const mixerModule = await WebAssembly.compile(mixerBuffer);
1664
+ this[moduleKey] = mixerModule;
1665
+ return { mixerBuffer, mixerModule };
1666
+ }
1667
+ getSyncInternalMixerModule(isDouble = false) {
1668
+ const bufferKey = isDouble ? "mixer64Buffer" : "mixer32Buffer";
1669
+ const moduleKey = isDouble ? "mixer64Module" : "mixer32Module";
1670
+ if (this[moduleKey])
1671
+ return { mixerBuffer: this[bufferKey], mixerModule: this[moduleKey] };
1672
+ const path = isDouble ? "/usr/rsrc/mixer64.wasm" : "/usr/rsrc/mixer32.wasm";
1673
+ const mixerBuffer = this.fs().readFile(path, { encoding: "binary" });
1674
+ this[bufferKey] = mixerBuffer;
1675
+ const mixerModule = new WebAssembly.Module(mixerBuffer);
1676
+ this[moduleKey] = mixerModule;
1677
+ return { mixerBuffer, mixerModule };
1678
+ }
1679
+ };
1680
+ var FaustCompiler = _FaustCompiler;
1681
+ FaustCompiler.gFactories = /* @__PURE__ */ new Map();
1682
+ var FaustCompiler_default = FaustCompiler;
1683
+
1684
+ // src/FaustDspInstance.ts
1685
+ var FaustDspInstance = class {
1686
+ constructor(exports) {
1687
+ this.fExports = exports;
1688
+ }
1689
+ compute($dsp, count, $input, $output) {
1690
+ this.fExports.compute($dsp, count, $input, $output);
1691
+ }
1692
+ getNumInputs($dsp) {
1693
+ return this.fExports.getNumInputs($dsp);
1694
+ }
1695
+ getNumOutputs($dsp) {
1696
+ return this.fExports.getNumOutputs($dsp);
1697
+ }
1698
+ getParamValue($dsp, index) {
1699
+ return this.fExports.getParamValue($dsp, index);
1700
+ }
1701
+ getSampleRate($dsp) {
1702
+ return this.fExports.getSampleRate($dsp);
1703
+ }
1704
+ init($dsp, sampleRate) {
1705
+ this.fExports.init($dsp, sampleRate);
1706
+ }
1707
+ instanceClear($dsp) {
1708
+ this.fExports.instanceClear($dsp);
1709
+ }
1710
+ instanceConstants($dsp, sampleRate) {
1711
+ this.fExports.instanceConstants($dsp, sampleRate);
1712
+ }
1713
+ instanceInit($dsp, sampleRate) {
1714
+ this.fExports.instanceInit($dsp, sampleRate);
1715
+ }
1716
+ instanceResetUserInterface($dsp) {
1717
+ this.fExports.instanceResetUserInterface($dsp);
1718
+ }
1719
+ setParamValue($dsp, index, value) {
1720
+ this.fExports.setParamValue($dsp, index, value);
1721
+ }
1722
+ };
1723
+ var FaustDspInstance_default = FaustDspInstance;
1724
+
1725
+ // src/FaustWasmInstantiator.ts
1726
+ var FaustWasmInstantiator = class {
1727
+ static createWasmImport(memory) {
1728
+ return {
1729
+ env: {
1730
+ memory: memory || new WebAssembly.Memory({ initial: 100 }),
1731
+ memoryBase: 0,
1732
+ tableBase: 0,
1733
+ _abs: Math.abs,
1734
+ _acosf: Math.acos,
1735
+ _asinf: Math.asin,
1736
+ _atanf: Math.atan,
1737
+ _atan2f: Math.atan2,
1738
+ _ceilf: Math.ceil,
1739
+ _cosf: Math.cos,
1740
+ _expf: Math.exp,
1741
+ _floorf: Math.floor,
1742
+ _fmodf: (x, y) => x % y,
1743
+ _logf: Math.log,
1744
+ _log10f: Math.log10,
1745
+ _max_f: Math.max,
1746
+ _min_f: Math.min,
1747
+ _remainderf: (x, y) => x - Math.round(x / y) * y,
1748
+ _powf: Math.pow,
1749
+ _roundf: Math.fround,
1750
+ _sinf: Math.sin,
1751
+ _sqrtf: Math.sqrt,
1752
+ _tanf: Math.tan,
1753
+ _acoshf: Math.acosh,
1754
+ _asinhf: Math.asinh,
1755
+ _atanhf: Math.atanh,
1756
+ _coshf: Math.cosh,
1757
+ _sinhf: Math.sinh,
1758
+ _tanhf: Math.tanh,
1759
+ _isnanf: Number.isNaN,
1760
+ _isinff: (x) => !isFinite(x),
1761
+ _copysignf: (x, y) => Math.sign(x) === Math.sign(y) ? x : -x,
1762
+ _acos: Math.acos,
1763
+ _asin: Math.asin,
1764
+ _atan: Math.atan,
1765
+ _atan2: Math.atan2,
1766
+ _ceil: Math.ceil,
1767
+ _cos: Math.cos,
1768
+ _exp: Math.exp,
1769
+ _floor: Math.floor,
1770
+ _fmod: (x, y) => x % y,
1771
+ _log: Math.log,
1772
+ _log10: Math.log10,
1773
+ _max_: Math.max,
1774
+ _min_: Math.min,
1775
+ _remainder: (x, y) => x - Math.round(x / y) * y,
1776
+ _pow: Math.pow,
1777
+ _round: Math.fround,
1778
+ _sin: Math.sin,
1779
+ _sqrt: Math.sqrt,
1780
+ _tan: Math.tan,
1781
+ _acosh: Math.acosh,
1782
+ _asinh: Math.asinh,
1783
+ _atanh: Math.atanh,
1784
+ _cosh: Math.cosh,
1785
+ _sinh: Math.sinh,
1786
+ _tanh: Math.tanh,
1787
+ _isnan: Number.isNaN,
1788
+ _isinf: (x) => !isFinite(x),
1789
+ _copysign: (x, y) => Math.sign(x) === Math.sign(y) ? x : -x,
1790
+ table: new WebAssembly.Table({ initial: 0, element: "anyfunc" })
1791
+ }
1792
+ };
1793
+ }
1794
+ static createWasmMemory(voicesIn, sampleSize, dspMeta, effectMeta, bufferSize) {
1795
+ const voices = Math.max(4, voicesIn);
1796
+ const ptrSize = sampleSize;
1797
+ const pow2limit = (x) => {
1798
+ let n = 65536;
1799
+ while (n < x) {
1800
+ n *= 2;
1801
+ }
1802
+ return n;
1803
+ };
1804
+ const effectSize = effectMeta ? effectMeta.size : 0;
1805
+ let memorySize = pow2limit(effectSize + dspMeta.size * voices + (dspMeta.inputs + dspMeta.outputs * 2) * (ptrSize + bufferSize * sampleSize)) / 65536;
1806
+ memorySize = Math.max(2, memorySize);
1807
+ return new WebAssembly.Memory({ initial: memorySize, maximum: memorySize });
1808
+ }
1809
+ static createMonoDSPInstanceAux(instance, json) {
1810
+ const functions = instance.exports;
1811
+ const api = new FaustDspInstance_default(functions);
1812
+ const memory = instance.exports.memory;
1813
+ return { memory, api, json };
1814
+ }
1815
+ static createMemoryAux(voices, voiceFactory, effectFactory) {
1816
+ const voiceMeta = JSON.parse(voiceFactory.json);
1817
+ const effectMeta = effectFactory && effectFactory.json ? JSON.parse(effectFactory.json) : null;
1818
+ const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
1819
+ return this.createWasmMemory(voices, sampleSize, voiceMeta, effectMeta, 8192);
1820
+ }
1821
+ static createMixerAux(mixerModule, memory) {
1822
+ const mixerImport = {
1823
+ imports: { print: console.log },
1824
+ memory: { memory }
1825
+ };
1826
+ const mixerInstance = new WebAssembly.Instance(mixerModule, mixerImport);
1827
+ const mixerFunctions = mixerInstance.exports;
1828
+ return mixerFunctions;
1829
+ }
1830
+ static async loadDSPFactory(wasmPath, jsonPath) {
1831
+ const wasmFile = await fetch(wasmPath);
1832
+ if (!wasmFile.ok) {
1833
+ throw new Error(`=> exception raised while running loadDSPFactory, file not found: ${wasmPath}`);
1834
+ }
1835
+ try {
1836
+ const wasmBuffer = await wasmFile.arrayBuffer();
1837
+ const module = await WebAssembly.compile(wasmBuffer);
1838
+ const jsonFile = await fetch(jsonPath);
1839
+ const json = await jsonFile.text();
1840
+ const meta = JSON.parse(json);
1841
+ const cOptions = meta.compile_options;
1842
+ const poly = cOptions.indexOf("wasm-e") !== -1;
1843
+ return { cfactory: 0, code: new Uint8Array(wasmBuffer), module, json, poly };
1844
+ } catch (e) {
1845
+ throw e;
1846
+ }
1847
+ }
1848
+ static async loadDSPMixer(mixerPath, fs) {
1849
+ try {
1850
+ let mixerBuffer = null;
1851
+ if (fs) {
1852
+ mixerBuffer = fs.readFile(mixerPath, { encoding: "binary" });
1853
+ } else {
1854
+ const mixerFile = await fetch(mixerPath);
1855
+ mixerBuffer = await mixerFile.arrayBuffer();
1856
+ }
1857
+ return WebAssembly.compile(mixerBuffer);
1858
+ } catch (e) {
1859
+ throw e;
1860
+ }
1861
+ }
1862
+ static async createAsyncMonoDSPInstance(factory) {
1863
+ const instance = await WebAssembly.instantiate(factory.module, this.createWasmImport());
1864
+ return this.createMonoDSPInstanceAux(instance, factory.json);
1865
+ }
1866
+ static createSyncMonoDSPInstance(factory) {
1867
+ const instance = new WebAssembly.Instance(factory.module, this.createWasmImport());
1868
+ return this.createMonoDSPInstanceAux(instance, factory.json);
1869
+ }
1870
+ static async createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory) {
1871
+ const memory = this.createMemoryAux(voices, voiceFactory, effectFactory);
1872
+ const voiceInstance = await WebAssembly.instantiate(voiceFactory.module, this.createWasmImport(memory));
1873
+ const voiceFunctions = voiceInstance.exports;
1874
+ const voiceAPI = new FaustDspInstance_default(voiceFunctions);
1875
+ const mixerAPI = this.createMixerAux(mixerModule, memory);
1876
+ if (effectFactory) {
1877
+ const effectInstance = await WebAssembly.instantiate(effectFactory.module, this.createWasmImport(memory));
1878
+ const effectFunctions = effectInstance.exports;
1879
+ const effectAPI = new FaustDspInstance_default(effectFunctions);
1880
+ return {
1881
+ memory,
1882
+ voices,
1883
+ voiceAPI,
1884
+ effectAPI,
1885
+ mixerAPI,
1886
+ voiceJSON: voiceFactory.json,
1887
+ effectJSON: effectFactory.json
1888
+ };
1889
+ } else {
1890
+ return {
1891
+ memory,
1892
+ voices,
1893
+ voiceAPI,
1894
+ mixerAPI,
1895
+ voiceJSON: voiceFactory.json
1896
+ };
1897
+ }
1898
+ }
1899
+ static createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory) {
1900
+ const memory = this.createMemoryAux(voices, voiceFactory, effectFactory);
1901
+ const voiceInstance = new WebAssembly.Instance(voiceFactory.module, this.createWasmImport(memory));
1902
+ const voiceFunctions = voiceInstance.exports;
1903
+ const voiceAPI = new FaustDspInstance_default(voiceFunctions);
1904
+ const mixerAPI = this.createMixerAux(mixerModule, memory);
1905
+ if (effectFactory) {
1906
+ const effectInstance = new WebAssembly.Instance(effectFactory.module, this.createWasmImport(memory));
1907
+ const effectFunctions = effectInstance.exports;
1908
+ const effectAPI = new FaustDspInstance_default(effectFunctions);
1909
+ return {
1910
+ memory,
1911
+ voices,
1912
+ voiceAPI,
1913
+ effectAPI,
1914
+ mixerAPI,
1915
+ voiceJSON: voiceFactory.json,
1916
+ effectJSON: effectFactory.json
1917
+ };
1918
+ } else {
1919
+ return {
1920
+ memory,
1921
+ voices,
1922
+ voiceAPI,
1923
+ mixerAPI,
1924
+ voiceJSON: voiceFactory.json
1925
+ };
1926
+ }
1927
+ }
1928
+ };
1929
+ var FaustWasmInstantiator_default = FaustWasmInstantiator;
1930
+
1931
+ // src/FaustWebAudioDsp.ts
1932
+ var FaustBaseWebAudioDsp = class {
1933
+ constructor(sampleSize, bufferSize) {
1934
+ this.fOutputHandler = null;
1935
+ this.fComputeHandler = null;
1936
+ this.fCachedEvents = [];
1937
+ this.fBufferNum = 0;
1938
+ this.fPlotHandler = null;
1939
+ this.fBufferSize = bufferSize;
1940
+ this.fInChannels = [];
1941
+ this.fOutChannels = [];
1942
+ this.gPtrSize = sampleSize;
1943
+ this.gSampleSize = sampleSize;
1944
+ this.fOutputsTimer = 5;
1945
+ this.fInputsItems = [];
1946
+ this.fOutputsItems = [];
1947
+ this.fDescriptor = [];
1948
+ this.fPitchwheelLabel = [];
1949
+ this.fCtrlLabel = new Array(128).fill(null).map(() => []);
1950
+ this.fPathTable = {};
1951
+ this.fProcessing = false;
1952
+ this.fDestroyed = false;
1953
+ this.fUICallback = (item) => {
1954
+ if (item.type === "hbargraph" || item.type === "vbargraph") {
1955
+ this.fOutputsItems.push(item.address);
1956
+ this.fPathTable[item.address] = item.index;
1957
+ } else if (item.type === "vslider" || item.type === "hslider" || item.type === "button" || item.type === "checkbox" || item.type === "nentry") {
1958
+ this.fInputsItems.push(item.address);
1959
+ this.fPathTable[item.address] = item.index;
1960
+ this.fDescriptor.push(item);
1961
+ if (!item.meta)
1962
+ return;
1963
+ item.meta.forEach((meta) => {
1964
+ const { midi } = meta;
1965
+ if (!midi)
1966
+ return;
1967
+ const strMidi = midi.trim();
1968
+ if (strMidi === "pitchwheel") {
1969
+ this.fPitchwheelLabel.push({ path: item.address, min: item.min, max: item.max });
1970
+ } else {
1971
+ const matched = strMidi.match(/^ctrl\s(\d+)/);
1972
+ if (!matched)
1973
+ return;
1974
+ this.fCtrlLabel[parseInt(matched[1])].push({ path: item.address, min: item.min, max: item.max });
1975
+ }
1976
+ });
1977
+ }
1978
+ };
1979
+ }
1980
+ static remap(v, mn0, mx0, mn1, mx1) {
1981
+ return (v - mn0) / (mx0 - mn0) * (mx1 - mn1) + mn1;
1982
+ }
1983
+ static parseUI(ui, callback) {
1984
+ ui.forEach((group) => this.parseGroup(group, callback));
1985
+ }
1986
+ static parseGroup(group, callback) {
1987
+ if (group.items) {
1988
+ this.parseItems(group.items, callback);
1989
+ }
1990
+ }
1991
+ static parseItems(items, callback) {
1992
+ items.forEach((item) => this.parseItem(item, callback));
1993
+ }
1994
+ static parseItem(item, callback) {
1995
+ if (item.type === "vgroup" || item.type === "hgroup" || item.type === "tgroup") {
1996
+ this.parseItems(item.items, callback);
1997
+ } else {
1998
+ callback(item);
1999
+ }
2000
+ }
2001
+ updateOutputs() {
2002
+ if (this.fOutputsItems.length > 0 && this.fOutputHandler && this.fOutputsTimer-- === 0) {
2003
+ this.fOutputsTimer = 5;
2004
+ this.fOutputsItems.forEach((item) => {
2005
+ var _a;
2006
+ return (_a = this.fOutputHandler) == null ? void 0 : _a.call(this, item, this.getParamValue(item));
2007
+ });
2008
+ }
2009
+ }
2010
+ metadata(handler) {
2011
+ if (this.fJSONDsp.meta) {
2012
+ this.fJSONDsp.meta.forEach((meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]]));
2013
+ }
2014
+ }
2015
+ compute(input, output) {
2016
+ return false;
2017
+ }
2018
+ setOutputParamHandler(handler) {
2019
+ this.fOutputHandler = handler;
2020
+ }
2021
+ getOutputParamHandler() {
2022
+ return this.fOutputHandler;
2023
+ }
2024
+ setComputeHandler(handler) {
2025
+ this.fComputeHandler = handler;
2026
+ }
2027
+ getComputeHandler() {
2028
+ return this.fComputeHandler;
2029
+ }
2030
+ setPlotHandler(handler) {
2031
+ this.fPlotHandler = handler;
2032
+ }
2033
+ getPlotHandler() {
2034
+ return this.fPlotHandler;
2035
+ }
2036
+ getNumInputs() {
2037
+ return -1;
2038
+ }
2039
+ getNumOutputs() {
2040
+ return -1;
2041
+ }
2042
+ midiMessage(data) {
2043
+ if (this.fPlotHandler)
2044
+ this.fCachedEvents.push({ data, type: "midi" });
2045
+ const cmd = data[0] >> 4;
2046
+ const channel = data[0] & 15;
2047
+ const data1 = data[1];
2048
+ const data2 = data[2];
2049
+ if (cmd === 11)
2050
+ return this.ctrlChange(channel, data1, data2);
2051
+ if (cmd === 14)
2052
+ return this.pitchWheel(channel, data2 * 128 + data1);
2053
+ }
2054
+ ctrlChange(channel, ctrl, value) {
2055
+ if (this.fPlotHandler)
2056
+ this.fCachedEvents.push({ type: "ctrlChange", data: [channel, ctrl, value] });
2057
+ if (this.fCtrlLabel[ctrl].length) {
2058
+ this.fCtrlLabel[ctrl].forEach((ctrl2) => {
2059
+ const { path } = ctrl2;
2060
+ this.setParamValue(path, FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
2061
+ if (this.fOutputHandler)
2062
+ this.fOutputHandler(path, this.getParamValue(path));
2063
+ });
2064
+ }
2065
+ }
2066
+ pitchWheel(channel, wheel) {
2067
+ if (this.fPlotHandler)
2068
+ this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
2069
+ this.fPitchwheelLabel.forEach((pw) => {
2070
+ this.setParamValue(pw.path, FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
2071
+ if (this.fOutputHandler)
2072
+ this.fOutputHandler(pw.path, this.getParamValue(pw.path));
2073
+ });
2074
+ }
2075
+ setParamValue(path, value) {
2076
+ }
2077
+ getParamValue(path) {
2078
+ return 0;
2079
+ }
2080
+ getParams() {
2081
+ return this.fInputsItems;
2082
+ }
2083
+ getMeta() {
2084
+ return this.fJSONDsp;
2085
+ }
2086
+ getJSON() {
2087
+ return JSON.stringify(this.getMeta());
2088
+ }
2089
+ getUI() {
2090
+ return this.fJSONDsp.ui;
2091
+ }
2092
+ getDescriptors() {
2093
+ return this.fDescriptor;
2094
+ }
2095
+ start() {
2096
+ this.fProcessing = true;
2097
+ }
2098
+ stop() {
2099
+ this.fProcessing = false;
2100
+ }
2101
+ destroy() {
2102
+ this.fDestroyed = true;
2103
+ this.fOutputHandler = null;
2104
+ this.fComputeHandler = null;
2105
+ this.fPlotHandler = null;
2106
+ }
2107
+ };
2108
+ var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
2109
+ constructor(instance, sampleRate, sampleSize, bufferSize) {
2110
+ super(sampleSize, bufferSize);
2111
+ this.fInstance = instance;
2112
+ this.fJSONDsp = JSON.parse(this.fInstance.json);
2113
+ FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
2114
+ this.initMemory();
2115
+ this.fInstance.api.init(this.fDSP, sampleRate);
2116
+ }
2117
+ initMemory() {
2118
+ this.fDSP = 0;
2119
+ const $audio = this.fJSONDsp.size;
2120
+ this.fAudioInputs = $audio;
2121
+ this.fAudioOutputs = this.fAudioInputs + this.getNumInputs() * this.gPtrSize;
2122
+ const $audioInputs = this.fAudioOutputs + this.getNumOutputs() * this.gPtrSize;
2123
+ const $audioOutputs = $audioInputs + this.getNumInputs() * this.fBufferSize * this.gSampleSize;
2124
+ const HEAP = this.fInstance.memory.buffer;
2125
+ const HEAP32 = new Int32Array(HEAP);
2126
+ const HEAPF = this.gSampleSize === 4 ? new Float32Array(HEAP) : new Float64Array(HEAP);
2127
+ if (this.getNumInputs() > 0) {
2128
+ for (let chan = 0; chan < this.getNumInputs(); chan++) {
2129
+ HEAP32[(this.fAudioInputs >> 2) + chan] = $audioInputs + this.fBufferSize * this.gSampleSize * chan;
2130
+ }
2131
+ const dspInChans = HEAP32.subarray(this.fAudioInputs >> 2, this.fAudioInputs + this.getNumInputs() * this.gPtrSize >> 2);
2132
+ for (let chan = 0; chan < this.getNumInputs(); chan++) {
2133
+ this.fInChannels[chan] = HEAPF.subarray(dspInChans[chan] >> Math.log2(this.gSampleSize), dspInChans[chan] + this.fBufferSize * this.gSampleSize >> Math.log2(this.gSampleSize));
2134
+ }
2135
+ }
2136
+ if (this.getNumOutputs() > 0) {
2137
+ for (let chan = 0; chan < this.getNumOutputs(); chan++) {
2138
+ HEAP32[(this.fAudioOutputs >> 2) + chan] = $audioOutputs + this.fBufferSize * this.gSampleSize * chan;
2139
+ }
2140
+ const dspOutChans = HEAP32.subarray(this.fAudioOutputs >> 2, this.fAudioOutputs + this.getNumOutputs() * this.gPtrSize >> 2);
2141
+ for (let chan = 0; chan < this.getNumOutputs(); chan++) {
2142
+ this.fOutChannels[chan] = HEAPF.subarray(dspOutChans[chan] >> Math.log2(this.gSampleSize), dspOutChans[chan] + this.fBufferSize * this.gSampleSize >> Math.log2(this.gSampleSize));
2143
+ }
2144
+ }
2145
+ }
2146
+ toString() {
2147
+ return `============== Mono Memory layout ==============
2148
+ this.fBufferSize: ${this.fBufferSize}
2149
+ this.fJSONDsp.size: ${this.fJSONDsp.size}
2150
+ this.fAudioInputs: ${this.fAudioInputs}
2151
+ this.fAudioOutputs: ${this.fAudioOutputs}
2152
+ this.fDSP: ${this.fDSP}`;
2153
+ }
2154
+ compute(input, output) {
2155
+ if (this.fDestroyed)
2156
+ return false;
2157
+ if (!this.fProcessing)
2158
+ return true;
2159
+ if (typeof input === "function") {
2160
+ input(this.fInChannels);
2161
+ } else {
2162
+ if (this.getNumInputs() > 0 && (!input || !input[0] || input[0].length === 0)) {
2163
+ return true;
2164
+ }
2165
+ if (this.getNumOutputs() > 0 && typeof output !== "function" && (!output || !output[0] || output[0].length === 0)) {
2166
+ return true;
2167
+ }
2168
+ if (input !== void 0) {
2169
+ for (let chan = 0; chan < Math.min(this.getNumInputs(), input.length); chan++) {
2170
+ const dspInput = this.fInChannels[chan];
2171
+ dspInput.set(input[chan]);
2172
+ }
2173
+ }
2174
+ }
2175
+ if (this.fComputeHandler)
2176
+ this.fComputeHandler(this.fBufferSize);
2177
+ this.fInstance.api.compute(this.fDSP, this.fBufferSize, this.fAudioInputs, this.fAudioOutputs);
2178
+ this.updateOutputs();
2179
+ let forPlot = this.fOutChannels;
2180
+ if (typeof output === "function") {
2181
+ output(this.fOutChannels);
2182
+ } else {
2183
+ for (let chan = 0; chan < Math.min(this.getNumOutputs(), output.length); chan++) {
2184
+ const dspOutput = this.fOutChannels[chan];
2185
+ output[chan].set(dspOutput);
2186
+ }
2187
+ forPlot = output;
2188
+ }
2189
+ if (this.fPlotHandler) {
2190
+ this.fPlotHandler(forPlot, this.fBufferNum++, this.fCachedEvents.length ? this.fCachedEvents : void 0);
2191
+ this.fCachedEvents = [];
2192
+ }
2193
+ return true;
2194
+ }
2195
+ metadata(handler) {
2196
+ super.metadata(handler);
2197
+ }
2198
+ getNumInputs() {
2199
+ return this.fInstance.api.getNumInputs(this.fDSP);
2200
+ }
2201
+ getNumOutputs() {
2202
+ return this.fInstance.api.getNumOutputs(this.fDSP);
2203
+ }
2204
+ setParamValue(path, value) {
2205
+ if (this.fPlotHandler)
2206
+ this.fCachedEvents.push({ type: "param", data: { path, value } });
2207
+ this.fInstance.api.setParamValue(this.fDSP, this.fPathTable[path], value);
2208
+ }
2209
+ getParamValue(path) {
2210
+ return this.fInstance.api.getParamValue(this.fDSP, this.fPathTable[path]);
2211
+ }
2212
+ getMeta() {
2213
+ return this.fJSONDsp;
2214
+ }
2215
+ getJSON() {
2216
+ return this.fInstance.json;
2217
+ }
2218
+ getDescriptors() {
2219
+ return this.fDescriptor;
2220
+ }
2221
+ getUI() {
2222
+ return this.fJSONDsp.ui;
2223
+ }
2224
+ };
2225
+ var FaustWebAudioDspVoice = class {
2226
+ constructor($dsp, api, inputItems, pathTable, sampleRate) {
2227
+ FaustWebAudioDspVoice.kActiveVoice = 0;
2228
+ FaustWebAudioDspVoice.kFreeVoice = -1;
2229
+ FaustWebAudioDspVoice.kReleaseVoice = -2;
2230
+ FaustWebAudioDspVoice.kLegatoVoice = -3;
2231
+ FaustWebAudioDspVoice.kNoVoice = -4;
2232
+ FaustWebAudioDspVoice.VOICE_STOP_LEVEL = 5e-4;
2233
+ this.fCurNote = FaustWebAudioDspVoice.kFreeVoice;
2234
+ this.fNextNote = this.fNextVel = -1;
2235
+ this.fLevel = 0;
2236
+ this.fDate = this.fRelease = 0;
2237
+ this.fDSP = $dsp;
2238
+ this.fAPI = api;
2239
+ this.fGateLabel = [];
2240
+ this.fGainLabel = [];
2241
+ this.fFreqLabel = [];
2242
+ this.fKeyLabel = [];
2243
+ this.fVelLabel = [];
2244
+ this.fAPI.init(this.fDSP, sampleRate);
2245
+ this.extractPaths(inputItems, pathTable);
2246
+ }
2247
+ static midiToFreq(note) {
2248
+ return 440 * 2 ** ((note - 69) / 12);
2249
+ }
2250
+ static normalizeVelocity(velocity) {
2251
+ return velocity / 127;
2252
+ }
2253
+ extractPaths(inputItems, pathTable) {
2254
+ inputItems.forEach((item) => {
2255
+ if (item.endsWith("/gate")) {
2256
+ this.fGateLabel.push(pathTable[item]);
2257
+ } else if (item.endsWith("/freq")) {
2258
+ this.fFreqLabel.push(pathTable[item]);
2259
+ } else if (item.endsWith("/key")) {
2260
+ this.fKeyLabel.push(pathTable[item]);
2261
+ } else if (item.endsWith("/gain")) {
2262
+ this.fGainLabel.push(pathTable[item]);
2263
+ } else if (item.endsWith("/vel") && item.endsWith("/velocity")) {
2264
+ this.fVelLabel.push(pathTable[item]);
2265
+ }
2266
+ });
2267
+ }
2268
+ keyOn(pitch, velocity, legato = false) {
2269
+ if (legato) {
2270
+ this.fNextNote = pitch;
2271
+ this.fNextVel = velocity;
2272
+ } else {
2273
+ this.fFreqLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, FaustWebAudioDspVoice.midiToFreq(pitch)));
2274
+ this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 1));
2275
+ this.fGainLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, FaustWebAudioDspVoice.normalizeVelocity(velocity)));
2276
+ this.fKeyLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, pitch));
2277
+ this.fVelLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, velocity));
2278
+ this.fCurNote = pitch;
2279
+ }
2280
+ }
2281
+ keyOff(hard = false) {
2282
+ this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 0));
2283
+ if (hard) {
2284
+ this.fCurNote = FaustWebAudioDspVoice.kFreeVoice;
2285
+ } else {
2286
+ this.fRelease = this.fAPI.getSampleRate(this.fDSP) / 2;
2287
+ this.fCurNote = FaustWebAudioDspVoice.kReleaseVoice;
2288
+ }
2289
+ }
2290
+ computeLegato(bufferSize, $inputs, $outputZero, $outputsHalf) {
2291
+ let size = bufferSize / 2;
2292
+ this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 0));
2293
+ this.fAPI.compute(this.fDSP, size, $inputs, $outputZero);
2294
+ this.keyOn(this.fNextNote, this.fNextVel);
2295
+ this.fAPI.compute(this.fDSP, size, $inputs, $outputsHalf);
2296
+ }
2297
+ compute(bufferSize, $inputs, $outputs) {
2298
+ this.fAPI.compute(this.fDSP, bufferSize, $inputs, $outputs);
2299
+ }
2300
+ setParamValue(index, value) {
2301
+ this.fAPI.setParamValue(this.fDSP, index, value);
2302
+ }
2303
+ getParamValue(index) {
2304
+ return this.fAPI.getParamValue(this.fDSP, index);
2305
+ }
2306
+ };
2307
+ var FaustPolyWebAudioDsp = class extends FaustBaseWebAudioDsp {
2308
+ constructor(instance, sampleRate, sampleSize, bufferSize) {
2309
+ super(sampleSize, bufferSize);
2310
+ this.fInstance = instance;
2311
+ this.fJSONDsp = JSON.parse(this.fInstance.voiceJSON);
2312
+ this.fJSONEffect = this.fInstance.effectAPI && this.fInstance.effectJSON ? JSON.parse(this.fInstance.effectJSON) : null;
2313
+ FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
2314
+ if (this.fJSONEffect)
2315
+ FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
2316
+ this.initMemory();
2317
+ this.fVoiceTable = [];
2318
+ for (let voice = 0; voice < this.fInstance.voices; voice++) {
2319
+ this.fVoiceTable.push(new FaustWebAudioDspVoice(this.fJSONDsp.size * voice, this.fInstance.voiceAPI, this.fInputsItems, this.fPathTable, sampleRate));
2320
+ }
2321
+ if (this.fInstance.effectAPI)
2322
+ this.fInstance.effectAPI.init(this.fEffect, sampleRate);
2323
+ }
2324
+ initMemory() {
2325
+ this.fEffect = this.fJSONDsp.size * this.fInstance.voices;
2326
+ const $audio = this.fEffect + (this.fJSONEffect ? this.fJSONEffect.size : 0);
2327
+ this.fAudioInputs = $audio;
2328
+ this.fAudioOutputs = this.fAudioInputs + this.getNumInputs() * this.gPtrSize;
2329
+ this.fAudioMixing = this.fAudioOutputs + this.getNumOutputs() * this.gPtrSize;
2330
+ this.fAudioMixingHalf = this.fAudioMixing + this.getNumOutputs() * this.gPtrSize;
2331
+ const $audioInputs = this.fAudioMixingHalf + this.getNumOutputs() * this.gPtrSize;
2332
+ const $audioOutputs = $audioInputs + this.getNumInputs() * this.fBufferSize * this.gSampleSize;
2333
+ const $audioMixing = $audioOutputs + this.getNumOutputs() * this.fBufferSize * this.gSampleSize;
2334
+ const HEAP = this.fInstance.memory.buffer;
2335
+ const HEAP32 = new Int32Array(HEAP);
2336
+ const HEAPF = this.gSampleSize === 4 ? new Float32Array(HEAP) : new Float64Array(HEAP);
2337
+ if (this.getNumInputs() > 0) {
2338
+ for (let chan = 0; chan < this.getNumInputs(); chan++) {
2339
+ HEAP32[(this.fAudioInputs >> 2) + chan] = $audioInputs + this.fBufferSize * this.gSampleSize * chan;
2340
+ }
2341
+ const dspInChans = HEAP32.subarray(this.fAudioInputs >> 2, this.fAudioInputs + this.getNumInputs() * this.gPtrSize >> 2);
2342
+ for (let chan = 0; chan < this.getNumInputs(); chan++) {
2343
+ this.fInChannels[chan] = HEAPF.subarray(dspInChans[chan] >> Math.log2(this.gSampleSize), dspInChans[chan] + this.fBufferSize * this.gSampleSize >> Math.log2(this.gSampleSize));
2344
+ }
2345
+ }
2346
+ if (this.getNumOutputs() > 0) {
2347
+ for (let chan = 0; chan < this.getNumOutputs(); chan++) {
2348
+ HEAP32[(this.fAudioOutputs >> 2) + chan] = $audioOutputs + this.fBufferSize * this.gSampleSize * chan;
2349
+ HEAP32[(this.fAudioMixing >> 2) + chan] = $audioMixing + this.fBufferSize * this.gSampleSize * chan;
2350
+ HEAP32[(this.fAudioMixingHalf >> 2) + chan] = $audioMixing + this.fBufferSize * this.gSampleSize * chan + this.fBufferSize / 2 * this.gSampleSize;
2351
+ }
2352
+ const dspOutChans = HEAP32.subarray(this.fAudioOutputs >> 2, this.fAudioOutputs + this.getNumOutputs() * this.gPtrSize >> 2);
2353
+ for (let chan = 0; chan < this.getNumOutputs(); chan++) {
2354
+ this.fOutChannels[chan] = HEAPF.subarray(dspOutChans[chan] >> Math.log2(this.gSampleSize), dspOutChans[chan] + this.fBufferSize * this.gSampleSize >> Math.log2(this.gSampleSize));
2355
+ }
2356
+ }
2357
+ }
2358
+ toString() {
2359
+ return `============== Poly Memory layout ==============
2360
+ this.fBufferSize: ${this.fBufferSize}
2361
+ this.fJSONDsp.size: ${this.fJSONDsp.size}
2362
+ this.fAudioInputs: ${this.fAudioInputs}
2363
+ this.fAudioOutputs: ${this.fAudioOutputs}
2364
+ this.fAudioMixing: ${this.fAudioMixing}
2365
+ this.fAudioMixingHalf: ${this.fAudioMixingHalf}`;
2366
+ }
2367
+ allocVoice(voice, type) {
2368
+ this.fVoiceTable[voice].fDate++;
2369
+ this.fVoiceTable[voice].fCurNote = type;
2370
+ return voice;
2371
+ }
2372
+ getPlayingVoice(pitch) {
2373
+ let voicePlaying = FaustWebAudioDspVoice.kNoVoice;
2374
+ let oldestDatePlaying = Number.MAX_VALUE;
2375
+ for (let voice = 0; voice < this.fInstance.voices; voice++) {
2376
+ if (this.fVoiceTable[voice].fCurNote === pitch) {
2377
+ if (this.fVoiceTable[voice].fDate < oldestDatePlaying) {
2378
+ oldestDatePlaying = this.fVoiceTable[voice].fDate;
2379
+ voicePlaying = voice;
2380
+ }
2381
+ }
2382
+ }
2383
+ return voicePlaying;
2384
+ }
2385
+ getFreeVoice() {
2386
+ for (let voice = 0; voice < this.fInstance.voices; voice++) {
2387
+ if (this.fVoiceTable[voice].fCurNote === FaustWebAudioDspVoice.kFreeVoice) {
2388
+ return this.allocVoice(voice, FaustWebAudioDspVoice.kActiveVoice);
2389
+ }
2390
+ }
2391
+ let voiceRelease = FaustWebAudioDspVoice.kNoVoice;
2392
+ let voicePlaying = FaustWebAudioDspVoice.kNoVoice;
2393
+ let oldestDateRelease = Number.MAX_VALUE;
2394
+ let oldestDatePlaying = Number.MAX_VALUE;
2395
+ for (let voice = 0; voice < this.fInstance.voices; voice++) {
2396
+ if (this.fVoiceTable[voice].fCurNote === FaustWebAudioDspVoice.kReleaseVoice) {
2397
+ if (this.fVoiceTable[voice].fDate < oldestDateRelease) {
2398
+ oldestDateRelease = this.fVoiceTable[voice].fDate;
2399
+ voiceRelease = voice;
2400
+ }
2401
+ } else if (this.fVoiceTable[voice].fDate < oldestDatePlaying) {
2402
+ oldestDatePlaying = this.fVoiceTable[voice].fDate;
2403
+ voicePlaying = voice;
2404
+ }
2405
+ }
2406
+ if (oldestDateRelease !== Number.MAX_VALUE) {
2407
+ console.log(`Steal release voice : voice_date = ${this.fVoiceTable[voiceRelease].fDate} voice = ${voiceRelease}`);
2408
+ return this.allocVoice(voiceRelease, FaustWebAudioDspVoice.kLegatoVoice);
2409
+ }
2410
+ if (oldestDatePlaying !== Number.MAX_VALUE) {
2411
+ console.log(`Steal playing voice : voice_date = ${this.fVoiceTable[voicePlaying].fDate} voice = ${voicePlaying}`);
2412
+ return this.allocVoice(voicePlaying, FaustWebAudioDspVoice.kLegatoVoice);
2413
+ }
2414
+ return FaustWebAudioDspVoice.kNoVoice;
2415
+ }
2416
+ compute(input, output) {
2417
+ if (this.fDestroyed)
2418
+ return false;
2419
+ if (!this.fProcessing)
2420
+ return true;
2421
+ if (this.getNumInputs() > 0 && (!input || !input[0] || input[0].length === 0)) {
2422
+ return true;
2423
+ }
2424
+ if (this.getNumOutputs() > 0 && (!output || !output[0] || output[0].length === 0)) {
2425
+ return true;
2426
+ }
2427
+ if (input !== void 0) {
2428
+ for (let chan = 0; chan < Math.min(this.getNumInputs(), input.length); ++chan) {
2429
+ const dspInput = this.fInChannels[chan];
2430
+ dspInput.set(input[chan]);
2431
+ }
2432
+ }
2433
+ if (this.fComputeHandler)
2434
+ this.fComputeHandler(this.fBufferSize);
2435
+ this.fInstance.mixerAPI.clearOutput(this.fBufferSize, this.getNumOutputs(), this.fAudioOutputs);
2436
+ this.fVoiceTable.forEach((voice) => {
2437
+ if (voice.fCurNote === FaustWebAudioDspVoice.kLegatoVoice) {
2438
+ voice.computeLegato(this.fBufferSize, this.fAudioInputs, this.fAudioMixing, this.fAudioMixingHalf);
2439
+ this.fInstance.mixerAPI.fadeOut(this.fBufferSize / 2, this.getNumOutputs(), this.fAudioMixing);
2440
+ voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(this.fBufferSize, this.getNumOutputs(), this.fAudioMixing, this.fAudioOutputs);
2441
+ } else if (voice.fCurNote !== FaustWebAudioDspVoice.kFreeVoice) {
2442
+ voice.compute(this.fBufferSize, this.fAudioInputs, this.fAudioMixing);
2443
+ voice.fLevel = this.fInstance.mixerAPI.mixCheckVoice(this.fBufferSize, this.getNumOutputs(), this.fAudioMixing, this.fAudioOutputs);
2444
+ voice.fRelease -= this.fBufferSize;
2445
+ if (voice.fCurNote == FaustWebAudioDspVoice.kReleaseVoice && (voice.fLevel < FaustWebAudioDspVoice.VOICE_STOP_LEVEL && voice.fRelease < 0)) {
2446
+ voice.fCurNote = FaustWebAudioDspVoice.kFreeVoice;
2447
+ }
2448
+ }
2449
+ });
2450
+ if (this.fInstance.effectAPI)
2451
+ this.fInstance.effectAPI.compute(this.fEffect, this.fBufferSize, this.fAudioOutputs, this.fAudioOutputs);
2452
+ this.updateOutputs();
2453
+ if (output !== void 0) {
2454
+ for (let chan = 0; chan < Math.min(this.getNumOutputs(), output.length); chan++) {
2455
+ const dspOutput = this.fOutChannels[chan];
2456
+ output[chan].set(dspOutput);
2457
+ }
2458
+ if (this.fPlotHandler) {
2459
+ this.fPlotHandler(output, this.fBufferNum++, this.fCachedEvents.length ? this.fCachedEvents : void 0);
2460
+ this.fCachedEvents = [];
2461
+ }
2462
+ }
2463
+ return true;
2464
+ }
2465
+ getNumInputs() {
2466
+ return this.fInstance.voiceAPI.getNumInputs(0);
2467
+ }
2468
+ getNumOutputs() {
2469
+ return this.fInstance.voiceAPI.getNumOutputs(0);
2470
+ }
2471
+ static findPath(o, p) {
2472
+ if (typeof o !== "object") {
2473
+ return false;
2474
+ } else if (o.address) {
2475
+ return o.address === p;
2476
+ } else {
2477
+ for (const k in o) {
2478
+ if (FaustPolyWebAudioDsp.findPath(o[k], p))
2479
+ return true;
2480
+ }
2481
+ return false;
2482
+ }
2483
+ }
2484
+ setParamValue(path, value) {
2485
+ if (this.fPlotHandler)
2486
+ this.fCachedEvents.push({ type: "param", data: { path, value } });
2487
+ if (this.fJSONEffect && FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2488
+ this.fInstance.effectAPI.setParamValue(this.fEffect, this.fPathTable[path], value);
2489
+ } else {
2490
+ this.fVoiceTable.forEach((voice) => voice.setParamValue(this.fPathTable[path], value));
2491
+ }
2492
+ }
2493
+ getParamValue(path) {
2494
+ if (this.fJSONEffect && FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2495
+ return this.fInstance.effectAPI.getParamValue(this.fEffect, this.fPathTable[path]);
2496
+ } else {
2497
+ return this.fVoiceTable[0].getParamValue(this.fPathTable[path]);
2498
+ }
2499
+ }
2500
+ getMeta() {
2501
+ const o = this.fJSONDsp;
2502
+ const e = this.fJSONEffect;
2503
+ const r = { ...o };
2504
+ if (e) {
2505
+ r.ui = [{
2506
+ type: "tgroup",
2507
+ label: "Sequencer",
2508
+ items: [
2509
+ { type: "vgroup", label: "Instrument", items: o.ui },
2510
+ { type: "vgroup", label: "Effect", items: e.ui }
2511
+ ]
2512
+ }];
2513
+ } else {
2514
+ r.ui = [{
2515
+ type: "tgroup",
2516
+ label: "Polyphonic",
2517
+ items: [
2518
+ { type: "vgroup", label: "Voices", items: o.ui }
2519
+ ]
2520
+ }];
2521
+ }
2522
+ return r;
2523
+ }
2524
+ getJSON() {
2525
+ return JSON.stringify(this.getMeta());
2526
+ }
2527
+ getUI() {
2528
+ return this.getMeta().ui;
2529
+ }
2530
+ getDescriptors() {
2531
+ return this.fDescriptor;
2532
+ }
2533
+ midiMessage(data) {
2534
+ const cmd = data[0] >> 4;
2535
+ const channel = data[0] & 15;
2536
+ const data1 = data[1];
2537
+ const data2 = data[2];
2538
+ if (cmd === 8 || cmd === 9 && data2 === 0)
2539
+ return this.keyOff(channel, data1, data2);
2540
+ else if (cmd === 9)
2541
+ return this.keyOn(channel, data1, data2);
2542
+ else
2543
+ super.midiMessage(data);
2544
+ }
2545
+ ctrlChange(channel, ctrl, value) {
2546
+ if (ctrl === 123 || ctrl === 120) {
2547
+ this.allNotesOff(true);
2548
+ } else {
2549
+ super.ctrlChange(channel, ctrl, value);
2550
+ }
2551
+ }
2552
+ keyOn(channel, pitch, velocity) {
2553
+ if (this.fPlotHandler)
2554
+ this.fCachedEvents.push({ type: "keyOn", data: [channel, pitch, velocity] });
2555
+ const voice = this.getFreeVoice();
2556
+ this.fVoiceTable[voice].keyOn(pitch, velocity, this.fVoiceTable[voice].fCurNote == FaustWebAudioDspVoice.kLegatoVoice);
2557
+ }
2558
+ keyOff(channel, pitch, velocity) {
2559
+ if (this.fPlotHandler)
2560
+ this.fCachedEvents.push({ type: "keyOff", data: [channel, pitch, velocity] });
2561
+ const voice = this.getPlayingVoice(pitch);
2562
+ if (voice !== FaustWebAudioDspVoice.kNoVoice) {
2563
+ this.fVoiceTable[voice].keyOff();
2564
+ } else {
2565
+ console.log("Playing pitch = %d not found\n", pitch);
2566
+ }
2567
+ }
2568
+ allNotesOff(hard = true) {
2569
+ this.fCachedEvents.push({ type: "ctrlChange", data: [0, 123, 0] });
2570
+ this.fVoiceTable.forEach((voice) => voice.keyOff(hard));
2571
+ }
2572
+ };
2573
+
2574
+ // src/FaustOfflineProcessor.ts
2575
+ var FaustOfflineProcessor = class {
2576
+ constructor(instance, bufferSize) {
2577
+ this.fDSPCode = instance;
2578
+ this.fBufferSize = bufferSize;
2579
+ this.fInputs = new Array(this.fDSPCode.getNumInputs()).fill(null).map(() => new Float32Array(bufferSize));
2580
+ this.fOutputs = new Array(this.fDSPCode.getNumOutputs()).fill(null).map(() => new Float32Array(bufferSize));
2581
+ }
2582
+ getParameterDescriptors() {
2583
+ const params = [];
2584
+ const callback = (item) => {
2585
+ let param = null;
2586
+ const polyKeywords = ["/gate", "/freq", "/gain", "/key", "/vel", "/velocity"];
2587
+ const isPolyReserved = "address" in item && !!polyKeywords.find((k) => item.address.endsWith(k));
2588
+ if (this.fDSPCode instanceof FaustMonoWebAudioDsp || !isPolyReserved) {
2589
+ if (item.type === "vslider" || item.type === "hslider" || item.type === "nentry") {
2590
+ param = { name: item.address, defaultValue: item.init || 0, minValue: item.min || 0, maxValue: item.max || 0 };
2591
+ } else if (item.type === "button" || item.type === "checkbox") {
2592
+ param = { name: item.address, defaultValue: item.init || 0, minValue: 0, maxValue: 1 };
2593
+ }
2594
+ }
2595
+ if (param)
2596
+ params.push(param);
2597
+ };
2598
+ FaustBaseWebAudioDsp.parseUI(this.fDSPCode.getUI(), callback);
2599
+ return params;
2600
+ }
2601
+ compute(input, output) {
2602
+ return this.fDSPCode.compute(input, output);
2603
+ }
2604
+ setOutputParamHandler(handler) {
2605
+ this.fDSPCode.setOutputParamHandler(handler);
2606
+ }
2607
+ getOutputParamHandler() {
2608
+ return this.fDSPCode.getOutputParamHandler();
2609
+ }
2610
+ setComputeHandler(handler) {
2611
+ this.fDSPCode.setComputeHandler(handler);
2612
+ }
2613
+ getComputeHandler() {
2614
+ return this.fDSPCode.getComputeHandler();
2615
+ }
2616
+ setPlotHandler(handler) {
2617
+ this.fDSPCode.setPlotHandler(handler);
2618
+ }
2619
+ getPlotHandler() {
2620
+ return this.fDSPCode.getPlotHandler();
2621
+ }
2622
+ getNumInputs() {
2623
+ return this.fDSPCode.getNumInputs();
2624
+ }
2625
+ getNumOutputs() {
2626
+ return this.fDSPCode.getNumOutputs();
2627
+ }
2628
+ metadata(handler) {
2629
+ }
2630
+ midiMessage(data) {
2631
+ this.fDSPCode.midiMessage(data);
2632
+ }
2633
+ ctrlChange(chan, ctrl, value) {
2634
+ this.fDSPCode.ctrlChange(chan, ctrl, value);
2635
+ }
2636
+ pitchWheel(chan, value) {
2637
+ this.fDSPCode.pitchWheel(chan, value);
2638
+ }
2639
+ setParamValue(path, value) {
2640
+ this.fDSPCode.setParamValue(path, value);
2641
+ }
2642
+ getParamValue(path) {
2643
+ return this.fDSPCode.getParamValue(path);
2644
+ }
2645
+ getParams() {
2646
+ return this.fDSPCode.getParams();
2647
+ }
2648
+ getMeta() {
2649
+ return this.fDSPCode.getMeta();
2650
+ }
2651
+ getJSON() {
2652
+ return this.fDSPCode.getJSON();
2653
+ }
2654
+ getDescriptors() {
2655
+ return this.fDSPCode.getDescriptors();
2656
+ }
2657
+ getUI() {
2658
+ return this.fDSPCode.getUI();
2659
+ }
2660
+ start() {
2661
+ this.fDSPCode.start();
2662
+ }
2663
+ stop() {
2664
+ this.fDSPCode.stop();
2665
+ }
2666
+ destroy() {
2667
+ this.fDSPCode.destroy();
2668
+ }
2669
+ render(inputs = [], length = this.fBufferSize, onUpdate) {
2670
+ let l = 0;
2671
+ const outputs = new Array(this.fDSPCode.getNumOutputs()).fill(null).map(() => new Float32Array(length));
2672
+ this.fDSPCode.start();
2673
+ while (l < length) {
2674
+ const sliceLength = Math.min(length - l, this.fBufferSize);
2675
+ for (let i = 0; i < this.fDSPCode.getNumInputs(); i++) {
2676
+ let input;
2677
+ if (inputs[i]) {
2678
+ if (inputs[i].length <= l) {
2679
+ input = new Float32Array(sliceLength);
2680
+ } else if (inputs[i].length > l + sliceLength) {
2681
+ input = inputs[i].subarray(l, l + sliceLength);
2682
+ } else {
2683
+ input = inputs[i].subarray(l, inputs[i].length);
2684
+ }
2685
+ } else {
2686
+ input = new Float32Array(sliceLength);
2687
+ }
2688
+ this.fInputs[i] = input;
2689
+ }
2690
+ this.fDSPCode.compute(this.fInputs, this.fOutputs);
2691
+ for (let i = 0; i < this.fDSPCode.getNumOutputs(); i++) {
2692
+ const output = this.fOutputs[i];
2693
+ if (sliceLength < this.fBufferSize) {
2694
+ outputs[i].set(output.subarray(0, sliceLength), l);
2695
+ } else {
2696
+ outputs[i].set(output, l);
2697
+ }
2698
+ }
2699
+ l += this.fBufferSize;
2700
+ onUpdate == null ? void 0 : onUpdate(l);
2701
+ }
2702
+ this.fDSPCode.stop();
2703
+ return outputs;
2704
+ }
2705
+ };
2706
+ var FaustMonoOfflineProcessor = class extends FaustOfflineProcessor {
2707
+ };
2708
+ var FaustPolyOfflineProcessor = class extends FaustOfflineProcessor {
2709
+ keyOn(channel, pitch, velocity) {
2710
+ this.fDSPCode.keyOn(channel, pitch, velocity);
2711
+ }
2712
+ keyOff(channel, pitch, velocity) {
2713
+ this.fDSPCode.keyOff(channel, pitch, velocity);
2714
+ }
2715
+ allNotesOff(hard) {
2716
+ this.fDSPCode.allNotesOff(hard);
2717
+ }
2718
+ };
2719
+ var FaustOfflineProcessor_default = FaustOfflineProcessor;
2720
+
2721
+ // src/FaustSvgDiagrams.ts
2722
+ var FaustSvgDiagrams = class {
2723
+ constructor(compiler) {
2724
+ this.compiler = compiler;
2725
+ }
2726
+ from(name, code, args) {
2727
+ const fs = this.compiler.fs();
2728
+ try {
2729
+ const files2 = fs.readdir(`/${name}-svg/`);
2730
+ files2.filter((file) => file !== "." && file !== "..").forEach((file) => fs.unlink(`/${name}-svg/${file}`));
2731
+ } catch {
2732
+ }
2733
+ const success = this.compiler.generateAuxFiles(name, code, `-lang wasm -svg ${args}`);
2734
+ if (!success)
2735
+ throw new Error(this.compiler.getErrorMessage());
2736
+ const svgs = {};
2737
+ const files = fs.readdir(`/${name}-svg/`);
2738
+ files.filter((file) => file !== "." && file !== "..").forEach((file) => svgs[file] = fs.readFile(`/${name}-svg/${file}`, { encoding: "utf8" }));
2739
+ return svgs;
2740
+ }
2741
+ };
2742
+ var FaustSvgDiagrams_default = FaustSvgDiagrams;
2743
+
2744
+ // src/LibFaust.ts
2745
+ var LibFaust = class {
2746
+ constructor(module) {
2747
+ this.fModule = module;
2748
+ this.fCompiler = new module.libFaustWasm();
2749
+ this.fFileSystem = this.fModule.FS;
2750
+ }
2751
+ module() {
2752
+ return this.fModule;
2753
+ }
2754
+ fs() {
2755
+ return this.fFileSystem;
2756
+ }
2757
+ version() {
2758
+ return this.fCompiler.version();
2759
+ }
2760
+ createDSPFactory(name, code, args, useInternalMemory) {
2761
+ return this.fCompiler.createDSPFactory(name, code, args, useInternalMemory);
2762
+ }
2763
+ deleteDSPFactory(cFactory) {
2764
+ return this.fCompiler.deleteDSPFactory(cFactory);
2765
+ }
2766
+ expandDSP(name, code, args) {
2767
+ return this.fCompiler.expandDSP(name, code, args);
2768
+ }
2769
+ generateAuxFiles(name, code, args) {
2770
+ return this.fCompiler.generateAuxFiles(name, code, args);
2771
+ }
2772
+ deleteAllDSPFactories() {
2773
+ return this.fCompiler.deleteAllDSPFactories();
2774
+ }
2775
+ getErrorAfterException() {
2776
+ return this.fCompiler.getErrorAfterException();
2777
+ }
2778
+ cleanupAfterException() {
2779
+ return this.fCompiler.cleanupAfterException();
2780
+ }
2781
+ getInfos(what) {
2782
+ return this.fCompiler.getInfos(what);
2783
+ }
2784
+ toString() {
2785
+ return `LibFaust module: ${this.fModule}, compiler: ${this.fCompiler}`;
2786
+ }
2787
+ };
2788
+ var LibFaust_default = LibFaust;
2789
+
2790
+ // src/WavEncoder.ts
2791
+ var WavEncoder = class {
2792
+ static encode(audioBuffer, options) {
2793
+ const numberOfChannels = audioBuffer.length;
2794
+ const length = audioBuffer[0].length;
2795
+ const { shared, float } = options;
2796
+ const bitDepth = float ? 32 : options.bitDepth | 0 || 16;
2797
+ const byteDepth = bitDepth >> 3;
2798
+ const byteLength = length * numberOfChannels * byteDepth;
2799
+ const AB = shared ? globalThis.SharedArrayBuffer || globalThis.ArrayBuffer : globalThis.ArrayBuffer;
2800
+ const ab = new AB((44 + byteLength) * Uint8Array.BYTES_PER_ELEMENT);
2801
+ const dataView = new DataView(ab);
2802
+ const writer = new Writer(dataView);
2803
+ const format = {
2804
+ formatId: float ? 3 : 1,
2805
+ float: !!float,
2806
+ numberOfChannels,
2807
+ sampleRate: options.sampleRate,
2808
+ symmetric: !!options.symmetric,
2809
+ length,
2810
+ bitDepth,
2811
+ byteDepth
2812
+ };
2813
+ this.writeHeader(writer, format);
2814
+ this.writeData(writer, audioBuffer, format);
2815
+ return ab;
2816
+ }
2817
+ static writeHeader(writer, format) {
2818
+ const { formatId, sampleRate, bitDepth, numberOfChannels, length, byteDepth } = format;
2819
+ writer.string("RIFF");
2820
+ writer.uint32(writer.dataView.byteLength - 8);
2821
+ writer.string("WAVE");
2822
+ writer.string("fmt ");
2823
+ writer.uint32(16);
2824
+ writer.uint16(formatId);
2825
+ writer.uint16(numberOfChannels);
2826
+ writer.uint32(sampleRate);
2827
+ writer.uint32(sampleRate * numberOfChannels * byteDepth);
2828
+ writer.uint16(numberOfChannels * byteDepth);
2829
+ writer.uint16(bitDepth);
2830
+ writer.string("data");
2831
+ writer.uint32(length * numberOfChannels * byteDepth);
2832
+ return writer.pos;
2833
+ }
2834
+ static writeData(writer, audioBuffer, format) {
2835
+ const { bitDepth, float, length, numberOfChannels, symmetric } = format;
2836
+ if (bitDepth === 32 && float) {
2837
+ const { dataView, pos } = writer;
2838
+ const ab = dataView.buffer;
2839
+ const f32View = new Float32Array(ab, pos);
2840
+ if (numberOfChannels === 1) {
2841
+ f32View.set(audioBuffer[0]);
2842
+ return;
2843
+ }
2844
+ for (let ch = 0; ch < numberOfChannels; ch++) {
2845
+ const channel = audioBuffer[ch];
2846
+ for (let i = 0; i < length; i++) {
2847
+ f32View[i * numberOfChannels + ch] = channel[i];
2848
+ }
2849
+ }
2850
+ return;
2851
+ }
2852
+ const encoderOption = float ? "f" : symmetric ? "s" : "";
2853
+ const methodName = "pcm" + bitDepth + encoderOption;
2854
+ if (!writer[methodName]) {
2855
+ throw new TypeError("Not supported bit depth: " + bitDepth);
2856
+ }
2857
+ const write = writer[methodName].bind(writer);
2858
+ for (let i = 0; i < length; i++) {
2859
+ for (let j = 0; j < numberOfChannels; j++) {
2860
+ write(audioBuffer[j][i]);
2861
+ }
2862
+ }
2863
+ }
2864
+ };
2865
+ var Writer = class {
2866
+ constructor(dataView) {
2867
+ this.pos = 0;
2868
+ this.dataView = dataView;
2869
+ }
2870
+ int16(value) {
2871
+ this.dataView.setInt16(this.pos, value, true);
2872
+ this.pos += 2;
2873
+ }
2874
+ uint16(value) {
2875
+ this.dataView.setUint16(this.pos, value, true);
2876
+ this.pos += 2;
2877
+ }
2878
+ uint32(value) {
2879
+ this.dataView.setUint32(this.pos, value, true);
2880
+ this.pos += 4;
2881
+ }
2882
+ string(value) {
2883
+ for (let i = 0, imax = value.length; i < imax; i++) {
2884
+ this.dataView.setUint8(this.pos++, value.charCodeAt(i));
2885
+ }
2886
+ }
2887
+ pcm8(valueIn) {
2888
+ let value = valueIn;
2889
+ value = Math.max(-1, Math.min(value, 1));
2890
+ value = (value * 0.5 + 0.5) * 255;
2891
+ value = Math.round(value) | 0;
2892
+ this.dataView.setUint8(this.pos, value);
2893
+ this.pos += 1;
2894
+ }
2895
+ pcm8s(valueIn) {
2896
+ let value = valueIn;
2897
+ value = Math.round(value * 128) + 128;
2898
+ value = Math.max(0, Math.min(value, 255));
2899
+ this.dataView.setUint8(this.pos, value);
2900
+ this.pos += 1;
2901
+ }
2902
+ pcm16(valueIn) {
2903
+ let value = valueIn;
2904
+ value = Math.max(-1, Math.min(value, 1));
2905
+ value = value < 0 ? value * 32768 : value * 32767;
2906
+ value = Math.round(value) | 0;
2907
+ this.dataView.setInt16(this.pos, value, true);
2908
+ this.pos += 2;
2909
+ }
2910
+ pcm16s(valueIn) {
2911
+ let value = valueIn;
2912
+ value = Math.round(value * 32768);
2913
+ value = Math.max(-32768, Math.min(value, 32767));
2914
+ this.dataView.setInt16(this.pos, value, true);
2915
+ this.pos += 2;
2916
+ }
2917
+ pcm24(valueIn) {
2918
+ let value = valueIn;
2919
+ value = Math.max(-1, Math.min(value, 1));
2920
+ value = value < 0 ? 16777216 + value * 8388608 : value * 8388607;
2921
+ value = Math.round(value) | 0;
2922
+ const x0 = value >> 0 & 255;
2923
+ const x1 = value >> 8 & 255;
2924
+ const x2 = value >> 16 & 255;
2925
+ this.dataView.setUint8(this.pos + 0, x0);
2926
+ this.dataView.setUint8(this.pos + 1, x1);
2927
+ this.dataView.setUint8(this.pos + 2, x2);
2928
+ this.pos += 3;
2929
+ }
2930
+ pcm24s(valueIn) {
2931
+ let value = valueIn;
2932
+ value = Math.round(value * 8388608);
2933
+ value = Math.max(-8388608, Math.min(value, 8388607));
2934
+ const x0 = value >> 0 & 255;
2935
+ const x1 = value >> 8 & 255;
2936
+ const x2 = value >> 16 & 255;
2937
+ this.dataView.setUint8(this.pos + 0, x0);
2938
+ this.dataView.setUint8(this.pos + 1, x1);
2939
+ this.dataView.setUint8(this.pos + 2, x2);
2940
+ this.pos += 3;
2941
+ }
2942
+ pcm32(valueIn) {
2943
+ let value = valueIn;
2944
+ value = Math.max(-1, Math.min(value, 1));
2945
+ value = value < 0 ? value * 2147483648 : value * 2147483647;
2946
+ value = Math.round(value) | 0;
2947
+ this.dataView.setInt32(this.pos, value, true);
2948
+ this.pos += 4;
2949
+ }
2950
+ pcm32s(valueIn) {
2951
+ let value = valueIn;
2952
+ value = Math.round(value * 2147483648);
2953
+ value = Math.max(-2147483648, Math.min(value, 2147483647));
2954
+ this.dataView.setInt32(this.pos, value, true);
2955
+ this.pos += 4;
2956
+ }
2957
+ pcm32f(value) {
2958
+ this.dataView.setFloat32(this.pos, value, true);
2959
+ this.pos += 4;
2960
+ }
2961
+ };
2962
+ var WavEncoder_default = WavEncoder;
2963
+
2964
+ // src/WavDecoder.ts
2965
+ var WavDecoder = class {
2966
+ static decode(buffer, options) {
2967
+ const dataView = new DataView(buffer);
2968
+ const reader = new Reader(dataView);
2969
+ if (reader.string(4) !== "RIFF") {
2970
+ throw new TypeError("Invalid WAV file");
2971
+ }
2972
+ reader.uint32();
2973
+ if (reader.string(4) !== "WAVE") {
2974
+ throw new TypeError("Invalid WAV file");
2975
+ }
2976
+ let format = null;
2977
+ let audioData = null;
2978
+ do {
2979
+ const chunkType = reader.string(4);
2980
+ const chunkSize = reader.uint32();
2981
+ if (chunkType === "fmt ") {
2982
+ format = this.decodeFormat(reader, chunkSize);
2983
+ } else if (chunkType === "data") {
2984
+ audioData = this.decodeData(reader, chunkSize, format, options || {});
2985
+ } else {
2986
+ reader.skip(chunkSize);
2987
+ }
2988
+ } while (audioData === null);
2989
+ return audioData;
2990
+ }
2991
+ static decodeFormat(reader, chunkSize) {
2992
+ const formats = {
2993
+ 1: "lpcm",
2994
+ 3: "lpcm"
2995
+ };
2996
+ const formatId = reader.uint16();
2997
+ if (!formats.hasOwnProperty(formatId)) {
2998
+ throw new TypeError("Unsupported format in WAV file: 0x" + formatId.toString(16));
2999
+ }
3000
+ const format = {
3001
+ formatId,
3002
+ float: formatId === 3,
3003
+ numberOfChannels: reader.uint16(),
3004
+ sampleRate: reader.uint32(),
3005
+ byteRate: reader.uint32(),
3006
+ blockSize: reader.uint16(),
3007
+ bitDepth: reader.uint16()
3008
+ };
3009
+ reader.skip(chunkSize - 16);
3010
+ return format;
3011
+ }
3012
+ static decodeData(reader, chunkSizeIn, format, options) {
3013
+ const chunkSize = Math.min(chunkSizeIn, reader.remain());
3014
+ const length = Math.floor(chunkSize / format.blockSize);
3015
+ const numberOfChannels = format.numberOfChannels;
3016
+ const sampleRate = format.sampleRate;
3017
+ const channelData = new Array(numberOfChannels);
3018
+ for (let ch = 0; ch < numberOfChannels; ch++) {
3019
+ const AB = options.shared ? globalThis.SharedArrayBuffer || globalThis.ArrayBuffer : globalThis.ArrayBuffer;
3020
+ const ab = new AB(length * Float32Array.BYTES_PER_ELEMENT);
3021
+ channelData[ch] = new Float32Array(ab);
3022
+ }
3023
+ this.readPCM(reader, channelData, length, format, options);
3024
+ return {
3025
+ numberOfChannels,
3026
+ length,
3027
+ sampleRate,
3028
+ channelData
3029
+ };
3030
+ }
3031
+ static readPCM(reader, channelData, length, format, options) {
3032
+ const bitDepth = format.bitDepth;
3033
+ const decoderOption = format.float ? "f" : options.symmetric ? "s" : "";
3034
+ const methodName = "pcm" + bitDepth + decoderOption;
3035
+ if (!reader[methodName]) {
3036
+ throw new TypeError("Not supported bit depth: " + format.bitDepth);
3037
+ }
3038
+ const read = reader[methodName].bind(reader);
3039
+ const numberOfChannels = format.numberOfChannels;
3040
+ for (let i = 0; i < length; i++) {
3041
+ for (let ch = 0; ch < numberOfChannels; ch++) {
3042
+ channelData[ch][i] = read();
3043
+ }
3044
+ }
3045
+ }
3046
+ };
3047
+ var Reader = class {
3048
+ constructor(dataView) {
3049
+ this.pos = 0;
3050
+ this.dataView = dataView;
3051
+ }
3052
+ remain() {
3053
+ return this.dataView.byteLength - this.pos;
3054
+ }
3055
+ skip(n) {
3056
+ this.pos += n;
3057
+ }
3058
+ uint8() {
3059
+ const data = this.dataView.getUint8(this.pos);
3060
+ this.pos += 1;
3061
+ return data;
3062
+ }
3063
+ int16() {
3064
+ const data = this.dataView.getInt16(this.pos, true);
3065
+ this.pos += 2;
3066
+ return data;
3067
+ }
3068
+ uint16() {
3069
+ const data = this.dataView.getUint16(this.pos, true);
3070
+ this.pos += 2;
3071
+ return data;
3072
+ }
3073
+ uint32() {
3074
+ const data = this.dataView.getUint32(this.pos, true);
3075
+ this.pos += 4;
3076
+ return data;
3077
+ }
3078
+ string(n) {
3079
+ let data = "";
3080
+ for (let i = 0; i < n; i++) {
3081
+ data += String.fromCharCode(this.uint8());
3082
+ }
3083
+ return data;
3084
+ }
3085
+ pcm8() {
3086
+ const data = this.dataView.getUint8(this.pos) - 128;
3087
+ this.pos += 1;
3088
+ return data < 0 ? data / 128 : data / 127;
3089
+ }
3090
+ pcm8s() {
3091
+ const data = this.dataView.getUint8(this.pos) - 127.5;
3092
+ this.pos += 1;
3093
+ return data / 127.5;
3094
+ }
3095
+ pcm16() {
3096
+ const data = this.dataView.getInt16(this.pos, true);
3097
+ this.pos += 2;
3098
+ return data < 0 ? data / 32768 : data / 32767;
3099
+ }
3100
+ pcm16s() {
3101
+ const data = this.dataView.getInt16(this.pos, true);
3102
+ this.pos += 2;
3103
+ return data / 32768;
3104
+ }
3105
+ pcm24() {
3106
+ const x0 = this.dataView.getUint8(this.pos + 0);
3107
+ const x1 = this.dataView.getUint8(this.pos + 1);
3108
+ const x2 = this.dataView.getUint8(this.pos + 2);
3109
+ const xx = x0 + (x1 << 8) + (x2 << 16);
3110
+ const data = xx > 8388608 ? xx - 16777216 : xx;
3111
+ this.pos += 3;
3112
+ return data < 0 ? data / 8388608 : data / 8388607;
3113
+ }
3114
+ pcm24s() {
3115
+ const x0 = this.dataView.getUint8(this.pos + 0);
3116
+ const x1 = this.dataView.getUint8(this.pos + 1);
3117
+ const x2 = this.dataView.getUint8(this.pos + 2);
3118
+ const xx = x0 + (x1 << 8) + (x2 << 16);
3119
+ const data = xx > 8388608 ? xx - 16777216 : xx;
3120
+ this.pos += 3;
3121
+ return data / 8388608;
3122
+ }
3123
+ pcm32() {
3124
+ const data = this.dataView.getInt32(this.pos, true);
3125
+ this.pos += 4;
3126
+ return data < 0 ? data / 2147483648 : data / 2147483647;
3127
+ }
3128
+ pcm32s() {
3129
+ const data = this.dataView.getInt32(this.pos, true);
3130
+ this.pos += 4;
3131
+ return data / 2147483648;
3132
+ }
3133
+ pcm32f() {
3134
+ const data = this.dataView.getFloat32(this.pos, true);
3135
+ this.pos += 4;
3136
+ return data;
3137
+ }
3138
+ pcm64f() {
3139
+ const data = this.dataView.getFloat64(this.pos, true);
3140
+ this.pos += 8;
3141
+ return data;
3142
+ }
3143
+ };
3144
+ var WavDecoder_default = WavDecoder;
3145
+
3146
+ // src/FaustAudioWorkletNode.ts
3147
+ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
3148
+ constructor(context, name, factory, options, nodeOptions = {}) {
3149
+ const JSONObj = JSON.parse(factory.json);
3150
+ super(context, name, {
3151
+ numberOfInputs: JSONObj.inputs > 0 ? 1 : 0,
3152
+ numberOfOutputs: JSONObj.outputs > 0 ? 1 : 0,
3153
+ channelCount: Math.max(1, JSONObj.inputs),
3154
+ outputChannelCount: [JSONObj.outputs],
3155
+ channelCountMode: "explicit",
3156
+ channelInterpretation: "speakers",
3157
+ processorOptions: options,
3158
+ ...nodeOptions
3159
+ });
3160
+ this.fJSONDsp = JSONObj;
3161
+ this.fJSON = factory.json;
3162
+ this.fOutputHandler = null;
3163
+ this.fComputeHandler = null;
3164
+ this.fPlotHandler = null;
3165
+ this.fDescriptor = [];
3166
+ this.fInputsItems = [];
3167
+ this.fUICallback = (item) => {
3168
+ if (item.type === "vslider" || item.type === "hslider" || item.type === "button" || item.type === "checkbox" || item.type === "nentry") {
3169
+ this.fInputsItems.push(item.address);
3170
+ this.fDescriptor.push(item);
3171
+ }
3172
+ };
3173
+ FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
3174
+ this.port.onmessage = (e) => {
3175
+ if (e.data.type === "param" && this.fOutputHandler) {
3176
+ this.fOutputHandler(e.data.path, e.data.value);
3177
+ } else if (e.data.type === "plot" && this.fPlotHandler) {
3178
+ this.fPlotHandler(e.data.value, e.data.index, e.data.events);
3179
+ }
3180
+ };
3181
+ }
3182
+ setOutputParamHandler(handler) {
3183
+ this.fOutputHandler = handler;
3184
+ }
3185
+ getOutputParamHandler() {
3186
+ return this.fOutputHandler;
3187
+ }
3188
+ setComputeHandler(handler) {
3189
+ this.fComputeHandler = handler;
3190
+ }
3191
+ getComputeHandler() {
3192
+ return this.fComputeHandler;
3193
+ }
3194
+ setPlotHandler(handler) {
3195
+ this.fPlotHandler = handler;
3196
+ if (this.fPlotHandler) {
3197
+ this.port.postMessage({ type: "setPlotHandler", data: true });
3198
+ } else {
3199
+ this.port.postMessage({ type: "setPlotHandler", data: false });
3200
+ }
3201
+ }
3202
+ getPlotHandler() {
3203
+ return this.fPlotHandler;
3204
+ }
3205
+ getNumInputs() {
3206
+ return this.fJSONDsp.inputs;
3207
+ }
3208
+ getNumOutputs() {
3209
+ return this.fJSONDsp.outputs;
3210
+ }
3211
+ compute(inputs, outputs) {
3212
+ return false;
3213
+ }
3214
+ metadata(handler) {
3215
+ if (this.fJSONDsp.meta) {
3216
+ this.fJSONDsp.meta.forEach((meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]]));
3217
+ }
3218
+ }
3219
+ midiMessage(data) {
3220
+ const cmd = data[0] >> 4;
3221
+ const channel = data[0] & 15;
3222
+ const data1 = data[1];
3223
+ const data2 = data[2];
3224
+ if (cmd === 11)
3225
+ this.ctrlChange(channel, data1, data2);
3226
+ else if (cmd === 14)
3227
+ this.pitchWheel(channel, data2 * 128 + data1);
3228
+ else
3229
+ this.port.postMessage({ type: "midi", data });
3230
+ }
3231
+ ctrlChange(channel, ctrl, value) {
3232
+ const e = { type: "ctrlChange", data: [channel, ctrl, value] };
3233
+ this.port.postMessage(e);
3234
+ }
3235
+ pitchWheel(channel, wheel) {
3236
+ const e = { type: "pitchWheel", data: [channel, wheel] };
3237
+ this.port.postMessage(e);
3238
+ }
3239
+ setParamValue(path, value) {
3240
+ const e = { type: "param", data: { path, value } };
3241
+ this.port.postMessage(e);
3242
+ const param = this.parameters.get(path);
3243
+ if (param)
3244
+ param.setValueAtTime(value, this.context.currentTime);
3245
+ }
3246
+ getParamValue(path) {
3247
+ const param = this.parameters.get(path);
3248
+ return param ? param.value : 0;
3249
+ }
3250
+ getParams() {
3251
+ return this.fInputsItems;
3252
+ }
3253
+ getMeta() {
3254
+ return this.fJSONDsp;
3255
+ }
3256
+ getJSON() {
3257
+ return JSON.stringify(this.getMeta());
3258
+ }
3259
+ getUI() {
3260
+ return this.fJSONDsp.ui;
3261
+ }
3262
+ getDescriptors() {
3263
+ return this.fDescriptor;
3264
+ }
3265
+ start() {
3266
+ this.port.postMessage({ type: "start" });
3267
+ }
3268
+ stop() {
3269
+ this.port.postMessage({ type: "stop" });
3270
+ }
3271
+ destroy() {
3272
+ this.port.postMessage({ type: "destroy" });
3273
+ this.port.close();
3274
+ }
3275
+ };
3276
+ var FaustMonoAudioWorkletNode = class extends FaustAudioWorkletNode {
3277
+ constructor(context, name, factory, sampleSize, nodeOptions = {}) {
3278
+ super(context, name, factory, { name, factory, sampleSize }, nodeOptions);
3279
+ this.onprocessorerror = (e) => {
3280
+ throw e;
3281
+ };
3282
+ }
3283
+ };
3284
+ var FaustPolyAudioWorkletNode = class extends FaustAudioWorkletNode {
3285
+ constructor(context, name, voiceFactory, mixerModule, voices, sampleSize, effectFactory, nodeOptions = {}) {
3286
+ super(context, name, voiceFactory, {
3287
+ name,
3288
+ voiceFactory,
3289
+ mixerModule,
3290
+ voices,
3291
+ sampleSize,
3292
+ effectFactory
3293
+ }, nodeOptions);
3294
+ this.onprocessorerror = (e) => {
3295
+ throw e;
3296
+ };
3297
+ this.fJSONEffect = effectFactory ? JSON.parse(effectFactory.json) : null;
3298
+ if (this.fJSONEffect) {
3299
+ FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
3300
+ }
3301
+ }
3302
+ keyOn(channel, pitch, velocity) {
3303
+ const e = { type: "keyOn", data: [channel, pitch, velocity] };
3304
+ this.port.postMessage(e);
3305
+ }
3306
+ keyOff(channel, pitch, velocity) {
3307
+ const e = { type: "keyOff", data: [channel, pitch, velocity] };
3308
+ this.port.postMessage(e);
3309
+ }
3310
+ allNotesOff(hard) {
3311
+ const e = { type: "ctrlChange", data: [0, 123, 0] };
3312
+ this.port.postMessage(e);
3313
+ }
3314
+ getMeta() {
3315
+ const o = this.fJSONDsp;
3316
+ const e = this.fJSONEffect;
3317
+ const r = { ...o };
3318
+ if (e) {
3319
+ r.ui = [{
3320
+ type: "tgroup",
3321
+ label: "Sequencer",
3322
+ items: [
3323
+ { type: "vgroup", label: "Instrument", items: o.ui },
3324
+ { type: "vgroup", label: "Effect", items: e.ui }
3325
+ ]
3326
+ }];
3327
+ } else {
3328
+ r.ui = [{
3329
+ type: "tgroup",
3330
+ label: "Polyphonic",
3331
+ items: [
3332
+ { type: "vgroup", label: "Voices", items: o.ui }
3333
+ ]
3334
+ }];
3335
+ }
3336
+ return r;
3337
+ }
3338
+ getJSON() {
3339
+ return JSON.stringify(this.getMeta());
3340
+ }
3341
+ getUI() {
3342
+ return this.getMeta().ui;
3343
+ }
3344
+ };
3345
+
3346
+ // src/FaustScriptProcessorNode.ts
3347
+ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode || null) {
3348
+ init(instance) {
3349
+ this.fDSPCode = instance;
3350
+ this.fInputs = new Array(this.fDSPCode.getNumInputs());
3351
+ this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
3352
+ this.onaudioprocess = (e) => {
3353
+ for (let chan = 0; chan < this.fDSPCode.getNumInputs(); chan++) {
3354
+ this.fInputs[chan] = e.inputBuffer.getChannelData(chan);
3355
+ }
3356
+ for (let chan = 0; chan < this.fDSPCode.getNumOutputs(); chan++) {
3357
+ this.fOutputs[chan] = e.outputBuffer.getChannelData(chan);
3358
+ }
3359
+ return this.fDSPCode.compute(this.fInputs, this.fOutputs);
3360
+ };
3361
+ this.start();
3362
+ }
3363
+ compute(input, output) {
3364
+ return this.fDSPCode.compute(input, output);
3365
+ }
3366
+ setOutputParamHandler(handler) {
3367
+ this.fDSPCode.setOutputParamHandler(handler);
3368
+ }
3369
+ getOutputParamHandler() {
3370
+ return this.fDSPCode.getOutputParamHandler();
3371
+ }
3372
+ setComputeHandler(handler) {
3373
+ this.fDSPCode.setComputeHandler(handler);
3374
+ }
3375
+ getComputeHandler() {
3376
+ return this.fDSPCode.getComputeHandler();
3377
+ }
3378
+ setPlotHandler(handler) {
3379
+ this.fDSPCode.setPlotHandler(handler);
3380
+ }
3381
+ getPlotHandler() {
3382
+ return this.fDSPCode.getPlotHandler();
3383
+ }
3384
+ getNumInputs() {
3385
+ return this.fDSPCode.getNumInputs();
3386
+ }
3387
+ getNumOutputs() {
3388
+ return this.fDSPCode.getNumOutputs();
3389
+ }
3390
+ metadata(handler) {
3391
+ }
3392
+ midiMessage(data) {
3393
+ this.fDSPCode.midiMessage(data);
3394
+ }
3395
+ ctrlChange(chan, ctrl, value) {
3396
+ this.fDSPCode.ctrlChange(chan, ctrl, value);
3397
+ }
3398
+ pitchWheel(chan, value) {
3399
+ this.fDSPCode.pitchWheel(chan, value);
3400
+ }
3401
+ setParamValue(path, value) {
3402
+ this.fDSPCode.setParamValue(path, value);
3403
+ }
3404
+ getParamValue(path) {
3405
+ return this.fDSPCode.getParamValue(path);
3406
+ }
3407
+ getParams() {
3408
+ return this.fDSPCode.getParams();
3409
+ }
3410
+ getMeta() {
3411
+ return this.fDSPCode.getMeta();
3412
+ }
3413
+ getJSON() {
3414
+ return this.fDSPCode.getJSON();
3415
+ }
3416
+ getDescriptors() {
3417
+ return this.fDSPCode.getDescriptors();
3418
+ }
3419
+ getUI() {
3420
+ return this.fDSPCode.getUI();
3421
+ }
3422
+ start() {
3423
+ this.fDSPCode.start();
3424
+ }
3425
+ stop() {
3426
+ this.fDSPCode.stop();
3427
+ }
3428
+ destroy() {
3429
+ this.fDSPCode.destroy();
3430
+ }
3431
+ };
3432
+ var FaustMonoScriptProcessorNode = class extends FaustScriptProcessorNode {
3433
+ };
3434
+ var FaustPolyScriptProcessorNode = class extends FaustScriptProcessorNode {
3435
+ keyOn(channel, pitch, velocity) {
3436
+ this.fDSPCode.keyOn(channel, pitch, velocity);
3437
+ }
3438
+ keyOff(channel, pitch, velocity) {
3439
+ this.fDSPCode.keyOff(channel, pitch, velocity);
3440
+ }
3441
+ allNotesOff(hard) {
3442
+ this.fDSPCode.allNotesOff(hard);
3443
+ }
3444
+ };
3445
+
3446
+ // src/FaustDspGenerator.ts
3447
+ var _FaustMonoDspGenerator = class {
3448
+ constructor() {
3449
+ this.factory = null;
3450
+ }
3451
+ async compile(compiler, name, code, args) {
3452
+ this.factory = await compiler.createMonoDSPFactory(name, code, args);
3453
+ if (!this.factory)
3454
+ return null;
3455
+ this.name = name;
3456
+ return this;
3457
+ }
3458
+ async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
3459
+ var _a, _b;
3460
+ if (!factory)
3461
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3462
+ const meta = JSON.parse(factory.json);
3463
+ const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
3464
+ if (sp) {
3465
+ const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
3466
+ const monoDsp = new FaustMonoWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize);
3467
+ const sp2 = context.createScriptProcessor(bufferSize, monoDsp.getNumInputs(), monoDsp.getNumOutputs());
3468
+ Object.setPrototypeOf(sp2, FaustMonoScriptProcessorNode.prototype);
3469
+ sp2.init(monoDsp);
3470
+ return sp2;
3471
+ } else {
3472
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
3473
+ _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
3474
+ if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
3475
+ try {
3476
+ const processorCode = `
3477
+ // DSP name and JSON string for DSP are generated
3478
+ const faustData = ${JSON.stringify({
3479
+ processorName,
3480
+ dspName: name,
3481
+ dspMeta: meta,
3482
+ poly: false
3483
+ })};
3484
+ // Implementation needed classes of functions
3485
+ const ${FaustDspInstance_default.name}_default = ${FaustDspInstance_default.toString()}
3486
+ const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3487
+ const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3488
+ const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3489
+ // Put them in dependencies
3490
+ const dependencies = {
3491
+ ${FaustBaseWebAudioDsp.name},
3492
+ ${FaustMonoWebAudioDsp.name},
3493
+ ${FaustWasmInstantiator_default.name}
3494
+ };
3495
+ // Generate the actual AudioWorkletProcessor code
3496
+ (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
3497
+ `;
3498
+ const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
3499
+ await context.audioWorklet.addModule(url);
3500
+ (_b = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
3501
+ } catch (e) {
3502
+ throw e;
3503
+ }
3504
+ }
3505
+ const node = new FaustMonoAudioWorkletNode(context, processorName, factory, sampleSize);
3506
+ return node;
3507
+ }
3508
+ }
3509
+ async createFFTNode(context, fftUtils, name = this.name, factory = this.factory, fftOptions = {}, processorName = (factory == null ? void 0 : factory.shaKey) ? `${factory.shaKey}_fft` : name) {
3510
+ var _a, _b;
3511
+ if (!factory)
3512
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3513
+ const meta = JSON.parse(factory.json);
3514
+ const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
3515
+ if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
3516
+ _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
3517
+ if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
3518
+ try {
3519
+ const processorCode = `
3520
+ // DSP name and JSON string for DSP are generated
3521
+ const faustData = ${JSON.stringify({
3522
+ processorName,
3523
+ dspName: name,
3524
+ dspMeta: meta,
3525
+ fftOptions
3526
+ })};
3527
+ // Implementation needed classes of functions
3528
+ const ${FaustDspInstance_default.name}_default = ${FaustDspInstance_default.toString()}
3529
+ const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3530
+ const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3531
+ const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3532
+ const FFTUtils = ${fftUtils.toString()}
3533
+ // Put them in dependencies
3534
+ const dependencies = {
3535
+ ${FaustBaseWebAudioDsp.name},
3536
+ ${FaustMonoWebAudioDsp.name},
3537
+ ${FaustWasmInstantiator_default.name},
3538
+ FFTUtils
3539
+ };
3540
+ // Generate the actual AudioWorkletProcessor code
3541
+ (${FaustFFTAudioWorkletProcessor_default.toString()})(dependencies, faustData);
3542
+ `;
3543
+ const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
3544
+ await context.audioWorklet.addModule(url);
3545
+ (_b = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
3546
+ } catch (e) {
3547
+ throw e;
3548
+ }
3549
+ }
3550
+ const node = new FaustMonoAudioWorkletNode(context, processorName, factory, sampleSize, { channelCount: Math.max(1, Math.ceil(meta.inputs / 3)), outputChannelCount: [Math.ceil(meta.outputs / 2)] });
3551
+ if (fftOptions.fftSize) {
3552
+ const param = node.parameters.get("fftSize");
3553
+ if (param)
3554
+ param.value = fftOptions.fftSize;
3555
+ }
3556
+ if (fftOptions.fftOverlap) {
3557
+ const param = node.parameters.get("fftOverlap");
3558
+ if (param)
3559
+ param.value = fftOptions.fftOverlap;
3560
+ }
3561
+ if (typeof fftOptions.defaultWindowFunction === "number") {
3562
+ const param = node.parameters.get("windowFunction");
3563
+ if (param)
3564
+ param.value = fftOptions.defaultWindowFunction + 1;
3565
+ }
3566
+ if (typeof fftOptions.noIFFT === "boolean") {
3567
+ const param = node.parameters.get("noIFFT");
3568
+ if (param)
3569
+ param.value = +fftOptions.noIFFT;
3570
+ }
3571
+ return node;
3572
+ }
3573
+ async createAudioWorkletProcessor(name = this.name, factory = this.factory, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
3574
+ if (!factory)
3575
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3576
+ const meta = JSON.parse(factory.json);
3577
+ const dependencies = {
3578
+ FaustBaseWebAudioDsp,
3579
+ FaustMonoWebAudioDsp,
3580
+ FaustWasmInstantiator: FaustWasmInstantiator_default,
3581
+ FaustPolyWebAudioDsp: void 0,
3582
+ FaustWebAudioDspVoice: void 0
3583
+ };
3584
+ try {
3585
+ const faustData = {
3586
+ processorName,
3587
+ dspName: name,
3588
+ dspMeta: meta,
3589
+ poly: false
3590
+ };
3591
+ const Processor = FaustAudioWorkletProcessor_default(dependencies, faustData);
3592
+ return Processor;
3593
+ } catch (e) {
3594
+ throw e;
3595
+ }
3596
+ }
3597
+ async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory) {
3598
+ if (!factory)
3599
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3600
+ const meta = JSON.parse(factory.json);
3601
+ const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
3602
+ const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
3603
+ const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize);
3604
+ return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
3605
+ }
3606
+ };
3607
+ var FaustMonoDspGenerator = _FaustMonoDspGenerator;
3608
+ FaustMonoDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
3609
+ var _FaustPolyDspGenerator = class {
3610
+ constructor() {
3611
+ this.voiceFactory = null;
3612
+ this.effectFactory = null;
3613
+ }
3614
+ async compile(compiler, name, dspCode, args, effectCode = `
3615
+ adapt(1,1) = _; adapt(2,2) = _,_; adapt(1,2) = _ <: _,_; adapt(2,1) = _,_ :> _;
3616
+ adaptor(F,G) = adapt(outputs(F),inputs(G));
3617
+ dsp_code = environment{${dspCode}};
3618
+ process = adaptor(dsp_code.process, dsp_code.effect) : dsp_code.effect;`) {
3619
+ this.voiceFactory = await compiler.createPolyDSPFactory(name, dspCode, args);
3620
+ if (!this.voiceFactory)
3621
+ return null;
3622
+ try {
3623
+ this.effectFactory = await compiler.createPolyDSPFactory(name, effectCode, args);
3624
+ } catch (e) {
3625
+ console.warn(e);
3626
+ }
3627
+ this.name = name;
3628
+ const voiceMeta = JSON.parse(this.voiceFactory.json);
3629
+ const isDouble = voiceMeta.compile_options.match("-double");
3630
+ const { mixerBuffer, mixerModule } = await compiler.getAsyncInternalMixerModule(!!isDouble);
3631
+ this.mixerBuffer = mixerBuffer;
3632
+ this.mixerModule = mixerModule;
3633
+ return this;
3634
+ }
3635
+ async createNode(context, voices, name = this.name, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, sp = false, bufferSize = 1024, processorName = ((voiceFactory == null ? void 0 : voiceFactory.shaKey) || "") + ((effectFactory == null ? void 0 : effectFactory.shaKey) || "") || `${name}_poly`) {
3636
+ var _a, _b;
3637
+ if (!voiceFactory)
3638
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3639
+ const voiceMeta = JSON.parse(voiceFactory.json);
3640
+ const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
3641
+ const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
3642
+ if (sp) {
3643
+ const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
3644
+ const polyDsp = new FaustPolyWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize);
3645
+ const sp2 = context.createScriptProcessor(bufferSize, polyDsp.getNumInputs(), polyDsp.getNumOutputs());
3646
+ Object.setPrototypeOf(sp2, FaustPolyScriptProcessorNode.prototype);
3647
+ sp2.init(polyDsp);
3648
+ return sp2;
3649
+ } else {
3650
+ if (!_FaustPolyDspGenerator.gWorkletProcessors.has(context))
3651
+ _FaustPolyDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
3652
+ if (!((_a = _FaustPolyDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
3653
+ try {
3654
+ const processorCode = `
3655
+ // DSP name and JSON string for DSP are generated
3656
+ const faustData = ${JSON.stringify({
3657
+ processorName,
3658
+ dspName: name,
3659
+ dspMeta: voiceMeta,
3660
+ poly: true,
3661
+ effectMeta
3662
+ })};
3663
+ // Implementation needed classes of functions
3664
+ const ${FaustDspInstance_default.name}_default = ${FaustDspInstance_default.toString()}
3665
+ const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3666
+ const ${FaustPolyWebAudioDsp.name} = ${FaustPolyWebAudioDsp.toString()}
3667
+ const ${FaustWebAudioDspVoice.name} = ${FaustWebAudioDspVoice.toString()}
3668
+ const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3669
+ // Put them in dependencies
3670
+ const dependencies = {
3671
+ ${FaustBaseWebAudioDsp.name},
3672
+ ${FaustPolyWebAudioDsp.name},
3673
+ ${FaustWasmInstantiator_default.name}
3674
+ };
3675
+ // Generate the actual AudioWorkletProcessor code
3676
+ (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
3677
+ `;
3678
+ const url = URL.createObjectURL(new Blob([processorCode], { type: "text/javascript" }));
3679
+ await context.audioWorklet.addModule(url);
3680
+ (_b = _FaustPolyDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _b.add(processorName);
3681
+ } catch (e) {
3682
+ throw e;
3683
+ }
3684
+ }
3685
+ const node = new FaustPolyAudioWorkletNode(context, processorName, voiceFactory, mixerModule, voices, sampleSize, effectFactory || void 0);
3686
+ return node;
3687
+ }
3688
+ }
3689
+ async createAudioWorkletProcessor(name = this.name, voiceFactory = this.voiceFactory, effectFactory = this.effectFactory, processorName = ((voiceFactory == null ? void 0 : voiceFactory.shaKey) || "") + ((effectFactory == null ? void 0 : effectFactory.shaKey) || "") || `${name}_poly`) {
3690
+ if (!voiceFactory)
3691
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3692
+ const voiceMeta = JSON.parse(voiceFactory.json);
3693
+ const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
3694
+ const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
3695
+ try {
3696
+ const dependencies = {
3697
+ FaustBaseWebAudioDsp,
3698
+ FaustMonoWebAudioDsp: void 0,
3699
+ FaustWasmInstantiator: FaustWasmInstantiator_default,
3700
+ FaustPolyWebAudioDsp,
3701
+ FaustWebAudioDspVoice
3702
+ };
3703
+ const faustData = {
3704
+ processorName,
3705
+ dspName: name,
3706
+ dspMeta: voiceMeta,
3707
+ poly: true,
3708
+ effectMeta
3709
+ };
3710
+ const Processor = FaustAudioWorkletProcessor_default(dependencies, faustData);
3711
+ return Processor;
3712
+ } catch (e) {
3713
+ throw e;
3714
+ }
3715
+ }
3716
+ async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory) {
3717
+ if (!voiceFactory)
3718
+ throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3719
+ const voiceMeta = JSON.parse(voiceFactory.json);
3720
+ const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
3721
+ const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
3722
+ const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
3723
+ const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize);
3724
+ return new FaustPolyOfflineProcessor(polyDsp, bufferSize);
3725
+ }
3726
+ };
3727
+ var FaustPolyDspGenerator = _FaustPolyDspGenerator;
3728
+ FaustPolyDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
3729
+ export {
3730
+ FaustAudioWorkletNode,
3731
+ FaustBaseWebAudioDsp,
3732
+ FaustCompiler_default as FaustCompiler,
3733
+ FaustDspInstance_default as FaustDspInstance,
3734
+ FaustMonoAudioWorkletNode,
3735
+ FaustMonoDspGenerator,
3736
+ FaustMonoOfflineProcessor,
3737
+ FaustMonoScriptProcessorNode,
3738
+ FaustMonoWebAudioDsp,
3739
+ FaustOfflineProcessor_default as FaustOfflineProcessor,
3740
+ FaustPolyAudioWorkletNode,
3741
+ FaustPolyDspGenerator,
3742
+ FaustPolyOfflineProcessor,
3743
+ FaustPolyScriptProcessorNode,
3744
+ FaustPolyWebAudioDsp,
3745
+ FaustScriptProcessorNode,
3746
+ FaustSvgDiagrams_default as FaustSvgDiagrams,
3747
+ FaustWasmInstantiator_default as FaustWasmInstantiator,
3748
+ FaustWebAudioDspVoice,
3749
+ LibFaust_default as LibFaust,
3750
+ WavDecoder_default as WavDecoder,
3751
+ WavEncoder_default as WavEncoder,
3752
+ ab2str,
3753
+ FaustAudioWorkletProcessor_default as getFaustAudioWorkletProcessor,
3754
+ FaustFFTAudioWorkletProcessor_default as getFaustFFTAudioWorkletProcessor,
3755
+ instantiateFaustModuleFromFile_default as instantiateFaustModuleFromFile,
3756
+ str2ab
3757
+ };
3758
+ /*! *****************************************************************************
3759
+ Copyright (c) Microsoft Corporation.
3760
+
3761
+ Permission to use, copy, modify, and/or distribute this software for any
3762
+ purpose with or without fee is hereby granted.
3763
+
3764
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3765
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3766
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3767
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3768
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3769
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3770
+ PERFORMANCE OF THIS SOFTWARE.
3771
+ ***************************************************************************** */
3772
+ //# sourceMappingURL=index.js.map