@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
@@ -237,6 +237,49 @@ export declare const instantiateFaustModule: (FaustModuleFactoryIn?: FaustModule
237
237
  * @param wasmFile path to `libfaust-wasm.wasm`
238
238
  */
239
239
  export declare const instantiateFaustModuleFromFile: (jsFile: string, dataFile?: string, wasmFile?: string) => Promise<FaustModule>;
240
+ declare class FaustAudioWorkletCommunicator {
241
+ protected readonly port: MessagePort;
242
+ protected readonly supportSharedArrayBuffer: boolean;
243
+ protected readonly byteLength: number;
244
+ protected uin8Invert: Uint8ClampedArray;
245
+ protected uin8NewAccData: Uint8ClampedArray;
246
+ protected uin8NewGyrData: Uint8ClampedArray;
247
+ protected f32Acc: Float32Array;
248
+ protected f32Gyr: Float32Array;
249
+ constructor(port: MessagePort);
250
+ initializeBuffer(ab: SharedArrayBuffer | ArrayBuffer): void;
251
+ setNewAccDataAvailable(value: boolean): void;
252
+ getNewAccDataAvailable(): boolean;
253
+ setNewGyrDataAvailable(value: boolean): void;
254
+ getNewGyrDataAvailable(): boolean;
255
+ setAcc({ x, y, z }: {
256
+ x: number;
257
+ y: number;
258
+ z: number;
259
+ }, invert?: boolean): void;
260
+ getAcc(): {
261
+ x: number;
262
+ y: number;
263
+ z: number;
264
+ invert: boolean;
265
+ } | undefined;
266
+ setGyr({ alpha, beta, gamma }: {
267
+ alpha: number;
268
+ beta: number;
269
+ gamma: number;
270
+ }): void;
271
+ getGyr(): {
272
+ alpha: number;
273
+ beta: number;
274
+ gamma: number;
275
+ } | undefined;
276
+ }
277
+ declare class FaustAudioWorkletNodeCommunicator extends FaustAudioWorkletCommunicator {
278
+ constructor(port: MessagePort);
279
+ }
280
+ declare class FaustAudioWorkletProcessorCommunicator extends FaustAudioWorkletCommunicator {
281
+ constructor(port: MessagePort);
282
+ }
240
283
  /**
241
284
  * The Faust wasm instance interface.
242
285
  */
@@ -627,6 +670,29 @@ export interface IFaustBaseWebAudioDsp {
627
670
  * @return the DSP JSON description
628
671
  */
629
672
  getJSON(): string;
673
+ /**
674
+ * Start accelerometer and gyroscope handlers.
675
+ */
676
+ startSensors(): void;
677
+ /**
678
+ * Stop accelerometer and gyroscope handlers.
679
+ */
680
+ stopSensors(): void;
681
+ /** Indicating if the DSP handles the accelerometer */
682
+ readonly hasAccInput: boolean;
683
+ /**
684
+ * Accelerometer handling.
685
+ * accelerationIncludingGravity: DeviceMotionEvent["accelerationIncludingGravity"]
686
+ * invert: boolean
687
+ */
688
+ propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
689
+ /** Indicating if the DSP handles the gyroscope */
690
+ readonly hasGyrInput: boolean;
691
+ /**
692
+ * Gyroscope handling.
693
+ * event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">
694
+ */
695
+ propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
630
696
  /**
631
697
  * Start the DSP audio processing.
632
698
  */
@@ -639,14 +705,6 @@ export interface IFaustBaseWebAudioDsp {
639
705
  * Destroy the DSP.
640
706
  */
641
707
  destroy(): void;
642
- /** Indicating if the DSP handles the accelerometer */
643
- readonly hasAccInput: boolean;
644
- /** Accelerometer handling */
645
- propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert: boolean): void;
646
- /** Indicating if the DSP handles the gyroscope */
647
- readonly hasGyrInput: boolean;
648
- /** Gyroscope handling */
649
- propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
650
708
  }
651
709
  export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp {
652
710
  }
@@ -784,6 +842,8 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
784
842
  getUI(): FaustUIDescriptor;
785
843
  getDescriptors(): FaustUIInputItem[];
786
844
  hasSoundfiles(): boolean;
845
+ startSensors(): void;
846
+ stopSensors(): void;
787
847
  start(): void;
788
848
  stop(): void;
789
849
  destroy(): void;
@@ -883,6 +943,7 @@ export interface FaustAudioWorkletProcessorDependencies<Poly extends boolean = f
883
943
  FaustPolyWebAudioDsp: Poly extends true ? typeof FaustPolyWebAudioDsp : undefined;
884
944
  FaustWebAudioDspVoice: Poly extends true ? typeof FaustWebAudioDspVoice : undefined;
885
945
  FaustWasmInstantiator: typeof FaustWasmInstantiator;
946
+ FaustAudioWorkletProcessorCommunicator: typeof FaustAudioWorkletProcessorCommunicator;
886
947
  }
887
948
  export interface FaustAudioWorkletNodeOptions<Poly extends boolean = false> extends AudioWorkletNodeOptions {
888
949
  processorOptions: Poly extends true ? FaustPolyAudioWorkletProcessorOptions : FaustMonoAudioWorkletProcessorOptions;
@@ -933,6 +994,7 @@ export interface FaustFFTAudioWorkletProcessorDependencies {
933
994
  FaustBaseWebAudioDsp: typeof FaustBaseWebAudioDsp;
934
995
  FaustMonoWebAudioDsp: typeof FaustMonoWebAudioDsp;
935
996
  FaustWasmInstantiator: typeof FaustWasmInstantiator;
997
+ FaustAudioWorkletProcessorCommunicator: typeof FaustAudioWorkletProcessorCommunicator;
936
998
  FFTUtils: typeof FFTUtils;
937
999
  }
938
1000
  export interface FaustFFTAudioWorkletNodeOptions extends AudioWorkletNodeOptions {
@@ -1139,6 +1201,8 @@ export declare class FaustOfflineProcessor<Poly extends boolean = false> {
1139
1201
  propagateAcc(accelerationIncludingGravity: NonNullable<DeviceMotionEvent["accelerationIncludingGravity"]>, invert?: boolean): void;
1140
1202
  get hasGyrInput(): boolean;
1141
1203
  propagateGyr(event: Pick<DeviceOrientationEvent, "alpha" | "beta" | "gamma">): void;
1204
+ startSensors(): void;
1205
+ stopSensors(): void;
1142
1206
  /**
1143
1207
  * Render frames in an array.
1144
1208
  *
@@ -1295,7 +1359,9 @@ export declare class FaustAudioWorkletNode<Poly extends boolean = false> extends
1295
1359
  protected fPlotHandler: PlotHandler | null;
1296
1360
  protected fUICallback: UIHandler;
1297
1361
  protected fDescriptor: FaustUIInputItem[];
1362
+ protected fCommunicator: FaustAudioWorkletNodeCommunicator;
1298
1363
  constructor(context: BaseAudioContext, name: string, factory: LooseFaustDspFactory, options?: Partial<FaustAudioWorkletNodeOptions<Poly>>);
1364
+ protected handleMessageAux: (e: MessageEvent) => void;
1299
1365
  private handleDeviceMotion;
1300
1366
  private handleDeviceOrientation;
1301
1367
  /** Setup accelerometer and gyroscope handlers */
@@ -1365,8 +1431,9 @@ export declare class FaustScriptProcessorNode<Poly extends boolean = false> exte
1365
1431
  protected handleDeviceMotion: any;
1366
1432
  protected handleDeviceOrientation: any;
1367
1433
  init(instance: Poly extends true ? FaustPolyWebAudioDsp : FaustMonoWebAudioDsp): void;
1368
- /** Setup accelerometer and gyroscope handlers */
1434
+ /** Start accelerometer and gyroscope handlers */
1369
1435
  startSensors(): Promise<void>;
1436
+ /** Stop accelerometer and gyroscope handlers */
1370
1437
  stopSensors(): void;
1371
1438
  compute(input: Float32Array[], output: Float32Array[]): boolean;
1372
1439
  setOutputParamHandler(handler: OutputParamHandler): void;