@grame/faustwasm 0.7.10 → 0.8.2
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/create-node.js +31 -1
- package/assets/standalone/faust-ui/index.js +2 -2
- package/assets/standalone/faust-ui/index.js.map +1 -1
- package/assets/standalone/faustwasm/index.d.ts +76 -9
- package/assets/standalone/faustwasm/index.js +272 -107
- package/assets/standalone/faustwasm/index.js.map +4 -4
- package/assets/standalone/index-pwa.js +132 -98
- package/assets/standalone/index-template.js +44 -23
- package/assets/standalone/index.js +95 -80
- package/assets/standalone/service-worker.js +47 -8
- package/dist/cjs/index.d.ts +76 -9
- package/dist/cjs/index.js +272 -107
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs-bundle/index.d.ts +76 -9
- package/dist/cjs-bundle/index.js +272 -107
- package/dist/cjs-bundle/index.js.map +4 -4
- package/dist/esm/index.d.ts +76 -9
- package/dist/esm/index.js +272 -107
- package/dist/esm/index.js.map +4 -4
- package/dist/esm-bundle/index.d.ts +76 -9
- package/dist/esm-bundle/index.js +272 -107
- package/dist/esm-bundle/index.js.map +4 -4
- package/package.json +2 -2
- package/src/FaustAudioWorkletCommunicator.ts +143 -0
- package/src/FaustAudioWorkletNode.ts +27 -42
- 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 +8 -31
- package/src/FaustWebAudioDsp.ts +38 -10
- package/test/faustlive-wasm/faust-ui/index.js +2 -2
- package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
- package/test/faustlive-wasm/faustwasm/index.d.ts +76 -9
- package/test/faustlive-wasm/faustwasm/index.js +272 -107
- package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
- package/assets/standalone/coi-serviceworker.js +0 -146
|
@@ -81,7 +81,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
81
81
|
const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
|
|
82
82
|
const {
|
|
83
83
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
84
|
-
FaustWasmInstantiator: FaustWasmInstantiator2
|
|
84
|
+
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
85
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
|
|
85
86
|
} = dependencies;
|
|
86
87
|
const {
|
|
87
88
|
processorName,
|
|
@@ -106,7 +107,7 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
106
107
|
constructor(options) {
|
|
107
108
|
super(options);
|
|
108
109
|
this.paramValuesCache = {};
|
|
109
|
-
this.
|
|
110
|
+
this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
110
111
|
const { parameterDescriptors } = this.constructor;
|
|
111
112
|
parameterDescriptors.forEach((pd) => {
|
|
112
113
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -153,19 +154,26 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
153
154
|
this.paramValuesCache[path] = paramValue;
|
|
154
155
|
}
|
|
155
156
|
}
|
|
157
|
+
if (this.fCommunicator.getNewAccDataAvailable()) {
|
|
158
|
+
const acc = this.fCommunicator.getAcc();
|
|
159
|
+
if (acc) {
|
|
160
|
+
this.fCommunicator.setNewAccDataAvailable(false);
|
|
161
|
+
const { invert, ...data } = acc;
|
|
162
|
+
this.propagateAcc(data, invert);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (this.fCommunicator.getNewGyrDataAvailable()) {
|
|
166
|
+
const gyr = this.fCommunicator.getGyr();
|
|
167
|
+
if (gyr) {
|
|
168
|
+
this.fCommunicator.setNewGyrDataAvailable(false);
|
|
169
|
+
this.propagateGyr(gyr);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
156
172
|
return this.fDSPCode.compute(inputs[0], outputs[0]);
|
|
157
173
|
}
|
|
158
174
|
handleMessageAux(e) {
|
|
159
175
|
const msg = e.data;
|
|
160
176
|
switch (msg.type) {
|
|
161
|
-
case "acc": {
|
|
162
|
-
this.propagateAcc(msg.data, msg.invert);
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
case "gyr": {
|
|
166
|
-
this.propagateGyr(msg.data);
|
|
167
|
-
break;
|
|
168
|
-
}
|
|
169
177
|
case "midi": {
|
|
170
178
|
this.midiMessage(msg.data);
|
|
171
179
|
break;
|
|
@@ -234,10 +242,15 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
234
242
|
class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
|
|
235
243
|
constructor(options) {
|
|
236
244
|
super(options);
|
|
245
|
+
this.handleMessageAux = (e) => {
|
|
246
|
+
super.handleMessageAux(e);
|
|
247
|
+
};
|
|
237
248
|
const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
|
|
238
249
|
const { factory, sampleSize } = options.processorOptions;
|
|
239
250
|
const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
|
|
240
251
|
this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
|
|
252
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
253
|
+
this.port.start();
|
|
241
254
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
242
255
|
this.fDSPCode.start();
|
|
243
256
|
}
|
|
@@ -264,7 +277,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
264
277
|
const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
|
|
265
278
|
const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
|
|
266
279
|
this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
|
|
267
|
-
this.port.
|
|
280
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
281
|
+
this.port.start();
|
|
268
282
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
269
283
|
this.fDSPCode.start();
|
|
270
284
|
}
|
|
@@ -310,6 +324,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
310
324
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
311
325
|
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
312
326
|
FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2,
|
|
327
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
|
|
313
328
|
FFTUtils
|
|
314
329
|
} = dependencies;
|
|
315
330
|
const {
|
|
@@ -393,7 +408,58 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
393
408
|
this.fBufferNum = 0;
|
|
394
409
|
this.soundfiles = {};
|
|
395
410
|
this.windowFunction = null;
|
|
396
|
-
this.
|
|
411
|
+
this.handleMessageAux = (e) => {
|
|
412
|
+
var _a, _b, _c;
|
|
413
|
+
const msg = e.data;
|
|
414
|
+
switch (msg.type) {
|
|
415
|
+
case "midi":
|
|
416
|
+
this.midiMessage(msg.data);
|
|
417
|
+
break;
|
|
418
|
+
case "ctrlChange":
|
|
419
|
+
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
420
|
+
break;
|
|
421
|
+
case "pitchWheel":
|
|
422
|
+
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
423
|
+
break;
|
|
424
|
+
case "param":
|
|
425
|
+
this.setParamValue(msg.data.path, msg.data.value);
|
|
426
|
+
break;
|
|
427
|
+
case "setPlotHandler": {
|
|
428
|
+
if (msg.data) {
|
|
429
|
+
this.fPlotHandler = (output, index, events) => {
|
|
430
|
+
if (events)
|
|
431
|
+
this.fCachedEvents.push(...events);
|
|
432
|
+
};
|
|
433
|
+
} else {
|
|
434
|
+
this.fPlotHandler = null;
|
|
435
|
+
}
|
|
436
|
+
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
case "setupWamEventHandler": {
|
|
440
|
+
this.setupWamEventHandler();
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
443
|
+
case "start": {
|
|
444
|
+
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
case "stop": {
|
|
448
|
+
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
449
|
+
break;
|
|
450
|
+
}
|
|
451
|
+
case "destroy": {
|
|
452
|
+
this.port.close();
|
|
453
|
+
this.destroy();
|
|
454
|
+
break;
|
|
455
|
+
}
|
|
456
|
+
default:
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
461
|
+
this.port.start();
|
|
462
|
+
this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
397
463
|
const { parameterDescriptors } = this.constructor;
|
|
398
464
|
parameterDescriptors.forEach((pd) => {
|
|
399
465
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -549,6 +615,21 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
549
615
|
this.paramValuesCache[path] = paramValue;
|
|
550
616
|
}
|
|
551
617
|
}
|
|
618
|
+
if (this.communicator.getNewAccDataAvailable()) {
|
|
619
|
+
const acc = this.communicator.getAcc();
|
|
620
|
+
if (acc) {
|
|
621
|
+
this.communicator.setNewAccDataAvailable(false);
|
|
622
|
+
const { invert, ...data } = acc;
|
|
623
|
+
this.propagateAcc(data, invert);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
if (this.communicator.getNewGyrDataAvailable()) {
|
|
627
|
+
const gyr = this.communicator.getGyr();
|
|
628
|
+
if (gyr) {
|
|
629
|
+
this.communicator.setNewGyrDataAvailable(false);
|
|
630
|
+
this.propagateGyr(gyr);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
552
633
|
if (input == null ? void 0 : input.length) {
|
|
553
634
|
let $inputWrite = 0;
|
|
554
635
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -578,55 +659,6 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
578
659
|
}
|
|
579
660
|
return true;
|
|
580
661
|
}
|
|
581
|
-
handleMessageAux(e) {
|
|
582
|
-
var _a, _b, _c;
|
|
583
|
-
const msg = e.data;
|
|
584
|
-
switch (msg.type) {
|
|
585
|
-
case "midi":
|
|
586
|
-
this.midiMessage(msg.data);
|
|
587
|
-
break;
|
|
588
|
-
case "ctrlChange":
|
|
589
|
-
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
590
|
-
break;
|
|
591
|
-
case "pitchWheel":
|
|
592
|
-
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
593
|
-
break;
|
|
594
|
-
case "param":
|
|
595
|
-
this.setParamValue(msg.data.path, msg.data.value);
|
|
596
|
-
break;
|
|
597
|
-
case "setPlotHandler": {
|
|
598
|
-
if (msg.data) {
|
|
599
|
-
this.fPlotHandler = (output, index, events) => {
|
|
600
|
-
if (events)
|
|
601
|
-
this.fCachedEvents.push(...events);
|
|
602
|
-
};
|
|
603
|
-
} else {
|
|
604
|
-
this.fPlotHandler = null;
|
|
605
|
-
}
|
|
606
|
-
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
607
|
-
break;
|
|
608
|
-
}
|
|
609
|
-
case "setupWamEventHandler": {
|
|
610
|
-
this.setupWamEventHandler();
|
|
611
|
-
break;
|
|
612
|
-
}
|
|
613
|
-
case "start": {
|
|
614
|
-
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
615
|
-
break;
|
|
616
|
-
}
|
|
617
|
-
case "stop": {
|
|
618
|
-
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
619
|
-
break;
|
|
620
|
-
}
|
|
621
|
-
case "destroy": {
|
|
622
|
-
this.port.close();
|
|
623
|
-
this.destroy();
|
|
624
|
-
break;
|
|
625
|
-
}
|
|
626
|
-
default:
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
662
|
setParamValue(path, value) {
|
|
631
663
|
var _a;
|
|
632
664
|
(_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(path, value);
|
|
@@ -644,6 +676,12 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
644
676
|
var _a;
|
|
645
677
|
(_a = this.fDSPCode) == null ? void 0 : _a.pitchWheel(channel, wheel);
|
|
646
678
|
}
|
|
679
|
+
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
680
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
681
|
+
}
|
|
682
|
+
propagateGyr(event) {
|
|
683
|
+
this.fDSPCode.propagateGyr(event);
|
|
684
|
+
}
|
|
647
685
|
resetFFT(sizeIn, overlapIn, windowFunctionIn, inputChannels, outputChannels, bufferSize) {
|
|
648
686
|
var _a, _b;
|
|
649
687
|
const fftSize = ~~ceil(Math.max(2, sizeIn || 1024), 2);
|
|
@@ -2414,6 +2452,12 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
|
|
|
2414
2452
|
hasSoundfiles() {
|
|
2415
2453
|
return this.fSoundfiles.length > 0;
|
|
2416
2454
|
}
|
|
2455
|
+
startSensors() {
|
|
2456
|
+
this.startSensors();
|
|
2457
|
+
}
|
|
2458
|
+
stopSensors() {
|
|
2459
|
+
this.stopSensors();
|
|
2460
|
+
}
|
|
2417
2461
|
start() {
|
|
2418
2462
|
this.fProcessing = true;
|
|
2419
2463
|
}
|
|
@@ -3051,6 +3095,10 @@ var FaustOfflineProcessor = class {
|
|
|
3051
3095
|
propagateGyr(event) {
|
|
3052
3096
|
this.fDSPCode.propagateGyr(event);
|
|
3053
3097
|
}
|
|
3098
|
+
startSensors() {
|
|
3099
|
+
}
|
|
3100
|
+
stopSensors() {
|
|
3101
|
+
}
|
|
3054
3102
|
/**
|
|
3055
3103
|
* Render frames in an array.
|
|
3056
3104
|
*
|
|
@@ -3679,6 +3727,130 @@ var SoundfileReader = class {
|
|
|
3679
3727
|
};
|
|
3680
3728
|
var SoundfileReader_default = SoundfileReader;
|
|
3681
3729
|
|
|
3730
|
+
// src/FaustAudioWorkletCommunicator.ts
|
|
3731
|
+
var FaustAudioWorkletCommunicator = class {
|
|
3732
|
+
constructor(port) {
|
|
3733
|
+
this.port = port;
|
|
3734
|
+
this.supportSharedArrayBuffer = !!globalThis.SharedArrayBuffer;
|
|
3735
|
+
this.byteLength = 4 * Uint8Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
3736
|
+
}
|
|
3737
|
+
initializeBuffer(ab) {
|
|
3738
|
+
let ptr = 0;
|
|
3739
|
+
this.uin8Invert = new Uint8ClampedArray(ab, ptr, 1);
|
|
3740
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3741
|
+
this.uin8NewAccData = new Uint8ClampedArray(ab, ptr, 1);
|
|
3742
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3743
|
+
this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
|
|
3744
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3745
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
3746
|
+
;
|
|
3747
|
+
this.f32Acc = new Float32Array(ab, ptr, 3);
|
|
3748
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
3749
|
+
this.f32Gyr = new Float32Array(ab, ptr, 3);
|
|
3750
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
3751
|
+
}
|
|
3752
|
+
setNewAccDataAvailable(value) {
|
|
3753
|
+
if (!this.uin8NewAccData)
|
|
3754
|
+
return;
|
|
3755
|
+
this.uin8NewAccData[0] = +value;
|
|
3756
|
+
}
|
|
3757
|
+
getNewAccDataAvailable() {
|
|
3758
|
+
var _a;
|
|
3759
|
+
return !!((_a = this.uin8NewAccData) == null ? void 0 : _a[0]);
|
|
3760
|
+
}
|
|
3761
|
+
setNewGyrDataAvailable(value) {
|
|
3762
|
+
if (!this.uin8NewGyrData)
|
|
3763
|
+
return;
|
|
3764
|
+
this.uin8NewGyrData[0] = +value;
|
|
3765
|
+
}
|
|
3766
|
+
getNewGyrDataAvailable() {
|
|
3767
|
+
var _a;
|
|
3768
|
+
return !!((_a = this.uin8NewGyrData) == null ? void 0 : _a[0]);
|
|
3769
|
+
}
|
|
3770
|
+
setAcc({ x, y, z }, invert = false) {
|
|
3771
|
+
if (!this.supportSharedArrayBuffer) {
|
|
3772
|
+
const e = { type: "acc", data: { x, y, z }, invert };
|
|
3773
|
+
this.port.postMessage(e);
|
|
3774
|
+
}
|
|
3775
|
+
if (!this.uin8NewAccData)
|
|
3776
|
+
return;
|
|
3777
|
+
this.uin8Invert[0] = +invert;
|
|
3778
|
+
this.f32Acc[0] = x;
|
|
3779
|
+
this.f32Acc[1] = y;
|
|
3780
|
+
this.f32Acc[2] = z;
|
|
3781
|
+
this.uin8NewAccData[0] = 1;
|
|
3782
|
+
}
|
|
3783
|
+
getAcc() {
|
|
3784
|
+
if (!this.uin8NewAccData)
|
|
3785
|
+
return;
|
|
3786
|
+
const invert = !!this.uin8Invert[0];
|
|
3787
|
+
const [x, y, z] = this.f32Acc;
|
|
3788
|
+
return { x, y, z, invert };
|
|
3789
|
+
}
|
|
3790
|
+
setGyr({ alpha, beta, gamma }) {
|
|
3791
|
+
if (!this.supportSharedArrayBuffer) {
|
|
3792
|
+
const e = { type: "gyr", data: { alpha, beta, gamma } };
|
|
3793
|
+
this.port.postMessage(e);
|
|
3794
|
+
}
|
|
3795
|
+
if (!this.uin8NewGyrData)
|
|
3796
|
+
return;
|
|
3797
|
+
this.f32Gyr[0] = alpha;
|
|
3798
|
+
this.f32Gyr[1] = beta;
|
|
3799
|
+
this.f32Gyr[2] = gamma;
|
|
3800
|
+
this.uin8NewGyrData[0] = 1;
|
|
3801
|
+
}
|
|
3802
|
+
getGyr() {
|
|
3803
|
+
if (!this.uin8NewGyrData)
|
|
3804
|
+
return;
|
|
3805
|
+
const [alpha, beta, gamma] = this.f32Gyr;
|
|
3806
|
+
return { alpha, beta, gamma };
|
|
3807
|
+
}
|
|
3808
|
+
};
|
|
3809
|
+
var FaustAudioWorkletNodeCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
3810
|
+
constructor(port) {
|
|
3811
|
+
super(port);
|
|
3812
|
+
if (this.supportSharedArrayBuffer) {
|
|
3813
|
+
const sab = new SharedArrayBuffer(this.byteLength);
|
|
3814
|
+
this.initializeBuffer(sab);
|
|
3815
|
+
this.port.postMessage({ type: "initSab", sab });
|
|
3816
|
+
} else {
|
|
3817
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
3818
|
+
this.initializeBuffer(ab);
|
|
3819
|
+
}
|
|
3820
|
+
}
|
|
3821
|
+
};
|
|
3822
|
+
var FaustAudioWorkletProcessorCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
3823
|
+
constructor(port) {
|
|
3824
|
+
super(port);
|
|
3825
|
+
if (this.supportSharedArrayBuffer) {
|
|
3826
|
+
this.port.addEventListener("message", (event) => {
|
|
3827
|
+
const { data } = event;
|
|
3828
|
+
if (data.type === "initSab") {
|
|
3829
|
+
this.initializeBuffer(data.sab);
|
|
3830
|
+
}
|
|
3831
|
+
});
|
|
3832
|
+
} else {
|
|
3833
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
3834
|
+
this.initializeBuffer(ab);
|
|
3835
|
+
this.port.addEventListener("message", (event) => {
|
|
3836
|
+
const msg = event.data;
|
|
3837
|
+
switch (msg.type) {
|
|
3838
|
+
case "acc": {
|
|
3839
|
+
this.setAcc(msg.data, msg.invert);
|
|
3840
|
+
break;
|
|
3841
|
+
}
|
|
3842
|
+
case "gyr": {
|
|
3843
|
+
this.setGyr(msg.data);
|
|
3844
|
+
break;
|
|
3845
|
+
}
|
|
3846
|
+
default:
|
|
3847
|
+
break;
|
|
3848
|
+
}
|
|
3849
|
+
});
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
};
|
|
3853
|
+
|
|
3682
3854
|
// src/FaustAudioWorkletNode.ts
|
|
3683
3855
|
var _hasAccInput, _hasGyrInput;
|
|
3684
3856
|
var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
|
|
@@ -3696,7 +3868,13 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
3696
3868
|
});
|
|
3697
3869
|
__privateAdd(this, _hasAccInput, false);
|
|
3698
3870
|
__privateAdd(this, _hasGyrInput, false);
|
|
3699
|
-
|
|
3871
|
+
this.handleMessageAux = (e) => {
|
|
3872
|
+
if (e.data.type === "param" && this.fOutputHandler) {
|
|
3873
|
+
this.fOutputHandler(e.data.path, e.data.value);
|
|
3874
|
+
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
3875
|
+
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
3876
|
+
}
|
|
3877
|
+
};
|
|
3700
3878
|
// Accelerometer and gyroscope handlers
|
|
3701
3879
|
this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3702
3880
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
@@ -3731,54 +3909,23 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
3731
3909
|
}
|
|
3732
3910
|
};
|
|
3733
3911
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
3734
|
-
this.
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
3738
|
-
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
3739
|
-
}
|
|
3740
|
-
};
|
|
3912
|
+
this.fCommunicator = new FaustAudioWorkletNodeCommunicator(this.port);
|
|
3913
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
3914
|
+
this.port.start();
|
|
3741
3915
|
}
|
|
3916
|
+
// Public API
|
|
3742
3917
|
/** Setup accelerometer and gyroscope handlers */
|
|
3743
3918
|
async startSensors() {
|
|
3744
3919
|
if (this.hasAccInput) {
|
|
3745
3920
|
if (window.DeviceMotionEvent) {
|
|
3746
|
-
|
|
3747
|
-
try {
|
|
3748
|
-
const response = await window.DeviceMotionEvent.requestPermission();
|
|
3749
|
-
if (response === "granted") {
|
|
3750
|
-
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
3751
|
-
} else if (response === "denied") {
|
|
3752
|
-
alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
|
|
3753
|
-
throw new Error("Unable to access the accelerometer.");
|
|
3754
|
-
}
|
|
3755
|
-
} catch (error) {
|
|
3756
|
-
console.error(error);
|
|
3757
|
-
}
|
|
3758
|
-
} else {
|
|
3759
|
-
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
3760
|
-
}
|
|
3921
|
+
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
3761
3922
|
} else {
|
|
3762
3923
|
console.log("Cannot set the accelerometer handler.");
|
|
3763
3924
|
}
|
|
3764
3925
|
}
|
|
3765
3926
|
if (this.hasGyrInput) {
|
|
3766
3927
|
if (window.DeviceMotionEvent) {
|
|
3767
|
-
|
|
3768
|
-
try {
|
|
3769
|
-
const response = await window.DeviceOrientationEvent.requestPermission();
|
|
3770
|
-
if (response === "granted") {
|
|
3771
|
-
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
3772
|
-
} else if (response === "denied") {
|
|
3773
|
-
alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
|
|
3774
|
-
throw new Error("Unable to access the gyroscope.");
|
|
3775
|
-
}
|
|
3776
|
-
} catch (error) {
|
|
3777
|
-
console.error(error);
|
|
3778
|
-
}
|
|
3779
|
-
} else {
|
|
3780
|
-
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
3781
|
-
}
|
|
3928
|
+
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
3782
3929
|
} else {
|
|
3783
3930
|
console.log("Cannot set the gyroscope handler.");
|
|
3784
3931
|
}
|
|
@@ -3859,8 +4006,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
3859
4006
|
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
3860
4007
|
if (!accelerationIncludingGravity)
|
|
3861
4008
|
return;
|
|
3862
|
-
const
|
|
3863
|
-
this.
|
|
4009
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
4010
|
+
this.fCommunicator.setAcc({ x, y, z }, invert);
|
|
3864
4011
|
}
|
|
3865
4012
|
get hasGyrInput() {
|
|
3866
4013
|
return __privateGet(this, _hasGyrInput);
|
|
@@ -3868,8 +4015,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
3868
4015
|
propagateGyr(event) {
|
|
3869
4016
|
if (!event)
|
|
3870
4017
|
return;
|
|
3871
|
-
const
|
|
3872
|
-
this.
|
|
4018
|
+
const { alpha, beta, gamma } = event;
|
|
4019
|
+
this.fCommunicator.setGyr({ alpha, beta, gamma });
|
|
3873
4020
|
}
|
|
3874
4021
|
setParamValue(path, value) {
|
|
3875
4022
|
const e = { type: "param", data: { path, value } };
|
|
@@ -4012,7 +4159,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
4012
4159
|
this.start();
|
|
4013
4160
|
}
|
|
4014
4161
|
// Public API
|
|
4015
|
-
/**
|
|
4162
|
+
/** Start accelerometer and gyroscope handlers */
|
|
4016
4163
|
async startSensors() {
|
|
4017
4164
|
if (this.hasAccInput) {
|
|
4018
4165
|
if (window.DeviceMotionEvent) {
|
|
@@ -4057,6 +4204,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
4057
4204
|
}
|
|
4058
4205
|
}
|
|
4059
4206
|
}
|
|
4207
|
+
/** Stop accelerometer and gyroscope handlers */
|
|
4060
4208
|
stopSensors() {
|
|
4061
4209
|
if (this.hasAccInput) {
|
|
4062
4210
|
window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
@@ -4230,11 +4378,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4230
4378
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4231
4379
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4232
4380
|
var FaustSensors = ${FaustSensors.name};
|
|
4381
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4382
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4383
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4384
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4233
4385
|
// Put them in dependencies
|
|
4234
4386
|
const dependencies = {
|
|
4235
4387
|
FaustBaseWebAudioDsp,
|
|
4236
4388
|
FaustMonoWebAudioDsp,
|
|
4237
|
-
FaustWasmInstantiator
|
|
4389
|
+
FaustWasmInstantiator,
|
|
4390
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4238
4391
|
};
|
|
4239
4392
|
// Generate the actual AudioWorkletProcessor code
|
|
4240
4393
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -4284,12 +4437,17 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4284
4437
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4285
4438
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4286
4439
|
var FaustSensors = ${FaustSensors.name};
|
|
4440
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4441
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4442
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4443
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4287
4444
|
var FFTUtils = ${fftUtils.toString()}
|
|
4288
4445
|
// Put them in dependencies
|
|
4289
4446
|
const dependencies = {
|
|
4290
4447
|
FaustBaseWebAudioDsp,
|
|
4291
4448
|
FaustMonoWebAudioDsp,
|
|
4292
4449
|
FaustWasmInstantiator,
|
|
4450
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
4293
4451
|
FFTUtils
|
|
4294
4452
|
};
|
|
4295
4453
|
// Generate the actual AudioWorkletProcessor code
|
|
@@ -4333,6 +4491,7 @@ const dependencies = {
|
|
|
4333
4491
|
FaustBaseWebAudioDsp,
|
|
4334
4492
|
FaustMonoWebAudioDsp,
|
|
4335
4493
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
4494
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
4336
4495
|
FaustPolyWebAudioDsp: void 0,
|
|
4337
4496
|
FaustWebAudioDspVoice: void 0
|
|
4338
4497
|
};
|
|
@@ -4513,11 +4672,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4513
4672
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4514
4673
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4515
4674
|
var FaustSensors = ${FaustSensors.name};
|
|
4675
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4676
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4677
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4678
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4516
4679
|
// Put them in dependencies
|
|
4517
4680
|
const dependencies = {
|
|
4518
4681
|
FaustBaseWebAudioDsp,
|
|
4519
4682
|
FaustPolyWebAudioDsp,
|
|
4520
|
-
FaustWasmInstantiator
|
|
4683
|
+
FaustWasmInstantiator,
|
|
4684
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4521
4685
|
};
|
|
4522
4686
|
// Generate the actual AudioWorkletProcessor code
|
|
4523
4687
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -4545,7 +4709,8 @@ const dependencies = {
|
|
|
4545
4709
|
FaustMonoWebAudioDsp: void 0,
|
|
4546
4710
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
4547
4711
|
FaustPolyWebAudioDsp,
|
|
4548
|
-
FaustWebAudioDspVoice
|
|
4712
|
+
FaustWebAudioDspVoice,
|
|
4713
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4549
4714
|
};
|
|
4550
4715
|
const faustData = {
|
|
4551
4716
|
processorName,
|