@grame/faustwasm 0.3.0 → 0.3.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/0001-Invert-x-y-z-accelerometer-on-Android.patch +194 -0
- package/assets/standalone/faustwasm/index.d.ts +7 -7
- package/assets/standalone/faustwasm/index.js +63 -30
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/assets/standalone/index-poly.js +15 -11
- package/assets/standalone/index.js +1 -1
- package/build +17 -0
- package/dist/cjs/index.d.ts +7 -7
- package/dist/cjs/index.js +63 -30
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +7 -7
- package/dist/cjs-bundle/index.js +63 -30
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +7 -7
- package/dist/esm/index.js +63 -30
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +7 -7
- package/dist/esm-bundle/index.js +63 -30
- package/dist/esm-bundle/index.js.map +2 -2
- package/package.json +1 -1
- package/src/FaustAudioWorkletNode.ts +20 -8
- package/src/FaustAudioWorkletProcessor.ts +3 -3
- package/src/FaustOfflineProcessor.ts +4 -4
- package/src/FaustScriptProcessorNode.ts +20 -10
- package/src/FaustWebAudioDsp.ts +13 -6
- package/test/faustlive-wasm/faustwasm/index.d.ts +7 -7
- package/test/faustlive-wasm/faustwasm/index.js +63 -30
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
From 401272a08a44c5c7bc8a33db920fe3bd7a246241 Mon Sep 17 00:00:00 2001
|
|
2
|
+
From: Stephane Letz <letz@grame.fr>
|
|
3
|
+
Date: Mon, 17 Jun 2024 18:04:39 +0200
|
|
4
|
+
Subject: [PATCH] Invert x,y,z accelerometer on Android.
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
src/FaustAudioWorkletNode.ts | 26 +++++++++++++++++++-------
|
|
8
|
+
src/FaustAudioWorkletProcessor.ts | 6 +++---
|
|
9
|
+
src/FaustOfflineProcessor.ts | 8 ++++----
|
|
10
|
+
src/FaustScriptProcessorNode.ts | 24 +++++++++++++++++-------
|
|
11
|
+
src/FaustWebAudioDsp.ts | 19 +++++++++++++------
|
|
12
|
+
5 files changed, 56 insertions(+), 27 deletions(-)
|
|
13
|
+
|
|
14
|
+
diff --git a/src/FaustAudioWorkletNode.ts b/src/FaustAudioWorkletNode.ts
|
|
15
|
+
index efbb741..ca64f0b 100644
|
|
16
|
+
--- a/src/FaustAudioWorkletNode.ts
|
|
17
|
+
+++ b/src/FaustAudioWorkletNode.ts
|
|
18
|
+
@@ -75,11 +75,23 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
|
|
19
|
+
/** Setup accelerometer and gyroscope handlers */
|
|
20
|
+
async listenSensors() {
|
|
21
|
+
if (this.hasAccInput) {
|
|
22
|
+
- const handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
23
|
+
- if (!accelerationIncludingGravity) return;
|
|
24
|
+
- const { x, y, z } = accelerationIncludingGravity;
|
|
25
|
+
- this.propagateAcc({ x, y, z });
|
|
26
|
+
- };
|
|
27
|
+
+ const isAndroid: boolean = /Android/i.test(navigator.userAgent);
|
|
28
|
+
+ console.log(navigator.userAgent);
|
|
29
|
+
+ console.log(isAndroid);
|
|
30
|
+
+ let handleDeviceMotion = null;
|
|
31
|
+
+ if (isAndroid) {
|
|
32
|
+
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
33
|
+
+ if (!accelerationIncludingGravity) return;
|
|
34
|
+
+ const { x, y, z } = accelerationIncludingGravity;
|
|
35
|
+
+ this.propagateAcc({ x, y, z }, true);
|
|
36
|
+
+ }
|
|
37
|
+
+ } else {
|
|
38
|
+
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
39
|
+
+ if (!accelerationIncludingGravity) return;
|
|
40
|
+
+ const { x, y, z } = accelerationIncludingGravity;
|
|
41
|
+
+ this.propagateAcc({ x, y, z });
|
|
42
|
+
+ }
|
|
43
|
+
+ }
|
|
44
|
+
if (window.DeviceMotionEvent) {
|
|
45
|
+
if (typeof (window.DeviceMotionEvent as any).requestPermission === "function") { // for iOS 13+
|
|
46
|
+
try {
|
|
47
|
+
@@ -185,9 +197,9 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get hasAccInput() { return this.#hasAccInput; }
|
|
51
|
+
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
|
|
52
|
+
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
|
|
53
|
+
if (!accelerationIncludingGravity) return;
|
|
54
|
+
- const e = { type: "acc", data: accelerationIncludingGravity };
|
|
55
|
+
+ const e = { type: "acc", data: accelerationIncludingGravity, invert: invert };
|
|
56
|
+
this.port.postMessage(e);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
diff --git a/src/FaustAudioWorkletProcessor.ts b/src/FaustAudioWorkletProcessor.ts
|
|
60
|
+
index 2b9be9a..1eba4e2 100644
|
|
61
|
+
--- a/src/FaustAudioWorkletProcessor.ts
|
|
62
|
+
+++ b/src/FaustAudioWorkletProcessor.ts
|
|
63
|
+
@@ -127,7 +127,7 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(dependencie
|
|
64
|
+
switch (msg.type) {
|
|
65
|
+
// Sensors messages
|
|
66
|
+
case "acc": {
|
|
67
|
+
- this.propagateAcc(msg.data);
|
|
68
|
+
+ this.propagateAcc(msg.data, msg.invert);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
case "gyr": {
|
|
72
|
+
@@ -197,8 +197,8 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(dependencie
|
|
73
|
+
this.fDSPCode.pitchWheel(channel, wheel);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
- protected propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
|
|
77
|
+
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
|
|
78
|
+
+ protected propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
|
|
79
|
+
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
protected propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">) {
|
|
83
|
+
diff --git a/src/FaustOfflineProcessor.ts b/src/FaustOfflineProcessor.ts
|
|
84
|
+
index b08414a..d3d6d91 100644
|
|
85
|
+
--- a/src/FaustOfflineProcessor.ts
|
|
86
|
+
+++ b/src/FaustOfflineProcessor.ts
|
|
87
|
+
@@ -8,8 +8,8 @@ export interface IFaustOfflineProcessor extends IFaustBaseWebAudioDsp {
|
|
88
|
+
render(inputs?: Float32Array[], length?: number, onUpdate?: (sample: number) => any): Float32Array[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
-export interface IFaustMonoOfflineProcessor extends IFaustOfflineProcessor, IFaustMonoWebAudioDsp {}
|
|
92
|
+
-export interface IFaustPolyOfflineProcessor extends IFaustOfflineProcessor, IFaustPolyWebAudioDsp {}
|
|
93
|
+
+export interface IFaustMonoOfflineProcessor extends IFaustOfflineProcessor, IFaustMonoWebAudioDsp { }
|
|
94
|
+
+export interface IFaustPolyOfflineProcessor extends IFaustOfflineProcessor, IFaustPolyWebAudioDsp { }
|
|
95
|
+
|
|
96
|
+
export class FaustOfflineProcessor<Poly extends boolean = false> {
|
|
97
|
+
protected fDSPCode!: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp;
|
|
98
|
+
@@ -82,8 +82,8 @@ export class FaustOfflineProcessor<Poly extends boolean = false> {
|
|
99
|
+
destroy() { this.fDSPCode.destroy(); }
|
|
100
|
+
|
|
101
|
+
get hasAccInput() { return this.fDSPCode.hasAccInput; }
|
|
102
|
+
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
|
|
103
|
+
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
|
|
104
|
+
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
|
|
105
|
+
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
get hasGyrInput() { return this.fDSPCode.hasGyrInput; }
|
|
109
|
+
diff --git a/src/FaustScriptProcessorNode.ts b/src/FaustScriptProcessorNode.ts
|
|
110
|
+
index 0c73ae8..36ce3b3 100644
|
|
111
|
+
--- a/src/FaustScriptProcessorNode.ts
|
|
112
|
+
+++ b/src/FaustScriptProcessorNode.ts
|
|
113
|
+
@@ -39,11 +39,21 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
|
|
114
|
+
/** Setup accelerometer and gyroscope handlers */
|
|
115
|
+
async listenSensors() {
|
|
116
|
+
if (this.hasAccInput) {
|
|
117
|
+
- const handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
118
|
+
- if (!accelerationIncludingGravity) return;
|
|
119
|
+
- const { x, y, z } = accelerationIncludingGravity;
|
|
120
|
+
- this.propagateAcc({ x, y, z });
|
|
121
|
+
- };
|
|
122
|
+
+ const isAndroid: boolean = /Android/i.test(navigator.userAgent);
|
|
123
|
+
+ let handleDeviceMotion = null;
|
|
124
|
+
+ if (isAndroid) {
|
|
125
|
+
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
126
|
+
+ if (!accelerationIncludingGravity) return;
|
|
127
|
+
+ const { x, y, z } = accelerationIncludingGravity;
|
|
128
|
+
+ this.propagateAcc({ x, y, z }, true);
|
|
129
|
+
+ }
|
|
130
|
+
+ } else {
|
|
131
|
+
+ handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
132
|
+
+ if (!accelerationIncludingGravity) return;
|
|
133
|
+
+ const { x, y, z } = accelerationIncludingGravity;
|
|
134
|
+
+ this.propagateAcc({ x, y, z });
|
|
135
|
+
+ }
|
|
136
|
+
+ }
|
|
137
|
+
if (window.DeviceMotionEvent) {
|
|
138
|
+
if (typeof (window.DeviceMotionEvent as any).requestPermission === "function") { // for iOS 13+
|
|
139
|
+
try {
|
|
140
|
+
@@ -120,8 +130,8 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
|
|
141
|
+
destroy() { this.fDSPCode.destroy(); }
|
|
142
|
+
|
|
143
|
+
get hasAccInput() { return this.fDSPCode.hasAccInput; }
|
|
144
|
+
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
|
|
145
|
+
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
|
|
146
|
+
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
|
|
147
|
+
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get hasGyrInput() { return this.fDSPCode.hasGyrInput; }
|
|
151
|
+
diff --git a/src/FaustWebAudioDsp.ts b/src/FaustWebAudioDsp.ts
|
|
152
|
+
index b3e728f..c225d11 100644
|
|
153
|
+
--- a/src/FaustWebAudioDsp.ts
|
|
154
|
+
+++ b/src/FaustWebAudioDsp.ts
|
|
155
|
+
@@ -514,7 +514,7 @@ export interface IFaustBaseWebAudioDsp {
|
|
156
|
+
/** Indicating if the DSP handles the accelerometer */
|
|
157
|
+
readonly hasAccInput: boolean;
|
|
158
|
+
/** Accelerometer handling */
|
|
159
|
+
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
|
|
160
|
+
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
|
|
161
|
+
|
|
162
|
+
/** Indicating if the DSP handles the gyroscope */
|
|
163
|
+
readonly hasGyrInput: boolean;
|
|
164
|
+
@@ -687,15 +687,22 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get hasAccInput() { return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0; }
|
|
168
|
+
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>) {
|
|
169
|
+
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
|
|
170
|
+
|
|
171
|
+
// Get accelerometervalues
|
|
172
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
173
|
+
|
|
174
|
+
- // Call the accelerometer handlers
|
|
175
|
+
- if (x !== null) this.fAcc.x.forEach(handler => handler(x));
|
|
176
|
+
- if (y !== null) this.fAcc.y.forEach(handler => handler(y));
|
|
177
|
+
- if (z !== null) this.fAcc.z.forEach(handler => handler(z));
|
|
178
|
+
+ if (invert) {
|
|
179
|
+
+ // Call the accelerometer handlers
|
|
180
|
+
+ if (x !== null) this.fAcc.x.forEach(handler => handler(-x));
|
|
181
|
+
+ if (y !== null) this.fAcc.y.forEach(handler => handler(-y));
|
|
182
|
+
+ if (z !== null) this.fAcc.z.forEach(handler => handler(-z));
|
|
183
|
+
+ } else {
|
|
184
|
+
+ // Call the accelerometer handlers
|
|
185
|
+
+ if (x !== null) this.fAcc.x.forEach(handler => handler(x));
|
|
186
|
+
+ if (y !== null) this.fAcc.y.forEach(handler => handler(y));
|
|
187
|
+
+ if (z !== null) this.fAcc.z.forEach(handler => handler(z));
|
|
188
|
+
+ }
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get hasGyrInput() { return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0; }
|
|
192
|
+
--
|
|
193
|
+
2.37.1 (Apple Git-137.1)
|
|
194
|
+
|
|
@@ -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"]
|
|
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"]
|
|
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"]
|
|
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
|
/**
|
|
@@ -1278,7 +1278,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
|
|
|
1278
1278
|
protected fDescriptor: FaustUIInputItem[];
|
|
1279
1279
|
constructor(context: BaseAudioContext, name: string, factory: LooseFaustDspFactory, options: FaustAudioWorkletNodeOptions<Poly>["processorOptions"], nodeOptions?: Partial<FaustAudioWorkletNodeOptions>);
|
|
1280
1280
|
/** Setup accelerometer and gyroscope handlers */
|
|
1281
|
-
|
|
1281
|
+
listenSensors(): Promise<void>;
|
|
1282
1282
|
setOutputParamHandler(handler: OutputParamHandler | null): void;
|
|
1283
1283
|
getOutputParamHandler(): OutputParamHandler | null;
|
|
1284
1284
|
setComputeHandler(handler: ComputeHandler | null): void;
|
|
@@ -1293,7 +1293,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
|
|
|
1293
1293
|
ctrlChange(channel: number, ctrl: number, value: number): void;
|
|
1294
1294
|
pitchWheel(channel: number, wheel: number): void;
|
|
1295
1295
|
get hasAccInput(): boolean;
|
|
1296
|
-
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]
|
|
1296
|
+
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
|
|
1297
1297
|
get hasGyrInput(): boolean;
|
|
1298
1298
|
propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
|
|
1299
1299
|
setParamValue(path: string, value: number): void;
|
|
@@ -1341,7 +1341,7 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
|
|
|
1341
1341
|
protected fOutputs: Float32Array[];
|
|
1342
1342
|
init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
|
|
1343
1343
|
/** Setup accelerometer and gyroscope handlers */
|
|
1344
|
-
|
|
1344
|
+
listenSensors(): Promise<void>;
|
|
1345
1345
|
compute(input: Float32Array[], output: Float32Array[]): boolean;
|
|
1346
1346
|
setOutputParamHandler(handler: OutputParamHandler): void;
|
|
1347
1347
|
getOutputParamHandler(): OutputParamHandler | null;
|
|
@@ -1366,7 +1366,7 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
|
|
|
1366
1366
|
stop(): void;
|
|
1367
1367
|
destroy(): void;
|
|
1368
1368
|
get hasAccInput(): boolean;
|
|
1369
|
-
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]
|
|
1369
|
+
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
|
|
1370
1370
|
get hasGyrInput(): boolean;
|
|
1371
1371
|
propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
|
|
1372
1372
|
}
|
|
@@ -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 (
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
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;
|
|
@@ -3647,14 +3656,27 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
3647
3656
|
}
|
|
3648
3657
|
// Public API
|
|
3649
3658
|
/** Setup accelerometer and gyroscope handlers */
|
|
3650
|
-
async
|
|
3659
|
+
async listenSensors() {
|
|
3651
3660
|
if (this.hasAccInput) {
|
|
3652
|
-
const
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3661
|
+
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
3662
|
+
console.log(navigator.userAgent);
|
|
3663
|
+
console.log(isAndroid);
|
|
3664
|
+
let handleDeviceMotion = null;
|
|
3665
|
+
if (isAndroid) {
|
|
3666
|
+
handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3667
|
+
if (!accelerationIncludingGravity)
|
|
3668
|
+
return;
|
|
3669
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
3670
|
+
this.propagateAcc({ x, y, z }, true);
|
|
3671
|
+
};
|
|
3672
|
+
} else {
|
|
3673
|
+
handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3674
|
+
if (!accelerationIncludingGravity)
|
|
3675
|
+
return;
|
|
3676
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
3677
|
+
this.propagateAcc({ x, y, z });
|
|
3678
|
+
};
|
|
3679
|
+
}
|
|
3658
3680
|
if (window.DeviceMotionEvent) {
|
|
3659
3681
|
if (typeof window.DeviceMotionEvent.requestPermission === "function") {
|
|
3660
3682
|
try {
|
|
@@ -3755,10 +3777,10 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
|
|
|
3755
3777
|
get hasAccInput() {
|
|
3756
3778
|
return __privateGet(this, _hasAccInput);
|
|
3757
3779
|
}
|
|
3758
|
-
propagateAcc(accelerationIncludingGravity) {
|
|
3780
|
+
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
3759
3781
|
if (!accelerationIncludingGravity)
|
|
3760
3782
|
return;
|
|
3761
|
-
const e = { type: "acc", data: accelerationIncludingGravity };
|
|
3783
|
+
const e = { type: "acc", data: accelerationIncludingGravity, invert };
|
|
3762
3784
|
this.port.postMessage(e);
|
|
3763
3785
|
}
|
|
3764
3786
|
get hasGyrInput() {
|
|
@@ -3905,14 +3927,25 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
3905
3927
|
}
|
|
3906
3928
|
// Public API
|
|
3907
3929
|
/** Setup accelerometer and gyroscope handlers */
|
|
3908
|
-
async
|
|
3930
|
+
async listenSensors() {
|
|
3909
3931
|
if (this.hasAccInput) {
|
|
3910
|
-
const
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3932
|
+
const isAndroid = /Android/i.test(navigator.userAgent);
|
|
3933
|
+
let handleDeviceMotion = null;
|
|
3934
|
+
if (isAndroid) {
|
|
3935
|
+
handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3936
|
+
if (!accelerationIncludingGravity)
|
|
3937
|
+
return;
|
|
3938
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
3939
|
+
this.propagateAcc({ x, y, z }, true);
|
|
3940
|
+
};
|
|
3941
|
+
} else {
|
|
3942
|
+
handleDeviceMotion = ({ accelerationIncludingGravity }) => {
|
|
3943
|
+
if (!accelerationIncludingGravity)
|
|
3944
|
+
return;
|
|
3945
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
3946
|
+
this.propagateAcc({ x, y, z });
|
|
3947
|
+
};
|
|
3948
|
+
}
|
|
3916
3949
|
if (window.DeviceMotionEvent) {
|
|
3917
3950
|
if (typeof window.DeviceMotionEvent.requestPermission === "function") {
|
|
3918
3951
|
try {
|
|
@@ -4023,8 +4056,8 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
|
|
|
4023
4056
|
get hasAccInput() {
|
|
4024
4057
|
return this.fDSPCode.hasAccInput;
|
|
4025
4058
|
}
|
|
4026
|
-
propagateAcc(accelerationIncludingGravity) {
|
|
4027
|
-
this.fDSPCode.propagateAcc(accelerationIncludingGravity);
|
|
4059
|
+
propagateAcc(accelerationIncludingGravity, invert = false) {
|
|
4060
|
+
this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
|
|
4028
4061
|
}
|
|
4029
4062
|
get hasGyrInput() {
|
|
4030
4063
|
return this.fDSPCode.hasGyrInput;
|