@grame/faustwasm 0.1.7 → 0.2.0

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 (35) hide show
  1. package/assets/standalone/faustwasm/index.d.ts +132 -99
  2. package/assets/standalone/faustwasm/index.js +907 -1230
  3. package/assets/standalone/faustwasm/index.js.map +4 -4
  4. package/dist/cjs/index.d.ts +132 -99
  5. package/dist/cjs/index.js +909 -1212
  6. package/dist/cjs/index.js.map +4 -4
  7. package/dist/cjs-bundle/index.d.ts +132 -99
  8. package/dist/cjs-bundle/index.js +1012 -1317
  9. package/dist/cjs-bundle/index.js.map +4 -4
  10. package/dist/esm/index.d.ts +132 -99
  11. package/dist/esm/index.js +907 -1230
  12. package/dist/esm/index.js.map +4 -4
  13. package/dist/esm-bundle/index.d.ts +132 -99
  14. package/dist/esm-bundle/index.js +1012 -1321
  15. package/dist/esm-bundle/index.js.map +4 -4
  16. package/libfaust-wasm/libfaust-wasm.js +1 -1
  17. package/libfaust-wasm/libfaust-wasm.wasm +0 -0
  18. package/package.json +15 -15
  19. package/src/FaustAudioWorkletProcessor.ts +3 -14
  20. package/src/FaustCmajor.ts +6 -6
  21. package/src/FaustCompiler.ts +2 -2
  22. package/src/FaustDspGenerator.ts +109 -75
  23. package/src/FaustDspInstance.ts +2 -2
  24. package/src/FaustFFTAudioWorkletProcessor.ts +3 -1
  25. package/src/FaustWebAudioDsp.ts +224 -449
  26. package/src/SoundfileReader.ts +117 -0
  27. package/src/exports.ts +1 -0
  28. package/src/faust2wasmFiles.js +1 -1
  29. package/src/types.ts +15 -7
  30. package/test/faustlive-wasm/faustwasm/index.d.ts +132 -99
  31. package/test/faustlive-wasm/faustwasm/index.js +907 -1230
  32. package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
  33. package/test/soundfile.dsp +15 -0
  34. package/test/soundfile1.dsp +23 -0
  35. package/test/web/soundfile.html +69 -0
package/dist/cjs/index.js CHANGED
@@ -10,11 +10,8 @@
10
10
  }) : x)(function(x) {
11
11
  if (typeof require !== "undefined")
12
12
  return require.apply(this, arguments);
13
- throw new Error('Dynamic require of "' + x + '" is not supported');
13
+ throw Error('Dynamic require of "' + x + '" is not supported');
14
14
  });
15
- var __commonJS = (cb, mod) => function __require2() {
16
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
- };
18
15
  var __copyProps = (to, from, except, desc) => {
19
16
  if (from && typeof from === "object" || typeof from === "function") {
20
17
  for (let key of __getOwnPropNames(from))
@@ -24,872 +21,14 @@
24
21
  return to;
25
22
  };
26
23
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
28
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
29
  mod
29
30
  ));
30
31
 
31
- // node_modules/tslib/tslib.js
32
- var require_tslib = __commonJS({
33
- "node_modules/tslib/tslib.js"(exports, module) {
34
- var __extends;
35
- var __assign;
36
- var __rest;
37
- var __decorate;
38
- var __param;
39
- var __metadata;
40
- var __awaiter;
41
- var __generator;
42
- var __exportStar;
43
- var __values;
44
- var __read;
45
- var __spread;
46
- var __spreadArrays;
47
- var __await;
48
- var __asyncGenerator;
49
- var __asyncDelegator;
50
- var __asyncValues;
51
- var __makeTemplateObject;
52
- var __importStar;
53
- var __importDefault;
54
- var __classPrivateFieldGet;
55
- var __classPrivateFieldSet;
56
- var __createBinding;
57
- (function(factory) {
58
- var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : {};
59
- if (typeof define === "function" && define.amd) {
60
- define("tslib", ["exports"], function(exports2) {
61
- factory(createExporter(root, createExporter(exports2)));
62
- });
63
- } else if (typeof module === "object" && typeof module.exports === "object") {
64
- factory(createExporter(root, createExporter(module.exports)));
65
- } else {
66
- factory(createExporter(root));
67
- }
68
- function createExporter(exports2, previous) {
69
- if (exports2 !== root) {
70
- if (typeof Object.create === "function") {
71
- Object.defineProperty(exports2, "__esModule", { value: true });
72
- } else {
73
- exports2.__esModule = true;
74
- }
75
- }
76
- return function(id, v) {
77
- return exports2[id] = previous ? previous(id, v) : v;
78
- };
79
- }
80
- })(function(exporter) {
81
- var extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d, b) {
82
- d.__proto__ = b;
83
- } || function(d, b) {
84
- for (var p in b)
85
- if (b.hasOwnProperty(p))
86
- d[p] = b[p];
87
- };
88
- __extends = function(d, b) {
89
- extendStatics(d, b);
90
- function __() {
91
- this.constructor = d;
92
- }
93
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
94
- };
95
- __assign = Object.assign || function(t) {
96
- for (var s, i = 1, n = arguments.length; i < n; i++) {
97
- s = arguments[i];
98
- for (var p in s)
99
- if (Object.prototype.hasOwnProperty.call(s, p))
100
- t[p] = s[p];
101
- }
102
- return t;
103
- };
104
- __rest = function(s, e) {
105
- var t = {};
106
- for (var p in s)
107
- if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
108
- t[p] = s[p];
109
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
110
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
111
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
112
- t[p[i]] = s[p[i]];
113
- }
114
- return t;
115
- };
116
- __decorate = function(decorators, target, key, desc) {
117
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
118
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
119
- r = Reflect.decorate(decorators, target, key, desc);
120
- else
121
- for (var i = decorators.length - 1; i >= 0; i--)
122
- if (d = decorators[i])
123
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
124
- return c > 3 && r && Object.defineProperty(target, key, r), r;
125
- };
126
- __param = function(paramIndex, decorator) {
127
- return function(target, key) {
128
- decorator(target, key, paramIndex);
129
- };
130
- };
131
- __metadata = function(metadataKey, metadataValue) {
132
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
133
- return Reflect.metadata(metadataKey, metadataValue);
134
- };
135
- __awaiter = function(thisArg, _arguments, P, generator) {
136
- function adopt(value) {
137
- return value instanceof P ? value : new P(function(resolve) {
138
- resolve(value);
139
- });
140
- }
141
- return new (P || (P = Promise))(function(resolve, reject) {
142
- function fulfilled(value) {
143
- try {
144
- step(generator.next(value));
145
- } catch (e) {
146
- reject(e);
147
- }
148
- }
149
- function rejected(value) {
150
- try {
151
- step(generator["throw"](value));
152
- } catch (e) {
153
- reject(e);
154
- }
155
- }
156
- function step(result) {
157
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
158
- }
159
- step((generator = generator.apply(thisArg, _arguments || [])).next());
160
- });
161
- };
162
- __generator = function(thisArg, body) {
163
- var _ = { label: 0, sent: function() {
164
- if (t[0] & 1)
165
- throw t[1];
166
- return t[1];
167
- }, trys: [], ops: [] }, f, y, t, g;
168
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
169
- return this;
170
- }), g;
171
- function verb(n) {
172
- return function(v) {
173
- return step([n, v]);
174
- };
175
- }
176
- function step(op) {
177
- if (f)
178
- throw new TypeError("Generator is already executing.");
179
- while (_)
180
- try {
181
- 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)
182
- return t;
183
- if (y = 0, t)
184
- op = [op[0] & 2, t.value];
185
- switch (op[0]) {
186
- case 0:
187
- case 1:
188
- t = op;
189
- break;
190
- case 4:
191
- _.label++;
192
- return { value: op[1], done: false };
193
- case 5:
194
- _.label++;
195
- y = op[1];
196
- op = [0];
197
- continue;
198
- case 7:
199
- op = _.ops.pop();
200
- _.trys.pop();
201
- continue;
202
- default:
203
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
204
- _ = 0;
205
- continue;
206
- }
207
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
208
- _.label = op[1];
209
- break;
210
- }
211
- if (op[0] === 6 && _.label < t[1]) {
212
- _.label = t[1];
213
- t = op;
214
- break;
215
- }
216
- if (t && _.label < t[2]) {
217
- _.label = t[2];
218
- _.ops.push(op);
219
- break;
220
- }
221
- if (t[2])
222
- _.ops.pop();
223
- _.trys.pop();
224
- continue;
225
- }
226
- op = body.call(thisArg, _);
227
- } catch (e) {
228
- op = [6, e];
229
- y = 0;
230
- } finally {
231
- f = t = 0;
232
- }
233
- if (op[0] & 5)
234
- throw op[1];
235
- return { value: op[0] ? op[1] : void 0, done: true };
236
- }
237
- };
238
- __createBinding = function(o, m, k, k2) {
239
- if (k2 === void 0)
240
- k2 = k;
241
- o[k2] = m[k];
242
- };
243
- __exportStar = function(m, exports2) {
244
- for (var p in m)
245
- if (p !== "default" && !exports2.hasOwnProperty(p))
246
- exports2[p] = m[p];
247
- };
248
- __values = function(o) {
249
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
250
- if (m)
251
- return m.call(o);
252
- if (o && typeof o.length === "number")
253
- return {
254
- next: function() {
255
- if (o && i >= o.length)
256
- o = void 0;
257
- return { value: o && o[i++], done: !o };
258
- }
259
- };
260
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
261
- };
262
- __read = function(o, n) {
263
- var m = typeof Symbol === "function" && o[Symbol.iterator];
264
- if (!m)
265
- return o;
266
- var i = m.call(o), r, ar = [], e;
267
- try {
268
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
269
- ar.push(r.value);
270
- } catch (error) {
271
- e = { error };
272
- } finally {
273
- try {
274
- if (r && !r.done && (m = i["return"]))
275
- m.call(i);
276
- } finally {
277
- if (e)
278
- throw e.error;
279
- }
280
- }
281
- return ar;
282
- };
283
- __spread = function() {
284
- for (var ar = [], i = 0; i < arguments.length; i++)
285
- ar = ar.concat(__read(arguments[i]));
286
- return ar;
287
- };
288
- __spreadArrays = function() {
289
- for (var s = 0, i = 0, il = arguments.length; i < il; i++)
290
- s += arguments[i].length;
291
- for (var r = Array(s), k = 0, i = 0; i < il; i++)
292
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
293
- r[k] = a[j];
294
- return r;
295
- };
296
- __await = function(v) {
297
- return this instanceof __await ? (this.v = v, this) : new __await(v);
298
- };
299
- __asyncGenerator = function(thisArg, _arguments, generator) {
300
- if (!Symbol.asyncIterator)
301
- throw new TypeError("Symbol.asyncIterator is not defined.");
302
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
303
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
304
- return this;
305
- }, i;
306
- function verb(n) {
307
- if (g[n])
308
- i[n] = function(v) {
309
- return new Promise(function(a, b) {
310
- q.push([n, v, a, b]) > 1 || resume(n, v);
311
- });
312
- };
313
- }
314
- function resume(n, v) {
315
- try {
316
- step(g[n](v));
317
- } catch (e) {
318
- settle(q[0][3], e);
319
- }
320
- }
321
- function step(r) {
322
- r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r);
323
- }
324
- function fulfill(value) {
325
- resume("next", value);
326
- }
327
- function reject(value) {
328
- resume("throw", value);
329
- }
330
- function settle(f, v) {
331
- if (f(v), q.shift(), q.length)
332
- resume(q[0][0], q[0][1]);
333
- }
334
- };
335
- __asyncDelegator = function(o) {
336
- var i, p;
337
- return i = {}, verb("next"), verb("throw", function(e) {
338
- throw e;
339
- }), verb("return"), i[Symbol.iterator] = function() {
340
- return this;
341
- }, i;
342
- function verb(n, f) {
343
- i[n] = o[n] ? function(v) {
344
- return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v;
345
- } : f;
346
- }
347
- };
348
- __asyncValues = function(o) {
349
- if (!Symbol.asyncIterator)
350
- throw new TypeError("Symbol.asyncIterator is not defined.");
351
- var m = o[Symbol.asyncIterator], i;
352
- 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() {
353
- return this;
354
- }, i);
355
- function verb(n) {
356
- i[n] = o[n] && function(v) {
357
- return new Promise(function(resolve, reject) {
358
- v = o[n](v), settle(resolve, reject, v.done, v.value);
359
- });
360
- };
361
- }
362
- function settle(resolve, reject, d, v) {
363
- Promise.resolve(v).then(function(v2) {
364
- resolve({ value: v2, done: d });
365
- }, reject);
366
- }
367
- };
368
- __makeTemplateObject = function(cooked, raw) {
369
- if (Object.defineProperty) {
370
- Object.defineProperty(cooked, "raw", { value: raw });
371
- } else {
372
- cooked.raw = raw;
373
- }
374
- return cooked;
375
- };
376
- __importStar = function(mod) {
377
- if (mod && mod.__esModule)
378
- return mod;
379
- var result = {};
380
- if (mod != null) {
381
- for (var k in mod)
382
- if (Object.hasOwnProperty.call(mod, k))
383
- result[k] = mod[k];
384
- }
385
- result["default"] = mod;
386
- return result;
387
- };
388
- __importDefault = function(mod) {
389
- return mod && mod.__esModule ? mod : { "default": mod };
390
- };
391
- __classPrivateFieldGet = function(receiver, privateMap) {
392
- if (!privateMap.has(receiver)) {
393
- throw new TypeError("attempted to get private field on non-instance");
394
- }
395
- return privateMap.get(receiver);
396
- };
397
- __classPrivateFieldSet = function(receiver, privateMap, value) {
398
- if (!privateMap.has(receiver)) {
399
- throw new TypeError("attempted to set private field on non-instance");
400
- }
401
- privateMap.set(receiver, value);
402
- return value;
403
- };
404
- exporter("__extends", __extends);
405
- exporter("__assign", __assign);
406
- exporter("__rest", __rest);
407
- exporter("__decorate", __decorate);
408
- exporter("__param", __param);
409
- exporter("__metadata", __metadata);
410
- exporter("__awaiter", __awaiter);
411
- exporter("__generator", __generator);
412
- exporter("__exportStar", __exportStar);
413
- exporter("__createBinding", __createBinding);
414
- exporter("__values", __values);
415
- exporter("__read", __read);
416
- exporter("__spread", __spread);
417
- exporter("__spreadArrays", __spreadArrays);
418
- exporter("__await", __await);
419
- exporter("__asyncGenerator", __asyncGenerator);
420
- exporter("__asyncDelegator", __asyncDelegator);
421
- exporter("__asyncValues", __asyncValues);
422
- exporter("__makeTemplateObject", __makeTemplateObject);
423
- exporter("__importStar", __importStar);
424
- exporter("__importDefault", __importDefault);
425
- exporter("__classPrivateFieldGet", __classPrivateFieldGet);
426
- exporter("__classPrivateFieldSet", __classPrivateFieldSet);
427
- });
428
- }
429
- });
430
-
431
- // node_modules/@aws-crypto/sha256-js/build/constants.js
432
- var require_constants = __commonJS({
433
- "node_modules/@aws-crypto/sha256-js/build/constants.js"(exports) {
434
- "use strict";
435
- Object.defineProperty(exports, "__esModule", { value: true });
436
- exports.MAX_HASHABLE_LENGTH = exports.INIT = exports.KEY = exports.DIGEST_LENGTH = exports.BLOCK_SIZE = void 0;
437
- exports.BLOCK_SIZE = 64;
438
- exports.DIGEST_LENGTH = 32;
439
- exports.KEY = new Uint32Array([
440
- 1116352408,
441
- 1899447441,
442
- 3049323471,
443
- 3921009573,
444
- 961987163,
445
- 1508970993,
446
- 2453635748,
447
- 2870763221,
448
- 3624381080,
449
- 310598401,
450
- 607225278,
451
- 1426881987,
452
- 1925078388,
453
- 2162078206,
454
- 2614888103,
455
- 3248222580,
456
- 3835390401,
457
- 4022224774,
458
- 264347078,
459
- 604807628,
460
- 770255983,
461
- 1249150122,
462
- 1555081692,
463
- 1996064986,
464
- 2554220882,
465
- 2821834349,
466
- 2952996808,
467
- 3210313671,
468
- 3336571891,
469
- 3584528711,
470
- 113926993,
471
- 338241895,
472
- 666307205,
473
- 773529912,
474
- 1294757372,
475
- 1396182291,
476
- 1695183700,
477
- 1986661051,
478
- 2177026350,
479
- 2456956037,
480
- 2730485921,
481
- 2820302411,
482
- 3259730800,
483
- 3345764771,
484
- 3516065817,
485
- 3600352804,
486
- 4094571909,
487
- 275423344,
488
- 430227734,
489
- 506948616,
490
- 659060556,
491
- 883997877,
492
- 958139571,
493
- 1322822218,
494
- 1537002063,
495
- 1747873779,
496
- 1955562222,
497
- 2024104815,
498
- 2227730452,
499
- 2361852424,
500
- 2428436474,
501
- 2756734187,
502
- 3204031479,
503
- 3329325298
504
- ]);
505
- exports.INIT = [
506
- 1779033703,
507
- 3144134277,
508
- 1013904242,
509
- 2773480762,
510
- 1359893119,
511
- 2600822924,
512
- 528734635,
513
- 1541459225
514
- ];
515
- exports.MAX_HASHABLE_LENGTH = Math.pow(2, 53) - 1;
516
- }
517
- });
518
-
519
- // node_modules/@aws-crypto/sha256-js/build/RawSha256.js
520
- var require_RawSha256 = __commonJS({
521
- "node_modules/@aws-crypto/sha256-js/build/RawSha256.js"(exports) {
522
- "use strict";
523
- Object.defineProperty(exports, "__esModule", { value: true });
524
- exports.RawSha256 = void 0;
525
- var constants_1 = require_constants();
526
- var RawSha256 = function() {
527
- function RawSha2562() {
528
- this.state = Int32Array.from(constants_1.INIT);
529
- this.temp = new Int32Array(64);
530
- this.buffer = new Uint8Array(64);
531
- this.bufferLength = 0;
532
- this.bytesHashed = 0;
533
- this.finished = false;
534
- }
535
- RawSha2562.prototype.update = function(data) {
536
- if (this.finished) {
537
- throw new Error("Attempted to update an already finished hash.");
538
- }
539
- var position = 0;
540
- var byteLength = data.byteLength;
541
- this.bytesHashed += byteLength;
542
- if (this.bytesHashed * 8 > constants_1.MAX_HASHABLE_LENGTH) {
543
- throw new Error("Cannot hash more than 2^53 - 1 bits");
544
- }
545
- while (byteLength > 0) {
546
- this.buffer[this.bufferLength++] = data[position++];
547
- byteLength--;
548
- if (this.bufferLength === constants_1.BLOCK_SIZE) {
549
- this.hashBuffer();
550
- this.bufferLength = 0;
551
- }
552
- }
553
- };
554
- RawSha2562.prototype.digest = function() {
555
- if (!this.finished) {
556
- var bitsHashed = this.bytesHashed * 8;
557
- var bufferView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
558
- var undecoratedLength = this.bufferLength;
559
- bufferView.setUint8(this.bufferLength++, 128);
560
- if (undecoratedLength % constants_1.BLOCK_SIZE >= constants_1.BLOCK_SIZE - 8) {
561
- for (var i = this.bufferLength; i < constants_1.BLOCK_SIZE; i++) {
562
- bufferView.setUint8(i, 0);
563
- }
564
- this.hashBuffer();
565
- this.bufferLength = 0;
566
- }
567
- for (var i = this.bufferLength; i < constants_1.BLOCK_SIZE - 8; i++) {
568
- bufferView.setUint8(i, 0);
569
- }
570
- bufferView.setUint32(constants_1.BLOCK_SIZE - 8, Math.floor(bitsHashed / 4294967296), true);
571
- bufferView.setUint32(constants_1.BLOCK_SIZE - 4, bitsHashed);
572
- this.hashBuffer();
573
- this.finished = true;
574
- }
575
- var out = new Uint8Array(constants_1.DIGEST_LENGTH);
576
- for (var i = 0; i < 8; i++) {
577
- out[i * 4] = this.state[i] >>> 24 & 255;
578
- out[i * 4 + 1] = this.state[i] >>> 16 & 255;
579
- out[i * 4 + 2] = this.state[i] >>> 8 & 255;
580
- out[i * 4 + 3] = this.state[i] >>> 0 & 255;
581
- }
582
- return out;
583
- };
584
- RawSha2562.prototype.hashBuffer = function() {
585
- var _a = this, buffer = _a.buffer, state = _a.state;
586
- 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];
587
- for (var i = 0; i < constants_1.BLOCK_SIZE; i++) {
588
- if (i < 16) {
589
- 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;
590
- } else {
591
- var u = this.temp[i - 2];
592
- var t1_1 = (u >>> 17 | u << 15) ^ (u >>> 19 | u << 13) ^ u >>> 10;
593
- u = this.temp[i - 15];
594
- var t2_1 = (u >>> 7 | u << 25) ^ (u >>> 18 | u << 14) ^ u >>> 3;
595
- this.temp[i] = (t1_1 + this.temp[i - 7] | 0) + (t2_1 + this.temp[i - 16] | 0);
596
- }
597
- 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;
598
- var t2 = ((state0 >>> 2 | state0 << 30) ^ (state0 >>> 13 | state0 << 19) ^ (state0 >>> 22 | state0 << 10)) + (state0 & state1 ^ state0 & state2 ^ state1 & state2) | 0;
599
- state7 = state6;
600
- state6 = state5;
601
- state5 = state4;
602
- state4 = state3 + t1 | 0;
603
- state3 = state2;
604
- state2 = state1;
605
- state1 = state0;
606
- state0 = t1 + t2 | 0;
607
- }
608
- state[0] += state0;
609
- state[1] += state1;
610
- state[2] += state2;
611
- state[3] += state3;
612
- state[4] += state4;
613
- state[5] += state5;
614
- state[6] += state6;
615
- state[7] += state7;
616
- };
617
- return RawSha2562;
618
- }();
619
- exports.RawSha256 = RawSha256;
620
- }
621
- });
622
-
623
- // node_modules/@aws-sdk/util-utf8-browser/dist-cjs/pureJs.js
624
- var require_pureJs = __commonJS({
625
- "node_modules/@aws-sdk/util-utf8-browser/dist-cjs/pureJs.js"(exports) {
626
- "use strict";
627
- Object.defineProperty(exports, "__esModule", { value: true });
628
- exports.toUtf8 = exports.fromUtf8 = void 0;
629
- var fromUtf8 = (input) => {
630
- const bytes = [];
631
- for (let i = 0, len = input.length; i < len; i++) {
632
- const value = input.charCodeAt(i);
633
- if (value < 128) {
634
- bytes.push(value);
635
- } else if (value < 2048) {
636
- bytes.push(value >> 6 | 192, value & 63 | 128);
637
- } else if (i + 1 < input.length && (value & 64512) === 55296 && (input.charCodeAt(i + 1) & 64512) === 56320) {
638
- const surrogatePair = 65536 + ((value & 1023) << 10) + (input.charCodeAt(++i) & 1023);
639
- bytes.push(surrogatePair >> 18 | 240, surrogatePair >> 12 & 63 | 128, surrogatePair >> 6 & 63 | 128, surrogatePair & 63 | 128);
640
- } else {
641
- bytes.push(value >> 12 | 224, value >> 6 & 63 | 128, value & 63 | 128);
642
- }
643
- }
644
- return Uint8Array.from(bytes);
645
- };
646
- exports.fromUtf8 = fromUtf8;
647
- var toUtf8 = (input) => {
648
- let decoded = "";
649
- for (let i = 0, len = input.length; i < len; i++) {
650
- const byte = input[i];
651
- if (byte < 128) {
652
- decoded += String.fromCharCode(byte);
653
- } else if (192 <= byte && byte < 224) {
654
- const nextByte = input[++i];
655
- decoded += String.fromCharCode((byte & 31) << 6 | nextByte & 63);
656
- } else if (240 <= byte && byte < 365) {
657
- const surrogatePair = [byte, input[++i], input[++i], input[++i]];
658
- const encoded = "%" + surrogatePair.map((byteValue) => byteValue.toString(16)).join("%");
659
- decoded += decodeURIComponent(encoded);
660
- } else {
661
- decoded += String.fromCharCode((byte & 15) << 12 | (input[++i] & 63) << 6 | input[++i] & 63);
662
- }
663
- }
664
- return decoded;
665
- };
666
- exports.toUtf8 = toUtf8;
667
- }
668
- });
669
-
670
- // node_modules/@aws-sdk/util-utf8-browser/dist-cjs/whatwgEncodingApi.js
671
- var require_whatwgEncodingApi = __commonJS({
672
- "node_modules/@aws-sdk/util-utf8-browser/dist-cjs/whatwgEncodingApi.js"(exports) {
673
- "use strict";
674
- Object.defineProperty(exports, "__esModule", { value: true });
675
- exports.toUtf8 = exports.fromUtf8 = void 0;
676
- function fromUtf8(input) {
677
- return new TextEncoder().encode(input);
678
- }
679
- exports.fromUtf8 = fromUtf8;
680
- function toUtf8(input) {
681
- return new TextDecoder("utf-8").decode(input);
682
- }
683
- exports.toUtf8 = toUtf8;
684
- }
685
- });
686
-
687
- // node_modules/@aws-sdk/util-utf8-browser/dist-cjs/index.js
688
- var require_dist_cjs = __commonJS({
689
- "node_modules/@aws-sdk/util-utf8-browser/dist-cjs/index.js"(exports) {
690
- "use strict";
691
- Object.defineProperty(exports, "__esModule", { value: true });
692
- exports.toUtf8 = exports.fromUtf8 = void 0;
693
- var pureJs_1 = require_pureJs();
694
- var whatwgEncodingApi_1 = require_whatwgEncodingApi();
695
- var fromUtf8 = (input) => typeof TextEncoder === "function" ? (0, whatwgEncodingApi_1.fromUtf8)(input) : (0, pureJs_1.fromUtf8)(input);
696
- exports.fromUtf8 = fromUtf8;
697
- var toUtf8 = (input) => typeof TextDecoder === "function" ? (0, whatwgEncodingApi_1.toUtf8)(input) : (0, pureJs_1.toUtf8)(input);
698
- exports.toUtf8 = toUtf8;
699
- }
700
- });
701
-
702
- // node_modules/@aws-crypto/util/build/convertToBuffer.js
703
- var require_convertToBuffer = __commonJS({
704
- "node_modules/@aws-crypto/util/build/convertToBuffer.js"(exports) {
705
- "use strict";
706
- Object.defineProperty(exports, "__esModule", { value: true });
707
- exports.convertToBuffer = void 0;
708
- var util_utf8_browser_1 = require_dist_cjs();
709
- var fromUtf8 = typeof Buffer !== "undefined" && Buffer.from ? function(input) {
710
- return Buffer.from(input, "utf8");
711
- } : util_utf8_browser_1.fromUtf8;
712
- function convertToBuffer(data) {
713
- if (data instanceof Uint8Array)
714
- return data;
715
- if (typeof data === "string") {
716
- return fromUtf8(data);
717
- }
718
- if (ArrayBuffer.isView(data)) {
719
- return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
720
- }
721
- return new Uint8Array(data);
722
- }
723
- exports.convertToBuffer = convertToBuffer;
724
- }
725
- });
726
-
727
- // node_modules/@aws-crypto/util/build/isEmptyData.js
728
- var require_isEmptyData = __commonJS({
729
- "node_modules/@aws-crypto/util/build/isEmptyData.js"(exports) {
730
- "use strict";
731
- Object.defineProperty(exports, "__esModule", { value: true });
732
- exports.isEmptyData = void 0;
733
- function isEmptyData(data) {
734
- if (typeof data === "string") {
735
- return data.length === 0;
736
- }
737
- return data.byteLength === 0;
738
- }
739
- exports.isEmptyData = isEmptyData;
740
- }
741
- });
742
-
743
- // node_modules/@aws-crypto/util/build/numToUint8.js
744
- var require_numToUint8 = __commonJS({
745
- "node_modules/@aws-crypto/util/build/numToUint8.js"(exports) {
746
- "use strict";
747
- Object.defineProperty(exports, "__esModule", { value: true });
748
- exports.numToUint8 = void 0;
749
- function numToUint8(num) {
750
- return new Uint8Array([
751
- (num & 4278190080) >> 24,
752
- (num & 16711680) >> 16,
753
- (num & 65280) >> 8,
754
- num & 255
755
- ]);
756
- }
757
- exports.numToUint8 = numToUint8;
758
- }
759
- });
760
-
761
- // node_modules/@aws-crypto/util/build/uint32ArrayFrom.js
762
- var require_uint32ArrayFrom = __commonJS({
763
- "node_modules/@aws-crypto/util/build/uint32ArrayFrom.js"(exports) {
764
- "use strict";
765
- Object.defineProperty(exports, "__esModule", { value: true });
766
- exports.uint32ArrayFrom = void 0;
767
- function uint32ArrayFrom(a_lookUpTable) {
768
- if (!Uint32Array.from) {
769
- var return_array = new Uint32Array(a_lookUpTable.length);
770
- var a_index = 0;
771
- while (a_index < a_lookUpTable.length) {
772
- return_array[a_index] = a_lookUpTable[a_index];
773
- a_index += 1;
774
- }
775
- return return_array;
776
- }
777
- return Uint32Array.from(a_lookUpTable);
778
- }
779
- exports.uint32ArrayFrom = uint32ArrayFrom;
780
- }
781
- });
782
-
783
- // node_modules/@aws-crypto/util/build/index.js
784
- var require_build = __commonJS({
785
- "node_modules/@aws-crypto/util/build/index.js"(exports) {
786
- "use strict";
787
- Object.defineProperty(exports, "__esModule", { value: true });
788
- exports.uint32ArrayFrom = exports.numToUint8 = exports.isEmptyData = exports.convertToBuffer = void 0;
789
- var convertToBuffer_1 = require_convertToBuffer();
790
- Object.defineProperty(exports, "convertToBuffer", { enumerable: true, get: function() {
791
- return convertToBuffer_1.convertToBuffer;
792
- } });
793
- var isEmptyData_1 = require_isEmptyData();
794
- Object.defineProperty(exports, "isEmptyData", { enumerable: true, get: function() {
795
- return isEmptyData_1.isEmptyData;
796
- } });
797
- var numToUint8_1 = require_numToUint8();
798
- Object.defineProperty(exports, "numToUint8", { enumerable: true, get: function() {
799
- return numToUint8_1.numToUint8;
800
- } });
801
- var uint32ArrayFrom_1 = require_uint32ArrayFrom();
802
- Object.defineProperty(exports, "uint32ArrayFrom", { enumerable: true, get: function() {
803
- return uint32ArrayFrom_1.uint32ArrayFrom;
804
- } });
805
- }
806
- });
807
-
808
- // node_modules/@aws-crypto/sha256-js/build/jsSha256.js
809
- var require_jsSha256 = __commonJS({
810
- "node_modules/@aws-crypto/sha256-js/build/jsSha256.js"(exports) {
811
- "use strict";
812
- Object.defineProperty(exports, "__esModule", { value: true });
813
- exports.Sha256 = void 0;
814
- var tslib_1 = require_tslib();
815
- var constants_1 = require_constants();
816
- var RawSha256_1 = require_RawSha256();
817
- var util_1 = require_build();
818
- var Sha2562 = function() {
819
- function Sha2563(secret) {
820
- this.hash = new RawSha256_1.RawSha256();
821
- if (secret) {
822
- this.outer = new RawSha256_1.RawSha256();
823
- var inner = bufferFromSecret(secret);
824
- var outer = new Uint8Array(constants_1.BLOCK_SIZE);
825
- outer.set(inner);
826
- for (var i = 0; i < constants_1.BLOCK_SIZE; i++) {
827
- inner[i] ^= 54;
828
- outer[i] ^= 92;
829
- }
830
- this.hash.update(inner);
831
- this.outer.update(outer);
832
- for (var i = 0; i < inner.byteLength; i++) {
833
- inner[i] = 0;
834
- }
835
- }
836
- }
837
- Sha2563.prototype.update = function(toHash) {
838
- if ((0, util_1.isEmptyData)(toHash) || this.error) {
839
- return;
840
- }
841
- try {
842
- this.hash.update((0, util_1.convertToBuffer)(toHash));
843
- } catch (e) {
844
- this.error = e;
845
- }
846
- };
847
- Sha2563.prototype.digestSync = function() {
848
- if (this.error) {
849
- throw this.error;
850
- }
851
- if (this.outer) {
852
- if (!this.outer.finished) {
853
- this.outer.update(this.hash.digest());
854
- }
855
- return this.outer.digest();
856
- }
857
- return this.hash.digest();
858
- };
859
- Sha2563.prototype.digest = function() {
860
- return tslib_1.__awaiter(this, void 0, void 0, function() {
861
- return tslib_1.__generator(this, function(_a) {
862
- return [2, this.digestSync()];
863
- });
864
- });
865
- };
866
- return Sha2563;
867
- }();
868
- exports.Sha256 = Sha2562;
869
- function bufferFromSecret(secret) {
870
- var input = (0, util_1.convertToBuffer)(secret);
871
- if (input.byteLength > constants_1.BLOCK_SIZE) {
872
- var bufferHash = new RawSha256_1.RawSha256();
873
- bufferHash.update(input);
874
- input = bufferHash.digest();
875
- }
876
- var buffer = new Uint8Array(constants_1.BLOCK_SIZE);
877
- buffer.set(input);
878
- return buffer;
879
- }
880
- }
881
- });
882
-
883
- // node_modules/@aws-crypto/sha256-js/build/index.js
884
- var require_build2 = __commonJS({
885
- "node_modules/@aws-crypto/sha256-js/build/index.js"(exports) {
886
- "use strict";
887
- Object.defineProperty(exports, "__esModule", { value: true });
888
- var tslib_1 = require_tslib();
889
- tslib_1.__exportStar(require_jsSha256(), exports);
890
- }
891
- });
892
-
893
32
  // src/instantiateFaustModuleFromFile.ts
894
33
  var instantiateFaustModuleFromFile = async (jsFile, dataFile = jsFile.replace(/c?js$/, "data"), wasmFile = jsFile.replace(/c?js$/, "wasm")) => {
895
34
  var _a, _b;
@@ -1067,11 +206,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1067
206
  const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
1068
207
  const { factory, sampleSize } = options.processorOptions;
1069
208
  const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
1070
- this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128);
1071
- if (this.fDSPCode.hasSoundfiles()) {
1072
- console.error("FaustAudioWorkletProcessor: Soundfile support is not implemented yet, switch to ScriptProcessorNode for now");
1073
- return;
1074
- }
209
+ this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
1075
210
  this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
1076
211
  this.fDSPCode.start();
1077
212
  }
@@ -1096,11 +231,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1096
231
  const { FaustPolyWebAudioDsp: FaustPolyWebAudioDsp3 } = dependencies;
1097
232
  const { voiceFactory, mixerModule, voices, effectFactory, sampleSize } = options.processorOptions;
1098
233
  const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
1099
- this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128);
1100
- if (this.fDSPCode.hasSoundfiles()) {
1101
- console.error("FaustAudioWorkletProcessor: Soundfile support is not implemented yet, switch to ScriptProcessorNode for now");
1102
- return;
1103
- }
234
+ const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
235
+ this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
1104
236
  this.port.onmessage = (e) => this.handleMessageAux(e);
1105
237
  this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
1106
238
  this.fDSPCode.start();
@@ -1117,6 +249,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1117
249
  else
1118
250
  super.midiMessage(data);
1119
251
  }
252
+ // Public API
1120
253
  keyOn(channel, pitch, velocity) {
1121
254
  this.fDSPCode.keyOn(channel, pitch, velocity);
1122
255
  }
@@ -1205,13 +338,21 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1205
338
  super(options);
1206
339
  this.paramValuesCache = {};
1207
340
  this.destroyed = false;
341
+ /** Pointer of next start sample to write of the FFT input window */
1208
342
  this.$inputWrite = 0;
343
+ /** Pointer of next start sample to read of the FFT input window */
1209
344
  this.$inputRead = 0;
345
+ /** Pointer of next start sample to write of the FFT output window */
1210
346
  this.$outputWrite = 0;
347
+ /** Pointer of next start sample to read of the FFT output window */
1211
348
  this.$outputRead = 0;
349
+ /** Not perform in IFFT when reconstruct the audio signal */
1212
350
  this.noIFFT = false;
351
+ /** audio data from input, array of channels */
1213
352
  this.fftInput = [];
353
+ /** audio data for output, array of channels */
1214
354
  this.fftOutput = [];
355
+ /** FFT Overlaps, 1 means no overlap */
1215
356
  this.fftOverlap = 0;
1216
357
  this.fftHopSize = 0;
1217
358
  this.fftSize = 0;
@@ -1219,6 +360,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1219
360
  this.fPlotHandler = null;
1220
361
  this.fCachedEvents = [];
1221
362
  this.fBufferNum = 0;
363
+ this.soundfiles = {};
1222
364
  this.windowFunction = null;
1223
365
  this.port.onmessage = (e) => this.handleMessageAux(e);
1224
366
  const { parameterDescriptors } = this.constructor;
@@ -1228,6 +370,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1228
370
  const { factory, sampleSize } = options.processorOptions;
1229
371
  this.dspInstance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
1230
372
  this.sampleSize = sampleSize;
373
+ this.soundfiles = factory.soundfiles;
1231
374
  this.initFFT();
1232
375
  }
1233
376
  get fftProcessorBufferSize() {
@@ -1513,7 +656,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1513
656
  var _a, _b;
1514
657
  (_a = this.fDSPCode) == null ? void 0 : _a.stop();
1515
658
  (_b = this.fDSPCode) == null ? void 0 : _b.destroy();
1516
- this.fDSPCode = new FaustMonoWebAudioDsp2(this.dspInstance, sampleRate, this.sampleSize, this.fftProcessorBufferSize);
659
+ this.fDSPCode = new FaustMonoWebAudioDsp2(this.dspInstance, sampleRate, this.sampleSize, this.fftProcessorBufferSize, this.soundfiles);
1517
660
  this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
1518
661
  this.fDSPCode.setPlotHandler(this.fPlotHandler);
1519
662
  const params = this.fDSPCode.getParams();
@@ -1551,8 +694,389 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1551
694
  };
1552
695
  var FaustFFTAudioWorkletProcessor_default = getFaustFFTAudioWorkletProcessor;
1553
696
 
697
+ // node_modules/tslib/tslib.es6.mjs
698
+ function __awaiter(thisArg, _arguments, P, generator) {
699
+ function adopt(value) {
700
+ return value instanceof P ? value : new P(function(resolve) {
701
+ resolve(value);
702
+ });
703
+ }
704
+ return new (P || (P = Promise))(function(resolve, reject) {
705
+ function fulfilled(value) {
706
+ try {
707
+ step(generator.next(value));
708
+ } catch (e) {
709
+ reject(e);
710
+ }
711
+ }
712
+ function rejected(value) {
713
+ try {
714
+ step(generator["throw"](value));
715
+ } catch (e) {
716
+ reject(e);
717
+ }
718
+ }
719
+ function step(result) {
720
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
721
+ }
722
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
723
+ });
724
+ }
725
+ function __generator(thisArg, body) {
726
+ var _ = { label: 0, sent: function() {
727
+ if (t[0] & 1)
728
+ throw t[1];
729
+ return t[1];
730
+ }, trys: [], ops: [] }, f, y, t, g;
731
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
732
+ return this;
733
+ }), g;
734
+ function verb(n) {
735
+ return function(v) {
736
+ return step([n, v]);
737
+ };
738
+ }
739
+ function step(op) {
740
+ if (f)
741
+ throw new TypeError("Generator is already executing.");
742
+ while (g && (g = 0, op[0] && (_ = 0)), _)
743
+ try {
744
+ 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)
745
+ return t;
746
+ if (y = 0, t)
747
+ op = [op[0] & 2, t.value];
748
+ switch (op[0]) {
749
+ case 0:
750
+ case 1:
751
+ t = op;
752
+ break;
753
+ case 4:
754
+ _.label++;
755
+ return { value: op[1], done: false };
756
+ case 5:
757
+ _.label++;
758
+ y = op[1];
759
+ op = [0];
760
+ continue;
761
+ case 7:
762
+ op = _.ops.pop();
763
+ _.trys.pop();
764
+ continue;
765
+ default:
766
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
767
+ _ = 0;
768
+ continue;
769
+ }
770
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
771
+ _.label = op[1];
772
+ break;
773
+ }
774
+ if (op[0] === 6 && _.label < t[1]) {
775
+ _.label = t[1];
776
+ t = op;
777
+ break;
778
+ }
779
+ if (t && _.label < t[2]) {
780
+ _.label = t[2];
781
+ _.ops.push(op);
782
+ break;
783
+ }
784
+ if (t[2])
785
+ _.ops.pop();
786
+ _.trys.pop();
787
+ continue;
788
+ }
789
+ op = body.call(thisArg, _);
790
+ } catch (e) {
791
+ op = [6, e];
792
+ y = 0;
793
+ } finally {
794
+ f = t = 0;
795
+ }
796
+ if (op[0] & 5)
797
+ throw op[1];
798
+ return { value: op[0] ? op[1] : void 0, done: true };
799
+ }
800
+ }
801
+
802
+ // node_modules/@aws-crypto/sha256-js/build/module/constants.js
803
+ var BLOCK_SIZE = 64;
804
+ var DIGEST_LENGTH = 32;
805
+ var KEY = new Uint32Array([
806
+ 1116352408,
807
+ 1899447441,
808
+ 3049323471,
809
+ 3921009573,
810
+ 961987163,
811
+ 1508970993,
812
+ 2453635748,
813
+ 2870763221,
814
+ 3624381080,
815
+ 310598401,
816
+ 607225278,
817
+ 1426881987,
818
+ 1925078388,
819
+ 2162078206,
820
+ 2614888103,
821
+ 3248222580,
822
+ 3835390401,
823
+ 4022224774,
824
+ 264347078,
825
+ 604807628,
826
+ 770255983,
827
+ 1249150122,
828
+ 1555081692,
829
+ 1996064986,
830
+ 2554220882,
831
+ 2821834349,
832
+ 2952996808,
833
+ 3210313671,
834
+ 3336571891,
835
+ 3584528711,
836
+ 113926993,
837
+ 338241895,
838
+ 666307205,
839
+ 773529912,
840
+ 1294757372,
841
+ 1396182291,
842
+ 1695183700,
843
+ 1986661051,
844
+ 2177026350,
845
+ 2456956037,
846
+ 2730485921,
847
+ 2820302411,
848
+ 3259730800,
849
+ 3345764771,
850
+ 3516065817,
851
+ 3600352804,
852
+ 4094571909,
853
+ 275423344,
854
+ 430227734,
855
+ 506948616,
856
+ 659060556,
857
+ 883997877,
858
+ 958139571,
859
+ 1322822218,
860
+ 1537002063,
861
+ 1747873779,
862
+ 1955562222,
863
+ 2024104815,
864
+ 2227730452,
865
+ 2361852424,
866
+ 2428436474,
867
+ 2756734187,
868
+ 3204031479,
869
+ 3329325298
870
+ ]);
871
+ var INIT = [
872
+ 1779033703,
873
+ 3144134277,
874
+ 1013904242,
875
+ 2773480762,
876
+ 1359893119,
877
+ 2600822924,
878
+ 528734635,
879
+ 1541459225
880
+ ];
881
+ var MAX_HASHABLE_LENGTH = Math.pow(2, 53) - 1;
882
+
883
+ // node_modules/@aws-crypto/sha256-js/build/module/RawSha256.js
884
+ var RawSha256 = (
885
+ /** @class */
886
+ function() {
887
+ function RawSha2562() {
888
+ this.state = Int32Array.from(INIT);
889
+ this.temp = new Int32Array(64);
890
+ this.buffer = new Uint8Array(64);
891
+ this.bufferLength = 0;
892
+ this.bytesHashed = 0;
893
+ this.finished = false;
894
+ }
895
+ RawSha2562.prototype.update = function(data) {
896
+ if (this.finished) {
897
+ throw new Error("Attempted to update an already finished hash.");
898
+ }
899
+ var position = 0;
900
+ var byteLength = data.byteLength;
901
+ this.bytesHashed += byteLength;
902
+ if (this.bytesHashed * 8 > MAX_HASHABLE_LENGTH) {
903
+ throw new Error("Cannot hash more than 2^53 - 1 bits");
904
+ }
905
+ while (byteLength > 0) {
906
+ this.buffer[this.bufferLength++] = data[position++];
907
+ byteLength--;
908
+ if (this.bufferLength === BLOCK_SIZE) {
909
+ this.hashBuffer();
910
+ this.bufferLength = 0;
911
+ }
912
+ }
913
+ };
914
+ RawSha2562.prototype.digest = function() {
915
+ if (!this.finished) {
916
+ var bitsHashed = this.bytesHashed * 8;
917
+ var bufferView = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
918
+ var undecoratedLength = this.bufferLength;
919
+ bufferView.setUint8(this.bufferLength++, 128);
920
+ if (undecoratedLength % BLOCK_SIZE >= BLOCK_SIZE - 8) {
921
+ for (var i = this.bufferLength; i < BLOCK_SIZE; i++) {
922
+ bufferView.setUint8(i, 0);
923
+ }
924
+ this.hashBuffer();
925
+ this.bufferLength = 0;
926
+ }
927
+ for (var i = this.bufferLength; i < BLOCK_SIZE - 8; i++) {
928
+ bufferView.setUint8(i, 0);
929
+ }
930
+ bufferView.setUint32(BLOCK_SIZE - 8, Math.floor(bitsHashed / 4294967296), true);
931
+ bufferView.setUint32(BLOCK_SIZE - 4, bitsHashed);
932
+ this.hashBuffer();
933
+ this.finished = true;
934
+ }
935
+ var out = new Uint8Array(DIGEST_LENGTH);
936
+ for (var i = 0; i < 8; i++) {
937
+ out[i * 4] = this.state[i] >>> 24 & 255;
938
+ out[i * 4 + 1] = this.state[i] >>> 16 & 255;
939
+ out[i * 4 + 2] = this.state[i] >>> 8 & 255;
940
+ out[i * 4 + 3] = this.state[i] >>> 0 & 255;
941
+ }
942
+ return out;
943
+ };
944
+ RawSha2562.prototype.hashBuffer = function() {
945
+ var _a = this, buffer = _a.buffer, state = _a.state;
946
+ 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];
947
+ for (var i = 0; i < BLOCK_SIZE; i++) {
948
+ if (i < 16) {
949
+ 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;
950
+ } else {
951
+ var u = this.temp[i - 2];
952
+ var t1_1 = (u >>> 17 | u << 15) ^ (u >>> 19 | u << 13) ^ u >>> 10;
953
+ u = this.temp[i - 15];
954
+ var t2_1 = (u >>> 7 | u << 25) ^ (u >>> 18 | u << 14) ^ u >>> 3;
955
+ this.temp[i] = (t1_1 + this.temp[i - 7] | 0) + (t2_1 + this.temp[i - 16] | 0);
956
+ }
957
+ var t1 = (((state4 >>> 6 | state4 << 26) ^ (state4 >>> 11 | state4 << 21) ^ (state4 >>> 25 | state4 << 7)) + (state4 & state5 ^ ~state4 & state6) | 0) + (state7 + (KEY[i] + this.temp[i] | 0) | 0) | 0;
958
+ var t2 = ((state0 >>> 2 | state0 << 30) ^ (state0 >>> 13 | state0 << 19) ^ (state0 >>> 22 | state0 << 10)) + (state0 & state1 ^ state0 & state2 ^ state1 & state2) | 0;
959
+ state7 = state6;
960
+ state6 = state5;
961
+ state5 = state4;
962
+ state4 = state3 + t1 | 0;
963
+ state3 = state2;
964
+ state2 = state1;
965
+ state1 = state0;
966
+ state0 = t1 + t2 | 0;
967
+ }
968
+ state[0] += state0;
969
+ state[1] += state1;
970
+ state[2] += state2;
971
+ state[3] += state3;
972
+ state[4] += state4;
973
+ state[5] += state5;
974
+ state[6] += state6;
975
+ state[7] += state7;
976
+ };
977
+ return RawSha2562;
978
+ }()
979
+ );
980
+
981
+ // node_modules/@smithy/util-utf8/dist-es/fromUtf8.browser.js
982
+ var fromUtf8 = (input) => new TextEncoder().encode(input);
983
+
984
+ // node_modules/@aws-crypto/util/build/module/convertToBuffer.js
985
+ var fromUtf82 = typeof Buffer !== "undefined" && Buffer.from ? function(input) {
986
+ return Buffer.from(input, "utf8");
987
+ } : fromUtf8;
988
+ function convertToBuffer(data) {
989
+ if (data instanceof Uint8Array)
990
+ return data;
991
+ if (typeof data === "string") {
992
+ return fromUtf82(data);
993
+ }
994
+ if (ArrayBuffer.isView(data)) {
995
+ return new Uint8Array(data.buffer, data.byteOffset, data.byteLength / Uint8Array.BYTES_PER_ELEMENT);
996
+ }
997
+ return new Uint8Array(data);
998
+ }
999
+
1000
+ // node_modules/@aws-crypto/util/build/module/isEmptyData.js
1001
+ function isEmptyData(data) {
1002
+ if (typeof data === "string") {
1003
+ return data.length === 0;
1004
+ }
1005
+ return data.byteLength === 0;
1006
+ }
1007
+
1008
+ // node_modules/@aws-crypto/sha256-js/build/module/jsSha256.js
1009
+ var Sha256 = (
1010
+ /** @class */
1011
+ function() {
1012
+ function Sha2562(secret) {
1013
+ this.secret = secret;
1014
+ this.hash = new RawSha256();
1015
+ this.reset();
1016
+ }
1017
+ Sha2562.prototype.update = function(toHash) {
1018
+ if (isEmptyData(toHash) || this.error) {
1019
+ return;
1020
+ }
1021
+ try {
1022
+ this.hash.update(convertToBuffer(toHash));
1023
+ } catch (e) {
1024
+ this.error = e;
1025
+ }
1026
+ };
1027
+ Sha2562.prototype.digestSync = function() {
1028
+ if (this.error) {
1029
+ throw this.error;
1030
+ }
1031
+ if (this.outer) {
1032
+ if (!this.outer.finished) {
1033
+ this.outer.update(this.hash.digest());
1034
+ }
1035
+ return this.outer.digest();
1036
+ }
1037
+ return this.hash.digest();
1038
+ };
1039
+ Sha2562.prototype.digest = function() {
1040
+ return __awaiter(this, void 0, void 0, function() {
1041
+ return __generator(this, function(_a) {
1042
+ return [2, this.digestSync()];
1043
+ });
1044
+ });
1045
+ };
1046
+ Sha2562.prototype.reset = function() {
1047
+ this.hash = new RawSha256();
1048
+ if (this.secret) {
1049
+ this.outer = new RawSha256();
1050
+ var inner = bufferFromSecret(this.secret);
1051
+ var outer = new Uint8Array(BLOCK_SIZE);
1052
+ outer.set(inner);
1053
+ for (var i = 0; i < BLOCK_SIZE; i++) {
1054
+ inner[i] ^= 54;
1055
+ outer[i] ^= 92;
1056
+ }
1057
+ this.hash.update(inner);
1058
+ this.outer.update(outer);
1059
+ for (var i = 0; i < inner.byteLength; i++) {
1060
+ inner[i] = 0;
1061
+ }
1062
+ }
1063
+ };
1064
+ return Sha2562;
1065
+ }()
1066
+ );
1067
+ function bufferFromSecret(secret) {
1068
+ var input = convertToBuffer(secret);
1069
+ if (input.byteLength > BLOCK_SIZE) {
1070
+ var bufferHash = new RawSha256();
1071
+ bufferHash.update(input);
1072
+ input = bufferHash.digest();
1073
+ }
1074
+ var buffer = new Uint8Array(BLOCK_SIZE);
1075
+ buffer.set(input);
1076
+ return buffer;
1077
+ }
1078
+
1554
1079
  // src/FaustCompiler.ts
1555
- var import_sha256_js = __toESM(require_build2(), 1);
1556
1080
  var ab2str = (buf) => String.fromCharCode.apply(null, buf);
1557
1081
  var str2ab = (str) => {
1558
1082
  const buf = new ArrayBuffer(str.length);
@@ -1563,13 +1087,16 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1563
1087
  return bufView;
1564
1088
  };
1565
1089
  var sha256 = async (str) => {
1566
- const sha2562 = new import_sha256_js.Sha256();
1090
+ const sha2562 = new Sha256();
1567
1091
  sha2562.update(str);
1568
1092
  const hashArray = Array.from(await sha2562.digest());
1569
1093
  const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
1570
1094
  return hashHex;
1571
1095
  };
1572
- var _FaustCompiler = class {
1096
+ var _FaustCompiler = class _FaustCompiler {
1097
+ /**
1098
+ * Get a stringified DSP factories table
1099
+ */
1573
1100
  static serializeDSPFactories() {
1574
1101
  const table = {};
1575
1102
  this.gFactories.forEach((factory, shaKey) => {
@@ -1578,19 +1105,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1578
1105
  });
1579
1106
  return table;
1580
1107
  }
1108
+ /**
1109
+ * Get a stringified DSP factories table as string
1110
+ */
1581
1111
  static stringifyDSPFactories() {
1582
1112
  return JSON.stringify(this.serializeDSPFactories());
1583
1113
  }
1114
+ /**
1115
+ * Import a DSP factories table
1116
+ */
1584
1117
  static deserializeDSPFactories(table) {
1585
1118
  const awaited = [];
1586
1119
  for (const shaKey in table) {
1587
1120
  const factory = table[shaKey];
1588
1121
  const { code, json, poly } = factory;
1589
1122
  const ab = str2ab(atob(code));
1590
- awaited.push(WebAssembly.compile(ab).then((module) => this.gFactories.set(shaKey, { shaKey, cfactory: 0, code: ab, module, json: JSON.stringify(json), poly })));
1123
+ awaited.push(WebAssembly.compile(ab).then((module) => this.gFactories.set(shaKey, { shaKey, cfactory: 0, code: ab, module, json: JSON.stringify(json), poly, soundfiles: {} })));
1591
1124
  }
1592
1125
  return Promise.all(awaited);
1593
1126
  }
1127
+ /**
1128
+ * Import a stringified DSP factories table
1129
+ */
1594
1130
  static importDSPFactories(tableStr) {
1595
1131
  const table = JSON.parse(tableStr);
1596
1132
  return this.deserializeDSPFactories(table);
@@ -1620,7 +1156,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1620
1156
  const ui8Code = this.intVec2intArray(faustDspWasm.data);
1621
1157
  faustDspWasm.data.delete();
1622
1158
  const module = await WebAssembly.compile(ui8Code);
1623
- const factory = { shaKey, cfactory: faustDspWasm.cfactory, code: ui8Code, module, json: faustDspWasm.json, poly };
1159
+ const factory = { shaKey, cfactory: faustDspWasm.cfactory, code: ui8Code, module, json: faustDspWasm.json, poly, soundfiles: {} };
1624
1160
  this.deleteDSPFactory(factory);
1625
1161
  _FaustCompiler.gFactories.set(shaKey, factory);
1626
1162
  return factory;
@@ -1696,8 +1232,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1696
1232
  return { mixerBuffer, mixerModule };
1697
1233
  }
1698
1234
  };
1235
+ _FaustCompiler.gFactories = /* @__PURE__ */ new Map();
1699
1236
  var FaustCompiler = _FaustCompiler;
1700
- FaustCompiler.gFactories = /* @__PURE__ */ new Map();
1701
1237
  var FaustCompiler_default = FaustCompiler;
1702
1238
 
1703
1239
  // src/FaustDspInstance.ts
@@ -1748,7 +1284,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1748
1284
  memory: memory || new WebAssembly.Memory({ initial: 100 }),
1749
1285
  memoryBase: 0,
1750
1286
  tableBase: 0,
1287
+ // Integer version
1751
1288
  _abs: Math.abs,
1289
+ // Float version
1752
1290
  _acosf: Math.acos,
1753
1291
  _asinf: Math.asin,
1754
1292
  _atanf: Math.atan,
@@ -1777,6 +1315,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1777
1315
  _isnanf: Number.isNaN,
1778
1316
  _isinff: (x) => !isFinite(x),
1779
1317
  _copysignf: (x, y) => Math.sign(x) === Math.sign(y) ? x : -x,
1318
+ // Double version
1780
1319
  _acos: Math.acos,
1781
1320
  _asin: Math.asin,
1782
1321
  _atan: Math.atan,
@@ -1857,6 +1396,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1857
1396
  const mixerFunctions = mixerInstance.exports;
1858
1397
  return mixerFunctions;
1859
1398
  }
1399
+ // Public API
1860
1400
  static async loadDSPFactory(wasmPath, jsonPath) {
1861
1401
  const wasmFile = await fetch(wasmPath);
1862
1402
  if (!wasmFile.ok) {
@@ -1980,6 +1520,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1980
1520
  this.memory = memory;
1981
1521
  this.allocatedBytes = offset;
1982
1522
  }
1523
+ /**
1524
+ * Allocates a block of memory of the specified size, returning the pointer to the
1525
+ * beginning of the block. The block is allocated at the current offset and the
1526
+ * offset is incremented by the size of the block.
1527
+ *
1528
+ * @param sizeInBytes The size of the block to allocate in bytes.
1529
+ * @returns The offset (pointer) to the beginning of the allocated block.
1530
+ */
1983
1531
  alloc(sizeInBytes) {
1984
1532
  const currentOffset = this.allocatedBytes;
1985
1533
  const newOffset = currentOffset + sizeInBytes;
@@ -1992,38 +1540,75 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
1992
1540
  this.allocatedBytes = newOffset;
1993
1541
  return currentOffset;
1994
1542
  }
1543
+ /**
1544
+ * Returns the underlying buffer object.
1545
+ *
1546
+ * @returns The buffer object.
1547
+ */
1995
1548
  getBuffer() {
1996
1549
  return this.memory.buffer;
1997
1550
  }
1551
+ /**
1552
+ * Returns the Int32 view of the underlying buffer object.
1553
+ *
1554
+ * @returns The view of the memory buffer as Int32Array.
1555
+ */
1998
1556
  getInt32Array() {
1999
1557
  return new Int32Array(this.memory.buffer);
2000
1558
  }
1559
+ /**
1560
+ * Returns the Int64 view of the underlying buffer object.
1561
+ *
1562
+ * @returns The view of the memory buffer as BigInt64Array.
1563
+ */
2001
1564
  getInt64Array() {
2002
1565
  return new BigInt64Array(this.memory.buffer);
2003
1566
  }
1567
+ /**
1568
+ * Returns the Float32 view of the underlying buffer object.
1569
+ *
1570
+ * @returns The view of the memory buffer as Float32Array.
1571
+ */
2004
1572
  getFloat32Array() {
2005
1573
  return new Float32Array(this.memory.buffer);
2006
1574
  }
1575
+ /**
1576
+ * Returns the Float64 view of the underlying buffer object..
1577
+ *
1578
+ * @returns The view of the memory buffer as Float64Array.
1579
+ */
2007
1580
  getFloat64Array() {
2008
1581
  return new Float64Array(this.memory.buffer);
2009
1582
  }
2010
1583
  };
2011
- var MAX_SOUNDFILE_PARTS = 256;
2012
- var MAX_CHAN = 64;
2013
- var BUFFER_SIZE = 1024;
2014
- var SAMPLE_RATE = 44100;
2015
- var Soundfile = class {
2016
- constructor(allocator, sampleSize, curChan, length2, maxChan, totalParts) {
1584
+ var Soundfile = class _Soundfile {
1585
+ /** Maximum number of soundfile parts. */
1586
+ static get MAX_SOUNDFILE_PARTS() {
1587
+ return 256;
1588
+ }
1589
+ /** Maximum number of channels. */
1590
+ static get MAX_CHAN() {
1591
+ return 64;
1592
+ }
1593
+ /** Maximum buffer size in frames. */
1594
+ static get BUFFER_SIZE() {
1595
+ return 1024;
1596
+ }
1597
+ /** Default sample rate. */
1598
+ static get SAMPLE_RATE() {
1599
+ return 44100;
1600
+ }
1601
+ constructor(allocator, sampleSize, curChan, length, maxChan, totalParts) {
2017
1602
  this.fSampleSize = sampleSize;
2018
1603
  this.fIntSize = this.fSampleSize;
2019
1604
  this.fPtrSize = 4;
2020
1605
  this.fAllocator = allocator;
2021
- console.log(`Soundfile constructor: curChan: ${curChan}, length: ${length2}, maxChan: ${maxChan}, totalParts: ${totalParts}`);
1606
+ console.log(`Soundfile constructor: curChan: ${curChan}, length: ${length}, maxChan: ${maxChan}, totalParts: ${totalParts}`);
2022
1607
  this.fPtr = allocator.alloc(4 * this.fPtrSize);
2023
- this.fLength = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
2024
- this.fSR = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
2025
- this.fOffset = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
2026
- this.fBuffers = this.allocBuffers(curChan, length2, maxChan);
1608
+ this.fLength = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
1609
+ this.fSR = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
1610
+ this.fOffset = allocator.alloc(_Soundfile.MAX_SOUNDFILE_PARTS * this.fIntSize);
1611
+ this.fBuffers = this.allocBuffers(curChan, length, maxChan);
2027
1612
  const HEAP32 = this.fAllocator.getInt32Array();
2028
1613
  HEAP32[this.fPtr >> 2] = this.fBuffers;
2029
1614
  HEAP32[this.fPtr + this.fPtrSize >> 2] = this.fLength;
@@ -2034,11 +1619,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2034
1619
  console.log(`allocBuffers AFTER: ${chan} - ${buffer}`);
2035
1620
  }
2036
1621
  }
2037
- allocBuffers(curChan, length2, maxChan) {
1622
+ allocBuffers(curChan, length, maxChan) {
2038
1623
  const buffers = this.fAllocator.alloc(maxChan * this.fPtrSize);
2039
1624
  console.log(`allocBuffers buffers: ${buffers}`);
2040
1625
  for (let chan = 0; chan < curChan; chan++) {
2041
- const buffer = this.fAllocator.alloc(length2 * this.fSampleSize);
1626
+ const buffer = this.fAllocator.alloc(length * this.fSampleSize);
2042
1627
  const HEAP32 = this.fAllocator.getInt32Array();
2043
1628
  HEAP32[(buffers >> 2) + chan] = buffer;
2044
1629
  }
@@ -2050,30 +1635,30 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2050
1635
  HEAP32[(this.fBuffers >> 2) + chan] = HEAP32[(this.fBuffers >> 2) + chan % curChan];
2051
1636
  }
2052
1637
  }
2053
- copyToOut(part, maxChannels, offset, buffer) {
1638
+ copyToOut(part, maxChannels, offset, audioData) {
2054
1639
  if (this.fIntSize === 4) {
2055
1640
  const HEAP32 = this.fAllocator.getInt32Array();
2056
- HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = buffer.length;
2057
- HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = buffer.sampleRate;
1641
+ HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = audioData.audioBuffer[0].length;
1642
+ HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = audioData.sampleRate;
2058
1643
  HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
2059
1644
  } else {
2060
1645
  const HEAP64 = this.fAllocator.getInt64Array();
2061
- HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(buffer.length);
2062
- HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(buffer.sampleRate);
1646
+ HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(audioData.audioBuffer[0].length);
1647
+ HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(audioData.sampleRate);
2063
1648
  HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
2064
1649
  }
2065
- console.log(`copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${buffer}`);
1650
+ console.log(`copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${audioData}`);
2066
1651
  if (this.fSampleSize === 8) {
2067
- this.copyToOutReal64(maxChannels, offset, buffer);
1652
+ this.copyToOutReal64(maxChannels, offset, audioData);
2068
1653
  } else {
2069
- this.copyToOutReal32(maxChannels, offset, buffer);
1654
+ this.copyToOutReal32(maxChannels, offset, audioData);
2070
1655
  }
2071
1656
  }
2072
- copyToOutReal32(maxChannels, offset, buffer) {
1657
+ copyToOutReal32(maxChannels, offset, audioData) {
2073
1658
  const HEAP32 = this.fAllocator.getInt32Array();
2074
1659
  const HEAPF = this.fAllocator.getFloat32Array();
2075
- for (let chan = 0; chan < buffer.numberOfChannels; chan++) {
2076
- const input = buffer.getChannelData(chan);
1660
+ for (let chan = 0; chan < audioData.audioBuffer.length; chan++) {
1661
+ const input = audioData.audioBuffer[chan];
2077
1662
  const output = HEAP32[(this.fBuffers >> 2) + chan];
2078
1663
  const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
2079
1664
  const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
@@ -2087,11 +1672,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2087
1672
  }
2088
1673
  }
2089
1674
  }
2090
- copyToOutReal64(maxChannels, offset, buffer) {
1675
+ copyToOutReal64(maxChannels, offset, audioData) {
2091
1676
  const HEAP32 = this.fAllocator.getInt32Array();
2092
1677
  const HEAPF = this.fAllocator.getFloat64Array();
2093
- for (let chan = 0; chan < buffer.numberOfChannels; chan++) {
2094
- const input = buffer.getChannelData(chan);
1678
+ for (let chan = 0; chan < audioData.audioBuffer.length; chan++) {
1679
+ const input = audioData.audioBuffer[chan];
2095
1680
  const output = HEAP32[(this.fBuffers >> 2) + chan];
2096
1681
  const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
2097
1682
  const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
@@ -2108,16 +1693,16 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2108
1693
  emptyFile(part, offset) {
2109
1694
  if (this.fIntSize === 4) {
2110
1695
  const HEAP32 = this.fAllocator.getInt32Array();
2111
- HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = BUFFER_SIZE;
2112
- HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = SAMPLE_RATE;
1696
+ HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = _Soundfile.BUFFER_SIZE;
1697
+ HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = _Soundfile.SAMPLE_RATE;
2113
1698
  HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
2114
1699
  } else {
2115
1700
  const HEAP64 = this.fAllocator.getInt64Array();
2116
- HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(BUFFER_SIZE);
2117
- HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(SAMPLE_RATE);
1701
+ HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(_Soundfile.BUFFER_SIZE);
1702
+ HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(_Soundfile.SAMPLE_RATE);
2118
1703
  HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
2119
1704
  }
2120
- return offset + BUFFER_SIZE;
1705
+ return offset + _Soundfile.BUFFER_SIZE;
2121
1706
  }
2122
1707
  displayMemory(where = "", mem = false) {
2123
1708
  console.log("Soundfile memory: " + where);
@@ -2134,6 +1719,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2134
1719
  console.log(`HEAP32[(this.fPtr + 2 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 2 * this.fPtrSize >> 2]}`);
2135
1720
  console.log(`HEAP32[(this.fPtr + 3 * ptrSize) >> 2]: ${HEAP32[this.fPtr + 3 * this.fPtrSize >> 2]}`);
2136
1721
  }
1722
+ // Return the pointer to the soundfile structure in wasm memory
2137
1723
  getPtr() {
2138
1724
  return this.fPtr;
2139
1725
  }
@@ -2147,139 +1733,28 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2147
1733
  return this.fAllocator.getFloat64Array();
2148
1734
  }
2149
1735
  };
2150
- var SoundfileReader = class {
2151
- constructor(allocator, context, sampleSize) {
2152
- this.fAllocator = allocator;
2153
- this.fSampleSize = sampleSize;
2154
- this.fContext = context;
2155
- this.fAudioBuffers = [];
2156
- }
2157
- async checkFileExists(url) {
2158
- try {
2159
- console.log(`"checkFileExists" url: ${url}`);
2160
- const response = await fetch(url, { method: "HEAD" });
2161
- return response.ok;
2162
- } catch (error) {
2163
- console.error("Fetch error:", error);
2164
- return false;
2165
- }
2166
- }
2167
- async checkFile(directories, fileName) {
2168
- if (await this.checkFileExists(fileName)) {
2169
- return fileName;
2170
- } else {
2171
- for (let i = 0; i < directories.length; i++) {
2172
- const pathName = directories[i] + "/" + fileName;
2173
- if (await this.checkFileExists(pathName)) {
2174
- return pathName;
2175
- }
2176
- }
2177
- return "";
2178
- }
2179
- }
2180
- async checkFiles(directories, fileNameList) {
2181
- const pathNameList = [];
2182
- for (let i = 0; i < fileNameList.length; i++) {
2183
- const pathName = await this.checkFile(directories, fileNameList[i]);
2184
- console.log(`checkFiles pathName: ${pathName}`);
2185
- pathNameList.push(pathName === "" ? "__empty_sound__" : pathName);
2186
- }
2187
- return pathNameList;
2188
- }
2189
- async getParamsFile(pathName) {
2190
- console.log(`Loading sound file from ${pathName}`);
2191
- const item = this.fAudioBuffers.find((element) => element.pathName === pathName);
2192
- if (item) {
2193
- console.log(`getItemByPathName FOUND`);
2194
- return { channels: item.audioBuffer.numberOfChannels, length: item.audioBuffer.length };
2195
- } else {
2196
- const response = await fetch(pathName);
2197
- if (!response.ok) {
2198
- console.log(`Failed to load sound file from ${pathName}: ${response.statusText}`);
2199
- return { channels: 1, length: BUFFER_SIZE };
2200
- } else {
2201
- const arrayBuffer = await response.arrayBuffer();
2202
- const audioBuffer = await this.fContext.decodeAudioData(arrayBuffer);
2203
- const { numberOfChannels, length: length2 } = audioBuffer;
2204
- this.fAudioBuffers.push({ pathName, audioBuffer });
2205
- return { channels: numberOfChannels, length: length2 };
2206
- }
2207
- }
2208
- }
2209
- readFile(soundfile, pathName, part, offset, maxChan) {
2210
- const item = this.fAudioBuffers.find((entry) => entry.pathName === pathName);
2211
- if (item) {
2212
- soundfile.copyToOut(part, maxChan, offset, item.audioBuffer);
2213
- return offset + item.audioBuffer.length;
2214
- } else {
2215
- console.error(`Failed to access sound file from ${pathName}`);
2216
- return offset + BUFFER_SIZE;
2217
- }
2218
- }
2219
- async createSoundfile(pathNameList, maxChan) {
2220
- try {
2221
- let curChan = 1;
2222
- let totalLength = 0;
2223
- for (const pathName of pathNameList) {
2224
- let chan = 0, len = 0;
2225
- if (pathName === "__empty_sound__") {
2226
- length = BUFFER_SIZE;
2227
- chan = 1;
2228
- } else {
2229
- const { channels, length: length2 } = await this.getParamsFile(pathName);
2230
- chan = channels;
2231
- len = length2;
2232
- }
2233
- curChan = Math.max(curChan, chan);
2234
- totalLength += len;
2235
- }
2236
- totalLength += (MAX_SOUNDFILE_PARTS - pathNameList.length) * BUFFER_SIZE;
2237
- let soundfile = new Soundfile(this.fAllocator, this.fSampleSize, curChan, totalLength, maxChan, pathNameList.length);
2238
- let offset = 0;
2239
- for (let part = 0; part < pathNameList.length; part++) {
2240
- if (pathNameList[part] === "__empty_sound__") {
2241
- offset = soundfile.emptyFile(part, offset);
2242
- } else {
2243
- offset = await this.readFile(soundfile, pathNameList[part], part, offset, maxChan);
2244
- }
2245
- }
2246
- for (let part = pathNameList.length; part < MAX_SOUNDFILE_PARTS; part++) {
2247
- offset = soundfile.emptyFile(part, offset);
2248
- }
2249
- soundfile.shareBuffers(curChan, maxChan);
2250
- return soundfile;
2251
- } catch (error) {
2252
- console.error("Failed to create soundfile:", error);
2253
- return null;
2254
- }
2255
- }
2256
- getHEAP32() {
2257
- return this.fAllocator.getInt32Array();
2258
- }
2259
- };
2260
- var FaustBaseWebAudioDsp = class {
2261
- constructor(sampleSize, bufferSize) {
1736
+ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
1737
+ constructor(sampleSize, bufferSize, soundfiles) {
2262
1738
  this.fOutputHandler = null;
2263
1739
  this.fComputeHandler = null;
1740
+ // To handle MIDI events plot
1741
+ this.fPlotHandler = null;
2264
1742
  this.fCachedEvents = [];
2265
1743
  this.fBufferNum = 0;
2266
- this.fPlotHandler = null;
2267
- this.fBufferSize = bufferSize;
2268
1744
  this.fInChannels = [];
2269
1745
  this.fOutChannels = [];
2270
- this.fPtrSize = sampleSize;
2271
- this.fSampleSize = sampleSize;
2272
1746
  this.fOutputsTimer = 5;
1747
+ // UI items path
2273
1748
  this.fInputsItems = [];
2274
1749
  this.fOutputsItems = [];
2275
1750
  this.fDescriptor = [];
1751
+ // Soundfile handling
2276
1752
  this.fSoundfiles = [];
1753
+ this.fSoundfileBuffers = {};
1754
+ // MIDI handling
2277
1755
  this.fPitchwheelLabel = [];
2278
1756
  this.fCtrlLabel = new Array(128).fill(null).map(() => []);
2279
1757
  this.fPathTable = {};
2280
- this.fProcessing = false;
2281
- this.fDestroyed = false;
2282
- this.fFirstCall = true;
2283
1758
  this.fUICallback = (item) => {
2284
1759
  if (item.type === "hbargraph" || item.type === "vbargraph") {
2285
1760
  this.fOutputsItems.push(item.address);
@@ -2308,10 +1783,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2308
1783
  this.fSoundfiles.push({ name: item.label, url: item.url, index: item.index, basePtr: -1 });
2309
1784
  }
2310
1785
  };
1786
+ // Audio callback
1787
+ this.fProcessing = false;
1788
+ this.fDestroyed = false;
1789
+ this.fFirstCall = true;
1790
+ this.fBufferSize = bufferSize;
1791
+ this.fPtrSize = sampleSize;
1792
+ this.fSampleSize = sampleSize;
1793
+ this.fSoundfileBuffers = soundfiles;
2311
1794
  }
1795
+ // Tools
2312
1796
  static remap(v, mn0, mx0, mn1, mx1) {
2313
1797
  return (v - mn0) / (mx0 - mn0) * (mx1 - mn1) + mn1;
2314
1798
  }
1799
+ // JSON parsing functions
2315
1800
  static parseUI(ui, callback) {
2316
1801
  ui.forEach((group) => this.parseGroup(group, callback));
2317
1802
  }
@@ -2330,51 +1815,98 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2330
1815
  callback(item);
2331
1816
  }
2332
1817
  }
2333
- static splitNames(input) {
1818
+ /** Split the soundfile names and return an array of names */
1819
+ static splitSoundfileNames(input) {
2334
1820
  let trimmed = input.replace(/^\{|\}$/g, "");
2335
1821
  return trimmed.split(";").map((str) => str.length <= 2 ? "" : str.substring(1, str.length - 1));
2336
1822
  }
2337
- extractURLsFromJSON() {
2338
- const soundfilesEntry = this.fJSONDsp.meta.find((entry) => entry.soundfiles !== void 0);
1823
+ static extractUrlsFromMeta(dspMeta) {
1824
+ const soundfilesEntry = dspMeta.meta.find((entry) => entry.soundfiles !== void 0);
2339
1825
  if (soundfilesEntry) {
2340
1826
  return soundfilesEntry.soundfiles.split(";").filter((url) => url !== "");
2341
1827
  } else {
2342
1828
  return [];
2343
1829
  }
2344
1830
  }
2345
- async loadSoundfile(sfReader, baseDSP, name, url) {
1831
+ /**
1832
+ * Load a soundfile possibly containing several parts in the DSP struct.
1833
+ * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
1834
+ * The DSP struct is located at baseDSP in the wasm memory,
1835
+ * either a monophonic DSP, or a voice in a polyphonic context.
1836
+ *
1837
+ * @param allocator : the wasm memory allocator
1838
+ * @param baseDSP : the base DSP in the wasm memory
1839
+ * @param name : the name of the soundfile
1840
+ * @param url : the url of the soundfile
1841
+ */
1842
+ loadSoundfile(allocator, baseDSP, name, url) {
2346
1843
  console.log(`Soundfile ${name} paths: ${url}`);
2347
- const sfReaderURLs = this.extractURLsFromJSON();
2348
- console.log(`sfReaderURLs ${sfReaderURLs}`);
2349
- const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
2350
- sfDirectories.push(...sfReaderURLs);
2351
- console.log(`sfDirectories ${sfDirectories}`);
2352
- const sfPathNames = await sfReader.checkFiles(sfDirectories, FaustBaseWebAudioDsp.splitNames(url));
2353
- console.log(`Soundfile ${name} paths: ${sfPathNames}`);
2354
- const item = this.fSoundfiles.find((element) => element.url === url);
2355
- if (item) {
2356
- if (item.basePtr !== -1) {
2357
- const HEAP32 = sfReader.getHEAP32();
2358
- console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
1844
+ const soundfileIds = _FaustBaseWebAudioDsp.splitSoundfileNames(url);
1845
+ const item = this.fSoundfiles.find((item2) => item2.url === url);
1846
+ if (!item)
1847
+ throw new Error(`Soundfile with ${url} cannot be found !}`);
1848
+ if (item.basePtr !== -1) {
1849
+ const HEAP32 = allocator.getInt32Array();
1850
+ console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
1851
+ HEAP32[baseDSP + item.index >> 2] = item.basePtr;
1852
+ } else {
1853
+ const soundfile = this.createSoundfile(allocator, soundfileIds, this.fSoundfileBuffers);
1854
+ if (soundfile) {
1855
+ const HEAP32 = soundfile.getHEAP32();
1856
+ item.basePtr = soundfile.getPtr();
1857
+ console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
2359
1858
  HEAP32[baseDSP + item.index >> 2] = item.basePtr;
2360
1859
  } else {
2361
- const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN);
2362
- if (soundfile) {
2363
- const HEAP32 = soundfile.getHEAP32();
2364
- item.basePtr = soundfile.getPtr();
2365
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
2366
- HEAP32[baseDSP + item.index >> 2] = item.basePtr;
2367
- } else {
2368
- console.log(`Soundfile ${name} for ${url} cannot be created !}`);
2369
- }
1860
+ console.log(`Soundfile ${name} for ${url} cannot be created !}`);
1861
+ }
1862
+ }
1863
+ }
1864
+ createSoundfile(allocator, soundfileIdList, soundfiles, maxChan = Soundfile.MAX_CHAN) {
1865
+ let curChan = 1;
1866
+ let totalLength = 0;
1867
+ for (const soundfileId of soundfileIdList) {
1868
+ let chan = 0;
1869
+ let len = 0;
1870
+ const audioData = soundfiles[soundfileId];
1871
+ if (audioData) {
1872
+ chan = audioData.audioBuffer.length;
1873
+ len = audioData.audioBuffer[0].length;
1874
+ } else {
1875
+ len = Soundfile.BUFFER_SIZE;
1876
+ chan = 1;
1877
+ }
1878
+ curChan = Math.max(curChan, chan);
1879
+ totalLength += len;
1880
+ }
1881
+ totalLength += (Soundfile.MAX_SOUNDFILE_PARTS - soundfileIdList.length) * Soundfile.BUFFER_SIZE;
1882
+ const soundfile = new Soundfile(allocator, this.fSampleSize, curChan, totalLength, maxChan, soundfileIdList.length);
1883
+ let offset = 0;
1884
+ for (let part = 0; part < soundfileIdList.length; part++) {
1885
+ const soundfileId = soundfileIdList[part];
1886
+ const audioData = soundfiles[soundfileId];
1887
+ if (audioData) {
1888
+ soundfile.copyToOut(part, maxChan, offset, audioData);
1889
+ offset += audioData.audioBuffer[0].length;
1890
+ } else {
1891
+ offset = soundfile.emptyFile(part, offset);
2370
1892
  }
2371
- } else {
2372
- console.log(`Soundfile with ${url} cannot be found !}`);
2373
1893
  }
1894
+ for (let part = soundfileIdList.length; part < Soundfile.MAX_SOUNDFILE_PARTS; part++) {
1895
+ offset = soundfile.emptyFile(part, offset);
1896
+ }
1897
+ soundfile.shareBuffers(curChan, maxChan);
1898
+ return soundfile;
2374
1899
  }
2375
- async initSoundfileMemory(allocator, sfReader, baseDSP) {
1900
+ /**
1901
+ * Init soundfiles memory.
1902
+ *
1903
+ * @param allocator : the wasm memory allocator
1904
+ * @param sfReader : the soundfile reader
1905
+ * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
1906
+ */
1907
+ initSoundfileMemory(allocator, baseDSP) {
2376
1908
  for (const { name, url } of this.fSoundfiles) {
2377
- await this.loadSoundfile(sfReader, baseDSP, name, url);
1909
+ this.loadSoundfile(allocator, baseDSP, name, url);
2378
1910
  }
2379
1911
  ;
2380
1912
  }
@@ -2387,6 +1919,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2387
1919
  });
2388
1920
  }
2389
1921
  }
1922
+ // Public API
2390
1923
  metadata(handler) {
2391
1924
  if (this.fJSONDsp.meta) {
2392
1925
  this.fJSONDsp.meta.forEach((meta) => handler(Object.keys(meta)[0], meta[Object.keys(meta)[0]]));
@@ -2437,7 +1970,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2437
1970
  if (this.fCtrlLabel[ctrl].length) {
2438
1971
  this.fCtrlLabel[ctrl].forEach((ctrl2) => {
2439
1972
  const { path } = ctrl2;
2440
- this.setParamValue(path, FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
1973
+ this.setParamValue(path, _FaustBaseWebAudioDsp.remap(value, 0, 127, ctrl2.min, ctrl2.max));
2441
1974
  if (this.fOutputHandler)
2442
1975
  this.fOutputHandler(path, this.getParamValue(path));
2443
1976
  });
@@ -2447,7 +1980,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2447
1980
  if (this.fPlotHandler)
2448
1981
  this.fCachedEvents.push({ type: "pitchWheel", data: [channel, wheel] });
2449
1982
  this.fPitchwheelLabel.forEach((pw) => {
2450
- this.setParamValue(pw.path, FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
1983
+ this.setParamValue(pw.path, _FaustBaseWebAudioDsp.remap(wheel, 0, 16383, pw.min, pw.max));
2451
1984
  if (this.fOutputHandler)
2452
1985
  this.fOutputHandler(pw.path, this.getParamValue(pw.path));
2453
1986
  });
@@ -2489,20 +2022,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2489
2022
  }
2490
2023
  };
2491
2024
  var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
2492
- constructor(instance, sampleRate, sampleSize, bufferSize) {
2493
- super(sampleSize, bufferSize);
2025
+ constructor(instance, sampleRate, sampleSize, bufferSize, soundfiles) {
2026
+ super(sampleSize, bufferSize, soundfiles);
2494
2027
  this.fInstance = instance;
2495
- console.log("sampleSize: " + sampleSize + " bufferSize: " + bufferSize);
2028
+ console.log(`sampleSize: ${sampleSize} bufferSize: ${bufferSize}`);
2496
2029
  this.fJSONDsp = JSON.parse(this.fInstance.json);
2497
2030
  FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
2498
2031
  this.fEndMemory = this.initMemory();
2499
2032
  this.fInstance.api.init(this.fDSP, sampleRate);
2500
- }
2501
- async init(context) {
2502
- if (this.fSoundfiles.length > 0 && context) {
2033
+ if (this.fSoundfiles.length > 0) {
2503
2034
  const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
2504
- const sfReader = new SoundfileReader(allocator, context, this.fSampleSize);
2505
- await this.initSoundfileMemory(allocator, sfReader, this.fDSP);
2035
+ this.initSoundfileMemory(allocator, this.fDSP);
2506
2036
  }
2507
2037
  }
2508
2038
  initMemory() {
@@ -2544,6 +2074,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2544
2074
  this.fAudioOutputs: ${this.fAudioOutputs}
2545
2075
  this.fDSP: ${this.fDSP}`;
2546
2076
  }
2077
+ // Public API
2547
2078
  compute(input, output) {
2548
2079
  if (this.fDestroyed)
2549
2080
  return false;
@@ -2619,28 +2150,45 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2619
2150
  return this.fJSONDsp.ui;
2620
2151
  }
2621
2152
  };
2622
- var FaustWebAudioDspVoice = class {
2153
+ var FaustWebAudioDspVoice = class _FaustWebAudioDspVoice {
2623
2154
  constructor($dsp, api, inputItems, pathTable, sampleRate) {
2624
- FaustWebAudioDspVoice.kActiveVoice = 0;
2625
- FaustWebAudioDspVoice.kFreeVoice = -1;
2626
- FaustWebAudioDspVoice.kReleaseVoice = -2;
2627
- FaustWebAudioDspVoice.kLegatoVoice = -3;
2628
- FaustWebAudioDspVoice.kNoVoice = -4;
2629
- FaustWebAudioDspVoice.VOICE_STOP_LEVEL = 5e-4;
2630
- this.fCurNote = FaustWebAudioDspVoice.kFreeVoice;
2631
- this.fNextNote = this.fNextVel = -1;
2632
- this.fLevel = 0;
2633
- this.fDate = this.fRelease = 0;
2634
- this.fDSP = $dsp;
2635
- this.fAPI = api;
2155
+ this.fFreqLabel = [];
2636
2156
  this.fGateLabel = [];
2637
2157
  this.fGainLabel = [];
2638
- this.fFreqLabel = [];
2639
2158
  this.fKeyLabel = [];
2640
2159
  this.fVelLabel = [];
2160
+ // Voice DSP code
2161
+ // Accessed by PolyDSPImp class
2162
+ this.fCurNote = _FaustWebAudioDspVoice.kFreeVoice;
2163
+ this.fNextNote = -1;
2164
+ this.fNextVel = -1;
2165
+ this.fDate = 0;
2166
+ this.fLevel = 0;
2167
+ this.fRelease = 0;
2168
+ this.fDSP = $dsp;
2169
+ this.fAPI = api;
2641
2170
  this.fAPI.init(this.fDSP, sampleRate);
2642
2171
  this.extractPaths(inputItems, pathTable);
2643
2172
  }
2173
+ // Voice state
2174
+ static get kActiveVoice() {
2175
+ return 0;
2176
+ }
2177
+ static get kFreeVoice() {
2178
+ return -1;
2179
+ }
2180
+ static get kReleaseVoice() {
2181
+ return -2;
2182
+ }
2183
+ static get kLegatoVoice() {
2184
+ return -3;
2185
+ }
2186
+ static get kNoVoice() {
2187
+ return -4;
2188
+ }
2189
+ static get VOICE_STOP_LEVEL() {
2190
+ return 5e-4;
2191
+ }
2644
2192
  static midiToFreq(note) {
2645
2193
  return 440 * 2 ** ((note - 69) / 12);
2646
2194
  }
@@ -2662,14 +2210,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2662
2210
  }
2663
2211
  });
2664
2212
  }
2213
+ // Public API
2665
2214
  keyOn(pitch, velocity, legato = false) {
2666
2215
  if (legato) {
2667
2216
  this.fNextNote = pitch;
2668
2217
  this.fNextVel = velocity;
2669
2218
  } else {
2670
- this.fFreqLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, FaustWebAudioDspVoice.midiToFreq(pitch)));
2219
+ this.fFreqLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, _FaustWebAudioDspVoice.midiToFreq(pitch)));
2671
2220
  this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 1));
2672
- this.fGainLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, FaustWebAudioDspVoice.normalizeVelocity(velocity)));
2221
+ this.fGainLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, _FaustWebAudioDspVoice.normalizeVelocity(velocity)));
2673
2222
  this.fKeyLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, pitch));
2674
2223
  this.fVelLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, velocity));
2675
2224
  this.fCurNote = pitch;
@@ -2678,10 +2227,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2678
2227
  keyOff(hard = false) {
2679
2228
  this.fGateLabel.forEach((index) => this.fAPI.setParamValue(this.fDSP, index, 0));
2680
2229
  if (hard) {
2681
- this.fCurNote = FaustWebAudioDspVoice.kFreeVoice;
2230
+ this.fCurNote = _FaustWebAudioDspVoice.kFreeVoice;
2682
2231
  } else {
2683
2232
  this.fRelease = this.fAPI.getSampleRate(this.fDSP) / 2;
2684
- this.fCurNote = FaustWebAudioDspVoice.kReleaseVoice;
2233
+ this.fCurNote = _FaustWebAudioDspVoice.kReleaseVoice;
2685
2234
  }
2686
2235
  }
2687
2236
  computeLegato(bufferSize, $inputs, $outputZero, $outputsHalf) {
@@ -2701,11 +2250,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2701
2250
  return this.fAPI.getParamValue(this.fDSP, index);
2702
2251
  }
2703
2252
  };
2704
- var FaustPolyWebAudioDsp = class extends FaustBaseWebAudioDsp {
2705
- constructor(instance, sampleRate, sampleSize, bufferSize) {
2706
- super(sampleSize, bufferSize);
2253
+ var FaustPolyWebAudioDsp = class _FaustPolyWebAudioDsp extends FaustBaseWebAudioDsp {
2254
+ constructor(instance, sampleRate, sampleSize, bufferSize, soundfiles) {
2255
+ super(sampleSize, bufferSize, soundfiles);
2707
2256
  this.fInstance = instance;
2708
- console.log("sampleSize: " + sampleSize + " bufferSize: " + bufferSize);
2257
+ console.log(`sampleSize: ${sampleSize} bufferSize: ${bufferSize}`);
2709
2258
  this.fJSONDsp = JSON.parse(this.fInstance.voiceJSON);
2710
2259
  this.fJSONEffect = this.fInstance.effectAPI && this.fInstance.effectJSON ? JSON.parse(this.fInstance.effectJSON) : null;
2711
2260
  FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
@@ -2724,13 +2273,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2724
2273
  }
2725
2274
  if (this.fInstance.effectAPI)
2726
2275
  this.fInstance.effectAPI.init(this.fEffect, sampleRate);
2727
- }
2728
- async init(context) {
2729
- if (this.fSoundfiles.length > 0 && context) {
2276
+ if (this.fSoundfiles.length > 0) {
2730
2277
  const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
2731
- const sfReader = new SoundfileReader(allocator, context, this.fSampleSize);
2732
2278
  for (let voice = 0; voice < this.fInstance.voices; voice++) {
2733
- await this.initSoundfileMemory(allocator, sfReader, this.fJSONDsp.size * voice);
2279
+ this.initSoundfileMemory(allocator, this.fJSONDsp.size * voice);
2734
2280
  }
2735
2281
  }
2736
2282
  }
@@ -2828,6 +2374,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2828
2374
  }
2829
2375
  return FaustWebAudioDspVoice.kNoVoice;
2830
2376
  }
2377
+ // Public API
2831
2378
  compute(input, output) {
2832
2379
  if (this.fDestroyed)
2833
2380
  return false;
@@ -2894,7 +2441,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2894
2441
  return o.address === p;
2895
2442
  } else {
2896
2443
  for (const k in o) {
2897
- if (FaustPolyWebAudioDsp.findPath(o[k], p))
2444
+ if (_FaustPolyWebAudioDsp.findPath(o[k], p))
2898
2445
  return true;
2899
2446
  }
2900
2447
  return false;
@@ -2903,14 +2450,14 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2903
2450
  setParamValue(path, value) {
2904
2451
  if (this.fPlotHandler)
2905
2452
  this.fCachedEvents.push({ type: "param", data: { path, value } });
2906
- if (this.fJSONEffect && FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2453
+ if (this.fJSONEffect && _FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2907
2454
  this.fInstance.effectAPI.setParamValue(this.fEffect, this.fPathTable[path], value);
2908
2455
  } else {
2909
2456
  this.fVoiceTable.forEach((voice) => voice.setParamValue(this.fPathTable[path], value));
2910
2457
  }
2911
2458
  }
2912
2459
  getParamValue(path) {
2913
- if (this.fJSONEffect && FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2460
+ if (this.fJSONEffect && _FaustPolyWebAudioDsp.findPath(this.fJSONEffect.ui, path) && this.fInstance.effectAPI) {
2914
2461
  return this.fInstance.effectAPI.getParamValue(this.fEffect, this.fPathTable[path]);
2915
2462
  } else {
2916
2463
  return this.fVoiceTable[0].getParamValue(this.fPathTable[path]);
@@ -2998,6 +2545,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2998
2545
  this.fInputs = new Array(this.fDSPCode.getNumInputs()).fill(null).map(() => new Float32Array(bufferSize));
2999
2546
  this.fOutputs = new Array(this.fDSPCode.getNumOutputs()).fill(null).map(() => new Float32Array(bufferSize));
3000
2547
  }
2548
+ // Public API
3001
2549
  getParameterDescriptors() {
3002
2550
  const params = [];
3003
2551
  const callback = (item) => {
@@ -3085,12 +2633,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3085
2633
  destroy() {
3086
2634
  this.fDSPCode.destroy();
3087
2635
  }
3088
- render(inputs = [], length2 = this.fBufferSize, onUpdate) {
2636
+ /**
2637
+ * Render frames in an array.
2638
+ *
2639
+ * @param inputs - input signal
2640
+ * @param length - the number of frames to render (default: bufferSize)
2641
+ * @param onUpdate - a callback after each buffer calculated, with an argument "current sample"
2642
+ * @return an array of Float32Array with the rendered frames
2643
+ */
2644
+ render(inputs = [], length = this.fBufferSize, onUpdate) {
3089
2645
  let l = 0;
3090
- const outputs = new Array(this.fDSPCode.getNumOutputs()).fill(null).map(() => new Float32Array(length2));
2646
+ const outputs = new Array(this.fDSPCode.getNumOutputs()).fill(null).map(() => new Float32Array(length));
3091
2647
  this.fDSPCode.start();
3092
- while (l < length2) {
3093
- const sliceLength = Math.min(length2 - l, this.fBufferSize);
2648
+ while (l < length) {
2649
+ const sliceLength = Math.min(length - l, this.fBufferSize);
3094
2650
  for (let i = 0; i < this.fDSPCode.getNumInputs(); i++) {
3095
2651
  let input;
3096
2652
  if (inputs[i]) {
@@ -3162,12 +2718,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3162
2718
 
3163
2719
  // src/FaustCmajor.ts
3164
2720
  var FaustCmajor = class {
3165
- constructor(libfaust) {
3166
- this.fLibFaust = libfaust;
2721
+ constructor(compiler) {
2722
+ this.fCompiler = compiler;
3167
2723
  }
3168
2724
  compile(name, code, args) {
3169
- const fs = this.fLibFaust.fs();
3170
- const success = this.fLibFaust.generateAuxFiles(name, code, `-lang cmajor-hybrid -cn ${name} -o ${name}.cmajor`);
2725
+ const fs = this.fCompiler.fs();
2726
+ const success = this.fCompiler.generateAuxFiles(name, code, `-lang cmajor-hybrid -cn ${name} -o ${name}.cmajor`);
3171
2727
  return success ? fs.readFile(`${name}.cmajor`, { encoding: "utf8" }) : "";
3172
2728
  }
3173
2729
  };
@@ -3223,11 +2779,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3223
2779
  var WavEncoder = class {
3224
2780
  static encode(audioBuffer, options) {
3225
2781
  const numberOfChannels = audioBuffer.length;
3226
- const length2 = audioBuffer[0].length;
2782
+ const length = audioBuffer[0].length;
3227
2783
  const { shared, float } = options;
3228
2784
  const bitDepth = float ? 32 : options.bitDepth | 0 || 16;
3229
2785
  const byteDepth = bitDepth >> 3;
3230
- const byteLength = length2 * numberOfChannels * byteDepth;
2786
+ const byteLength = length * numberOfChannels * byteDepth;
3231
2787
  const AB = shared ? globalThis.SharedArrayBuffer || globalThis.ArrayBuffer : globalThis.ArrayBuffer;
3232
2788
  const ab = new AB((44 + byteLength) * Uint8Array.BYTES_PER_ELEMENT);
3233
2789
  const dataView = new DataView(ab);
@@ -3238,7 +2794,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3238
2794
  numberOfChannels,
3239
2795
  sampleRate: options.sampleRate,
3240
2796
  symmetric: !!options.symmetric,
3241
- length: length2,
2797
+ length,
3242
2798
  bitDepth,
3243
2799
  byteDepth
3244
2800
  };
@@ -3247,7 +2803,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3247
2803
  return ab;
3248
2804
  }
3249
2805
  static writeHeader(writer, format) {
3250
- const { formatId, sampleRate, bitDepth, numberOfChannels, length: length2, byteDepth } = format;
2806
+ const { formatId, sampleRate, bitDepth, numberOfChannels, length, byteDepth } = format;
3251
2807
  writer.string("RIFF");
3252
2808
  writer.uint32(writer.dataView.byteLength - 8);
3253
2809
  writer.string("WAVE");
@@ -3260,11 +2816,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3260
2816
  writer.uint16(numberOfChannels * byteDepth);
3261
2817
  writer.uint16(bitDepth);
3262
2818
  writer.string("data");
3263
- writer.uint32(length2 * numberOfChannels * byteDepth);
2819
+ writer.uint32(length * numberOfChannels * byteDepth);
3264
2820
  return writer.pos;
3265
2821
  }
3266
2822
  static writeData(writer, audioBuffer, format) {
3267
- const { bitDepth, float, length: length2, numberOfChannels, symmetric } = format;
2823
+ const { bitDepth, float, length, numberOfChannels, symmetric } = format;
3268
2824
  if (bitDepth === 32 && float) {
3269
2825
  const { dataView, pos } = writer;
3270
2826
  const ab = dataView.buffer;
@@ -3275,7 +2831,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3275
2831
  }
3276
2832
  for (let ch = 0; ch < numberOfChannels; ch++) {
3277
2833
  const channel = audioBuffer[ch];
3278
- for (let i = 0; i < length2; i++) {
2834
+ for (let i = 0; i < length; i++) {
3279
2835
  f32View[i * numberOfChannels + ch] = channel[i];
3280
2836
  }
3281
2837
  }
@@ -3287,7 +2843,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3287
2843
  throw new TypeError("Not supported bit depth: " + bitDepth);
3288
2844
  }
3289
2845
  const write = writer[methodName].bind(writer);
3290
- for (let i = 0; i < length2; i++) {
2846
+ for (let i = 0; i < length; i++) {
3291
2847
  for (let j = 0; j < numberOfChannels; j++) {
3292
2848
  write(audioBuffer[j][i]);
3293
2849
  }
@@ -3321,14 +2877,22 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3321
2877
  value = Math.max(-1, Math.min(value, 1));
3322
2878
  value = (value * 0.5 + 0.5) * 255;
3323
2879
  value = Math.round(value) | 0;
3324
- this.dataView.setUint8(this.pos, value);
2880
+ this.dataView.setUint8(
2881
+ this.pos,
2882
+ value
2883
+ /* , true*/
2884
+ );
3325
2885
  this.pos += 1;
3326
2886
  }
3327
2887
  pcm8s(valueIn) {
3328
2888
  let value = valueIn;
3329
2889
  value = Math.round(value * 128) + 128;
3330
2890
  value = Math.max(0, Math.min(value, 255));
3331
- this.dataView.setUint8(this.pos, value);
2891
+ this.dataView.setUint8(
2892
+ this.pos,
2893
+ value
2894
+ /* , true*/
2895
+ );
3332
2896
  this.pos += 1;
3333
2897
  }
3334
2898
  pcm16(valueIn) {
@@ -3443,24 +3007,24 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3443
3007
  }
3444
3008
  static decodeData(reader, chunkSizeIn, format, options) {
3445
3009
  const chunkSize = Math.min(chunkSizeIn, reader.remain());
3446
- const length2 = Math.floor(chunkSize / format.blockSize);
3010
+ const length = Math.floor(chunkSize / format.blockSize);
3447
3011
  const numberOfChannels = format.numberOfChannels;
3448
3012
  const sampleRate = format.sampleRate;
3449
3013
  const channelData = new Array(numberOfChannels);
3450
3014
  for (let ch = 0; ch < numberOfChannels; ch++) {
3451
3015
  const AB = options.shared ? globalThis.SharedArrayBuffer || globalThis.ArrayBuffer : globalThis.ArrayBuffer;
3452
- const ab = new AB(length2 * Float32Array.BYTES_PER_ELEMENT);
3016
+ const ab = new AB(length * Float32Array.BYTES_PER_ELEMENT);
3453
3017
  channelData[ch] = new Float32Array(ab);
3454
3018
  }
3455
- this.readPCM(reader, channelData, length2, format, options);
3019
+ this.readPCM(reader, channelData, length, format, options);
3456
3020
  return {
3457
3021
  numberOfChannels,
3458
- length: length2,
3022
+ length,
3459
3023
  sampleRate,
3460
3024
  channelData
3461
3025
  };
3462
3026
  }
3463
- static readPCM(reader, channelData, length2, format, options) {
3027
+ static readPCM(reader, channelData, length, format, options) {
3464
3028
  const bitDepth = format.bitDepth;
3465
3029
  const decoderOption = format.float ? "f" : options.symmetric ? "s" : "";
3466
3030
  const methodName = "pcm" + bitDepth + decoderOption;
@@ -3469,7 +3033,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3469
3033
  }
3470
3034
  const read = reader[methodName].bind(reader);
3471
3035
  const numberOfChannels = format.numberOfChannels;
3472
- for (let i = 0; i < length2; i++) {
3036
+ for (let i = 0; i < length; i++) {
3473
3037
  for (let ch = 0; ch < numberOfChannels; ch++) {
3474
3038
  channelData[ch][i] = read();
3475
3039
  }
@@ -3575,6 +3139,118 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3575
3139
  };
3576
3140
  var WavDecoder_default = WavDecoder;
3577
3141
 
3142
+ // src/SoundfileReader.ts
3143
+ var SoundfileReader = class {
3144
+ static get fallbackPaths() {
3145
+ return [location.href, location.origin, "http://127.0.0.1:8000"];
3146
+ }
3147
+ /**
3148
+ * Convert an audio buffer to audio data.
3149
+ *
3150
+ * @param audioBuffer : the audio buffer to convert
3151
+ * @returns : the audio data
3152
+ */
3153
+ static toAudioData(audioBuffer) {
3154
+ const { sampleRate, numberOfChannels } = audioBuffer;
3155
+ return {
3156
+ sampleRate,
3157
+ audioBuffer: new Array(numberOfChannels).fill(null).map((v, i) => audioBuffer.getChannelData(i))
3158
+ };
3159
+ }
3160
+ /**
3161
+ * Extract the URLs from the metadata.
3162
+ *
3163
+ * @param dspMeta : the metadata
3164
+ * @returns : the URLs
3165
+ */
3166
+ static findSoundfilesFromMeta(dspMeta) {
3167
+ const soundfiles = {};
3168
+ const callback = (item) => {
3169
+ if (item.type === "soundfile") {
3170
+ const urls = FaustBaseWebAudioDsp.splitSoundfileNames(item.url);
3171
+ urls.forEach((url) => soundfiles[url] = null);
3172
+ }
3173
+ };
3174
+ FaustBaseWebAudioDsp.parseUI(dspMeta.ui, callback);
3175
+ return soundfiles;
3176
+ }
3177
+ /**
3178
+ * Check if the file exists.
3179
+ *
3180
+ * @param url : the url of the file to check
3181
+ * @returns : true if the file exists, otherwise false
3182
+ */
3183
+ static async checkFileExists(url) {
3184
+ try {
3185
+ console.log(`"checkFileExists" url: ${url}`);
3186
+ const response = await fetch(url, { method: "HEAD" });
3187
+ return response.ok;
3188
+ } catch (error) {
3189
+ console.error("Fetch error:", error);
3190
+ return false;
3191
+ }
3192
+ }
3193
+ /**
3194
+ * Fetch the soundfile.
3195
+ *
3196
+ * @param url : the url of the soundfile
3197
+ * @param audioCtx : the audio context
3198
+ * @returns : the audio data
3199
+ */
3200
+ static async fetchSoundfile(url, audioCtx) {
3201
+ console.log(`Loading sound file from ${url}`);
3202
+ const response = await fetch(url);
3203
+ if (!response.ok)
3204
+ throw new Error(`Failed to load sound file from ${url}: ${response.statusText}`);
3205
+ const arrayBuffer = await response.arrayBuffer();
3206
+ const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
3207
+ return this.toAudioData(audioBuffer);
3208
+ }
3209
+ /**
3210
+ * Load the soundfile.
3211
+ *
3212
+ * @param filename : the filename
3213
+ * @param metaUrls : the metadata URLs
3214
+ * @param soundfiles : the soundfiles
3215
+ * @param audioCtx : the audio context
3216
+ */
3217
+ static async loadSoundfile(filename, metaUrls, soundfiles, audioCtx) {
3218
+ if (soundfiles[filename])
3219
+ return;
3220
+ const urlsToCheck = [filename, ...[...metaUrls, ...this.fallbackPaths].map((path) => new URL(filename, path.endsWith("/") ? path : `${path}/`).href)];
3221
+ const checkResults = await Promise.all(urlsToCheck.map((url) => this.checkFileExists(url)));
3222
+ const successIndex = checkResults.findIndex((r) => !!r);
3223
+ if (successIndex === -1)
3224
+ throw new Error(`Failed to load sound file ${filename}, all check failed.`);
3225
+ soundfiles[filename] = await this.fetchSoundfile(urlsToCheck[successIndex], audioCtx);
3226
+ }
3227
+ /**
3228
+ * Load the soundfiles, public API.
3229
+ *
3230
+ * @param dspMeta : the metadata
3231
+ * @param soundfilesIn : the soundfiles
3232
+ * @param audioCtx : the audio context
3233
+ * @returns : the soundfiles
3234
+ */
3235
+ static async loadSoundfiles(dspMeta, soundfilesIn, audioCtx) {
3236
+ const metaUrls = FaustBaseWebAudioDsp.extractUrlsFromMeta(dspMeta);
3237
+ const soundfiles = this.findSoundfilesFromMeta(dspMeta);
3238
+ for (const id in soundfiles) {
3239
+ if (soundfilesIn[id]) {
3240
+ soundfiles[id] = soundfilesIn[id];
3241
+ continue;
3242
+ }
3243
+ try {
3244
+ await this.loadSoundfile(id, metaUrls, soundfiles, audioCtx);
3245
+ } catch (error) {
3246
+ console.error(error);
3247
+ }
3248
+ }
3249
+ return soundfiles;
3250
+ }
3251
+ };
3252
+ var SoundfileReader_default = SoundfileReader;
3253
+
3578
3254
  // src/FaustAudioWorkletNode.ts
3579
3255
  var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
3580
3256
  constructor(context, name, factory, options, nodeOptions = {}) {
@@ -3611,6 +3287,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3611
3287
  }
3612
3288
  };
3613
3289
  }
3290
+ // Public API
3614
3291
  setOutputParamHandler(handler) {
3615
3292
  this.fOutputHandler = handler;
3616
3293
  }
@@ -3640,6 +3317,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3640
3317
  getNumOutputs() {
3641
3318
  return this.fJSONDsp.outputs;
3642
3319
  }
3320
+ // Implemented in subclasses
3643
3321
  compute(inputs, outputs) {
3644
3322
  return false;
3645
3323
  }
@@ -3737,6 +3415,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3737
3415
  FaustBaseWebAudioDsp.parseUI(this.fJSONEffect.ui, this.fUICallback);
3738
3416
  }
3739
3417
  }
3418
+ // Public API
3740
3419
  keyOn(channel, pitch, velocity) {
3741
3420
  const e = { type: "keyOn", data: [channel, pitch, velocity] };
3742
3421
  this.port.postMessage(e);
@@ -3798,6 +3477,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3798
3477
  };
3799
3478
  this.start();
3800
3479
  }
3480
+ // Public API
3801
3481
  compute(input, output) {
3802
3482
  return this.fDSPCode.compute(input, output);
3803
3483
  }
@@ -3882,7 +3562,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3882
3562
  };
3883
3563
 
3884
3564
  // src/FaustDspGenerator.ts
3885
- var _FaustMonoDspGenerator = class {
3565
+ var _FaustMonoDspGenerator = class _FaustMonoDspGenerator {
3886
3566
  constructor() {
3887
3567
  this.factory = null;
3888
3568
  }
@@ -3901,10 +3581,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3901
3581
  throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3902
3582
  const meta = JSON.parse(factory.json);
3903
3583
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
3584
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
3904
3585
  if (sp) {
3905
3586
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
3906
- const monoDsp = new FaustMonoWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize);
3907
- await monoDsp.init(context);
3587
+ const monoDsp = new FaustMonoWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize, factory.soundfiles);
3908
3588
  const sp2 = context.createScriptProcessor(bufferSize, monoDsp.getNumInputs(), monoDsp.getNumOutputs());
3909
3589
  Object.setPrototypeOf(sp2, FaustMonoScriptProcessorNode.prototype);
3910
3590
  sp2.init(monoDsp);
@@ -3923,15 +3603,23 @@ const faustData = ${JSON.stringify({
3923
3603
  poly: false
3924
3604
  })};
3925
3605
  // Implementation needed classes of functions
3926
- const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3927
- const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3928
- const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3929
- const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3606
+ var ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3607
+ var FaustDspInstance = ${FaustDspInstance.name};
3608
+ var ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3609
+ var FaustBaseWebAudioDsp = ${FaustBaseWebAudioDsp.name};
3610
+ var ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3611
+ var FaustMonoWebAudioDsp = ${FaustMonoWebAudioDsp.name};
3612
+ var ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3613
+ var FaustWasmInstantiator = ${FaustWasmInstantiator_default.name};
3614
+ var ${Soundfile.name} = ${Soundfile.toString()}
3615
+ var Soundfile = ${Soundfile.name};
3616
+ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
3617
+ var WasmAllocator = ${WasmAllocator.name};
3930
3618
  // Put them in dependencies
3931
3619
  const dependencies = {
3932
- FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
3933
- FaustMonoWebAudioDsp: ${FaustMonoWebAudioDsp.name},
3934
- FaustWasmInstantiator: ${FaustWasmInstantiator_default.name}
3620
+ FaustBaseWebAudioDsp,
3621
+ FaustMonoWebAudioDsp,
3622
+ FaustWasmInstantiator
3935
3623
  };
3936
3624
  // Generate the actual AudioWorkletProcessor code
3937
3625
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
@@ -3953,6 +3641,7 @@ const dependencies = {
3953
3641
  throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3954
3642
  const meta = JSON.parse(factory.json);
3955
3643
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
3644
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
3956
3645
  if (!_FaustMonoDspGenerator.gWorkletProcessors.has(context))
3957
3646
  _FaustMonoDspGenerator.gWorkletProcessors.set(context, /* @__PURE__ */ new Set());
3958
3647
  if (!((_a = _FaustMonoDspGenerator.gWorkletProcessors.get(context)) == null ? void 0 : _a.has(processorName))) {
@@ -3966,16 +3655,24 @@ const faustData = ${JSON.stringify({
3966
3655
  fftOptions
3967
3656
  })};
3968
3657
  // Implementation needed classes of functions
3969
- const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3970
- const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3971
- const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3972
- const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3973
- const FFTUtils = ${fftUtils.toString()}
3658
+ var ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3659
+ var FaustDspInstance = ${FaustDspInstance.name};
3660
+ var ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3661
+ var FaustBaseWebAudioDsp = ${FaustBaseWebAudioDsp.name};
3662
+ var ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
3663
+ var FaustMonoWebAudioDsp = ${FaustMonoWebAudioDsp.name};
3664
+ var ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3665
+ var FaustWasmInstantiator = ${FaustWasmInstantiator_default.name};
3666
+ var ${Soundfile.name} = ${Soundfile.toString()}
3667
+ var Soundfile = ${Soundfile.name};
3668
+ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
3669
+ var WasmAllocator = ${WasmAllocator.name};
3670
+ var FFTUtils = ${fftUtils.toString()}
3974
3671
  // Put them in dependencies
3975
3672
  const dependencies = {
3976
- FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
3977
- FaustMonoWebAudioDsp: ${FaustMonoWebAudioDsp.name},
3978
- FaustWasmInstantiator: ${FaustWasmInstantiator_default.name},
3673
+ FaustBaseWebAudioDsp,
3674
+ FaustMonoWebAudioDsp,
3675
+ FaustWasmInstantiator,
3979
3676
  FFTUtils
3980
3677
  };
3981
3678
  // Generate the actual AudioWorkletProcessor code
@@ -4041,8 +3738,7 @@ const dependencies = {
4041
3738
  const meta = JSON.parse(factory.json);
4042
3739
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
4043
3740
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
4044
- const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize);
4045
- await monoDsp.init(null);
3741
+ const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
4046
3742
  return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
4047
3743
  }
4048
3744
  getMeta() {
@@ -4055,9 +3751,10 @@ const dependencies = {
4055
3751
  return this.getMeta().ui;
4056
3752
  }
4057
3753
  };
3754
+ // Set of all created WorkletProcessors, each of them has to be unique
3755
+ _FaustMonoDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
4058
3756
  var FaustMonoDspGenerator = _FaustMonoDspGenerator;
4059
- FaustMonoDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
4060
- var _FaustPolyDspGenerator = class {
3757
+ var _FaustPolyDspGenerator = class _FaustPolyDspGenerator {
4061
3758
  constructor() {
4062
3759
  this.voiceFactory = null;
4063
3760
  this.effectFactory = null;
@@ -4070,43 +3767,43 @@ const dependencies = {
4070
3767
  this.effectFactory = await compiler.createPolyDSPFactory(name, effectCodeAux, args);
4071
3768
  if (this.effectFactory) {
4072
3769
  const effectJSON = JSON.parse(this.effectFactory.json);
4073
- const dspCode = `
4074
- // Voice output is forced to 2, when DSP is stereo or effect has 2 ins or 2 outs,
4075
- // so that the effect can process the 2 channels of the voice
4076
- adaptOut(1,1,1) = _;
4077
- adaptOut(1,1,2) = _ <: _,0; // The left channel only is kept
4078
- adaptOut(1,2,1) = _ <: _,_;
4079
- adaptOut(1,2,2) = _ <: _,_;
4080
- adaptOut(2,1,1) = _,_;
4081
- adaptOut(2,1,2) = _,_;
4082
- adaptOut(2,2,1) = _,_;
4083
- adaptOut(2,2,2) = _,_;
4084
- adaptor(F) = adaptOut(outputs(F),${effectJSON.inputs},${effectJSON.outputs});
4085
- dsp_code = environment{
4086
- ${dspCodeAux}
4087
- };
4088
- process = dsp_code.process : adaptor(dsp_code.process);`;
4089
- const effectCode = `
4090
- // Inputs
4091
- adaptIn(1,1,1) = _;
4092
- adaptIn(1,1,2) = _,_ :> _;
4093
- adaptIn(1,2,1) = _,_;
4094
- adaptIn(1,2,2) = _,_;
4095
- adaptIn(2,1,1) = _,_ :> _;
4096
- adaptIn(2,1,2) = _,_ :> _;
4097
- adaptIn(2,2,1) = _,_;
4098
- adaptIn(2,2,2) = _,_;
4099
- // Outputs
4100
- adaptOut(1,1) = _ <: _,0; // The left channel only is kept
4101
- adaptOut(1,2) = _,_;
4102
- adaptOut(2,1) = _ <: _,0; // The left channel only is kept
4103
- adaptOut(2,2) = _,_;
4104
- adaptorIns(F) = adaptIn(outputs(F),${effectJSON.inputs},${effectJSON.outputs});
4105
- adaptorOuts = adaptOut(${effectJSON.inputs},${effectJSON.outputs});
4106
- dsp_code = environment{
4107
- ${dspCodeAux}
4108
- };
4109
- process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;`;
3770
+ const dspCode = `// Voice output is forced to 2, when DSP is stereo or effect has 2 ins or 2 outs,
3771
+ // so that the effect can process the 2 channels of the voice
3772
+ adaptOut(1,1,1) = _;
3773
+ adaptOut(1,1,2) = _ <: _,0; // The left channel only is kept
3774
+ adaptOut(1,2,1) = _ <: _,_;
3775
+ adaptOut(1,2,2) = _ <: _,_;
3776
+ adaptOut(2,1,1) = _,_;
3777
+ adaptOut(2,1,2) = _,_;
3778
+ adaptOut(2,2,1) = _,_;
3779
+ adaptOut(2,2,2) = _,_;
3780
+ adaptor(F) = adaptOut(outputs(F),${effectJSON.inputs},${effectJSON.outputs});
3781
+ dsp_code = environment{
3782
+ ${dspCodeAux}
3783
+ };
3784
+ process = dsp_code.process : adaptor(dsp_code.process);
3785
+ `;
3786
+ const effectCode = `// Inputs
3787
+ adaptIn(1,1,1) = _;
3788
+ adaptIn(1,1,2) = _,_ :> _;
3789
+ adaptIn(1,2,1) = _,_;
3790
+ adaptIn(1,2,2) = _,_;
3791
+ adaptIn(2,1,1) = _,_ :> _;
3792
+ adaptIn(2,1,2) = _,_ :> _;
3793
+ adaptIn(2,2,1) = _,_;
3794
+ adaptIn(2,2,2) = _,_;
3795
+ // Outputs
3796
+ adaptOut(1,1) = _ <: _,0; // The left channel only is kept
3797
+ adaptOut(1,2) = _,_;
3798
+ adaptOut(2,1) = _ <: _,0; // The left channel only is kept
3799
+ adaptOut(2,2) = _,_;
3800
+ adaptorIns(F) = adaptIn(outputs(F),${effectJSON.inputs},${effectJSON.outputs});
3801
+ adaptorOuts = adaptOut(${effectJSON.inputs},${effectJSON.outputs});
3802
+ dsp_code = environment{
3803
+ ${dspCodeAux}
3804
+ };
3805
+ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
3806
+ `;
4110
3807
  this.voiceFactory = await compiler.createPolyDSPFactory(name, dspCode, args);
4111
3808
  try {
4112
3809
  this.effectFactory = await compiler.createPolyDSPFactory(name, effectCode, args + " -inpl");
@@ -4137,10 +3834,13 @@ const dependencies = {
4137
3834
  const voiceMeta = JSON.parse(voiceFactory.json);
4138
3835
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4139
3836
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
3837
+ voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
3838
+ if (effectFactory)
3839
+ effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
4140
3840
  if (sp) {
4141
3841
  const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
4142
- const polyDsp = new FaustPolyWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize);
4143
- await polyDsp.init(context);
3842
+ const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
3843
+ const polyDsp = new FaustPolyWebAudioDsp(instance, context.sampleRate, sampleSize, bufferSize, soundfiles);
4144
3844
  const sp2 = context.createScriptProcessor(bufferSize, polyDsp.getNumInputs(), polyDsp.getNumOutputs());
4145
3845
  Object.setPrototypeOf(sp2, FaustPolyScriptProcessorNode.prototype);
4146
3846
  sp2.init(polyDsp);
@@ -4160,16 +3860,25 @@ const faustData = ${JSON.stringify({
4160
3860
  effectMeta
4161
3861
  })};
4162
3862
  // Implementation needed classes of functions
4163
- const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
4164
- const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
4165
- const ${FaustPolyWebAudioDsp.name} = ${FaustPolyWebAudioDsp.toString()}
4166
- const ${FaustWebAudioDspVoice.name} = ${FaustWebAudioDspVoice.toString()}
4167
- const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3863
+ var ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
3864
+ var FaustDspInstance = ${FaustDspInstance.name};
3865
+ var ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
3866
+ var FaustBaseWebAudioDsp = ${FaustBaseWebAudioDsp.name};
3867
+ var ${FaustPolyWebAudioDsp.name} = ${FaustPolyWebAudioDsp.toString()}
3868
+ var FaustPolyWebAudioDsp = ${FaustPolyWebAudioDsp.name};
3869
+ var ${FaustWebAudioDspVoice.name} = ${FaustWebAudioDspVoice.toString()}
3870
+ var FaustWebAudioDspVoice = ${FaustWebAudioDspVoice.name};
3871
+ var ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
3872
+ var FaustWasmInstantiator = ${FaustWasmInstantiator_default.name};
3873
+ var ${Soundfile.name} = ${Soundfile.toString()}
3874
+ var Soundfile = ${Soundfile.name};
3875
+ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
3876
+ var WasmAllocator = ${WasmAllocator.name};
4168
3877
  // Put them in dependencies
4169
3878
  const dependencies = {
4170
- FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
4171
- FaustPolyWebAudioDsp: ${FaustPolyWebAudioDsp.name},
4172
- FaustWasmInstantiator: ${FaustWasmInstantiator_default.name}
3879
+ FaustBaseWebAudioDsp,
3880
+ FaustPolyWebAudioDsp,
3881
+ FaustWasmInstantiator
4173
3882
  };
4174
3883
  // Generate the actual AudioWorkletProcessor code
4175
3884
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
@@ -4219,7 +3928,8 @@ const dependencies = {
4219
3928
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
4220
3929
  const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
4221
3930
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
4222
- const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize);
3931
+ const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
3932
+ const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
4223
3933
  return new FaustPolyOfflineProcessor(polyDsp, bufferSize);
4224
3934
  }
4225
3935
  getMeta() {
@@ -4253,21 +3963,8 @@ const dependencies = {
4253
3963
  return this.getMeta().ui;
4254
3964
  }
4255
3965
  };
3966
+ // Set of all created WorkletProcessors, each of them has to be unique
3967
+ _FaustPolyDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
4256
3968
  var FaustPolyDspGenerator = _FaustPolyDspGenerator;
4257
- FaustPolyDspGenerator.gWorkletProcessors = /* @__PURE__ */ new Map();
4258
3969
  })();
4259
- /*! *****************************************************************************
4260
- Copyright (c) Microsoft Corporation.
4261
-
4262
- Permission to use, copy, modify, and/or distribute this software for any
4263
- purpose with or without fee is hereby granted.
4264
-
4265
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4266
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4267
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4268
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4269
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4270
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4271
- PERFORMANCE OF THIS SOFTWARE.
4272
- ***************************************************************************** */
4273
3970
  //# sourceMappingURL=index.js.map