@grame/faustwasm 0.7.10 → 0.8.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.
Files changed (38) hide show
  1. package/README.md +2 -2
  2. package/assets/standalone/create-node.js +31 -1
  3. package/assets/standalone/faust-ui/index.js +2 -2
  4. package/assets/standalone/faust-ui/index.js.map +1 -1
  5. package/assets/standalone/faustwasm/index.d.ts +76 -9
  6. package/assets/standalone/faustwasm/index.js +272 -107
  7. package/assets/standalone/faustwasm/index.js.map +4 -4
  8. package/assets/standalone/index-pwa.js +132 -98
  9. package/assets/standalone/index-template.js +44 -23
  10. package/assets/standalone/index.js +95 -80
  11. package/assets/standalone/service-worker.js +47 -8
  12. package/dist/cjs/index.d.ts +76 -9
  13. package/dist/cjs/index.js +272 -107
  14. package/dist/cjs/index.js.map +4 -4
  15. package/dist/cjs-bundle/index.d.ts +76 -9
  16. package/dist/cjs-bundle/index.js +272 -107
  17. package/dist/cjs-bundle/index.js.map +4 -4
  18. package/dist/esm/index.d.ts +76 -9
  19. package/dist/esm/index.js +272 -107
  20. package/dist/esm/index.js.map +4 -4
  21. package/dist/esm-bundle/index.d.ts +76 -9
  22. package/dist/esm-bundle/index.js +272 -107
  23. package/dist/esm-bundle/index.js.map +4 -4
  24. package/package.json +2 -2
  25. package/src/FaustAudioWorkletCommunicator.ts +143 -0
  26. package/src/FaustAudioWorkletNode.ts +27 -42
  27. package/src/FaustAudioWorkletProcessor.ts +34 -15
  28. package/src/FaustDspGenerator.ts +20 -2
  29. package/src/FaustFFTAudioWorkletProcessor.ts +31 -2
  30. package/src/FaustOfflineProcessor.ts +6 -0
  31. package/src/FaustScriptProcessorNode.ts +8 -31
  32. package/src/FaustWebAudioDsp.ts +38 -10
  33. package/test/faustlive-wasm/faust-ui/index.js +2 -2
  34. package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
  35. package/test/faustlive-wasm/faustwasm/index.d.ts +76 -9
  36. package/test/faustlive-wasm/faustwasm/index.js +272 -107
  37. package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
  38. package/assets/standalone/coi-serviceworker.js +0 -146
@@ -230,6 +230,49 @@ interface AudioData$1 {
230
230
  * @param wasmFile path to `libfaust-wasm.wasm`
231
231
  */
232
232
  export declare const instantiateFaustModuleFromFile: (jsFile: string, dataFile?: string, wasmFile?: string) => Promise<FaustModule>;
233
+ declare class FaustAudioWorkletCommunicator {
234
+ protected readonly port: MessagePort;
235
+ protected readonly supportSharedArrayBuffer: boolean;
236
+ protected readonly byteLength: number;
237
+ protected uin8Invert: Uint8ClampedArray;
238
+ protected uin8NewAccData: Uint8ClampedArray;
239
+ protected uin8NewGyrData: Uint8ClampedArray;
240
+ protected f32Acc: Float32Array;
241
+ protected f32Gyr: Float32Array;
242
+ constructor(port: MessagePort);
243
+ initializeBuffer(ab: SharedArrayBuffer | ArrayBuffer): void;
244
+ setNewAccDataAvailable(value: boolean): void;
245
+ getNewAccDataAvailable(): boolean;
246
+ setNewGyrDataAvailable(value: boolean): void;
247
+ getNewGyrDataAvailable(): boolean;
248
+ setAcc({ x, y, z }: {
249
+ x: number;
250
+ y: number;
251
+ z: number;
252
+ }, invert?: boolean): void;
253
+ getAcc(): {
254
+ x: number;
255
+ y: number;
256
+ z: number;
257
+ invert: boolean;
258
+ } | undefined;
259
+ setGyr({ alpha, beta, gamma }: {
260
+ alpha: number;
261
+ beta: number;
262
+ gamma: number;
263
+ }): void;
264
+ getGyr(): {
265
+ alpha: number;
266
+ beta: number;
267
+ gamma: number;
268
+ } | undefined;
269
+ }
270
+ declare class FaustAudioWorkletNodeCommunicator extends FaustAudioWorkletCommunicator {
271
+ constructor(port: MessagePort);
272
+ }
273
+ declare class FaustAudioWorkletProcessorCommunicator extends FaustAudioWorkletCommunicator {
274
+ constructor(port: MessagePort);
275
+ }
233
276
  /**
234
277
  * The Faust wasm instance interface.
235
278
  */
@@ -620,6 +663,29 @@ export interface IFaustBaseWebAudioDsp {
620
663
  * @return the DSP JSON description
621
664
  */
622
665
  getJSON(): string;
666
+ /**
667
+ * Start accelerometer and gyroscope handlers.
668
+ */
669
+ startSensors(): void;
670
+ /**
671
+ * Stop accelerometer and gyroscope handlers.
672
+ */
673
+ stopSensors(): void;
674
+ /** Indicating if the DSP handles the accelerometer */
675
+ readonly hasAccInput: boolean;
676
+ /**
677
+ * Accelerometer handling.
678
+ * accelerationIncludingGravity: DeviceMotionEvent["accelerationIncludingGravity"]
679
+ * invert: boolean
680
+ */
681
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
682
+ /** Indicating if the DSP handles the gyroscope */
683
+ readonly hasGyrInput: boolean;
684
+ /**
685
+ * Gyroscope handling.
686
+ * event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">
687
+ */
688
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
623
689
  /**
624
690
  * Start the DSP audio processing.
625
691
  */
@@ -632,14 +698,6 @@ export interface IFaustBaseWebAudioDsp {
632
698
  * Destroy the DSP.
633
699
  */
634
700
  destroy(): void;
635
- /** Indicating if the DSP handles the accelerometer */
636
- readonly hasAccInput: boolean;
637
- /** Accelerometer handling */
638
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): 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;
643
701
  }
644
702
  export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp {
645
703
  }
@@ -777,6 +835,8 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
777
835
  getUI(): FaustUIDescriptor;
778
836
  getDescriptors(): FaustUIInputItem[];
779
837
  hasSoundfiles(): boolean;
838
+ startSensors(): void;
839
+ stopSensors(): void;
780
840
  start(): void;
781
841
  stop(): void;
782
842
  destroy(): void;
@@ -876,6 +936,7 @@ export interface FaustAudioWorkletProcessorDependencies<Poly extends boolean = f
876
936
  FaustPolyWebAudioDsp: Poly extends true ? typeof FaustPolyWebAudioDsp : undefined;
877
937
  FaustWebAudioDspVoice: Poly extends true ? typeof FaustWebAudioDspVoice : undefined;
878
938
  FaustWasmInstantiator: typeof FaustWasmInstantiator;
939
+ FaustAudioWorkletProcessorCommunicator: typeof FaustAudioWorkletProcessorCommunicator;
879
940
  }
880
941
  export interface FaustAudioWorkletNodeOptions<Poly extends boolean = false> extends AudioWorkletNodeOptions {
881
942
  processorOptions: Poly extends true ? FaustPolyAudioWorkletProcessorOptions : FaustMonoAudioWorkletProcessorOptions;
@@ -926,6 +987,7 @@ export interface FaustFFTAudioWorkletProcessorDependencies {
926
987
  FaustBaseWebAudioDsp: typeof FaustBaseWebAudioDsp;
927
988
  FaustMonoWebAudioDsp: typeof FaustMonoWebAudioDsp;
928
989
  FaustWasmInstantiator: typeof FaustWasmInstantiator;
990
+ FaustAudioWorkletProcessorCommunicator: typeof FaustAudioWorkletProcessorCommunicator;
929
991
  FFTUtils: typeof FFTUtils;
930
992
  }
931
993
  export interface FaustFFTAudioWorkletNodeOptions extends AudioWorkletNodeOptions {
@@ -1132,6 +1194,8 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1132
1194
  propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1133
1195
  get hasGyrInput(): boolean;
1134
1196
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1197
+ startSensors(): void;
1198
+ stopSensors(): void;
1135
1199
  /**
1136
1200
  * Render frames in an array.
1137
1201
  *
@@ -1288,7 +1352,9 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1288
1352
  protected fPlotHandler: PlotHandler | null;
1289
1353
  protected fUICallback: UIHandler;
1290
1354
  protected fDescriptor: FaustUIInputItem[];
1355
+ protected fCommunicator: FaustAudioWorkletNodeCommunicator;
1291
1356
  constructor(context: BaseAudioContext, name: string, factory: LooseFaustDspFactory, options?: Partial<FaustAudioWorkletNodeOptions<Poly>>);
1357
+ protected handleMessageAux: (e: MessageEvent) => void;
1292
1358
  private handleDeviceMotion;
1293
1359
  private handleDeviceOrientation;
1294
1360
  /** Setup accelerometer and gyroscope handlers */
@@ -1358,8 +1424,9 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1358
1424
  protected handleDeviceMotion: any;
1359
1425
  protected handleDeviceOrientation: any;
1360
1426
  init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1361
- /** Setup accelerometer and gyroscope handlers */
1427
+ /** Start accelerometer and gyroscope handlers */
1362
1428
  startSensors(): Promise<void>;
1429
+ /** Stop accelerometer and gyroscope handlers */
1363
1430
  stopSensors(): void;
1364
1431
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1365
1432
  setOutputParamHandler(handler: OutputParamHandler): void;