@grame/faustwasm 0.7.9 → 0.8.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.
- package/README.md +2 -2
- package/assets/standalone/faustwasm/index.d.ts +76 -9
- package/assets/standalone/faustwasm/index.js +270 -77
- package/assets/standalone/faustwasm/index.js.map +4 -4
- package/assets/standalone/index-pwa.js +7 -8
- package/assets/standalone/index-template.js +2 -2
- package/assets/standalone/index.js +59 -61
- package/assets/standalone/service-worker.js +47 -8
- package/dist/cjs/index.d.ts +76 -9
- package/dist/cjs/index.js +270 -77
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs-bundle/index.d.ts +76 -9
- package/dist/cjs-bundle/index.js +271 -78
- package/dist/cjs-bundle/index.js.map +4 -4
- package/dist/esm/index.d.ts +76 -9
- package/dist/esm/index.js +270 -77
- package/dist/esm/index.js.map +4 -4
- package/dist/esm-bundle/index.d.ts +76 -9
- package/dist/esm-bundle/index.js +271 -78
- package/dist/esm-bundle/index.js.map +4 -4
- package/libfaust-wasm/libfaust-wasm.wasm +0 -0
- package/package.json +1 -1
- package/src/FaustAudioWorkletCommunicator.ts +143 -0
- package/src/FaustAudioWorkletNode.ts +23 -12
- package/src/FaustAudioWorkletProcessor.ts +34 -15
- package/src/FaustDspGenerator.ts +20 -2
- package/src/FaustFFTAudioWorkletProcessor.ts +31 -2
- package/src/FaustOfflineProcessor.ts +6 -0
- package/src/FaustScriptProcessorNode.ts +4 -1
- package/src/FaustWebAudioDsp.ts +38 -10
- package/test/faustlive-wasm/faustwasm/index.d.ts +76 -9
- package/test/faustlive-wasm/faustwasm/index.js +270 -77
- package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
- package/assets/standalone/coi-serviceworker.js +0 -146
package/dist/cjs/index.js
CHANGED
|
@@ -111,7 +111,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
111
111
|
const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
|
|
112
112
|
const {
|
|
113
113
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
114
|
-
FaustWasmInstantiator: FaustWasmInstantiator2
|
|
114
|
+
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
115
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
|
|
115
116
|
} = dependencies;
|
|
116
117
|
const {
|
|
117
118
|
processorName,
|
|
@@ -136,7 +137,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
136
137
|
constructor(options) {
|
|
137
138
|
super(options);
|
|
138
139
|
this.paramValuesCache = {};
|
|
139
|
-
this.
|
|
140
|
+
this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
140
141
|
const { parameterDescriptors } = this.constructor;
|
|
141
142
|
parameterDescriptors.forEach((pd) => {
|
|
142
143
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -183,19 +184,26 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
183
184
|
this.paramValuesCache[path] = paramValue;
|
|
184
185
|
}
|
|
185
186
|
}
|
|
187
|
+
if (this.fCommunicator.getNewAccDataAvailable()) {
|
|
188
|
+
const acc = this.fCommunicator.getAcc();
|
|
189
|
+
if (acc) {
|
|
190
|
+
this.fCommunicator.setNewAccDataAvailable(false);
|
|
191
|
+
const { invert, ...data } = acc;
|
|
192
|
+
this.propagateAcc(data, invert);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (this.fCommunicator.getNewGyrDataAvailable()) {
|
|
196
|
+
const gyr = this.fCommunicator.getGyr();
|
|
197
|
+
if (gyr) {
|
|
198
|
+
this.fCommunicator.setNewGyrDataAvailable(false);
|
|
199
|
+
this.propagateGyr(gyr);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
186
202
|
return this.fDSPCode.compute(inputs[0], outputs[0]);
|
|
187
203
|
}
|
|
188
204
|
handleMessageAux(e) {
|
|
189
205
|
const msg = e.data;
|
|
190
206
|
switch (msg.type) {
|
|
191
|
-
case "acc": {
|
|
192
|
-
this.propagateAcc(msg.data, msg.invert);
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
case "gyr": {
|
|
196
|
-
this.propagateGyr(msg.data);
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
207
|
case "midi": {
|
|
200
208
|
this.midiMessage(msg.data);
|
|
201
209
|
break;
|
|
@@ -264,10 +272,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
264
272
|
class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
|
|
265
273
|
constructor(options) {
|
|
266
274
|
super(options);
|
|
275
|
+
this.handleMessageAux = (e) => {
|
|
276
|
+
super.handleMessageAux(e);
|
|
277
|
+
};
|
|
267
278
|
const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
|
|
268
279
|
const { factory, sampleSize } = options.processorOptions;
|
|
269
280
|
const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
|
|
270
281
|
this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
|
|
282
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
283
|
+
this.port.start();
|
|
271
284
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
272
285
|
this.fDSPCode.start();
|
|
273
286
|
}
|
|
@@ -294,7 +307,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
294
307
|
const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
|
|
295
308
|
const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
|
|
296
309
|
this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
|
|
297
|
-
this.port.
|
|
310
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
311
|
+
this.port.start();
|
|
298
312
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
299
313
|
this.fDSPCode.start();
|
|
300
314
|
}
|
|
@@ -340,6 +354,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
340
354
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
341
355
|
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
342
356
|
FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2,
|
|
357
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
|
|
343
358
|
FFTUtils
|
|
344
359
|
} = dependencies;
|
|
345
360
|
const {
|
|
@@ -423,7 +438,58 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
423
438
|
this.fBufferNum = 0;
|
|
424
439
|
this.soundfiles = {};
|
|
425
440
|
this.windowFunction = null;
|
|
426
|
-
this.
|
|
441
|
+
this.handleMessageAux = (e) => {
|
|
442
|
+
var _a, _b, _c;
|
|
443
|
+
const msg = e.data;
|
|
444
|
+
switch (msg.type) {
|
|
445
|
+
case "midi":
|
|
446
|
+
this.midiMessage(msg.data);
|
|
447
|
+
break;
|
|
448
|
+
case "ctrlChange":
|
|
449
|
+
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
450
|
+
break;
|
|
451
|
+
case "pitchWheel":
|
|
452
|
+
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
453
|
+
break;
|
|
454
|
+
case "param":
|
|
455
|
+
this.setParamValue(msg.data.path, msg.data.value);
|
|
456
|
+
break;
|
|
457
|
+
case "setPlotHandler": {
|
|
458
|
+
if (msg.data) {
|
|
459
|
+
this.fPlotHandler = (output, index, events) => {
|
|
460
|
+
if (events)
|
|
461
|
+
this.fCachedEvents.push(...events);
|
|
462
|
+
};
|
|
463
|
+
} else {
|
|
464
|
+
this.fPlotHandler = null;
|
|
465
|
+
}
|
|
466
|
+
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
467
|
+
break;
|
|
468
|
+
}
|
|
469
|
+
case "setupWamEventHandler": {
|
|
470
|
+
this.setupWamEventHandler();
|
|
471
|
+
break;
|
|
472
|
+
}
|
|
473
|
+
case "start": {
|
|
474
|
+
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
case "stop": {
|
|
478
|
+
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
479
|
+
break;
|
|
480
|
+
}
|
|
481
|
+
case "destroy": {
|
|
482
|
+
this.port.close();
|
|
483
|
+
this.destroy();
|
|
484
|
+
break;
|
|
485
|
+
}
|
|
486
|
+
default:
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
491
|
+
this.port.start();
|
|
492
|
+
this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
427
493
|
const { parameterDescriptors } = this.constructor;
|
|
428
494
|
parameterDescriptors.forEach((pd) => {
|
|
429
495
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -579,6 +645,21 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
579
645
|
this.paramValuesCache[path] = paramValue;
|
|
580
646
|
}
|
|
581
647
|
}
|
|
648
|
+
if (this.communicator.getNewAccDataAvailable()) {
|
|
649
|
+
const acc = this.communicator.getAcc();
|
|
650
|
+
if (acc) {
|
|
651
|
+
this.communicator.setNewAccDataAvailable(false);
|
|
652
|
+
const { invert, ...data } = acc;
|
|
653
|
+
this.propagateAcc(data, invert);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (this.communicator.getNewGyrDataAvailable()) {
|
|
657
|
+
const gyr = this.communicator.getGyr();
|
|
658
|
+
if (gyr) {
|
|
659
|
+
this.communicator.setNewGyrDataAvailable(false);
|
|
660
|
+
this.propagateGyr(gyr);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
582
663
|
if (input == null ? void 0 : input.length) {
|
|
583
664
|
let $inputWrite = 0;
|
|
584
665
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -608,55 +689,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
608
689
|
}
|
|
609
690
|
return true;
|
|
610
691
|
}
|
|
611
|
-
handleMessageAux(e) {
|
|
612
|
-
var _a, _b, _c;
|
|
613
|
-
const msg = e.data;
|
|
614
|
-
switch (msg.type) {
|
|
615
|
-
case "midi":
|
|
616
|
-
this.midiMessage(msg.data);
|
|
617
|
-
break;
|
|
618
|
-
case "ctrlChange":
|
|
619
|
-
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
620
|
-
break;
|
|
621
|
-
case "pitchWheel":
|
|
622
|
-
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
623
|
-
break;
|
|
624
|
-
case "param":
|
|
625
|
-
this.setParamValue(msg.data.path, msg.data.value);
|
|
626
|
-
break;
|
|
627
|
-
case "setPlotHandler": {
|
|
628
|
-
if (msg.data) {
|
|
629
|
-
this.fPlotHandler = (output, index, events) => {
|
|
630
|
-
if (events)
|
|
631
|
-
this.fCachedEvents.push(...events);
|
|
632
|
-
};
|
|
633
|
-
} else {
|
|
634
|
-
this.fPlotHandler = null;
|
|
635
|
-
}
|
|
636
|
-
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
637
|
-
break;
|
|
638
|
-
}
|
|
639
|
-
case "setupWamEventHandler": {
|
|
640
|
-
this.setupWamEventHandler();
|
|
641
|
-
break;
|
|
642
|
-
}
|
|
643
|
-
case "start": {
|
|
644
|
-
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
645
|
-
break;
|
|
646
|
-
}
|
|
647
|
-
case "stop": {
|
|
648
|
-
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
649
|
-
break;
|
|
650
|
-
}
|
|
651
|
-
case "destroy": {
|
|
652
|
-
this.port.close();
|
|
653
|
-
this.destroy();
|
|
654
|
-
break;
|
|
655
|
-
}
|
|
656
|
-
default:
|
|
657
|
-
break;
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
692
|
setParamValue(path, value) {
|
|
661
693
|
var _a;
|
|
662
694
|
(_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(path, value);
|
|
@@ -674,6 +706,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
674
706
|
var _a;
|
|
675
707
|
(_a = this.fDSPCode) == null ? void 0 : _a.pitchWheel(channel, wheel);
|
|
676
708
|
}
|
|
709
|
+
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
710
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
711
|
+
}
|
|
712
|
+
propagateGyr(event) {
|
|
713
|
+
this.fDSPCode.propagateGyr(event);
|
|
714
|
+
}
|
|
677
715
|
resetFFT(sizeIn, overlapIn, windowFunctionIn, inputChannels, outputChannels, bufferSize) {
|
|
678
716
|
var _a, _b;
|
|
679
717
|
const fftSize = ~~ceil(Math.max(2, sizeIn || 1024), 2);
|
|
@@ -2456,6 +2494,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2456
2494
|
this.fComputeHandler = null;
|
|
2457
2495
|
this.fPlotHandler = null;
|
|
2458
2496
|
}
|
|
2497
|
+
startSensors() {
|
|
2498
|
+
this.startSensors();
|
|
2499
|
+
}
|
|
2500
|
+
stopSensors() {
|
|
2501
|
+
this.stopSensors();
|
|
2502
|
+
}
|
|
2459
2503
|
};
|
|
2460
2504
|
var FaustMonoWebAudioDsp = class extends FaustBaseWebAudioDsp {
|
|
2461
2505
|
constructor(instance, sampleRate, sampleSize, bufferSize, soundfiles) {
|
|
@@ -3081,6 +3125,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3081
3125
|
propagateGyr(event) {
|
|
3082
3126
|
this.fDSPCode.propagateGyr(event);
|
|
3083
3127
|
}
|
|
3128
|
+
startSensors() {
|
|
3129
|
+
}
|
|
3130
|
+
stopSensors() {
|
|
3131
|
+
}
|
|
3084
3132
|
/**
|
|
3085
3133
|
* Render frames in an array.
|
|
3086
3134
|
*
|
|
@@ -3709,6 +3757,130 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3709
3757
|
};
|
|
3710
3758
|
var SoundfileReader_default = SoundfileReader;
|
|
3711
3759
|
|
|
3760
|
+
// src/FaustAudioWorkletCommunicator.ts
|
|
3761
|
+
var FaustAudioWorkletCommunicator = class {
|
|
3762
|
+
constructor(port) {
|
|
3763
|
+
this.port = port;
|
|
3764
|
+
this.supportSharedArrayBuffer = !!globalThis.SharedArrayBuffer;
|
|
3765
|
+
this.byteLength = 4 * Uint8Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
3766
|
+
}
|
|
3767
|
+
initializeBuffer(ab) {
|
|
3768
|
+
let ptr = 0;
|
|
3769
|
+
this.uin8Invert = new Uint8ClampedArray(ab, ptr, 1);
|
|
3770
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3771
|
+
this.uin8NewAccData = new Uint8ClampedArray(ab, ptr, 1);
|
|
3772
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3773
|
+
this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
|
|
3774
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3775
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3776
|
+
;
|
|
3777
|
+
this.f32Acc = new Float32Array(ab, ptr, 3);
|
|
3778
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
3779
|
+
this.f32Gyr = new Float32Array(ab, ptr, 3);
|
|
3780
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
3781
|
+
}
|
|
3782
|
+
setNewAccDataAvailable(value) {
|
|
3783
|
+
if (!this.uin8NewAccData)
|
|
3784
|
+
return;
|
|
3785
|
+
this.uin8NewAccData[0] = +value;
|
|
3786
|
+
}
|
|
3787
|
+
getNewAccDataAvailable() {
|
|
3788
|
+
var _a;
|
|
3789
|
+
return !!((_a = this.uin8NewAccData) == null ? void 0 : _a[0]);
|
|
3790
|
+
}
|
|
3791
|
+
setNewGyrDataAvailable(value) {
|
|
3792
|
+
if (!this.uin8NewGyrData)
|
|
3793
|
+
return;
|
|
3794
|
+
this.uin8NewGyrData[0] = +value;
|
|
3795
|
+
}
|
|
3796
|
+
getNewGyrDataAvailable() {
|
|
3797
|
+
var _a;
|
|
3798
|
+
return !!((_a = this.uin8NewGyrData) == null ? void 0 : _a[0]);
|
|
3799
|
+
}
|
|
3800
|
+
setAcc({ x, y, z }, invert = false) {
|
|
3801
|
+
if (!this.supportSharedArrayBuffer) {
|
|
3802
|
+
const e = { type: "acc", data: { x, y, z }, invert };
|
|
3803
|
+
this.port.postMessage(e);
|
|
3804
|
+
}
|
|
3805
|
+
if (!this.uin8NewAccData)
|
|
3806
|
+
return;
|
|
3807
|
+
this.uin8Invert[0] = +invert;
|
|
3808
|
+
this.f32Acc[0] = x;
|
|
3809
|
+
this.f32Acc[1] = y;
|
|
3810
|
+
this.f32Acc[2] = z;
|
|
3811
|
+
this.uin8NewAccData[0] = 1;
|
|
3812
|
+
}
|
|
3813
|
+
getAcc() {
|
|
3814
|
+
if (!this.uin8NewAccData)
|
|
3815
|
+
return;
|
|
3816
|
+
const invert = !!this.uin8Invert[0];
|
|
3817
|
+
const [x, y, z] = this.f32Acc;
|
|
3818
|
+
return { x, y, z, invert };
|
|
3819
|
+
}
|
|
3820
|
+
setGyr({ alpha, beta, gamma }) {
|
|
3821
|
+
if (!this.supportSharedArrayBuffer) {
|
|
3822
|
+
const e = { type: "gyr", data: { alpha, beta, gamma } };
|
|
3823
|
+
this.port.postMessage(e);
|
|
3824
|
+
}
|
|
3825
|
+
if (!this.uin8NewGyrData)
|
|
3826
|
+
return;
|
|
3827
|
+
this.f32Gyr[0] = alpha;
|
|
3828
|
+
this.f32Gyr[1] = beta;
|
|
3829
|
+
this.f32Gyr[2] = gamma;
|
|
3830
|
+
this.uin8NewGyrData[0] = 1;
|
|
3831
|
+
}
|
|
3832
|
+
getGyr() {
|
|
3833
|
+
if (!this.uin8NewGyrData)
|
|
3834
|
+
return;
|
|
3835
|
+
const [alpha, beta, gamma] = this.f32Gyr;
|
|
3836
|
+
return { alpha, beta, gamma };
|
|
3837
|
+
}
|
|
3838
|
+
};
|
|
3839
|
+
var FaustAudioWorkletNodeCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
3840
|
+
constructor(port) {
|
|
3841
|
+
super(port);
|
|
3842
|
+
if (this.supportSharedArrayBuffer) {
|
|
3843
|
+
const sab = new SharedArrayBuffer(this.byteLength);
|
|
3844
|
+
this.initializeBuffer(sab);
|
|
3845
|
+
this.port.postMessage({ type: "initSab", sab });
|
|
3846
|
+
} else {
|
|
3847
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
3848
|
+
this.initializeBuffer(ab);
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
};
|
|
3852
|
+
var FaustAudioWorkletProcessorCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
3853
|
+
constructor(port) {
|
|
3854
|
+
super(port);
|
|
3855
|
+
if (this.supportSharedArrayBuffer) {
|
|
3856
|
+
this.port.addEventListener("message", (event) => {
|
|
3857
|
+
const { data } = event;
|
|
3858
|
+
if (data.type === "initSab") {
|
|
3859
|
+
this.initializeBuffer(data.sab);
|
|
3860
|
+
}
|
|
3861
|
+
});
|
|
3862
|
+
} else {
|
|
3863
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
3864
|
+
this.initializeBuffer(ab);
|
|
3865
|
+
this.port.addEventListener("message", (event) => {
|
|
3866
|
+
const msg = event.data;
|
|
3867
|
+
switch (msg.type) {
|
|
3868
|
+
case "acc": {
|
|
3869
|
+
this.setAcc(msg.data, msg.invert);
|
|
3870
|
+
break;
|
|
3871
|
+
}
|
|
3872
|
+
case "gyr": {
|
|
3873
|
+
this.setGyr(msg.data);
|
|
3874
|
+
break;
|
|
3875
|
+
}
|
|
3876
|
+
default:
|
|
3877
|
+
break;
|
|
3878
|
+
}
|
|
3879
|
+
});
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
};
|
|
3883
|
+
|
|
3712
3884
|
// src/FaustAudioWorkletNode.ts
|
|
3713
3885
|
var _hasAccInput, _hasGyrInput;
|
|
3714
3886
|
var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
|
|
@@ -3726,7 +3898,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3726
3898
|
});
|
|
3727
3899
|
__privateAdd(this, _hasAccInput, false);
|
|
3728
3900
|
__privateAdd(this, _hasGyrInput, false);
|
|
3729
|
-
|
|
3901
|
+
this.handleMessageAux = (e) => {
|
|
3902
|
+
if (e.data.type === "param" && this.fOutputHandler) {
|
|
3903
|
+
this.fOutputHandler(e.data.path, e.data.value);
|
|
3904
|
+
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
3905
|
+
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
3906
|
+
}
|
|
3907
|
+
};
|
|
3730
3908
|
// Accelerometer and gyroscope handlers
|
|
3731
3909
|
this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3732
3910
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
@@ -3761,14 +3939,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3761
3939
|
}
|
|
3762
3940
|
};
|
|
3763
3941
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
3764
|
-
this.
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
3768
|
-
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
3769
|
-
}
|
|
3770
|
-
};
|
|
3942
|
+
this.fCommunicator = new FaustAudioWorkletNodeCommunicator(this.port);
|
|
3943
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
3944
|
+
this.port.start();
|
|
3771
3945
|
}
|
|
3946
|
+
// Public API
|
|
3772
3947
|
/** Setup accelerometer and gyroscope handlers */
|
|
3773
3948
|
async startSensors() {
|
|
3774
3949
|
if (this.hasAccInput) {
|
|
@@ -3889,8 +4064,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3889
4064
|
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
3890
4065
|
if (!accelerationIncludingGravity)
|
|
3891
4066
|
return;
|
|
3892
|
-
const
|
|
3893
|
-
this.
|
|
4067
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
4068
|
+
this.fCommunicator.setAcc({ x, y, z }, invert);
|
|
3894
4069
|
}
|
|
3895
4070
|
get hasGyrInput() {
|
|
3896
4071
|
return __privateGet(this, _hasGyrInput);
|
|
@@ -3898,8 +4073,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3898
4073
|
propagateGyr(event) {
|
|
3899
4074
|
if (!event)
|
|
3900
4075
|
return;
|
|
3901
|
-
const
|
|
3902
|
-
this.
|
|
4076
|
+
const { alpha, beta, gamma } = event;
|
|
4077
|
+
this.fCommunicator.setGyr({ alpha, beta, gamma });
|
|
3903
4078
|
}
|
|
3904
4079
|
setParamValue(path, value) {
|
|
3905
4080
|
const e = { type: "param", data: { path, value } };
|
|
@@ -4042,7 +4217,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
4042
4217
|
this.start();
|
|
4043
4218
|
}
|
|
4044
4219
|
// Public API
|
|
4045
|
-
/**
|
|
4220
|
+
/** Start accelerometer and gyroscope handlers */
|
|
4046
4221
|
async startSensors() {
|
|
4047
4222
|
if (this.hasAccInput) {
|
|
4048
4223
|
if (window.DeviceMotionEvent) {
|
|
@@ -4087,6 +4262,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
4087
4262
|
}
|
|
4088
4263
|
}
|
|
4089
4264
|
}
|
|
4265
|
+
/** Stop accelerometer and gyroscope handlers */
|
|
4090
4266
|
stopSensors() {
|
|
4091
4267
|
if (this.hasAccInput) {
|
|
4092
4268
|
window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
@@ -4260,11 +4436,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4260
4436
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4261
4437
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4262
4438
|
var FaustSensors = ${FaustSensors.name};
|
|
4439
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4440
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4441
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4442
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4263
4443
|
// Put them in dependencies
|
|
4264
4444
|
const dependencies = {
|
|
4265
4445
|
FaustBaseWebAudioDsp,
|
|
4266
4446
|
FaustMonoWebAudioDsp,
|
|
4267
|
-
FaustWasmInstantiator
|
|
4447
|
+
FaustWasmInstantiator,
|
|
4448
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4268
4449
|
};
|
|
4269
4450
|
// Generate the actual AudioWorkletProcessor code
|
|
4270
4451
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -4314,12 +4495,17 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4314
4495
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4315
4496
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4316
4497
|
var FaustSensors = ${FaustSensors.name};
|
|
4498
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4499
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4500
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4501
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4317
4502
|
var FFTUtils = ${fftUtils.toString()}
|
|
4318
4503
|
// Put them in dependencies
|
|
4319
4504
|
const dependencies = {
|
|
4320
4505
|
FaustBaseWebAudioDsp,
|
|
4321
4506
|
FaustMonoWebAudioDsp,
|
|
4322
4507
|
FaustWasmInstantiator,
|
|
4508
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
4323
4509
|
FFTUtils
|
|
4324
4510
|
};
|
|
4325
4511
|
// Generate the actual AudioWorkletProcessor code
|
|
@@ -4363,6 +4549,7 @@ const dependencies = {
|
|
|
4363
4549
|
FaustBaseWebAudioDsp,
|
|
4364
4550
|
FaustMonoWebAudioDsp,
|
|
4365
4551
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
4552
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
4366
4553
|
FaustPolyWebAudioDsp: void 0,
|
|
4367
4554
|
FaustWebAudioDspVoice: void 0
|
|
4368
4555
|
};
|
|
@@ -4543,11 +4730,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4543
4730
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4544
4731
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4545
4732
|
var FaustSensors = ${FaustSensors.name};
|
|
4733
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4734
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4735
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4736
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4546
4737
|
// Put them in dependencies
|
|
4547
4738
|
const dependencies = {
|
|
4548
4739
|
FaustBaseWebAudioDsp,
|
|
4549
4740
|
FaustPolyWebAudioDsp,
|
|
4550
|
-
FaustWasmInstantiator
|
|
4741
|
+
FaustWasmInstantiator,
|
|
4742
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4551
4743
|
};
|
|
4552
4744
|
// Generate the actual AudioWorkletProcessor code
|
|
4553
4745
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -4575,7 +4767,8 @@ const dependencies = {
|
|
|
4575
4767
|
FaustMonoWebAudioDsp: void 0,
|
|
4576
4768
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
4577
4769
|
FaustPolyWebAudioDsp,
|
|
4578
|
-
FaustWebAudioDspVoice
|
|
4770
|
+
FaustWebAudioDspVoice,
|
|
4771
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4579
4772
|
};
|
|
4580
4773
|
const faustData = {
|
|
4581
4774
|
processorName,
|