@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.
@@ -642,7 +642,7 @@ export interface IFaustBaseWebAudioDsp {
642
642
  /** Indicating if the DSP handles the accelerometer */
643
643
  readonly hasAccInput: boolean;
644
644
  /** Accelerometer handling */
645
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
645
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
646
646
  /** Indicating if the DSP handles the gyroscope */
647
647
  readonly hasGyrInput: boolean;
648
648
  /** Gyroscope handling */
@@ -731,7 +731,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
731
731
  /** Split the soundfile names and return an array of names */
732
732
  static splitSoundfileNames(input: string): string[];
733
733
  get hasAccInput(): boolean;
734
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
734
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
735
735
  get hasGyrInput(): boolean;
736
736
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
737
737
  /** Build the accelerometer handler */
@@ -1130,7 +1130,7 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1130
1130
  stop(): void;
1131
1131
  destroy(): void;
1132
1132
  get hasAccInput(): boolean;
1133
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1133
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1134
1134
  get hasGyrInput(): boolean;
1135
1135
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1136
1136
  /**
@@ -1218,6 +1218,12 @@ export declare class WavDecoder {
1218
1218
  /** Read metadata and fetch soundfiles */
1219
1219
  export declare class SoundfileReader {
1220
1220
  static get fallbackPaths(): string[];
1221
+ /**
1222
+ * Extract the parent URL from an URL.
1223
+ * @param url : the URL
1224
+ * @returns : the parent URL
1225
+ */
1226
+ private static getParentUrl;
1221
1227
  /**
1222
1228
  * Convert an audio buffer to audio data.
1223
1229
  *
@@ -1300,7 +1306,7 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1300
1306
  ctrlChange(channel: number, ctrl: number, value: number): void;
1301
1307
  pitchWheel(channel: number, wheel: number): void;
1302
1308
  get hasAccInput(): boolean;
1303
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1309
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1304
1310
  get hasGyrInput(): boolean;
1305
1311
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1306
1312
  setParamValue(path: string, value: number): void;
@@ -1373,7 +1379,7 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1373
1379
  stop(): void;
1374
1380
  destroy(): void;
1375
1381
  get hasAccInput(): boolean;
1376
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1382
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1377
1383
  get hasGyrInput(): boolean;
1378
1384
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1379
1385
  }
@@ -6140,7 +6140,7 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
6140
6140
  const msg = e.data;
6141
6141
  switch (msg.type) {
6142
6142
  case "acc": {
6143
- this.propagateAcc(msg.data);
6143
+ this.propagateAcc(msg.data, msg.invert);
6144
6144
  break;
6145
6145
  }
6146
6146
  case "gyr": {
@@ -6201,8 +6201,8 @@ var getFaustAudioWorkletProcessor = (dependencies, faustData, register = true) =
6201
6201
  pitchWheel(channel, wheel) {
6202
6202
  this.fDSPCode.pitchWheel(channel, wheel);
6203
6203
  }
6204
- propagateAcc(accelerationIncludingGravity) {
6205
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
6204
+ propagateAcc(accelerationIncludingGravity, invert = false) {
6205
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
6206
6206
  }
6207
6207
  propagateGyr(event) {
6208
6208
  this.fDSPCode.propagateGyr(event);
@@ -8105,14 +8105,23 @@ var FaustBaseWebAudioDsp = class _FaustBaseWebAudioDsp {
8105
8105
  get hasAccInput() {
8106
8106
  return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
8107
8107
  }
8108
- propagateAcc(accelerationIncludingGravity) {
8108
+ propagateAcc(accelerationIncludingGravity, invert = false) {
8109
8109
  const { x, y, z } = accelerationIncludingGravity;
8110
- if (x !== null)
8111
- this.fAcc.x.forEach((handler) => handler(x));
8112
- if (y !== null)
8113
- this.fAcc.y.forEach((handler) => handler(y));
8114
- if (z !== null)
8115
- this.fAcc.z.forEach((handler) => handler(z));
8110
+ if (invert) {
8111
+ if (x !== null)
8112
+ this.fAcc.x.forEach((handler) => handler(-x));
8113
+ if (y !== null)
8114
+ this.fAcc.y.forEach((handler) => handler(-y));
8115
+ if (z !== null)
8116
+ this.fAcc.z.forEach((handler) => handler(-z));
8117
+ } else {
8118
+ if (x !== null)
8119
+ this.fAcc.x.forEach((handler) => handler(x));
8120
+ if (y !== null)
8121
+ this.fAcc.y.forEach((handler) => handler(y));
8122
+ if (z !== null)
8123
+ this.fAcc.z.forEach((handler) => handler(z));
8124
+ }
8116
8125
  }
8117
8126
  get hasGyrInput() {
8118
8127
  return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0;
@@ -8972,8 +8981,8 @@ var FaustOfflineProcessor = class {
8972
8981
  get hasAccInput() {
8973
8982
  return this.fDSPCode.hasAccInput;
8974
8983
  }
8975
- propagateAcc(accelerationIncludingGravity) {
8976
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
8984
+ propagateAcc(accelerationIncludingGravity, invert = false) {
8985
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
8977
8986
  }
8978
8987
  get hasGyrInput() {
8979
8988
  return this.fDSPCode.hasGyrInput;
@@ -9489,8 +9498,17 @@ var WavDecoder_default = WavDecoder;
9489
9498
 
9490
9499
  // src/SoundfileReader.ts
9491
9500
  var SoundfileReader = class {
9501
+ // Set the fallback paths
9492
9502
  static get fallbackPaths() {
9493
- return [location.href, location.origin];
9503
+ return [location.href, this.getParentUrl(location.href), location.origin];
9504
+ }
9505
+ /**
9506
+ * Extract the parent URL from an URL.
9507
+ * @param url : the URL
9508
+ * @returns : the parent URL
9509
+ */
9510
+ static getParentUrl(url) {
9511
+ return url.substring(0, url.lastIndexOf("/") + 1);
9494
9512
  }
9495
9513
  /**
9496
9514
  * Convert an audio buffer to audio data.
@@ -9531,7 +9549,8 @@ var SoundfileReader = class {
9531
9549
  static async checkFileExists(url) {
9532
9550
  try {
9533
9551
  console.log(`"checkFileExists" url: ${url}`);
9534
- const response = await fetch(url, { method: "HEAD" });
9552
+ const response = await fetch(url);
9553
+ console.log(`"checkFileExists" response.ok: ${response.ok}`);
9535
9554
  return response.ok;
9536
9555
  } catch (error) {
9537
9556
  console.error("Fetch error:", error);
@@ -9651,12 +9670,23 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
9651
9670
  /** Setup accelerometer and gyroscope handlers */
9652
9671
  async listenSensors() {
9653
9672
  if (this.hasAccInput) {
9654
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9655
- if (!accelerationIncludingGravity)
9656
- return;
9657
- const { x, y, z } = accelerationIncludingGravity;
9658
- this.propagateAcc({ x, y, z });
9659
- };
9673
+ const isAndroid = /Android/i.test(navigator.userAgent);
9674
+ let handleDeviceMotion = null;
9675
+ if (isAndroid) {
9676
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9677
+ if (!accelerationIncludingGravity)
9678
+ return;
9679
+ const { x, y, z } = accelerationIncludingGravity;
9680
+ this.propagateAcc({ x, y, z }, true);
9681
+ };
9682
+ } else {
9683
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9684
+ if (!accelerationIncludingGravity)
9685
+ return;
9686
+ const { x, y, z } = accelerationIncludingGravity;
9687
+ this.propagateAcc({ x, y, z });
9688
+ };
9689
+ }
9660
9690
  if (window.DeviceMotionEvent) {
9661
9691
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
9662
9692
  try {
@@ -9757,10 +9787,10 @@ var FaustAudioWorkletNode = class extends (globalThis.AudioWorkletNode || null)
9757
9787
  get hasAccInput() {
9758
9788
  return __privateGet(this, _hasAccInput);
9759
9789
  }
9760
- propagateAcc(accelerationIncludingGravity) {
9790
+ propagateAcc(accelerationIncludingGravity, invert = false) {
9761
9791
  if (!accelerationIncludingGravity)
9762
9792
  return;
9763
- const e = { type: "acc", data: accelerationIncludingGravity };
9793
+ const e = { type: "acc", data: accelerationIncludingGravity, invert };
9764
9794
  this.port.postMessage(e);
9765
9795
  }
9766
9796
  get hasGyrInput() {
@@ -9909,12 +9939,23 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
9909
9939
  /** Setup accelerometer and gyroscope handlers */
9910
9940
  async listenSensors() {
9911
9941
  if (this.hasAccInput) {
9912
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9913
- if (!accelerationIncludingGravity)
9914
- return;
9915
- const { x, y, z } = accelerationIncludingGravity;
9916
- this.propagateAcc({ x, y, z });
9917
- };
9942
+ const isAndroid = /Android/i.test(navigator.userAgent);
9943
+ let handleDeviceMotion = null;
9944
+ if (isAndroid) {
9945
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9946
+ if (!accelerationIncludingGravity)
9947
+ return;
9948
+ const { x, y, z } = accelerationIncludingGravity;
9949
+ this.propagateAcc({ x, y, z }, true);
9950
+ };
9951
+ } else {
9952
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
9953
+ if (!accelerationIncludingGravity)
9954
+ return;
9955
+ const { x, y, z } = accelerationIncludingGravity;
9956
+ this.propagateAcc({ x, y, z });
9957
+ };
9958
+ }
9918
9959
  if (window.DeviceMotionEvent) {
9919
9960
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
9920
9961
  try {
@@ -10025,8 +10066,8 @@ var FaustScriptProcessorNode = class extends (globalThis.ScriptProcessorNode ||
10025
10066
  get hasAccInput() {
10026
10067
  return this.fDSPCode.hasAccInput;
10027
10068
  }
10028
- propagateAcc(accelerationIncludingGravity) {
10029
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
10069
+ propagateAcc(accelerationIncludingGravity, invert = false) {
10070
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
10030
10071
  }
10031
10072
  get hasGyrInput() {
10032
10073
  return this.fDSPCode.hasGyrInput;