@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
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);
|
|
@@ -2444,6 +2482,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2444
2482
|
hasSoundfiles() {
|
|
2445
2483
|
return this.fSoundfiles.length > 0;
|
|
2446
2484
|
}
|
|
2485
|
+
startSensors() {
|
|
2486
|
+
this.startSensors();
|
|
2487
|
+
}
|
|
2488
|
+
stopSensors() {
|
|
2489
|
+
this.stopSensors();
|
|
2490
|
+
}
|
|
2447
2491
|
start() {
|
|
2448
2492
|
this.fProcessing = true;
|
|
2449
2493
|
}
|
|
@@ -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,54 +3939,23 @@ 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) {
|
|
3775
3950
|
if (window.DeviceMotionEvent) {
|
|
3776
|
-
|
|
3777
|
-
try {
|
|
3778
|
-
const response = await window.DeviceMotionEvent.requestPermission();
|
|
3779
|
-
if (response === "granted") {
|
|
3780
|
-
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
3781
|
-
} else if (response === "denied") {
|
|
3782
|
-
alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
|
|
3783
|
-
throw new Error("Unable to access the accelerometer.");
|
|
3784
|
-
}
|
|
3785
|
-
} catch (error) {
|
|
3786
|
-
console.error(error);
|
|
3787
|
-
}
|
|
3788
|
-
} else {
|
|
3789
|
-
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
3790
|
-
}
|
|
3951
|
+
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
3791
3952
|
} else {
|
|
3792
3953
|
console.log("Cannot set the accelerometer handler.");
|
|
3793
3954
|
}
|
|
3794
3955
|
}
|
|
3795
3956
|
if (this.hasGyrInput) {
|
|
3796
3957
|
if (window.DeviceMotionEvent) {
|
|
3797
|
-
|
|
3798
|
-
try {
|
|
3799
|
-
const response = await window.DeviceOrientationEvent.requestPermission();
|
|
3800
|
-
if (response === "granted") {
|
|
3801
|
-
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
3802
|
-
} else if (response === "denied") {
|
|
3803
|
-
alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
|
|
3804
|
-
throw new Error("Unable to access the gyroscope.");
|
|
3805
|
-
}
|
|
3806
|
-
} catch (error) {
|
|
3807
|
-
console.error(error);
|
|
3808
|
-
}
|
|
3809
|
-
} else {
|
|
3810
|
-
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
3811
|
-
}
|
|
3958
|
+
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
3812
3959
|
} else {
|
|
3813
3960
|
console.log("Cannot set the gyroscope handler.");
|
|
3814
3961
|
}
|
|
@@ -3889,8 +4036,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3889
4036
|
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
3890
4037
|
if (!accelerationIncludingGravity)
|
|
3891
4038
|
return;
|
|
3892
|
-
const
|
|
3893
|
-
this.
|
|
4039
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
4040
|
+
this.fCommunicator.setAcc({ x, y, z }, invert);
|
|
3894
4041
|
}
|
|
3895
4042
|
get hasGyrInput() {
|
|
3896
4043
|
return __privateGet(this, _hasGyrInput);
|
|
@@ -3898,8 +4045,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
3898
4045
|
propagateGyr(event) {
|
|
3899
4046
|
if (!event)
|
|
3900
4047
|
return;
|
|
3901
|
-
const
|
|
3902
|
-
this.
|
|
4048
|
+
const { alpha, beta, gamma } = event;
|
|
4049
|
+
this.fCommunicator.setGyr({ alpha, beta, gamma });
|
|
3903
4050
|
}
|
|
3904
4051
|
setParamValue(path, value) {
|
|
3905
4052
|
const e = { type: "param", data: { path, value } };
|
|
@@ -4042,7 +4189,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
4042
4189
|
this.start();
|
|
4043
4190
|
}
|
|
4044
4191
|
// Public API
|
|
4045
|
-
/**
|
|
4192
|
+
/** Start accelerometer and gyroscope handlers */
|
|
4046
4193
|
async startSensors() {
|
|
4047
4194
|
if (this.hasAccInput) {
|
|
4048
4195
|
if (window.DeviceMotionEvent) {
|
|
@@ -4087,6 +4234,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
4087
4234
|
}
|
|
4088
4235
|
}
|
|
4089
4236
|
}
|
|
4237
|
+
/** Stop accelerometer and gyroscope handlers */
|
|
4090
4238
|
stopSensors() {
|
|
4091
4239
|
if (this.hasAccInput) {
|
|
4092
4240
|
window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
@@ -4260,11 +4408,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4260
4408
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4261
4409
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4262
4410
|
var FaustSensors = ${FaustSensors.name};
|
|
4411
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4412
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4413
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4414
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4263
4415
|
// Put them in dependencies
|
|
4264
4416
|
const dependencies = {
|
|
4265
4417
|
FaustBaseWebAudioDsp,
|
|
4266
4418
|
FaustMonoWebAudioDsp,
|
|
4267
|
-
FaustWasmInstantiator
|
|
4419
|
+
FaustWasmInstantiator,
|
|
4420
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4268
4421
|
};
|
|
4269
4422
|
// Generate the actual AudioWorkletProcessor code
|
|
4270
4423
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -4314,12 +4467,17 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4314
4467
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4315
4468
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4316
4469
|
var FaustSensors = ${FaustSensors.name};
|
|
4470
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4471
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4472
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4473
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4317
4474
|
var FFTUtils = ${fftUtils.toString()}
|
|
4318
4475
|
// Put them in dependencies
|
|
4319
4476
|
const dependencies = {
|
|
4320
4477
|
FaustBaseWebAudioDsp,
|
|
4321
4478
|
FaustMonoWebAudioDsp,
|
|
4322
4479
|
FaustWasmInstantiator,
|
|
4480
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
4323
4481
|
FFTUtils
|
|
4324
4482
|
};
|
|
4325
4483
|
// Generate the actual AudioWorkletProcessor code
|
|
@@ -4363,6 +4521,7 @@ const dependencies = {
|
|
|
4363
4521
|
FaustBaseWebAudioDsp,
|
|
4364
4522
|
FaustMonoWebAudioDsp,
|
|
4365
4523
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
4524
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
4366
4525
|
FaustPolyWebAudioDsp: void 0,
|
|
4367
4526
|
FaustWebAudioDspVoice: void 0
|
|
4368
4527
|
};
|
|
@@ -4543,11 +4702,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
4543
4702
|
var WasmAllocator = ${WasmAllocator.name};
|
|
4544
4703
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
4545
4704
|
var FaustSensors = ${FaustSensors.name};
|
|
4705
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
4706
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
4707
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
4708
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
4546
4709
|
// Put them in dependencies
|
|
4547
4710
|
const dependencies = {
|
|
4548
4711
|
FaustBaseWebAudioDsp,
|
|
4549
4712
|
FaustPolyWebAudioDsp,
|
|
4550
|
-
FaustWasmInstantiator
|
|
4713
|
+
FaustWasmInstantiator,
|
|
4714
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4551
4715
|
};
|
|
4552
4716
|
// Generate the actual AudioWorkletProcessor code
|
|
4553
4717
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -4575,7 +4739,8 @@ const dependencies = {
|
|
|
4575
4739
|
FaustMonoWebAudioDsp: void 0,
|
|
4576
4740
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
4577
4741
|
FaustPolyWebAudioDsp,
|
|
4578
|
-
FaustWebAudioDspVoice
|
|
4742
|
+
FaustWebAudioDspVoice,
|
|
4743
|
+
FaustAudioWorkletProcessorCommunicator
|
|
4579
4744
|
};
|
|
4580
4745
|
const faustData = {
|
|
4581
4746
|
processorName,
|