@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.
@@ -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
  /**
@@ -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
- listenMotion(): Promise<void>;
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"]>): void;
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
- listenMotion(): Promise<void>;
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"]>): void;
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
  }
package/dist/esm/index.js CHANGED
@@ -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;
@@ -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 listenMotion() {
3659
+ async listenSensors() {
3651
3660
  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
- };
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 listenMotion() {
3930
+ async listenSensors() {
3909
3931
  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
- };
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;