@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.
Files changed (38) hide show
  1. package/README.md +2 -2
  2. package/assets/standalone/create-node.js +31 -1
  3. package/assets/standalone/faust-ui/index.js +2 -2
  4. package/assets/standalone/faust-ui/index.js.map +1 -1
  5. package/assets/standalone/faustwasm/index.d.ts +76 -9
  6. package/assets/standalone/faustwasm/index.js +272 -107
  7. package/assets/standalone/faustwasm/index.js.map +4 -4
  8. package/assets/standalone/index-pwa.js +132 -98
  9. package/assets/standalone/index-template.js +44 -23
  10. package/assets/standalone/index.js +95 -80
  11. package/assets/standalone/service-worker.js +47 -8
  12. package/dist/cjs/index.d.ts +76 -9
  13. package/dist/cjs/index.js +272 -107
  14. package/dist/cjs/index.js.map +4 -4
  15. package/dist/cjs-bundle/index.d.ts +76 -9
  16. package/dist/cjs-bundle/index.js +272 -107
  17. package/dist/cjs-bundle/index.js.map +4 -4
  18. package/dist/esm/index.d.ts +76 -9
  19. package/dist/esm/index.js +272 -107
  20. package/dist/esm/index.js.map +4 -4
  21. package/dist/esm-bundle/index.d.ts +76 -9
  22. package/dist/esm-bundle/index.js +272 -107
  23. package/dist/esm-bundle/index.js.map +4 -4
  24. package/package.json +2 -2
  25. package/src/FaustAudioWorkletCommunicator.ts +143 -0
  26. package/src/FaustAudioWorkletNode.ts +27 -42
  27. package/src/FaustAudioWorkletProcessor.ts +34 -15
  28. package/src/FaustDspGenerator.ts +20 -2
  29. package/src/FaustFFTAudioWorkletProcessor.ts +31 -2
  30. package/src/FaustOfflineProcessor.ts +6 -0
  31. package/src/FaustScriptProcessorNode.ts +8 -31
  32. package/src/FaustWebAudioDsp.ts +38 -10
  33. package/test/faustlive-wasm/faust-ui/index.js +2 -2
  34. package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
  35. package/test/faustlive-wasm/faustwasm/index.d.ts +76 -9
  36. package/test/faustlive-wasm/faustwasm/index.js +272 -107
  37. package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
  38. package/assets/standalone/coi-serviceworker.js +0 -146
@@ -6128,7 +6128,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6128
6128
  const { registerProcessor, AudioWorkletProcessor, sampleRate } = globalThis;
6129
6129
  const {
6130
6130
  FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
6131
- FaustWasmInstantiator: FaustWasmInstantiator2
6131
+ FaustWasmInstantiator: FaustWasmInstantiator2,
6132
+ FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2
6132
6133
  } = dependencies;
6133
6134
  const {
6134
6135
  processorName,
@@ -6153,7 +6154,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6153
6154
  constructor(options) {
6154
6155
  super(options);
6155
6156
  this.paramValuesCache = {};
6156
- this.port.onmessage = (e) => this.handleMessageAux(e);
6157
+ this.fCommunicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
6157
6158
  const { parameterDescriptors } = this.constructor;
6158
6159
  parameterDescriptors.forEach((pd) => {
6159
6160
  this.paramValuesCache[pd.name] = pd.defaultValue || 0;
@@ -6200,19 +6201,26 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6200
6201
  this.paramValuesCache[path] = paramValue;
6201
6202
  }
6202
6203
  }
6204
+ if (this.fCommunicator.getNewAccDataAvailable()) {
6205
+ const acc = this.fCommunicator.getAcc();
6206
+ if (acc) {
6207
+ this.fCommunicator.setNewAccDataAvailable(false);
6208
+ const { invert, ...data } = acc;
6209
+ this.propagateAcc(data, invert);
6210
+ }
6211
+ }
6212
+ if (this.fCommunicator.getNewGyrDataAvailable()) {
6213
+ const gyr = this.fCommunicator.getGyr();
6214
+ if (gyr) {
6215
+ this.fCommunicator.setNewGyrDataAvailable(false);
6216
+ this.propagateGyr(gyr);
6217
+ }
6218
+ }
6203
6219
  return this.fDSPCode.compute(inputs[0], outputs[0]);
6204
6220
  }
6205
6221
  handleMessageAux(e) {
6206
6222
  const msg = e.data;
6207
6223
  switch (msg.type) {
6208
- case "acc": {
6209
- this.propagateAcc(msg.data, msg.invert);
6210
- break;
6211
- }
6212
- case "gyr": {
6213
- this.propagateGyr(msg.data);
6214
- break;
6215
- }
6216
6224
  case "midi": {
6217
6225
  this.midiMessage(msg.data);
6218
6226
  break;
@@ -6281,10 +6289,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6281
6289
  class FaustMonoAudioWorkletProcessor extends FaustAudioWorkletProcessor {
6282
6290
  constructor(options) {
6283
6291
  super(options);
6292
+ this.handleMessageAux = (e) => {
6293
+ super.handleMessageAux(e);
6294
+ };
6284
6295
  const { FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2 } = dependencies;
6285
6296
  const { factory, sampleSize } = options.processorOptions;
6286
6297
  const instance = FaustWasmInstantiator2.createSyncMonoDSPInstance(factory);
6287
6298
  this.fDSPCode = new FaustMonoWebAudioDsp2(instance, sampleRate, sampleSize, 128, factory.soundfiles);
6299
+ this.port.addEventListener("message", this.handleMessageAux);
6300
+ this.port.start();
6288
6301
  this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
6289
6302
  this.fDSPCode.start();
6290
6303
  }
@@ -6311,7 +6324,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6311
6324
  const instance = FaustWasmInstantiator2.createSyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory);
6312
6325
  const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
6313
6326
  this.fDSPCode = new FaustPolyWebAudioDsp3(instance, sampleRate, sampleSize, 128, soundfiles);
6314
- this.port.onmessage = (e) => this.handleMessageAux(e);
6327
+ this.port.addEventListener("message", this.handleMessageAux);
6328
+ this.port.start();
6315
6329
  this.fDSPCode.setOutputParamHandler((path, value) => this.port.postMessage({ path, value, type: "param" }));
6316
6330
  this.fDSPCode.start();
6317
6331
  }
@@ -6357,6 +6371,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6357
6371
  FaustBaseWebAudioDsp: FaustBaseWebAudioDsp2,
6358
6372
  FaustWasmInstantiator: FaustWasmInstantiator2,
6359
6373
  FaustMonoWebAudioDsp: FaustMonoWebAudioDsp2,
6374
+ FaustAudioWorkletProcessorCommunicator: FaustAudioWorkletProcessorCommunicator2,
6360
6375
  FFTUtils
6361
6376
  } = dependencies;
6362
6377
  const {
@@ -6440,7 +6455,58 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6440
6455
  this.fBufferNum = 0;
6441
6456
  this.soundfiles = {};
6442
6457
  this.windowFunction = null;
6443
- this.port.onmessage = (e) => this.handleMessageAux(e);
6458
+ this.handleMessageAux = (e) => {
6459
+ var _a, _b, _c;
6460
+ const msg = e.data;
6461
+ switch (msg.type) {
6462
+ case "midi":
6463
+ this.midiMessage(msg.data);
6464
+ break;
6465
+ case "ctrlChange":
6466
+ this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
6467
+ break;
6468
+ case "pitchWheel":
6469
+ this.pitchWheel(msg.data[0], msg.data[1]);
6470
+ break;
6471
+ case "param":
6472
+ this.setParamValue(msg.data.path, msg.data.value);
6473
+ break;
6474
+ case "setPlotHandler": {
6475
+ if (msg.data) {
6476
+ this.fPlotHandler = (output, index, events) => {
6477
+ if (events)
6478
+ this.fCachedEvents.push(...events);
6479
+ };
6480
+ } else {
6481
+ this.fPlotHandler = null;
6482
+ }
6483
+ (_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
6484
+ break;
6485
+ }
6486
+ case "setupWamEventHandler": {
6487
+ this.setupWamEventHandler();
6488
+ break;
6489
+ }
6490
+ case "start": {
6491
+ (_b = this.fDSPCode) == null ? void 0 : _b.start();
6492
+ break;
6493
+ }
6494
+ case "stop": {
6495
+ (_c = this.fDSPCode) == null ? void 0 : _c.stop();
6496
+ break;
6497
+ }
6498
+ case "destroy": {
6499
+ this.port.close();
6500
+ this.destroy();
6501
+ break;
6502
+ }
6503
+ default:
6504
+ break;
6505
+ }
6506
+ };
6507
+ this.port.addEventListener("message", this.handleMessageAux);
6508
+ this.port.start();
6509
+ this.communicator = new FaustAudioWorkletProcessorCommunicator2(this.port);
6444
6510
  const { parameterDescriptors } = this.constructor;
6445
6511
  parameterDescriptors.forEach((pd) => {
6446
6512
  this.paramValuesCache[pd.name] = pd.defaultValue || 0;
@@ -6596,6 +6662,21 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6596
6662
  this.paramValuesCache[path] = paramValue;
6597
6663
  }
6598
6664
  }
6665
+ if (this.communicator.getNewAccDataAvailable()) {
6666
+ const acc = this.communicator.getAcc();
6667
+ if (acc) {
6668
+ this.communicator.setNewAccDataAvailable(false);
6669
+ const { invert, ...data } = acc;
6670
+ this.propagateAcc(data, invert);
6671
+ }
6672
+ }
6673
+ if (this.communicator.getNewGyrDataAvailable()) {
6674
+ const gyr = this.communicator.getGyr();
6675
+ if (gyr) {
6676
+ this.communicator.setNewGyrDataAvailable(false);
6677
+ this.propagateGyr(gyr);
6678
+ }
6679
+ }
6599
6680
  if (input == null ? void 0 : input.length) {
6600
6681
  let $inputWrite = 0;
6601
6682
  for (let i = 0; i < input.length; i++) {
@@ -6625,55 +6706,6 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6625
6706
  }
6626
6707
  return true;
6627
6708
  }
6628
- handleMessageAux(e) {
6629
- var _a, _b, _c;
6630
- const msg = e.data;
6631
- switch (msg.type) {
6632
- case "midi":
6633
- this.midiMessage(msg.data);
6634
- break;
6635
- case "ctrlChange":
6636
- this.ctrlChange(msg.data[0], msg.data[1], msg.data[2]);
6637
- break;
6638
- case "pitchWheel":
6639
- this.pitchWheel(msg.data[0], msg.data[1]);
6640
- break;
6641
- case "param":
6642
- this.setParamValue(msg.data.path, msg.data.value);
6643
- break;
6644
- case "setPlotHandler": {
6645
- if (msg.data) {
6646
- this.fPlotHandler = (output, index, events) => {
6647
- if (events)
6648
- this.fCachedEvents.push(...events);
6649
- };
6650
- } else {
6651
- this.fPlotHandler = null;
6652
- }
6653
- (_a = this.fDSPCode) == null ? void 0 : _a.setPlotHandler(this.fPlotHandler);
6654
- break;
6655
- }
6656
- case "setupWamEventHandler": {
6657
- this.setupWamEventHandler();
6658
- break;
6659
- }
6660
- case "start": {
6661
- (_b = this.fDSPCode) == null ? void 0 : _b.start();
6662
- break;
6663
- }
6664
- case "stop": {
6665
- (_c = this.fDSPCode) == null ? void 0 : _c.stop();
6666
- break;
6667
- }
6668
- case "destroy": {
6669
- this.port.close();
6670
- this.destroy();
6671
- break;
6672
- }
6673
- default:
6674
- break;
6675
- }
6676
- }
6677
6709
  setParamValue(path, value) {
6678
6710
  var _a;
6679
6711
  (_a = this.fDSPCode) == null ? void 0 : _a.setParamValue(path, value);
@@ -6691,6 +6723,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
6691
6723
  var _a;
6692
6724
  (_a = this.fDSPCode) == null ? void 0 : _a.pitchWheel(channel, wheel);
6693
6725
  }
6726
+ propagateAcc(accelerationIncludingGravity, invert = false) {
6727
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
6728
+ }
6729
+ propagateGyr(event) {
6730
+ this.fDSPCode.propagateGyr(event);
6731
+ }
6694
6732
  resetFFT(sizeIn, overlapIn, windowFunctionIn, inputChannels, outputChannels, bufferSize) {
6695
6733
  var _a, _b;
6696
6734
  const fftSize = ~~ceil(Math.max(2, sizeIn || 1024), 2);
@@ -8461,6 +8499,12 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8461
8499
  hasSoundfiles() {
8462
8500
  return this.fSoundfiles.length > 0;
8463
8501
  }
8502
+ startSensors() {
8503
+ this.startSensors();
8504
+ }
8505
+ stopSensors() {
8506
+ this.stopSensors();
8507
+ }
8464
8508
  start() {
8465
8509
  this.fProcessing = true;
8466
8510
  }
@@ -9098,6 +9142,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9098
9142
  propagateGyr(event) {
9099
9143
  this.fDSPCode.propagateGyr(event);
9100
9144
  }
9145
+ startSensors() {
9146
+ }
9147
+ stopSensors() {
9148
+ }
9101
9149
  /**
9102
9150
  * Render frames in an array.
9103
9151
  *
@@ -9726,6 +9774,130 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9726
9774
  };
9727
9775
  var SoundfileReader_default = SoundfileReader;
9728
9776
 
9777
+ // src/FaustAudioWorkletCommunicator.ts
9778
+ var FaustAudioWorkletCommunicator = class {
9779
+ constructor(port) {
9780
+ this.port = port;
9781
+ this.supportSharedArrayBuffer = !!globalThis.SharedArrayBuffer;
9782
+ this.byteLength = 4 * Uint8Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT + 3 * Float32Array.BYTES_PER_ELEMENT;
9783
+ }
9784
+ initializeBuffer(ab) {
9785
+ let ptr = 0;
9786
+ this.uin8Invert = new Uint8ClampedArray(ab, ptr, 1);
9787
+ ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
9788
+ this.uin8NewAccData = new Uint8ClampedArray(ab, ptr, 1);
9789
+ ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
9790
+ this.uin8NewGyrData = new Uint8ClampedArray(ab, ptr, 1);
9791
+ ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
9792
+ ptr += Uint8ClampedArray.BYTES_PER_ELEMENT;
9793
+ ;
9794
+ this.f32Acc = new Float32Array(ab, ptr, 3);
9795
+ ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
9796
+ this.f32Gyr = new Float32Array(ab, ptr, 3);
9797
+ ptr += 3 * Float32Array.BYTES_PER_ELEMENT;
9798
+ }
9799
+ setNewAccDataAvailable(value) {
9800
+ if (!this.uin8NewAccData)
9801
+ return;
9802
+ this.uin8NewAccData[0] = +value;
9803
+ }
9804
+ getNewAccDataAvailable() {
9805
+ var _a;
9806
+ return !!((_a = this.uin8NewAccData) == null ? void 0 : _a[0]);
9807
+ }
9808
+ setNewGyrDataAvailable(value) {
9809
+ if (!this.uin8NewGyrData)
9810
+ return;
9811
+ this.uin8NewGyrData[0] = +value;
9812
+ }
9813
+ getNewGyrDataAvailable() {
9814
+ var _a;
9815
+ return !!((_a = this.uin8NewGyrData) == null ? void 0 : _a[0]);
9816
+ }
9817
+ setAcc({ x, y, z }, invert = false) {
9818
+ if (!this.supportSharedArrayBuffer) {
9819
+ const e = { type: "acc", data: { x, y, z }, invert };
9820
+ this.port.postMessage(e);
9821
+ }
9822
+ if (!this.uin8NewAccData)
9823
+ return;
9824
+ this.uin8Invert[0] = +invert;
9825
+ this.f32Acc[0] = x;
9826
+ this.f32Acc[1] = y;
9827
+ this.f32Acc[2] = z;
9828
+ this.uin8NewAccData[0] = 1;
9829
+ }
9830
+ getAcc() {
9831
+ if (!this.uin8NewAccData)
9832
+ return;
9833
+ const invert = !!this.uin8Invert[0];
9834
+ const [x, y, z] = this.f32Acc;
9835
+ return { x, y, z, invert };
9836
+ }
9837
+ setGyr({ alpha, beta, gamma }) {
9838
+ if (!this.supportSharedArrayBuffer) {
9839
+ const e = { type: "gyr", data: { alpha, beta, gamma } };
9840
+ this.port.postMessage(e);
9841
+ }
9842
+ if (!this.uin8NewGyrData)
9843
+ return;
9844
+ this.f32Gyr[0] = alpha;
9845
+ this.f32Gyr[1] = beta;
9846
+ this.f32Gyr[2] = gamma;
9847
+ this.uin8NewGyrData[0] = 1;
9848
+ }
9849
+ getGyr() {
9850
+ if (!this.uin8NewGyrData)
9851
+ return;
9852
+ const [alpha, beta, gamma] = this.f32Gyr;
9853
+ return { alpha, beta, gamma };
9854
+ }
9855
+ };
9856
+ var FaustAudioWorkletNodeCommunicator = class extends FaustAudioWorkletCommunicator {
9857
+ constructor(port) {
9858
+ super(port);
9859
+ if (this.supportSharedArrayBuffer) {
9860
+ const sab = new SharedArrayBuffer(this.byteLength);
9861
+ this.initializeBuffer(sab);
9862
+ this.port.postMessage({ type: "initSab", sab });
9863
+ } else {
9864
+ const ab = new ArrayBuffer(this.byteLength);
9865
+ this.initializeBuffer(ab);
9866
+ }
9867
+ }
9868
+ };
9869
+ var FaustAudioWorkletProcessorCommunicator = class extends FaustAudioWorkletCommunicator {
9870
+ constructor(port) {
9871
+ super(port);
9872
+ if (this.supportSharedArrayBuffer) {
9873
+ this.port.addEventListener("message", (event) => {
9874
+ const { data } = event;
9875
+ if (data.type === "initSab") {
9876
+ this.initializeBuffer(data.sab);
9877
+ }
9878
+ });
9879
+ } else {
9880
+ const ab = new ArrayBuffer(this.byteLength);
9881
+ this.initializeBuffer(ab);
9882
+ this.port.addEventListener("message", (event) => {
9883
+ const msg = event.data;
9884
+ switch (msg.type) {
9885
+ case "acc": {
9886
+ this.setAcc(msg.data, msg.invert);
9887
+ break;
9888
+ }
9889
+ case "gyr": {
9890
+ this.setGyr(msg.data);
9891
+ break;
9892
+ }
9893
+ default:
9894
+ break;
9895
+ }
9896
+ });
9897
+ }
9898
+ }
9899
+ };
9900
+
9729
9901
  // src/FaustAudioWorkletNode.ts
9730
9902
  var _hasAccInput, _hasGyrInput;
9731
9903
  var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null) {
@@ -9743,7 +9915,13 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9743
9915
  });
9744
9916
  __privateAdd(this, _hasAccInput, false);
9745
9917
  __privateAdd(this, _hasGyrInput, false);
9746
- // Public API
9918
+ this.handleMessageAux = (e) => {
9919
+ if (e.data.type === "param" && this.fOutputHandler) {
9920
+ this.fOutputHandler(e.data.path, e.data.value);
9921
+ } else if (e.data.type === "plot" && this.fPlotHandler) {
9922
+ this.fPlotHandler(e.data.value, e.data.index, e.data.events);
9923
+ }
9924
+ };
9747
9925
  // Accelerometer and gyroscope handlers
9748
9926
  this.handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9749
9927
  const isAndroid = /Android/i.test(navigator.userAgent);
@@ -9778,54 +9956,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9778
9956
  }
9779
9957
  };
9780
9958
  FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
9781
- this.port.onmessage = (e) => {
9782
- if (e.data.type === "param" && this.fOutputHandler) {
9783
- this.fOutputHandler(e.data.path, e.data.value);
9784
- } else if (e.data.type === "plot" && this.fPlotHandler) {
9785
- this.fPlotHandler(e.data.value, e.data.index, e.data.events);
9786
- }
9787
- };
9959
+ this.fCommunicator = new FaustAudioWorkletNodeCommunicator(this.port);
9960
+ this.port.addEventListener("message", this.handleMessageAux);
9961
+ this.port.start();
9788
9962
  }
9963
+ // Public API
9789
9964
  /** Setup accelerometer and gyroscope handlers */
9790
9965
  async startSensors() {
9791
9966
  if (this.hasAccInput) {
9792
9967
  if (window.DeviceMotionEvent) {
9793
- if (typeof window.DeviceMotionEvent.requestPermission === "function") {
9794
- try {
9795
- const response = await window.DeviceMotionEvent.requestPermission();
9796
- if (response === "granted") {
9797
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
9798
- } else if (response === "denied") {
9799
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
9800
- throw new Error("Unable to access the accelerometer.");
9801
- }
9802
- } catch (error) {
9803
- console.error(error);
9804
- }
9805
- } else {
9806
- window.addEventListener("devicemotion", this.handleDeviceMotion, true);
9807
- }
9968
+ window.addEventListener("devicemotion", this.handleDeviceMotion, true);
9808
9969
  } else {
9809
9970
  console.log("Cannot set the accelerometer handler.");
9810
9971
  }
9811
9972
  }
9812
9973
  if (this.hasGyrInput) {
9813
9974
  if (window.DeviceMotionEvent) {
9814
- if (typeof window.DeviceOrientationEvent.requestPermission === "function") {
9815
- try {
9816
- const response = await window.DeviceOrientationEvent.requestPermission();
9817
- if (response === "granted") {
9818
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
9819
- } else if (response === "denied") {
9820
- alert("You have denied access to motion and orientation data. To enable it, go to Settings > Safari > Motion & Orientation Access.");
9821
- throw new Error("Unable to access the gyroscope.");
9822
- }
9823
- } catch (error) {
9824
- console.error(error);
9825
- }
9826
- } else {
9827
- window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
9828
- }
9975
+ window.addEventListener("deviceorientation", this.handleDeviceOrientation, true);
9829
9976
  } else {
9830
9977
  console.log("Cannot set the gyroscope handler.");
9831
9978
  }
@@ -9906,8 +10053,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9906
10053
  propagateAcc(accelerationIncludingGravity, invert = false) {
9907
10054
  if (!accelerationIncludingGravity)
9908
10055
  return;
9909
- const e = { type: "acc", data: accelerationIncludingGravity, invert };
9910
- this.port.postMessage(e);
10056
+ const { x, y, z } = accelerationIncludingGravity;
10057
+ this.fCommunicator.setAcc({ x, y, z }, invert);
9911
10058
  }
9912
10059
  get hasGyrInput() {
9913
10060
  return __privateGet(this, _hasGyrInput);
@@ -9915,8 +10062,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
9915
10062
  propagateGyr(event) {
9916
10063
  if (!event)
9917
10064
  return;
9918
- const e = { type: "gyr", data: event };
9919
- this.port.postMessage(e);
10065
+ const { alpha, beta, gamma } = event;
10066
+ this.fCommunicator.setGyr({ alpha, beta, gamma });
9920
10067
  }
9921
10068
  setParamValue(path, value) {
9922
10069
  const e = { type: "param", data: { path, value } };
@@ -10059,7 +10206,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10059
10206
  this.start();
10060
10207
  }
10061
10208
  // Public API
10062
- /** Setup accelerometer and gyroscope handlers */
10209
+ /** Start accelerometer and gyroscope handlers */
10063
10210
  async startSensors() {
10064
10211
  if (this.hasAccInput) {
10065
10212
  if (window.DeviceMotionEvent) {
@@ -10104,6 +10251,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
10104
10251
  }
10105
10252
  }
10106
10253
  }
10254
+ /** Stop accelerometer and gyroscope handlers */
10107
10255
  stopSensors() {
10108
10256
  if (this.hasAccInput) {
10109
10257
  window.removeEventListener("devicemotion", this.handleDeviceMotion, true);
@@ -10277,11 +10425,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
10277
10425
  var WasmAllocator = ${WasmAllocator.name};
10278
10426
  var ${FaustSensors.name} = ${FaustSensors.toString()}
10279
10427
  var FaustSensors = ${FaustSensors.name};
10428
+ var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
10429
+ var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
10430
+ var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
10431
+ var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
10280
10432
  // Put them in dependencies
10281
10433
  const dependencies = {
10282
10434
  FaustBaseWebAudioDsp,
10283
10435
  FaustMonoWebAudioDsp,
10284
- FaustWasmInstantiator
10436
+ FaustWasmInstantiator,
10437
+ FaustAudioWorkletProcessorCommunicator
10285
10438
  };
10286
10439
  // Generate the actual AudioWorkletProcessor code
10287
10440
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
@@ -10331,12 +10484,17 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
10331
10484
  var WasmAllocator = ${WasmAllocator.name};
10332
10485
  var ${FaustSensors.name} = ${FaustSensors.toString()}
10333
10486
  var FaustSensors = ${FaustSensors.name};
10487
+ var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
10488
+ var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
10489
+ var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
10490
+ var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
10334
10491
  var FFTUtils = ${fftUtils.toString()}
10335
10492
  // Put them in dependencies
10336
10493
  const dependencies = {
10337
10494
  FaustBaseWebAudioDsp,
10338
10495
  FaustMonoWebAudioDsp,
10339
10496
  FaustWasmInstantiator,
10497
+ FaustAudioWorkletProcessorCommunicator,
10340
10498
  FFTUtils
10341
10499
  };
10342
10500
  // Generate the actual AudioWorkletProcessor code
@@ -10380,6 +10538,7 @@ const dependencies = {
10380
10538
  FaustBaseWebAudioDsp,
10381
10539
  FaustMonoWebAudioDsp,
10382
10540
  FaustWasmInstantiator: FaustWasmInstantiator_default,
10541
+ FaustAudioWorkletProcessorCommunicator,
10383
10542
  FaustPolyWebAudioDsp: void 0,
10384
10543
  FaustWebAudioDspVoice: void 0
10385
10544
  };
@@ -10560,11 +10719,16 @@ var ${WasmAllocator.name} = ${WasmAllocator.toString()}
10560
10719
  var WasmAllocator = ${WasmAllocator.name};
10561
10720
  var ${FaustSensors.name} = ${FaustSensors.toString()}
10562
10721
  var FaustSensors = ${FaustSensors.name};
10722
+ var ${FaustAudioWorkletCommunicator.name} = ${FaustAudioWorkletCommunicator.toString()}
10723
+ var FaustAudioWorkletCommunicator = ${FaustAudioWorkletCommunicator.name};
10724
+ var ${FaustAudioWorkletProcessorCommunicator.name} = ${FaustAudioWorkletProcessorCommunicator.toString()}
10725
+ var FaustAudioWorkletProcessorCommunicator = ${FaustAudioWorkletProcessorCommunicator.name};
10563
10726
  // Put them in dependencies
10564
10727
  const dependencies = {
10565
10728
  FaustBaseWebAudioDsp,
10566
10729
  FaustPolyWebAudioDsp,
10567
- FaustWasmInstantiator
10730
+ FaustWasmInstantiator,
10731
+ FaustAudioWorkletProcessorCommunicator
10568
10732
  };
10569
10733
  // Generate the actual AudioWorkletProcessor code
10570
10734
  (${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
@@ -10592,7 +10756,8 @@ const dependencies = {
10592
10756
  FaustMonoWebAudioDsp: void 0,
10593
10757
  FaustWasmInstantiator: FaustWasmInstantiator_default,
10594
10758
  FaustPolyWebAudioDsp,
10595
- FaustWebAudioDspVoice
10759
+ FaustWebAudioDspVoice,
10760
+ FaustAudioWorkletProcessorCommunicator
10596
10761
  };
10597
10762
  const faustData = {
10598
10763
  processorName,