@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.
@@ -25,6 +25,7 @@ const AudioCtx = window.AudioContext || window.webkitAudioContext;
25
25
  const audioContext = new AudioCtx({ latencyHint: 0.00001, echoCancellation: false, autoGainControl: false, noiseSuppression: false });
26
26
  audioContext.destination.channelInterpretation = "discrete";
27
27
  audioContext.suspend();
28
+ $buttonDsp.disabled = true;
28
29
 
29
30
  /**
30
31
  * @param {FaustAudioWorkletNode} faustNode
@@ -107,17 +108,6 @@ const buildMidiDeviceMenu = async (faustNode) => {
107
108
  };
108
109
  };
109
110
 
110
- $buttonDsp.disabled = true;
111
- $buttonDsp.onclick = () => {
112
- if (audioContext.state === "running") {
113
- $buttonDsp.textContent = "Suspended";
114
- audioContext.suspend();
115
- } else if (audioContext.state === "suspended") {
116
- $buttonDsp.textContent = "Running";
117
- audioContext.resume();
118
- }
119
- }
120
-
121
111
  /**
122
112
  * Creates a Faust audio node for use in the Web Audio API.
123
113
  *
@@ -216,4 +206,18 @@ const createFaustUI = async (faustNode) => {
216
206
  else $spanMidiInput.hidden = true;
217
207
  $buttonDsp.disabled = false;
218
208
  document.title = name;
209
+ let motionHandlersBound = false;
210
+ $buttonDsp.onclick = async () => {
211
+ if (!motionHandlersBound) {
212
+ await faustNode.listenSensors();
213
+ motionHandlersBound = true;
214
+ }
215
+ if (audioContext.state === "running") {
216
+ $buttonDsp.textContent = "Suspended";
217
+ audioContext.suspend();
218
+ } else if (audioContext.state === "suspended") {
219
+ $buttonDsp.textContent = "Running";
220
+ audioContext.resume();
221
+ }
222
+ }
219
223
  })();
@@ -211,7 +211,7 @@ const createFaustUI = async (faustNode) => {
211
211
  let motionHandlersBound = false;
212
212
  $buttonDsp.onclick = async () => {
213
213
  if (!motionHandlersBound) {
214
- await faustNode.listenMotion();
214
+ await faustNode.listenSensors();
215
215
  motionHandlersBound = true;
216
216
  }
217
217
  if (audioContext.state === "running") {
package/build ADDED
@@ -0,0 +1,17 @@
1
+ node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/atomicro/atomicro.dsp /Users/letz/Developpements/sletz.github.io/atomicro -standalone
2
+
3
+ node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/attackey/attackey.dsp /Users/letz/Developpements/sletz.github.io/attackey -standalone
4
+
5
+ node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/baliphone/baliphone.dsp /Users/letz/Developpements/sletz.github.io/baliphone -standalone
6
+
7
+ node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/drone/drone.dsp /Users/letz/Developpements/sletz.github.io/drone -standalone
8
+
9
+ node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/sequenceur/sequenceur.dsp /Users/letz/Developpements/sletz.github.io/sequenceur -standalone
10
+
11
+ node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/shakerxy/shakerxy.dsp /Users/letz/Developpements/sletz.github.io/shakerxy -standalone
12
+
13
+ node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/sinusoide/sinusoide.dsp /Users/letz/Developpements/sletz.github.io/sinusoide -standalone
14
+
15
+
16
+ #node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/test.dsp /Users/letz/Developpements/sletz.github.io/out -standalone
17
+ #node scripts/faust2wasm.js test/organ.dsp /Users/letz/Developpements/sletz.github.io/organ -poly -standalone
@@ -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/cjs/index.js CHANGED
@@ -168,7 +168,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
168
168
  const msg = e.data;
169
169
  switch (msg.type) {
170
170
  case "acc": {
171
- this.propagateAcc(msg.data);
171
+ this.propagateAcc(msg.data, msg.invert);
172
172
  break;
173
173
  }
174
174
  case "gyr": {
@@ -229,8 +229,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
229
229
  pitchWheel(channel, wheel) {
230
230
  this.fDSPCode.pitchWheel(channel, wheel);
231
231
  }
232
- propagateAcc(accelerationIncludingGravity) {
233
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
232
+ propagateAcc(accelerationIncludingGravity, invert = false) {
233
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
234
234
  }
235
235
  propagateGyr(event) {
236
236
  this.fDSPCode.propagateGyr(event);
@@ -2133,14 +2133,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
2133
2133
  get hasAccInput() {
2134
2134
  return this.fAcc.x.length + this.fAcc.y.length + this.fAcc.z.length > 0;
2135
2135
  }
2136
- propagateAcc(accelerationIncludingGravity) {
2136
+ propagateAcc(accelerationIncludingGravity, invert = false) {
2137
2137
  const { x, y, z } = accelerationIncludingGravity;
2138
- if (x !== null)
2139
- this.fAcc.x.forEach((handler) => handler(x));
2140
- if (y !== null)
2141
- this.fAcc.y.forEach((handler) => handler(y));
2142
- if (z !== null)
2143
- this.fAcc.z.forEach((handler) => handler(z));
2138
+ if (invert) {
2139
+ if (x !== null)
2140
+ this.fAcc.x.forEach((handler) => handler(-x));
2141
+ if (y !== null)
2142
+ this.fAcc.y.forEach((handler) => handler(-y));
2143
+ if (z !== null)
2144
+ this.fAcc.z.forEach((handler) => handler(-z));
2145
+ } else {
2146
+ if (x !== null)
2147
+ this.fAcc.x.forEach((handler) => handler(x));
2148
+ if (y !== null)
2149
+ this.fAcc.y.forEach((handler) => handler(y));
2150
+ if (z !== null)
2151
+ this.fAcc.z.forEach((handler) => handler(z));
2152
+ }
2144
2153
  }
2145
2154
  get hasGyrInput() {
2146
2155
  return this.fGyr.x.length + this.fGyr.y.length + this.fGyr.z.length > 0;
@@ -3000,8 +3009,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3000
3009
  get hasAccInput() {
3001
3010
  return this.fDSPCode.hasAccInput;
3002
3011
  }
3003
- propagateAcc(accelerationIncludingGravity) {
3004
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
3012
+ propagateAcc(accelerationIncludingGravity, invert = false) {
3013
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
3005
3014
  }
3006
3015
  get hasGyrInput() {
3007
3016
  return this.fDSPCode.hasGyrInput;
@@ -3677,14 +3686,27 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3677
3686
  }
3678
3687
  // Public API
3679
3688
  /** Setup accelerometer and gyroscope handlers */
3680
- async listenMotion() {
3689
+ async listenSensors() {
3681
3690
  if (this.hasAccInput) {
3682
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3683
- if (!accelerationIncludingGravity)
3684
- return;
3685
- const { x, y, z } = accelerationIncludingGravity;
3686
- this.propagateAcc({ x, y, z });
3687
- };
3691
+ const isAndroid = /Android/i.test(navigator.userAgent);
3692
+ console.log(navigator.userAgent);
3693
+ console.log(isAndroid);
3694
+ let handleDeviceMotion = null;
3695
+ if (isAndroid) {
3696
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3697
+ if (!accelerationIncludingGravity)
3698
+ return;
3699
+ const { x, y, z } = accelerationIncludingGravity;
3700
+ this.propagateAcc({ x, y, z }, true);
3701
+ };
3702
+ } else {
3703
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3704
+ if (!accelerationIncludingGravity)
3705
+ return;
3706
+ const { x, y, z } = accelerationIncludingGravity;
3707
+ this.propagateAcc({ x, y, z });
3708
+ };
3709
+ }
3688
3710
  if (window.DeviceMotionEvent) {
3689
3711
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3690
3712
  try {
@@ -3785,10 +3807,10 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3785
3807
  get hasAccInput() {
3786
3808
  return __privateGet(this, _hasAccInput);
3787
3809
  }
3788
- propagateAcc(accelerationIncludingGravity) {
3810
+ propagateAcc(accelerationIncludingGravity, invert = false) {
3789
3811
  if (!accelerationIncludingGravity)
3790
3812
  return;
3791
- const e = { type: "acc", data: accelerationIncludingGravity };
3813
+ const e = { type: "acc", data: accelerationIncludingGravity, invert };
3792
3814
  this.port.postMessage(e);
3793
3815
  }
3794
3816
  get hasGyrInput() {
@@ -3935,14 +3957,25 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
3935
3957
  }
3936
3958
  // Public API
3937
3959
  /** Setup accelerometer and gyroscope handlers */
3938
- async listenMotion() {
3960
+ async listenSensors() {
3939
3961
  if (this.hasAccInput) {
3940
- const handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3941
- if (!accelerationIncludingGravity)
3942
- return;
3943
- const { x, y, z } = accelerationIncludingGravity;
3944
- this.propagateAcc({ x, y, z });
3945
- };
3962
+ const isAndroid = /Android/i.test(navigator.userAgent);
3963
+ let handleDeviceMotion = null;
3964
+ if (isAndroid) {
3965
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3966
+ if (!accelerationIncludingGravity)
3967
+ return;
3968
+ const { x, y, z } = accelerationIncludingGravity;
3969
+ this.propagateAcc({ x, y, z }, true);
3970
+ };
3971
+ } else {
3972
+ handleDeviceMotion = ({ accelerationIncludingGravity }) => {
3973
+ if (!accelerationIncludingGravity)
3974
+ return;
3975
+ const { x, y, z } = accelerationIncludingGravity;
3976
+ this.propagateAcc({ x, y, z });
3977
+ };
3978
+ }
3946
3979
  if (window.DeviceMotionEvent) {
3947
3980
  if (typeof window.DeviceMotionEvent.requestPermission === "function") {
3948
3981
  try {
@@ -4053,8 +4086,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
4053
4086
  get hasAccInput() {
4054
4087
  return this.fDSPCode.hasAccInput;
4055
4088
  }
4056
- propagateAcc(accelerationIncludingGravity) {
4057
- this.fDSPCode.propagateAcc(accelerationIncludingGravity);
4089
+ propagateAcc(accelerationIncludingGravity, invert = false) {
4090
+ this.fDSPCode.propagateAcc(accelerationIncludingGravity, invert);
4058
4091
  }
4059
4092
  get hasGyrInput() {
4060
4093
  return this.fDSPCode.hasGyrInput;