@grame/faustwasm 0.12.2 → 0.13.1

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 (81) hide show
  1. package/.prettierrc +5 -0
  2. package/README.md +21 -3
  3. package/assets/standalone/faustwasm/index.d.ts +38 -16
  4. package/assets/standalone/faustwasm/index.js +1593 -404
  5. package/assets/standalone/faustwasm/index.js.map +2 -2
  6. package/dist/cjs/index.d.ts +38 -16
  7. package/dist/cjs/index.js +1592 -404
  8. package/dist/cjs/index.js.map +2 -2
  9. package/dist/cjs-bundle/index.d.ts +38 -16
  10. package/dist/cjs-bundle/index.js +1595 -406
  11. package/dist/cjs-bundle/index.js.map +2 -2
  12. package/dist/esm/index.d.ts +38 -16
  13. package/dist/esm/index.js +1593 -404
  14. package/dist/esm/index.js.map +2 -2
  15. package/dist/esm-bundle/index.d.ts +38 -16
  16. package/dist/esm-bundle/index.js +1595 -406
  17. package/dist/esm-bundle/index.js.map +2 -2
  18. package/eslint.config.js +11 -0
  19. package/package.json +57 -51
  20. package/sound.cpp +163 -0
  21. package/sound.dsp +4 -0
  22. package/sound.json +1 -0
  23. package/sound.wasm +0 -0
  24. package/src/FaustAudioWorkletCommunicator.ts +150 -143
  25. package/src/FaustAudioWorkletNode.ts +173 -75
  26. package/src/FaustAudioWorkletProcessor.ts +218 -90
  27. package/src/FaustCmajor.ts +9 -3
  28. package/src/FaustCompiler.ts +112 -35
  29. package/src/FaustDspGenerator.ts +589 -117
  30. package/src/FaustDspInstance.ts +58 -24
  31. package/src/FaustFFTAudioWorkletProcessor.ts +822 -612
  32. package/src/FaustOfflineProcessor.ts +187 -56
  33. package/src/FaustScriptProcessorNode.ts +156 -49
  34. package/src/FaustSensors.ts +426 -96
  35. package/src/FaustSvgDiagrams.ts +18 -5
  36. package/src/FaustWasmInstantiator.ts +224 -70
  37. package/src/FaustWebAudioDsp.ts +1060 -349
  38. package/src/LibFaust.ts +13 -4
  39. package/src/SoundfileReader.ts +175 -131
  40. package/src/WavDecoder.ts +42 -20
  41. package/src/WavEncoder.ts +35 -21
  42. package/src/copyWebStandaloneAssets.d.ts +20 -5
  43. package/src/copyWebStandaloneAssets.js +203 -75
  44. package/src/exports-bundle.ts +5 -5
  45. package/src/exports.ts +24 -24
  46. package/src/faust2CmajorFiles.d.ts +7 -3
  47. package/src/faust2cmajorFiles.js +10 -8
  48. package/src/faust2svgFiles.d.ts +7 -3
  49. package/src/faust2svgFiles.js +9 -7
  50. package/src/faust2wasmFiles.d.ts +10 -5
  51. package/src/faust2wasmFiles.js +34 -17
  52. package/src/faust2wavFiles.d.ts +12 -3
  53. package/src/faust2wavFiles.js +25 -12
  54. package/src/index-bundle-iife.ts +2 -2
  55. package/src/index-bundle.ts +1 -1
  56. package/src/index.ts +1 -1
  57. package/src/instantiateFaustModule.ts +43 -36
  58. package/src/instantiateFaustModuleFromFile.ts +30 -14
  59. package/src/types.ts +101 -25
  60. package/test/faustlive-wasm/faustwasm/index.d.ts +38 -16
  61. package/test/faustlive-wasm/faustwasm/index.js +1593 -404
  62. package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
  63. package/test/web/create-faust-node.html +53 -0
  64. package/test/web/create-faust-node.js +181 -0
  65. package/test/organ/create-node.js +0 -252
  66. package/test/organ/dsp-meta.json +0 -131
  67. package/test/organ/dsp-module.wasm +0 -0
  68. package/test/organ/faust-pwa.js +0 -344
  69. package/test/organ/faust-ui/index.css +0 -442
  70. package/test/organ/faust-ui/index.css.map +0 -1
  71. package/test/organ/faust-ui/index.d.ts +0 -1
  72. package/test/organ/faust-ui/index.js +0 -3756
  73. package/test/organ/faust-ui/index.js.map +0 -1
  74. package/test/organ/faustwasm/index.d.ts +0 -1705
  75. package/test/organ/faustwasm/index.js +0 -4773
  76. package/test/organ/faustwasm/index.js.map +0 -7
  77. package/test/organ/icon.png +0 -0
  78. package/test/organ/index.html +0 -76
  79. package/test/organ/index.js +0 -69
  80. package/test/organ/manifest.json +0 -17
  81. package/test/organ/service-worker.js +0 -165
package/.prettierrc ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "none",
4
+ "tabWidth": 4
5
+ }
package/README.md CHANGED
@@ -37,6 +37,20 @@ Build the files:
37
37
  npm run build
38
38
  ```
39
39
 
40
+ The source code uses [Prettier code formatter](https://prettier.io) to properly format all TS and JS files. Use:
41
+
42
+ ```bash
43
+ npm run format
44
+ ```
45
+
46
+ to apply format rules on `src`, and:
47
+
48
+ ```bash
49
+ npm run lint
50
+ ```
51
+
52
+ to check format rules on `src`.
53
+
40
54
  ### Versioning
41
55
 
42
56
  You'll have to raise the package version number in `package.json` before `npm run build` to properly work.
@@ -319,7 +333,13 @@ An offline processor to render a DSP in a non real-time context and get the comp
319
333
 
320
334
  #### High-level API <a name="high"></a>
321
335
 
322
- A high-level API is available to compile a DSP program and create the audio node, either monophonic or polyphonic using `createNode`. Offline processing monophonic or polyphonic nodes can be created using `createOfflineProcessor`. FFT processing nodes can be created using `createFFTNode`. It is described in `FaustDspGenerator.ts`.
336
+ The high-level API provides convenient functions to compile a Faust DSP program and create its corresponding audio node, either monophonic or polyphonic.
337
+ - using the appropriate `FaustMonoDspGenerator` or `FaustPolyDspGenerator` class, `createNode` explicitly builds a mono or polyphonic node.
338
+ - `createFaustNode` automatically selects mono or polyphonic mode by inspecting the `[nvoices:N] `field in the DSP metadata.
339
+
340
+ For offline rendering, `createOfflineProcessor` is available and supports both mono and polyphonic processing. FFT processing nodes can be created using `createFFTNode`.
341
+
342
+ This API is implemented in FaustDspGenerator.ts.
323
343
 
324
344
  #### How to use with typescript <a name="tsuse"></a>
325
345
 
@@ -348,5 +368,3 @@ Html pages embedding the Faust compiler must be served using https, unless using
348
368
 
349
369
 
350
370
 
351
-
352
-
@@ -91,8 +91,7 @@ export interface LibFaustWasm {
91
91
  */
92
92
  getInfos(what: FaustInfoType): string;
93
93
  }
94
- export interface FaustDspFactory extends Required<LooseFaustDspFactory> {
95
- }
94
+ export type FaustDspFactory = Required<LooseFaustDspFactory>;
96
95
  /**
97
96
  * The Factory structure.
98
97
  */
@@ -404,7 +403,7 @@ export declare class FaustWasmInstantiator {
404
403
  private static createMemoryMono;
405
404
  private static createMemoryPoly;
406
405
  private static createMixerAux;
407
- static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<FaustDspFactory>;
406
+ static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<Required<LooseFaustDspFactory>>;
408
407
  static loadDSPMixer(mixerPath: string, fs?: typeof FS): Promise<WebAssembly.Module>;
409
408
  static createAsyncMonoDSPInstance(factory: LooseFaustDspFactory): Promise<FaustMonoDspInstance>;
410
409
  static createSyncMonoDSPInstance(factory: LooseFaustDspFactory): FaustMonoDspInstance;
@@ -673,10 +672,10 @@ export interface IFaustBaseWebAudioDsp {
673
672
  */
674
673
  getUI(): FaustUIDescriptor;
675
674
  /**
676
- * Get DSP UI items description.
677
- *
678
- * @return the DSP UI items description
679
- */
675
+ * Get DSP UI items description.
676
+ *
677
+ * @return the DSP UI items description
678
+ */
680
679
  getDescriptors(): FaustUIInputItem[];
681
680
  /**
682
681
  * Get DSP JSON description with its UI and metadata.
@@ -685,8 +684,8 @@ export interface IFaustBaseWebAudioDsp {
685
684
  */
686
685
  getJSON(): string;
687
686
  /**
688
- * Start accelerometer and gyroscope handlers.
689
- */
687
+ * Start accelerometer and gyroscope handlers.
688
+ */
690
689
  startSensors(): void;
691
690
  /**
692
691
  * Stop accelerometer and gyroscope handlers.
@@ -720,8 +719,7 @@ export interface IFaustBaseWebAudioDsp {
720
719
  */
721
720
  destroy(): void;
722
721
  }
723
- export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp {
724
- }
722
+ export type IFaustMonoWebAudioDsp = IFaustBaseWebAudioDsp;
725
723
  export interface IFaustMonoWebAudioNode extends IFaustMonoWebAudioDsp, AudioNode {
726
724
  }
727
725
  export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
@@ -849,7 +847,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
849
847
  *
850
848
  * @param allocator : the wasm memory allocator
851
849
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
852
- */
850
+ */
853
851
  protected initSoundfileMemory(allocator: WasmAllocator, baseDSP: number): void;
854
852
  protected updateOutputs(): void;
855
853
  metadata(handler: MetadataHandler): void;
@@ -1164,18 +1162,18 @@ export declare class FaustCompiler implements IFaustCompiler {
1164
1162
  code: string;
1165
1163
  json: any;
1166
1164
  poly: boolean;
1167
- }>): Promise<Map<string, FaustDspFactory>[]>;
1165
+ }>): Promise<Map<string, Required<LooseFaustDspFactory>>[]>;
1168
1166
  /**
1169
1167
  * Import a stringified DSP factories table
1170
1168
  */
1171
- static importDSPFactories(tableStr: string): Promise<Map<string, FaustDspFactory>[]>;
1169
+ static importDSPFactories(tableStr: string): Promise<Map<string, Required<LooseFaustDspFactory>>[]>;
1172
1170
  constructor(libFaust: ILibFaust);
1173
1171
  private intVec2intArray;
1174
1172
  private createDSPFactory;
1175
1173
  version(): string;
1176
1174
  getErrorMessage(): string;
1177
- createMonoDSPFactory(name: string, code: string, args: string): Promise<FaustDspFactory | null>;
1178
- createPolyDSPFactory(name: string, code: string, args: string): Promise<FaustDspFactory | null>;
1175
+ createMonoDSPFactory(name: string, code: string, args: string): Promise<Required<LooseFaustDspFactory> | null>;
1176
+ createPolyDSPFactory(name: string, code: string, args: string): Promise<Required<LooseFaustDspFactory> | null>;
1179
1177
  deleteDSPFactory(factory: FaustDspFactory): void;
1180
1178
  expandDSP(code: string, args: string): string;
1181
1179
  generateAuxFiles(name: string, code: string, args: string): boolean;
@@ -1524,6 +1522,20 @@ export interface GeneratorSupportingSoundfiles {
1524
1522
  */
1525
1523
  getSoundfileList(): string[];
1526
1524
  }
1525
+ export interface IFaustDspGenerator {
1526
+ /**
1527
+ * Create a monophonic or polyphonic WebAudio node (either ScriptProcessorNode or AudioWorkletNode).
1528
+ * Analyze the code to decide whether to create a monophonic or polyphonic node.
1529
+ *
1530
+ * @param context - the WebAudio context
1531
+ * @param name - DSP name, can be used for processorName
1532
+ * @param code - the DSP code
1533
+ * @param sp - whether to compile a ScriptProcessorNode or an AudioWorkletNode
1534
+ * @param bufferSize - the buffer size in frames to be used in ScriptProcessorNode only, since AudioWorkletNode always uses 128 frames
1535
+ * @returns the compiled monophonic or polyphonic WebAudio node or 'null' if failure
1536
+ */
1537
+ createFaustNode(context: BaseAudioContext, name: string, code: string, sp?: boolean, bufferSize?: number): Promise<IFaustMonoWebAudioNode | IFaustPolyWebAudioNode | null>;
1538
+ }
1527
1539
  export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
1528
1540
  /**
1529
1541
  * Compile a monophonic DSP factory from given code.
@@ -1697,6 +1709,16 @@ export declare class FaustPolyDspGenerator implements IFaustPolyDspGenerator {
1697
1709
  getJSON(): string;
1698
1710
  getUI(): FaustUIDescriptor;
1699
1711
  }
1712
+ export declare class FaustDspGenerator implements IFaustDspGenerator {
1713
+ private static compilerPromise;
1714
+ private extractMidiAndNvoices;
1715
+ /**
1716
+ * Compile DSP code, inspect metadata for [nvoices:] (and optionally [midi:on]), and build either a mono
1717
+ * or poly WebAudio node (ScriptProcessor or AudioWorklet depending on `sp`). Compilation uses a shared,
1718
+ * lazily-created libfaust instance to avoid repeatedly instantiating the WASM compiler.
1719
+ */
1720
+ createFaustNode(context: BaseAudioContext, name: string, code: string, sp?: boolean, bufferSize?: number): Promise<IFaustMonoWebAudioNode | IFaustPolyWebAudioNode | null>;
1721
+ }
1700
1722
 
1701
1723
  export {
1702
1724
  AudioData$1 as AudioData,