@grame/faustwasm 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -75,11 +75,21 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
75
75
  /** Setup accelerometer and gyroscope handlers */
76
76
  async listenSensors() {
77
77
  if (this.hasAccInput) {
78
- const handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
79
- if (!accelerationIncludingGravity) return;
80
- const { x, y, z } = accelerationIncludingGravity;
81
- this.propagateAcc({ x, y, z });
82
- };
78
+ const isAndroid: boolean = /Android/i.test(navigator.userAgent);
79
+ let handleDeviceMotion = null;
80
+ if (isAndroid) {
81
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
82
+ if (!accelerationIncludingGravity) return;
83
+ const { x, y, z } = accelerationIncludingGravity;
84
+ this.propagateAcc({ x, y, z }, true);
85
+ }
86
+ } else {
87
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
88
+ if (!accelerationIncludingGravity) return;
89
+ const { x, y, z } = accelerationIncludingGravity;
90
+ this.propagateAcc({ x, y, z });
91
+ }
92
+ }
83
93
  if (window.DeviceMotionEvent) {
84
94
  if (typeof (window.DeviceMotionEvent as any).requestPermission === "function") { // for iOS 13+
85
95
  try {
@@ -185,9 +195,9 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
185
195
  }
186
196
 
187
197
  get hasAccInput() { return this.#hasAccInput; }
188
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
198
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
189
199
  if (!accelerationIncludingGravity) return;
190
- const e = { type: "acc", data: accelerationIncludingGravity };
200
+ const e = { type: "acc", data: accelerationIncludingGravity, invert: invert };
191
201
  this.port.postMessage(e);
192
202
  }
193
203
 
@@ -230,7 +240,6 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
230
240
  this.port.postMessage({ type: "destroy" });
231
241
  this.port.close();
232
242
  }
233
-
234
243
  }
235
244
 
236
245
  /**
@@ -127,7 +127,7 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(dependencie
127
127
  switch (msg.type) {
128
128
  // Sensors messages
129
129
  case "acc": {
130
- this.propagateAcc(msg.data);
130
+ this.propagateAcc(msg.data, msg.invert);
131
131
  break;
132
132
  }
133
133
  case "gyr": {
@@ -197,8 +197,8 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(dependencie
197
197
  this.fDSPCode.pitchWheel(channel, wheel);
198
198
  }
199
199
 
200
- protected propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
201
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
200
+ protected propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
201
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
202
202
  }
203
203
 
204
204
  protected propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">) {
@@ -8,8 +8,8 @@ export interface IFaustOfflineProcessor extends IFaustBaseWebAudioDsp {
8
8
  render(inputs?: Float32Array[], length?: number, onUpdate?: (sample: number) => any): Float32Array[];
9
9
  }
10
10
 
11
- export interface IFaustMonoOfflineProcessor extends IFaustOfflineProcessor, IFaustMonoWebAudioDsp {}
12
- export interface IFaustPolyOfflineProcessor extends IFaustOfflineProcessor, IFaustPolyWebAudioDsp {}
11
+ export interface IFaustMonoOfflineProcessor extends IFaustOfflineProcessor, IFaustMonoWebAudioDsp { }
12
+ export interface IFaustPolyOfflineProcessor extends IFaustOfflineProcessor, IFaustPolyWebAudioDsp { }
13
13
 
14
14
  export class FaustOfflineProcessor<Poly extends boolean = false> {
15
15
  protected fDSPCode!: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp;
@@ -82,8 +82,8 @@ export class FaustOfflineProcessor<Poly extends boolean = false> {
82
82
  destroy() { this.fDSPCode.destroy(); }
83
83
 
84
84
  get hasAccInput() { return this.fDSPCode.hasAccInput; }
85
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
86
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
85
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
86
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
87
87
  }
88
88
 
89
89
  get hasGyrInput() { return this.fDSPCode.hasGyrInput; }
@@ -39,11 +39,21 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
39
39
  /** Setup accelerometer and gyroscope handlers */
40
40
  async listenSensors() {
41
41
  if (this.hasAccInput) {
42
- const handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
43
- if (!accelerationIncludingGravity) return;
44
- const { x, y, z } = accelerationIncludingGravity;
45
- this.propagateAcc({ x, y, z });
46
- };
42
+ const isAndroid: boolean = /Android/i.test(navigator.userAgent);
43
+ let handleDeviceMotion = null;
44
+ if (isAndroid) {
45
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
46
+ if (!accelerationIncludingGravity) return;
47
+ const { x, y, z } = accelerationIncludingGravity;
48
+ this.propagateAcc({ x, y, z }, true);
49
+ }
50
+ } else {
51
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
52
+ if (!accelerationIncludingGravity) return;
53
+ const { x, y, z } = accelerationIncludingGravity;
54
+ this.propagateAcc({ x, y, z });
55
+ }
56
+ }
47
57
  if (window.DeviceMotionEvent) {
48
58
  if (typeof (window.DeviceMotionEvent as any).requestPermission === "function") { // for iOS 13+
49
59
  try {
@@ -120,8 +130,8 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
120
130
  destroy() { this.fDSPCode.destroy(); }
121
131
 
122
132
  get hasAccInput() { return this.fDSPCode.hasAccInput; }
123
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
124
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
133
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
134
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
125
135
  }
126
136
 
127
137
  get hasGyrInput() { return this.fDSPCode.hasGyrInput; }
@@ -514,7 +514,7 @@ export interface IFaustBaseWebAudioDsp {
514
514
  /** Indicating if the DSP handles the accelerometer */
515
515
  readonly hasAccInput: boolean;
516
516
  /** Accelerometer handling */
517
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
517
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
518
518
 
519
519
  /** Indicating if the DSP handles the gyroscope */
520
520
  readonly hasGyrInput: boolean;
@@ -687,15 +687,22 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
687
687
  }
688
688
 
689
689
  get hasAccInput() { return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0; }
690
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
690
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
691
691
 
692
692
  // Get accelerometervalues
693
693
  const { x, y, z } = accelerationIncludingGravity;
694
694
 
695
- // Call the accelerometer handlers
696
- if (x !== null) this.fAcc.x.forEach(handler => handler(x));
697
- if (y !== null) this.fAcc.y.forEach(handler => handler(y));
698
- if (z !== null) this.fAcc.z.forEach(handler => handler(z));
695
+ if (invert) {
696
+ // Call the accelerometer handlers
697
+ if (x !== null) this.fAcc.x.forEach(handler => handler(-x));
698
+ if (y !== null) this.fAcc.y.forEach(handler => handler(-y));
699
+ if (z !== null) this.fAcc.z.forEach(handler => handler(-z));
700
+ } else {
701
+ // Call the accelerometer handlers
702
+ if (x !== null) this.fAcc.x.forEach(handler => handler(x));
703
+ if (y !== null) this.fAcc.y.forEach(handler => handler(y));
704
+ if (z !== null) this.fAcc.z.forEach(handler => handler(z));
705
+ }
699
706
  }
700
707
 
701
708
  get hasGyrInput() { return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0; }
@@ -3,7 +3,18 @@ import type { AudioData, FaustDspMeta, FaustUIItem, LooseFaustDspFactory } from
3
3
 
4
4
  /** Read metadata and fetch soundfiles */
5
5
  class SoundfileReader {
6
- static get fallbackPaths() { return [location.href, location.origin]; }
6
+
7
+ // Set the fallback paths
8
+ static get fallbackPaths() { return [location.href, this.getParentUrl(location.href), location.origin]; }
9
+
10
+ /**
11
+ * Extract the parent URL from an URL.
12
+ * @param url : the URL
13
+ * @returns : the parent URL
14
+ */
15
+ private static getParentUrl(url: string) {
16
+ return url.substring(0, url.lastIndexOf('/') + 1);
17
+ }
7
18
 
8
19
  /**
9
20
  * Convert an audio buffer to audio data.
@@ -46,7 +57,10 @@ class SoundfileReader {
46
57
  private static async checkFileExists(url: string): Promise<boolean> {
47
58
  try {
48
59
  console.log(`"checkFileExists" url: ${url}`);
49
- const response = await fetch(url, { method: "HEAD" });
60
+ // Fetch in "HEAD" mode does not properly work with the service-worker.js cache, so use "GET" mode for now
61
+ //const response = await fetch(url, { method: "HEAD" });
62
+ const response = await fetch(url);
63
+ console.log(`"checkFileExists" response.ok: ${response.ok}`);
50
64
  return response.ok; // Will be true if the status code is 200-299
51
65
  } catch (error) {
52
66
  console.error('Fetch error:', error);
@@ -22,13 +22,23 @@ const copyWebStandaloneAssets = (outputDir, dspName, poly = false) => {
22
22
  cpSyncModify(templateJSPath, outputDir + `/${dspName}.js`, "FAUST_DSP", dspName);
23
23
 
24
24
  const templateHTMLPath = path.join(__dirname, "../assets/standalone/index.html");
25
- cpSyncModify(templateHTMLPath, outputDir + `/${dspName}.html`, "FAUST_DSP", dspName);
25
+ //cpSyncModify(templateHTMLPath, outputDir + `/${dspName}.html`, "FAUST_DSP", dspName);
26
+ cpSyncModify(templateHTMLPath, outputDir + `/index.html`, "FAUST_DSP", dspName);
27
+
28
+ const templateServerJSPath = path.join(__dirname, "../assets/standalone/service-worker.js");
29
+ cpSyncModify(templateServerJSPath, outputDir + `/service-worker.js`, "FAUST_DSP", dspName);
30
+
31
+ const templateIconPath = path.join(__dirname, "../assets/standalone/icon.png");
32
+ cpSync(templateIconPath, outputDir + `/icon.png`);
26
33
 
27
34
  const faustwasmPath = path.join(__dirname, "../assets/standalone/faustwasm");
28
35
  cpSync(faustwasmPath, outputDir + "/faustwasm");
29
36
 
30
37
  const faustuiPath = path.join(__dirname, "../assets/standalone/faust-ui");
31
38
  cpSync(faustuiPath, outputDir + "/faust-ui");
39
+
40
+ const templateManifestPath = path.join(__dirname, "../assets/standalone/manifest.json");
41
+ cpSyncModify(templateManifestPath, outputDir + `/manifest.json`, "FAUST_DSP", dspName);
32
42
  };
33
43
 
34
44
  /**
@@ -635,7 +635,7 @@ export interface IFaustBaseWebAudioDsp {
635
635
  /** Indicating if the DSP handles the accelerometer */
636
636
  readonly hasAccInput: boolean;
637
637
  /** Accelerometer handling */
638
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
638
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
639
639
  /** Indicating if the DSP handles the gyroscope */
640
640
  readonly hasGyrInput: boolean;
641
641
  /** Gyroscope handling */
@@ -724,7 +724,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
724
724
  /** Split the soundfile names and return an array of names */
725
725
  static splitSoundfileNames(input: string): string[];
726
726
  get hasAccInput(): boolean;
727
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
727
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
728
728
  get hasGyrInput(): boolean;
729
729
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
730
730
  /** Build the accelerometer handler */
@@ -1123,7 +1123,7 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1123
1123
  stop(): void;
1124
1124
  destroy(): void;
1125
1125
  get hasAccInput(): boolean;
1126
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1126
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1127
1127
  get hasGyrInput(): boolean;
1128
1128
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1129
1129
  /**
@@ -1211,6 +1211,12 @@ export declare class WavDecoder {
1211
1211
  /** Read metadata and fetch soundfiles */
1212
1212
  export declare class SoundfileReader {
1213
1213
  static get fallbackPaths(): string[];
1214
+ /**
1215
+ * Extract the parent URL from an URL.
1216
+ * @param url : the URL
1217
+ * @returns : the parent URL
1218
+ */
1219
+ private static getParentUrl;
1214
1220
  /**
1215
1221
  * Convert an audio buffer to audio data.
1216
1222
  *
@@ -1293,7 +1299,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1293
1299
  ctrlChange(channel: number, ctrl: number, value: number): void;
1294
1300
  pitchWheel(channel: number, wheel: number): void;
1295
1301
  get hasAccInput(): boolean;
1296
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1302
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1297
1303
  get hasGyrInput(): boolean;
1298
1304
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1299
1305
  setParamValue(path: string, value: number): void;
@@ -1366,7 +1372,7 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1366
1372
  stop(): void;
1367
1373
  destroy(): void;
1368
1374
  get hasAccInput(): boolean;
1369
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1375
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1370
1376
  get hasGyrInput(): boolean;
1371
1377
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1372
1378
  }
@@ -138,7 +138,7 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
138
138
  const msg = e.data;
139
139
  switch (msg.type) {
140
140
  case "acc": {
141
- this.propagateAcc(msg.data);
141
+ this.propagateAcc(msg.data, msg.invert);
142
142
  break;
143
143
  }
144
144
  case "gyr": {
@@ -199,8 +199,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
199
199
  pitchWheel(channel, wheel) {
200
200
  this.fDSPCode.pitchWheel(channel, wheel);
201
201
  }
202
- propagateAcc(accelerationIncludingGravity) {
203
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
202
+ propagateAcc(accelerationIncludingGravity, invert = false) {
203
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
204
204
  }
205
205
  propagateGyr(event) {
206
206
  this.fDSPCode.propagateGyr(event);
@@ -2103,14 +2103,23 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
2103
2103
  get hasAccInput() {
2104
2104
  return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
2105
2105
  }
2106
- propagateAcc(accelerationIncludingGravity) {
2106
+ propagateAcc(accelerationIncludingGravity, invert = false) {
2107
2107
  const { x, y, z } = accelerationIncludingGravity;
2108
- if (x !== null)
2109
- this.fAcc.x.forEach((handler) => handler(x));
2110
- if (y !== null)
2111
- this.fAcc.y.forEach((handler) => handler(y));
2112
- if (z !== null)
2113
- this.fAcc.z.forEach((handler) => handler(z));
2108
+ if (invert) {
2109
+ if (x !== null)
2110
+ this.fAcc.x.forEach((handler) => handler(-x));
2111
+ if (y !== null)
2112
+ this.fAcc.y.forEach((handler) => handler(-y));
2113
+ if (z !== null)
2114
+ this.fAcc.z.forEach((handler) => handler(-z));
2115
+ } else {
2116
+ if (x !== null)
2117
+ this.fAcc.x.forEach((handler) => handler(x));
2118
+ if (y !== null)
2119
+ this.fAcc.y.forEach((handler) => handler(y));
2120
+ if (z !== null)
2121
+ this.fAcc.z.forEach((handler) => handler(z));
2122
+ }
2114
2123
  }
2115
2124
  get hasGyrInput() {
2116
2125
  return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0;
@@ -2970,8 +2979,8 @@ var FaustOfflineProcessor = class {
2970
2979
  get hasAccInput() {
2971
2980
  return this.fDSPCode.hasAccInput;
2972
2981
  }
2973
- propagateAcc(accelerationIncludingGravity) {
2974
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
2982
+ propagateAcc(accelerationIncludingGravity, invert = false) {
2983
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
2975
2984
  }
2976
2985
  get hasGyrInput() {
2977
2986
  return this.fDSPCode.hasGyrInput;
@@ -3487,8 +3496,17 @@ var WavDecoder_default = WavDecoder;
3487
3496
 
3488
3497
  // src/SoundfileReader.ts
3489
3498
  var SoundfileReader = class {
3499
+ // Set the fallback paths
3490
3500
  static get fallbackPaths() {
3491
- return [location.href, location.origin];
3501
+ return [location.href, this.getParentUrl(location.href), location.origin];
3502
+ }
3503
+ /**
3504
+ * Extract the parent URL from an URL.
3505
+ * @param url : the URL
3506
+ * @returns : the parent URL
3507
+ */
3508
+ static getParentUrl(url) {
3509
+ return url.substring(0, url.lastIndexOf("/") + 1);
3492
3510
  }
3493
3511
  /**
3494
3512
  * Convert an audio buffer to audio data.
@@ -3529,7 +3547,8 @@ var SoundfileReader = class {
3529
3547
  static async checkFileExists(url) {
3530
3548
  try {
3531
3549
  console.log(`"checkFileExists" url: ${url}`);
3532
- const response = await fetch(url, { method: "HEAD" });
3550
+ const response = await fetch(url);
3551
+ console.log(`"checkFileExists" response.ok: ${response.ok}`);
3533
3552
  return response.ok;
3534
3553
  } catch (error) {
3535
3554
  console.error("Fetch error:", error);
@@ -3649,12 +3668,23 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3649
3668
  /** Setup accelerometer and gyroscope handlers */
3650
3669
  async listenSensors() {
3651
3670
  if (this.hasAccInput) {
3652
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3653
- if (!accelerationIncludingGravity)
3654
- return;
3655
- const { x, y, z } = accelerationIncludingGravity;
3656
- this.propagateAcc({ x, y, z });
3657
- };
3671
+ const isAndroid = /Android/i.test(navigator.userAgent);
3672
+ let handleDeviceMotion = null;
3673
+ if (isAndroid) {
3674
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3675
+ if (!accelerationIncludingGravity)
3676
+ return;
3677
+ const { x, y, z } = accelerationIncludingGravity;
3678
+ this.propagateAcc({ x, y, z }, true);
3679
+ };
3680
+ } else {
3681
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3682
+ if (!accelerationIncludingGravity)
3683
+ return;
3684
+ const { x, y, z } = accelerationIncludingGravity;
3685
+ this.propagateAcc({ x, y, z });
3686
+ };
3687
+ }
3658
3688
  if (window.DeviceMotionEvent) {
3659
3689
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3660
3690
  try {
@@ -3755,10 +3785,10 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
3755
3785
  get hasAccInput() {
3756
3786
  return __privateGet(this, _hasAccInput);
3757
3787
  }
3758
- propagateAcc(accelerationIncludingGravity) {
3788
+ propagateAcc(accelerationIncludingGravity, invert = false) {
3759
3789
  if (!accelerationIncludingGravity)
3760
3790
  return;
3761
- const e = { type: "acc", data: accelerationIncludingGravity };
3791
+ const e = { type: "acc", data: accelerationIncludingGravity, invert };
3762
3792
  this.port.postMessage(e);
3763
3793
  }
3764
3794
  get hasGyrInput() {
@@ -3907,12 +3937,23 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
3907
3937
  /** Setup accelerometer and gyroscope handlers */
3908
3938
  async listenSensors() {
3909
3939
  if (this.hasAccInput) {
3910
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3911
- if (!accelerationIncludingGravity)
3912
- return;
3913
- const { x, y, z } = accelerationIncludingGravity;
3914
- this.propagateAcc({ x, y, z });
3915
- };
3940
+ const isAndroid = /Android/i.test(navigator.userAgent);
3941
+ let handleDeviceMotion = null;
3942
+ if (isAndroid) {
3943
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3944
+ if (!accelerationIncludingGravity)
3945
+ return;
3946
+ const { x, y, z } = accelerationIncludingGravity;
3947
+ this.propagateAcc({ x, y, z }, true);
3948
+ };
3949
+ } else {
3950
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3951
+ if (!accelerationIncludingGravity)
3952
+ return;
3953
+ const { x, y, z } = accelerationIncludingGravity;
3954
+ this.propagateAcc({ x, y, z });
3955
+ };
3956
+ }
3916
3957
  if (window.DeviceMotionEvent) {
3917
3958
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3918
3959
  try {
@@ -4023,8 +4064,8 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
4023
4064
  get hasAccInput() {
4024
4065
  return this.fDSPCode.hasAccInput;
4025
4066
  }
4026
- propagateAcc(accelerationIncludingGravity) {
4027
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
4067
+ propagateAcc(accelerationIncludingGravity, invert = false) {
4068
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
4028
4069
  }
4029
4070
  get hasGyrInput() {
4030
4071
  return this.fDSPCode.hasGyrInput;