@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
package/package.json
CHANGED
|
@@ -73,13 +73,25 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
|
|
|
73
73
|
// Public API
|
|
74
74
|
|
|
75
75
|
/** Setup accelerometer and gyroscope handlers */
|
|
76
|
-
async
|
|
76
|
+
async listenSensors() {
|
|
77
77
|
if (this.hasAccInput) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
78
|
+
const isAndroid: boolean = /Android/i.test(navigator.userAgent);
|
|
79
|
+
console.log(navigator.userAgent);
|
|
80
|
+
console.log(isAndroid);
|
|
81
|
+
let handleDeviceMotion = null;
|
|
82
|
+
if (isAndroid) {
|
|
83
|
+
handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
84
|
+
if (!accelerationIncludingGravity) return;
|
|
85
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
86
|
+
this.propagateAcc({ x, y, z }, true);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
handleDeviceMotion = ({ accelerationIncludingGravity }: DeviceMotionEvent) => {
|
|
90
|
+
if (!accelerationIncludingGravity) return;
|
|
91
|
+
const { x, y, z } = accelerationIncludingGravity;
|
|
92
|
+
this.propagateAcc({ x, y, z });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
83
95
|
if (window.DeviceMotionEvent) {
|
|
84
96
|
if (typeof (window.DeviceMotionEvent as any).requestPermission === "function") { // for iOS 13+
|
|
85
97
|
try {
|
|
@@ -185,9 +197,9 @@ export class FaustAudioWorkletNode<Poly extends boolean = false> extends (global
|
|
|
185
197
|
}
|
|
186
198
|
|
|
187
199
|
get hasAccInput() { return this.#hasAccInput; }
|
|
188
|
-
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]
|
|
200
|
+
propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean = false) {
|
|
189
201
|
if (!accelerationIncludingGravity) return;
|
|
190
|
-
const e = { type: "acc", data: accelerationIncludingGravity };
|
|
202
|
+
const e = { type: "acc", data: accelerationIncludingGravity, invert: invert };
|
|
191
203
|
this.port.postMessage(e);
|
|
192
204
|
}
|
|
193
205
|
|
|
@@ -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; }
|
|
@@ -15,7 +15,7 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
|
|
|
15
15
|
|
|
16
16
|
this.fInputs = new Array(this.fDSPCode.getNumInputs());
|
|
17
17
|
this.fOutputs = new Array(this.fDSPCode.getNumOutputs());
|
|
18
|
-
|
|
18
|
+
|
|
19
19
|
this.onaudioprocess = (e) => {
|
|
20
20
|
|
|
21
21
|
// Read inputs
|
|
@@ -33,17 +33,27 @@ export class FaustScriptProcessorNode<Poly extends boolean = false> extends (glo
|
|
|
33
33
|
|
|
34
34
|
this.start();
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
// Public API
|
|
38
38
|
|
|
39
39
|
/** Setup accelerometer and gyroscope handlers */
|
|
40
|
-
async
|
|
40
|
+
async listenSensors() {
|
|
41
41
|
if (this.hasAccInput) {
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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; }
|
package/src/FaustWebAudioDsp.ts
CHANGED
|
@@ -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"]
|
|
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
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
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; }
|
|
@@ -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;
|