@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/esm-bundle/index.js
CHANGED
|
@@ -6083,7 +6083,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6083
6083
|
const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
|
|
6084
6084
|
const {
|
|
6085
6085
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
6086
|
-
FaustWasmInstantiator: FaustWasmInstantiator2
|
|
6086
|
+
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
6087
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
|
|
6087
6088
|
} = dependencies;
|
|
6088
6089
|
const {
|
|
6089
6090
|
processorName,
|
|
@@ -6108,7 +6109,7 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6108
6109
|
constructor(options) {
|
|
6109
6110
|
super(options);
|
|
6110
6111
|
this.paramValuesCache = {};
|
|
6111
|
-
this.
|
|
6112
|
+
this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
6112
6113
|
const { parameterDescriptors } = this.constructor;
|
|
6113
6114
|
parameterDescriptors.forEach((pd) => {
|
|
6114
6115
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -6155,19 +6156,26 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6155
6156
|
this.paramValuesCache[path] = paramValue;
|
|
6156
6157
|
}
|
|
6157
6158
|
}
|
|
6159
|
+
if (this.fCommunicator.getNewAccDataAvailable()) {
|
|
6160
|
+
const acc = this.fCommunicator.getAcc();
|
|
6161
|
+
if (acc) {
|
|
6162
|
+
this.fCommunicator.setNewAccDataAvailable(false);
|
|
6163
|
+
const { invert, ...data } = acc;
|
|
6164
|
+
this.propagateAcc(data, invert);
|
|
6165
|
+
}
|
|
6166
|
+
}
|
|
6167
|
+
if (this.fCommunicator.getNewGyrDataAvailable()) {
|
|
6168
|
+
const gyr = this.fCommunicator.getGyr();
|
|
6169
|
+
if (gyr) {
|
|
6170
|
+
this.fCommunicator.setNewGyrDataAvailable(false);
|
|
6171
|
+
this.propagateGyr(gyr);
|
|
6172
|
+
}
|
|
6173
|
+
}
|
|
6158
6174
|
return this.fDSPCode.compute(inputs[0], outputs[0]);
|
|
6159
6175
|
}
|
|
6160
6176
|
handleMessageAux(e) {
|
|
6161
6177
|
const msg = e.data;
|
|
6162
6178
|
switch (msg.type) {
|
|
6163
|
-
case "acc": {
|
|
6164
|
-
this.propagateAcc(msg.data, msg.invert);
|
|
6165
|
-
break;
|
|
6166
|
-
}
|
|
6167
|
-
case "gyr": {
|
|
6168
|
-
this.propagateGyr(msg.data);
|
|
6169
|
-
break;
|
|
6170
|
-
}
|
|
6171
6179
|
case "midi": {
|
|
6172
6180
|
this.midiMessage(msg.data);
|
|
6173
6181
|
break;
|
|
@@ -6236,10 +6244,15 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6236
6244
|
class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
|
|
6237
6245
|
constructor(options) {
|
|
6238
6246
|
super(options);
|
|
6247
|
+
this.handleMessageAux = (e) => {
|
|
6248
|
+
super.handleMessageAux(e);
|
|
6249
|
+
};
|
|
6239
6250
|
const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
|
|
6240
6251
|
const { factory, sampleSize } = options.processorOptions;
|
|
6241
6252
|
const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
|
|
6242
6253
|
this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
|
|
6254
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6255
|
+
this.port.start();
|
|
6243
6256
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
6244
6257
|
this.fDSPCode.start();
|
|
6245
6258
|
}
|
|
@@ -6266,7 +6279,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
|
|
|
6266
6279
|
const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
|
|
6267
6280
|
const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
|
|
6268
6281
|
this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
|
|
6269
|
-
this.port.
|
|
6282
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6283
|
+
this.port.start();
|
|
6270
6284
|
this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
|
|
6271
6285
|
this.fDSPCode.start();
|
|
6272
6286
|
}
|
|
@@ -6312,6 +6326,7 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6312
6326
|
FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
|
|
6313
6327
|
FaustWasmInstantiator: FaustWasmInstantiator2,
|
|
6314
6328
|
FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2,
|
|
6329
|
+
FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
|
|
6315
6330
|
FFTUtils
|
|
6316
6331
|
} = dependencies;
|
|
6317
6332
|
const {
|
|
@@ -6395,7 +6410,58 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6395
6410
|
this.fBufferNum = 0;
|
|
6396
6411
|
this.soundfiles = {};
|
|
6397
6412
|
this.windowFunction = null;
|
|
6398
|
-
this.
|
|
6413
|
+
this.handleMessageAux = (e) => {
|
|
6414
|
+
var _a, _b, _c;
|
|
6415
|
+
const msg = e.data;
|
|
6416
|
+
switch (msg.type) {
|
|
6417
|
+
case "midi":
|
|
6418
|
+
this.midiMessage(msg.data);
|
|
6419
|
+
break;
|
|
6420
|
+
case "ctrlChange":
|
|
6421
|
+
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
6422
|
+
break;
|
|
6423
|
+
case "pitchWheel":
|
|
6424
|
+
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
6425
|
+
break;
|
|
6426
|
+
case "param":
|
|
6427
|
+
this.setParamValue(msg.data.path, msg.data.value);
|
|
6428
|
+
break;
|
|
6429
|
+
case "setPlotHandler": {
|
|
6430
|
+
if (msg.data) {
|
|
6431
|
+
this.fPlotHandler = (output, index, events) => {
|
|
6432
|
+
if (events)
|
|
6433
|
+
this.fCachedEvents.push(...events);
|
|
6434
|
+
};
|
|
6435
|
+
} else {
|
|
6436
|
+
this.fPlotHandler = null;
|
|
6437
|
+
}
|
|
6438
|
+
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
6439
|
+
break;
|
|
6440
|
+
}
|
|
6441
|
+
case "setupWamEventHandler": {
|
|
6442
|
+
this.setupWamEventHandler();
|
|
6443
|
+
break;
|
|
6444
|
+
}
|
|
6445
|
+
case "start": {
|
|
6446
|
+
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
6447
|
+
break;
|
|
6448
|
+
}
|
|
6449
|
+
case "stop": {
|
|
6450
|
+
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
6451
|
+
break;
|
|
6452
|
+
}
|
|
6453
|
+
case "destroy": {
|
|
6454
|
+
this.port.close();
|
|
6455
|
+
this.destroy();
|
|
6456
|
+
break;
|
|
6457
|
+
}
|
|
6458
|
+
default:
|
|
6459
|
+
break;
|
|
6460
|
+
}
|
|
6461
|
+
};
|
|
6462
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
6463
|
+
this.port.start();
|
|
6464
|
+
this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
|
|
6399
6465
|
const { parameterDescriptors } = this.constructor;
|
|
6400
6466
|
parameterDescriptors.forEach((pd) => {
|
|
6401
6467
|
this.paramValuesCache[pd.name] = pd.defaultValue || 0;
|
|
@@ -6551,6 +6617,21 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6551
6617
|
this.paramValuesCache[path] = paramValue;
|
|
6552
6618
|
}
|
|
6553
6619
|
}
|
|
6620
|
+
if (this.communicator.getNewAccDataAvailable()) {
|
|
6621
|
+
const acc = this.communicator.getAcc();
|
|
6622
|
+
if (acc) {
|
|
6623
|
+
this.communicator.setNewAccDataAvailable(false);
|
|
6624
|
+
const { invert, ...data } = acc;
|
|
6625
|
+
this.propagateAcc(data, invert);
|
|
6626
|
+
}
|
|
6627
|
+
}
|
|
6628
|
+
if (this.communicator.getNewGyrDataAvailable()) {
|
|
6629
|
+
const gyr = this.communicator.getGyr();
|
|
6630
|
+
if (gyr) {
|
|
6631
|
+
this.communicator.setNewGyrDataAvailable(false);
|
|
6632
|
+
this.propagateGyr(gyr);
|
|
6633
|
+
}
|
|
6634
|
+
}
|
|
6554
6635
|
if (input == null ? void 0 : input.length) {
|
|
6555
6636
|
let $inputWrite = 0;
|
|
6556
6637
|
for (let i = 0; i < input.length; i++) {
|
|
@@ -6580,55 +6661,6 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6580
6661
|
}
|
|
6581
6662
|
return true;
|
|
6582
6663
|
}
|
|
6583
|
-
handleMessageAux(e) {
|
|
6584
|
-
var _a, _b, _c;
|
|
6585
|
-
const msg = e.data;
|
|
6586
|
-
switch (msg.type) {
|
|
6587
|
-
case "midi":
|
|
6588
|
-
this.midiMessage(msg.data);
|
|
6589
|
-
break;
|
|
6590
|
-
case "ctrlChange":
|
|
6591
|
-
this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
|
|
6592
|
-
break;
|
|
6593
|
-
case "pitchWheel":
|
|
6594
|
-
this.pitchWheel(msg.data[0], msg.data[1]);
|
|
6595
|
-
break;
|
|
6596
|
-
case "param":
|
|
6597
|
-
this.setParamValue(msg.data.path, msg.data.value);
|
|
6598
|
-
break;
|
|
6599
|
-
case "setPlotHandler": {
|
|
6600
|
-
if (msg.data) {
|
|
6601
|
-
this.fPlotHandler = (output, index, events) => {
|
|
6602
|
-
if (events)
|
|
6603
|
-
this.fCachedEvents.push(...events);
|
|
6604
|
-
};
|
|
6605
|
-
} else {
|
|
6606
|
-
this.fPlotHandler = null;
|
|
6607
|
-
}
|
|
6608
|
-
(_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
|
|
6609
|
-
break;
|
|
6610
|
-
}
|
|
6611
|
-
case "setupWamEventHandler": {
|
|
6612
|
-
this.setupWamEventHandler();
|
|
6613
|
-
break;
|
|
6614
|
-
}
|
|
6615
|
-
case "start": {
|
|
6616
|
-
(_b = this.fDSPCode) == null ? void 0 : _b.start();
|
|
6617
|
-
break;
|
|
6618
|
-
}
|
|
6619
|
-
case "stop": {
|
|
6620
|
-
(_c = this.fDSPCode) == null ? void 0 : _c.stop();
|
|
6621
|
-
break;
|
|
6622
|
-
}
|
|
6623
|
-
case "destroy": {
|
|
6624
|
-
this.port.close();
|
|
6625
|
-
this.destroy();
|
|
6626
|
-
break;
|
|
6627
|
-
}
|
|
6628
|
-
default:
|
|
6629
|
-
break;
|
|
6630
|
-
}
|
|
6631
|
-
}
|
|
6632
6664
|
setParamValue(path, value) {
|
|
6633
6665
|
var _a;
|
|
6634
6666
|
(_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(path, value);
|
|
@@ -6646,6 +6678,12 @@ var getFaustFFTAudioWorkletProcessor = (dependencies, faustData, register = true
|
|
|
6646
6678
|
var _a;
|
|
6647
6679
|
(_a = this.fDSPCode) == null ? void 0 : _a.pitchWheel(channel, wheel);
|
|
6648
6680
|
}
|
|
6681
|
+
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
6682
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
6683
|
+
}
|
|
6684
|
+
propagateGyr(event) {
|
|
6685
|
+
this.fDSPCode.propagateGyr(event);
|
|
6686
|
+
}
|
|
6649
6687
|
resetFFT(sizeIn, overlapIn, windowFunctionIn, inputChannels, outputChannels, bufferSize) {
|
|
6650
6688
|
var _a, _b;
|
|
6651
6689
|
const fftSize = ~~ceil(Math.max(2, sizeIn || 1024), 2);
|
|
@@ -8416,6 +8454,12 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
|
|
|
8416
8454
|
hasSoundfiles() {
|
|
8417
8455
|
return this.fSoundfiles.length > 0;
|
|
8418
8456
|
}
|
|
8457
|
+
startSensors() {
|
|
8458
|
+
this.startSensors();
|
|
8459
|
+
}
|
|
8460
|
+
stopSensors() {
|
|
8461
|
+
this.stopSensors();
|
|
8462
|
+
}
|
|
8419
8463
|
start() {
|
|
8420
8464
|
this.fProcessing = true;
|
|
8421
8465
|
}
|
|
@@ -9053,6 +9097,10 @@ var FaustOfflineProcessor = class {
|
|
|
9053
9097
|
propagateGyr(event) {
|
|
9054
9098
|
this.fDSPCode.propagateGyr(event);
|
|
9055
9099
|
}
|
|
9100
|
+
startSensors() {
|
|
9101
|
+
}
|
|
9102
|
+
stopSensors() {
|
|
9103
|
+
}
|
|
9056
9104
|
/**
|
|
9057
9105
|
* Render frames in an array.
|
|
9058
9106
|
*
|
|
@@ -9681,6 +9729,130 @@ var SoundfileReader = class {
|
|
|
9681
9729
|
};
|
|
9682
9730
|
var SoundfileReader_default = SoundfileReader;
|
|
9683
9731
|
|
|
9732
|
+
// src/FaustAudioWorkletCommunicator.ts
|
|
9733
|
+
var FaustAudioWorkletCommunicator = class {
|
|
9734
|
+
constructor(port) {
|
|
9735
|
+
this.port = port;
|
|
9736
|
+
this.supportSharedArrayBuffer = !!globalThis.SharedArrayBuffer;
|
|
9737
|
+
this.byteLength = 4 * Uint8Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9738
|
+
}
|
|
9739
|
+
initializeBuffer(ab) {
|
|
9740
|
+
let ptr = 0;
|
|
9741
|
+
this.uin8Invert = new Uint8ClampedArray(ab, ptr, 1);
|
|
9742
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9743
|
+
this.uin8NewAccData = new Uint8ClampedArray(ab, ptr, 1);
|
|
9744
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9745
|
+
this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
|
|
9746
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9747
|
+
ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
|
|
9748
|
+
;
|
|
9749
|
+
this.f32Acc = new Float32Array(ab, ptr, 3);
|
|
9750
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9751
|
+
this.f32Gyr = new Float32Array(ab, ptr, 3);
|
|
9752
|
+
ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
|
|
9753
|
+
}
|
|
9754
|
+
setNewAccDataAvailable(value) {
|
|
9755
|
+
if (!this.uin8NewAccData)
|
|
9756
|
+
return;
|
|
9757
|
+
this.uin8NewAccData[0] = +value;
|
|
9758
|
+
}
|
|
9759
|
+
getNewAccDataAvailable() {
|
|
9760
|
+
var _a;
|
|
9761
|
+
return !!((_a = this.uin8NewAccData) == null ? void 0 : _a[0]);
|
|
9762
|
+
}
|
|
9763
|
+
setNewGyrDataAvailable(value) {
|
|
9764
|
+
if (!this.uin8NewGyrData)
|
|
9765
|
+
return;
|
|
9766
|
+
this.uin8NewGyrData[0] = +value;
|
|
9767
|
+
}
|
|
9768
|
+
getNewGyrDataAvailable() {
|
|
9769
|
+
var _a;
|
|
9770
|
+
return !!((_a = this.uin8NewGyrData) == null ? void 0 : _a[0]);
|
|
9771
|
+
}
|
|
9772
|
+
setAcc({ x, y, z }, invert = false) {
|
|
9773
|
+
if (!this.supportSharedArrayBuffer) {
|
|
9774
|
+
const e = { type: "acc", data: { x, y, z }, invert };
|
|
9775
|
+
this.port.postMessage(e);
|
|
9776
|
+
}
|
|
9777
|
+
if (!this.uin8NewAccData)
|
|
9778
|
+
return;
|
|
9779
|
+
this.uin8Invert[0] = +invert;
|
|
9780
|
+
this.f32Acc[0] = x;
|
|
9781
|
+
this.f32Acc[1] = y;
|
|
9782
|
+
this.f32Acc[2] = z;
|
|
9783
|
+
this.uin8NewAccData[0] = 1;
|
|
9784
|
+
}
|
|
9785
|
+
getAcc() {
|
|
9786
|
+
if (!this.uin8NewAccData)
|
|
9787
|
+
return;
|
|
9788
|
+
const invert = !!this.uin8Invert[0];
|
|
9789
|
+
const [x, y, z] = this.f32Acc;
|
|
9790
|
+
return { x, y, z, invert };
|
|
9791
|
+
}
|
|
9792
|
+
setGyr({ alpha, beta, gamma }) {
|
|
9793
|
+
if (!this.supportSharedArrayBuffer) {
|
|
9794
|
+
const e = { type: "gyr", data: { alpha, beta, gamma } };
|
|
9795
|
+
this.port.postMessage(e);
|
|
9796
|
+
}
|
|
9797
|
+
if (!this.uin8NewGyrData)
|
|
9798
|
+
return;
|
|
9799
|
+
this.f32Gyr[0] = alpha;
|
|
9800
|
+
this.f32Gyr[1] = beta;
|
|
9801
|
+
this.f32Gyr[2] = gamma;
|
|
9802
|
+
this.uin8NewGyrData[0] = 1;
|
|
9803
|
+
}
|
|
9804
|
+
getGyr() {
|
|
9805
|
+
if (!this.uin8NewGyrData)
|
|
9806
|
+
return;
|
|
9807
|
+
const [alpha, beta, gamma] = this.f32Gyr;
|
|
9808
|
+
return { alpha, beta, gamma };
|
|
9809
|
+
}
|
|
9810
|
+
};
|
|
9811
|
+
var FaustAudioWorkletNodeCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
9812
|
+
constructor(port) {
|
|
9813
|
+
super(port);
|
|
9814
|
+
if (this.supportSharedArrayBuffer) {
|
|
9815
|
+
const sab = new SharedArrayBuffer(this.byteLength);
|
|
9816
|
+
this.initializeBuffer(sab);
|
|
9817
|
+
this.port.postMessage({ type: "initSab", sab });
|
|
9818
|
+
} else {
|
|
9819
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
9820
|
+
this.initializeBuffer(ab);
|
|
9821
|
+
}
|
|
9822
|
+
}
|
|
9823
|
+
};
|
|
9824
|
+
var FaustAudioWorkletProcessorCommunicator = class extends FaustAudioWorkletCommunicator {
|
|
9825
|
+
constructor(port) {
|
|
9826
|
+
super(port);
|
|
9827
|
+
if (this.supportSharedArrayBuffer) {
|
|
9828
|
+
this.port.addEventListener("message", (event) => {
|
|
9829
|
+
const { data } = event;
|
|
9830
|
+
if (data.type === "initSab") {
|
|
9831
|
+
this.initializeBuffer(data.sab);
|
|
9832
|
+
}
|
|
9833
|
+
});
|
|
9834
|
+
} else {
|
|
9835
|
+
const ab = new ArrayBuffer(this.byteLength);
|
|
9836
|
+
this.initializeBuffer(ab);
|
|
9837
|
+
this.port.addEventListener("message", (event) => {
|
|
9838
|
+
const msg = event.data;
|
|
9839
|
+
switch (msg.type) {
|
|
9840
|
+
case "acc": {
|
|
9841
|
+
this.setAcc(msg.data, msg.invert);
|
|
9842
|
+
break;
|
|
9843
|
+
}
|
|
9844
|
+
case "gyr": {
|
|
9845
|
+
this.setGyr(msg.data);
|
|
9846
|
+
break;
|
|
9847
|
+
}
|
|
9848
|
+
default:
|
|
9849
|
+
break;
|
|
9850
|
+
}
|
|
9851
|
+
});
|
|
9852
|
+
}
|
|
9853
|
+
}
|
|
9854
|
+
};
|
|
9855
|
+
|
|
9684
9856
|
// src/FaustAudioWorkletNode.ts
|
|
9685
9857
|
var _hasAccInput, _hasGyrInput;
|
|
9686
9858
|
var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
|
|
@@ -9698,7 +9870,13 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9698
9870
|
});
|
|
9699
9871
|
__privateAdd(this, _hasAccInput, false);
|
|
9700
9872
|
__privateAdd(this, _hasGyrInput, false);
|
|
9701
|
-
|
|
9873
|
+
this.handleMessageAux = (e) => {
|
|
9874
|
+
if (e.data.type === "param" && this.fOutputHandler) {
|
|
9875
|
+
this.fOutputHandler(e.data.path, e.data.value);
|
|
9876
|
+
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
9877
|
+
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
9878
|
+
}
|
|
9879
|
+
};
|
|
9702
9880
|
// Accelerometer and gyroscope handlers
|
|
9703
9881
|
this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
9704
9882
|
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
@@ -9733,54 +9911,23 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9733
9911
|
}
|
|
9734
9912
|
};
|
|
9735
9913
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
9736
|
-
this.
|
|
9737
|
-
|
|
9738
|
-
|
|
9739
|
-
} else if (e.data.type === "plot" && this.fPlotHandler) {
|
|
9740
|
-
this.fPlotHandler(e.data.value, e.data.index, e.data.events);
|
|
9741
|
-
}
|
|
9742
|
-
};
|
|
9914
|
+
this.fCommunicator = new FaustAudioWorkletNodeCommunicator(this.port);
|
|
9915
|
+
this.port.addEventListener("message", this.handleMessageAux);
|
|
9916
|
+
this.port.start();
|
|
9743
9917
|
}
|
|
9918
|
+
// Public API
|
|
9744
9919
|
/** Setup accelerometer and gyroscope handlers */
|
|
9745
9920
|
async startSensors() {
|
|
9746
9921
|
if (this.hasAccInput) {
|
|
9747
9922
|
if (window.DeviceMotionEvent) {
|
|
9748
|
-
|
|
9749
|
-
try {
|
|
9750
|
-
const response = await window.DeviceMotionEvent.requestPermission();
|
|
9751
|
-
if (response === "granted") {
|
|
9752
|
-
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
9753
|
-
} else if (response === "denied") {
|
|
9754
|
-
alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
|
|
9755
|
-
throw new Error("Unable to access the accelerometer.");
|
|
9756
|
-
}
|
|
9757
|
-
} catch (error) {
|
|
9758
|
-
console.error(error);
|
|
9759
|
-
}
|
|
9760
|
-
} else {
|
|
9761
|
-
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
9762
|
-
}
|
|
9923
|
+
window.addEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
9763
9924
|
} else {
|
|
9764
9925
|
console.log("Cannot set the accelerometer handler.");
|
|
9765
9926
|
}
|
|
9766
9927
|
}
|
|
9767
9928
|
if (this.hasGyrInput) {
|
|
9768
9929
|
if (window.DeviceMotionEvent) {
|
|
9769
|
-
|
|
9770
|
-
try {
|
|
9771
|
-
const response = await window.DeviceOrientationEvent.requestPermission();
|
|
9772
|
-
if (response === "granted") {
|
|
9773
|
-
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
9774
|
-
} else if (response === "denied") {
|
|
9775
|
-
alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
|
|
9776
|
-
throw new Error("Unable to access the gyroscope.");
|
|
9777
|
-
}
|
|
9778
|
-
} catch (error) {
|
|
9779
|
-
console.error(error);
|
|
9780
|
-
}
|
|
9781
|
-
} else {
|
|
9782
|
-
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
9783
|
-
}
|
|
9930
|
+
window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
|
|
9784
9931
|
} else {
|
|
9785
9932
|
console.log("Cannot set the gyroscope handler.");
|
|
9786
9933
|
}
|
|
@@ -9861,8 +10008,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9861
10008
|
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
9862
10009
|
if (!accelerationIncludingGravity)
|
|
9863
10010
|
return;
|
|
9864
|
-
const
|
|
9865
|
-
this.
|
|
10011
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
10012
|
+
this.fCommunicator.setAcc({ x, y, z }, invert);
|
|
9866
10013
|
}
|
|
9867
10014
|
get hasGyrInput() {
|
|
9868
10015
|
return __privateGet(this, _hasGyrInput);
|
|
@@ -9870,8 +10017,8 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
9870
10017
|
propagateGyr(event) {
|
|
9871
10018
|
if (!event)
|
|
9872
10019
|
return;
|
|
9873
|
-
const
|
|
9874
|
-
this.
|
|
10020
|
+
const { alpha, beta, gamma } = event;
|
|
10021
|
+
this.fCommunicator.setGyr({ alpha, beta, gamma });
|
|
9875
10022
|
}
|
|
9876
10023
|
setParamValue(path, value) {
|
|
9877
10024
|
const e = { type: "param", data: { path, value } };
|
|
@@ -10014,7 +10161,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
10014
10161
|
this.start();
|
|
10015
10162
|
}
|
|
10016
10163
|
// Public API
|
|
10017
|
-
/**
|
|
10164
|
+
/** Start accelerometer and gyroscope handlers */
|
|
10018
10165
|
async startSensors() {
|
|
10019
10166
|
if (this.hasAccInput) {
|
|
10020
10167
|
if (window.DeviceMotionEvent) {
|
|
@@ -10059,6 +10206,7 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
10059
10206
|
}
|
|
10060
10207
|
}
|
|
10061
10208
|
}
|
|
10209
|
+
/** Stop accelerometer and gyroscope handlers */
|
|
10062
10210
|
stopSensors() {
|
|
10063
10211
|
if (this.hasAccInput) {
|
|
10064
10212
|
window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
|
|
@@ -10232,11 +10380,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10232
10380
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10233
10381
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10234
10382
|
var FaustSensors = ${FaustSensors.name};
|
|
10383
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10384
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10385
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10386
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10235
10387
|
// Put them in dependencies
|
|
10236
10388
|
const dependencies = {
|
|
10237
10389
|
FaustBaseWebAudioDsp,
|
|
10238
10390
|
FaustMonoWebAudioDsp,
|
|
10239
|
-
FaustWasmInstantiator
|
|
10391
|
+
FaustWasmInstantiator,
|
|
10392
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10240
10393
|
};
|
|
10241
10394
|
// Generate the actual AudioWorkletProcessor code
|
|
10242
10395
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -10286,12 +10439,17 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10286
10439
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10287
10440
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10288
10441
|
var FaustSensors = ${FaustSensors.name};
|
|
10442
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10443
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10444
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10445
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10289
10446
|
var FFTUtils = ${fftUtils.toString()}
|
|
10290
10447
|
// Put them in dependencies
|
|
10291
10448
|
const dependencies = {
|
|
10292
10449
|
FaustBaseWebAudioDsp,
|
|
10293
10450
|
FaustMonoWebAudioDsp,
|
|
10294
10451
|
FaustWasmInstantiator,
|
|
10452
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
10295
10453
|
FFTUtils
|
|
10296
10454
|
};
|
|
10297
10455
|
// Generate the actual AudioWorkletProcessor code
|
|
@@ -10335,6 +10493,7 @@ const dependencies = {
|
|
|
10335
10493
|
FaustBaseWebAudioDsp,
|
|
10336
10494
|
FaustMonoWebAudioDsp,
|
|
10337
10495
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
10496
|
+
FaustAudioWorkletProcessorCommunicator,
|
|
10338
10497
|
FaustPolyWebAudioDsp: void 0,
|
|
10339
10498
|
FaustWebAudioDspVoice: void 0
|
|
10340
10499
|
};
|
|
@@ -10515,11 +10674,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
|
|
|
10515
10674
|
var WasmAllocator = ${WasmAllocator.name};
|
|
10516
10675
|
var ${FaustSensors.name} = ${FaustSensors.toString()}
|
|
10517
10676
|
var FaustSensors = ${FaustSensors.name};
|
|
10677
|
+
var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
|
|
10678
|
+
var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
|
|
10679
|
+
var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
|
|
10680
|
+
var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
|
|
10518
10681
|
// Put them in dependencies
|
|
10519
10682
|
const dependencies = {
|
|
10520
10683
|
FaustBaseWebAudioDsp,
|
|
10521
10684
|
FaustPolyWebAudioDsp,
|
|
10522
|
-
FaustWasmInstantiator
|
|
10685
|
+
FaustWasmInstantiator,
|
|
10686
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10523
10687
|
};
|
|
10524
10688
|
// Generate the actual AudioWorkletProcessor code
|
|
10525
10689
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -10547,7 +10711,8 @@ const dependencies = {
|
|
|
10547
10711
|
FaustMonoWebAudioDsp: void 0,
|
|
10548
10712
|
FaustWasmInstantiator: FaustWasmInstantiator_default,
|
|
10549
10713
|
FaustPolyWebAudioDsp,
|
|
10550
|
-
FaustWebAudioDspVoice
|
|
10714
|
+
FaustWebAudioDspVoice,
|
|
10715
|
+
FaustAudioWorkletProcessorCommunicator
|
|
10551
10716
|
};
|
|
10552
10717
|
const faustData = {
|
|
10553
10718
|
processorName,
|