@grame/faustwasm 0.2.2 → 0.3.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.
@@ -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
  *
@@ -207,6 +197,8 @@ const createFaustUI = async (faustNode) => {
207
197
  };
208
198
 
209
199
  (async () => {
200
+ // To test the ScriptProcessorNode mode
201
+ //const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP", 0, true);
210
202
  const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP");
211
203
  await createFaustUI(faustNode);
212
204
  faustNode.connect(audioContext.destination);
@@ -216,4 +208,18 @@ const createFaustUI = async (faustNode) => {
216
208
  else $spanMidiInput.hidden = true;
217
209
  $buttonDsp.disabled = false;
218
210
  document.title = name;
211
+ let motionHandlersBound = false;
212
+ $buttonDsp.onclick = async () => {
213
+ if (!motionHandlersBound) {
214
+ await faustNode.listenMotion();
215
+ motionHandlersBound = true;
216
+ }
217
+ if (audioContext.state === "running") {
218
+ $buttonDsp.textContent = "Suspended";
219
+ audioContext.suspend();
220
+ } else if (audioContext.state === "suspended") {
221
+ $buttonDsp.textContent = "Running";
222
+ audioContext.resume();
223
+ }
224
+ }
219
225
  })();
@@ -376,6 +376,12 @@ export type PlotHandler = (plotted: Float32Array[] | Float64Array[], index: numb
376
376
  }[]) => void;
377
377
  export type MetadataHandler = (key: string, value: string) => void;
378
378
  export type UIHandler = (item: FaustUIItem) => void;
379
+ export type SensorEventHandler = (val: number) => void;
380
+ export type SensorEventHandlers = {
381
+ x: SensorEventHandler[];
382
+ y: SensorEventHandler[];
383
+ z: SensorEventHandler[];
384
+ };
379
385
  /** Definition of the AudioBufferItem type */
380
386
  export interface AudioBufferItem {
381
387
  pathName: string;
@@ -481,10 +487,10 @@ export declare class Soundfile {
481
487
  getHEAPFloat64(): Float64Array;
482
488
  }
483
489
  /**
484
- * DSP implementation: mimic the C++ 'dsp' class:
490
+ * DSP implementation that mimic the C++ 'dsp' class:
485
491
  * - adding MIDI control: metadata are decoded and incoming MIDI messages will control the associated controllers
486
492
  * - an output handler can be set to treat produced output controllers (like 'bargraph')
487
- * - regular controllers are handled using setParamValue/getParamValue
493
+ * - regular controllers are handled using setParamValue/getParamValue and getParams methods
488
494
  */
489
495
  export interface IFaustBaseWebAudioDsp {
490
496
  /**
@@ -596,12 +602,6 @@ export interface IFaustBaseWebAudioDsp {
596
602
  * @return the DSP JSON description as object
597
603
  */
598
604
  getMeta(): FaustDspMeta;
599
- /**
600
- * Get DSP JSON description with its UI and metadata.
601
- *
602
- * @return the DSP JSON description
603
- */
604
- getJSON(): string;
605
605
  /**
606
606
  * Get DSP UI description.
607
607
  *
@@ -614,6 +614,12 @@ export interface IFaustBaseWebAudioDsp {
614
614
  * @return the DSP UI items description
615
615
  */
616
616
  getDescriptors(): FaustUIInputItem[];
617
+ /**
618
+ * Get DSP JSON description with its UI and metadata.
619
+ *
620
+ * @return the DSP JSON description
621
+ */
622
+ getJSON(): string;
617
623
  /**
618
624
  * Start the DSP.
619
625
  */
@@ -626,6 +632,14 @@ export interface IFaustBaseWebAudioDsp {
626
632
  * Destroy the DSP.
627
633
  */
628
634
  destroy(): void;
635
+ /** Indicating if the DSP handles the accelerometer */
636
+ readonly hasAccInput: boolean;
637
+ /** Accelerometer handling */
638
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
639
+ /** Indicating if the DSP handles the gyroscope */
640
+ readonly hasGyrInput: boolean;
641
+ /** Gyroscope handling */
642
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
629
643
  }
630
644
  export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp {
631
645
  }
@@ -676,6 +690,8 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
676
690
  protected fSoundfileBuffers: LooseFaustDspFactory["soundfiles"];
677
691
  /** Keep the end of memory offset before soundfiles */
678
692
  protected fEndMemory: number;
693
+ protected fAcc: SensorEventHandlers;
694
+ protected fGyr: SensorEventHandlers;
679
695
  protected fAudioInputs: number;
680
696
  protected fAudioOutputs: number;
681
697
  protected fBufferSize: number;
@@ -707,6 +723,14 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
707
723
  static parseItem(item: FaustUIItem, callback: (item: FaustUIItem) => any): void;
708
724
  /** Split the soundfile names and return an array of names */
709
725
  static splitSoundfileNames(input: string): string[];
726
+ get hasAccInput(): boolean;
727
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
728
+ get hasGyrInput(): boolean;
729
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
730
+ /** Build the accelerometer handler */
731
+ private setupAccHandler;
732
+ /** Build the gyroscope handler */
733
+ private setupGyrHandler;
710
734
  static extractUrlsFromMeta(dspMeta: FaustDspMeta): string[];
711
735
  /**
712
736
  * Load a soundfile possibly containing several parts in the DSP struct.
@@ -1098,6 +1122,10 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1098
1122
  start(): void;
1099
1123
  stop(): void;
1100
1124
  destroy(): void;
1125
+ get hasAccInput(): boolean;
1126
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1127
+ get hasGyrInput(): boolean;
1128
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1101
1129
  /**
1102
1130
  * Render frames in an array.
1103
1131
  *
@@ -1239,6 +1267,7 @@ declare const FaustAudioWorkletNode_base: {
1239
1267
  * Base class for Monophonic and Polyphonic AudioWorkletNode
1240
1268
  */
1241
1269
  export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends FaustAudioWorkletNode_base {
1270
+ #private;
1242
1271
  protected fJSONDsp: FaustDspMeta;
1243
1272
  protected fJSON: string;
1244
1273
  protected fInputsItems: string[];
@@ -1248,6 +1277,8 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1248
1277
  protected fUICallback: UIHandler;
1249
1278
  protected fDescriptor: FaustUIInputItem[];
1250
1279
  constructor(context: BaseAudioContext, name: string, factory: LooseFaustDspFactory, options: FaustAudioWorkletNodeOptions<Poly>["processorOptions"], nodeOptions?: Partial<FaustAudioWorkletNodeOptions>);
1280
+ /** Setup accelerometer and gyroscope handlers */
1281
+ listenMotion(): Promise<void>;
1251
1282
  setOutputParamHandler(handler: OutputParamHandler | null): void;
1252
1283
  getOutputParamHandler(): OutputParamHandler | null;
1253
1284
  setComputeHandler(handler: ComputeHandler | null): void;
@@ -1261,6 +1292,10 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1261
1292
  midiMessage(data: number[] | Uint8Array): void;
1262
1293
  ctrlChange(channel: number, ctrl: number, value: number): void;
1263
1294
  pitchWheel(channel: number, wheel: number): void;
1295
+ get hasAccInput(): boolean;
1296
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1297
+ get hasGyrInput(): boolean;
1298
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1264
1299
  setParamValue(path: string, value: number): void;
1265
1300
  getParamValue(path: string): number;
1266
1301
  getParams(): string[];
@@ -1305,6 +1340,8 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1305
1340
  protected fInputs: Float32Array[];
1306
1341
  protected fOutputs: Float32Array[];
1307
1342
  init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1343
+ /** Setup accelerometer and gyroscope handlers */
1344
+ listenMotion(): Promise<void>;
1308
1345
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1309
1346
  setOutputParamHandler(handler: OutputParamHandler): void;
1310
1347
  getOutputParamHandler(): OutputParamHandler | null;
@@ -1328,6 +1365,10 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1328
1365
  start(): void;
1329
1366
  stop(): void;
1330
1367
  destroy(): void;
1368
+ get hasAccInput(): boolean;
1369
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>): void;
1370
+ get hasGyrInput(): boolean;
1371
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1331
1372
  }
1332
1373
  export declare class FaustMonoScriptProcessorNode extends FaustScriptProcessorNode<false> implements IFaustMonoWebAudioDsp {
1333
1374
  }