@grame/faustwasm 0.12.2 → 0.13.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.
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 +1574 -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 +1573 -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 +1576 -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 +1574 -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 +1576 -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 +561 -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 +1574 -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 +186 -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
@@ -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
  */
@@ -411,7 +410,7 @@ export declare class FaustWasmInstantiator {
411
410
  private static createMemoryMono;
412
411
  private static createMemoryPoly;
413
412
  private static createMixerAux;
414
- static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<FaustDspFactory>;
413
+ static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<Required<LooseFaustDspFactory>>;
415
414
  static loadDSPMixer(mixerPath: string, fs?: typeof FS): Promise<WebAssembly.Module>;
416
415
  static createAsyncMonoDSPInstance(factory: LooseFaustDspFactory): Promise<FaustMonoDspInstance>;
417
416
  static createSyncMonoDSPInstance(factory: LooseFaustDspFactory): FaustMonoDspInstance;
@@ -680,10 +679,10 @@ export interface IFaustBaseWebAudioDsp {
680
679
  */
681
680
  getUI(): FaustUIDescriptor;
682
681
  /**
683
- * Get DSP UI items description.
684
- *
685
- * @return the DSP UI items description
686
- */
682
+ * Get DSP UI items description.
683
+ *
684
+ * @return the DSP UI items description
685
+ */
687
686
  getDescriptors(): FaustUIInputItem[];
688
687
  /**
689
688
  * Get DSP JSON description with its UI and metadata.
@@ -692,8 +691,8 @@ export interface IFaustBaseWebAudioDsp {
692
691
  */
693
692
  getJSON(): string;
694
693
  /**
695
- * Start accelerometer and gyroscope handlers.
696
- */
694
+ * Start accelerometer and gyroscope handlers.
695
+ */
697
696
  startSensors(): void;
698
697
  /**
699
698
  * Stop accelerometer and gyroscope handlers.
@@ -727,8 +726,7 @@ export interface IFaustBaseWebAudioDsp {
727
726
  */
728
727
  destroy(): void;
729
728
  }
730
- export interface IFaustMonoWebAudioDsp extends IFaustBaseWebAudioDsp {
731
- }
729
+ export type IFaustMonoWebAudioDsp = IFaustBaseWebAudioDsp;
732
730
  export interface IFaustMonoWebAudioNode extends IFaustMonoWebAudioDsp, AudioNode {
733
731
  }
734
732
  export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
@@ -856,7 +854,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
856
854
  *
857
855
  * @param allocator : the wasm memory allocator
858
856
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
859
- */
857
+ */
860
858
  protected initSoundfileMemory(allocator: WasmAllocator, baseDSP: number): void;
861
859
  protected updateOutputs(): void;
862
860
  metadata(handler: MetadataHandler): void;
@@ -1171,18 +1169,18 @@ export declare class FaustCompiler implements IFaustCompiler {
1171
1169
  code: string;
1172
1170
  json: any;
1173
1171
  poly: boolean;
1174
- }>): Promise<Map<string, FaustDspFactory>[]>;
1172
+ }>): Promise<Map<string, Required<LooseFaustDspFactory>>[]>;
1175
1173
  /**
1176
1174
  * Import a stringified DSP factories table
1177
1175
  */
1178
- static importDSPFactories(tableStr: string): Promise<Map<string, FaustDspFactory>[]>;
1176
+ static importDSPFactories(tableStr: string): Promise<Map<string, Required<LooseFaustDspFactory>>[]>;
1179
1177
  constructor(libFaust: ILibFaust);
1180
1178
  private intVec2intArray;
1181
1179
  private createDSPFactory;
1182
1180
  version(): string;
1183
1181
  getErrorMessage(): string;
1184
- createMonoDSPFactory(name: string, code: string, args: string): Promise<FaustDspFactory | null>;
1185
- createPolyDSPFactory(name: string, code: string, args: string): Promise<FaustDspFactory | null>;
1182
+ createMonoDSPFactory(name: string, code: string, args: string): Promise<Required<LooseFaustDspFactory> | null>;
1183
+ createPolyDSPFactory(name: string, code: string, args: string): Promise<Required<LooseFaustDspFactory> | null>;
1186
1184
  deleteDSPFactory(factory: FaustDspFactory): void;
1187
1185
  expandDSP(code: string, args: string): string;
1188
1186
  generateAuxFiles(name: string, code: string, args: string): boolean;
@@ -1531,6 +1529,20 @@ export interface GeneratorSupportingSoundfiles {
1531
1529
  */
1532
1530
  getSoundfileList(): string[];
1533
1531
  }
1532
+ export interface IFaustDspGenerator {
1533
+ /**
1534
+ * Create a monophonic or polyphonic WebAudio node (either ScriptProcessorNode or AudioWorkletNode).
1535
+ * Analyze the code to decide whether to create a monophonic or polyphonic node.
1536
+ *
1537
+ * @param context - the WebAudio context
1538
+ * @param name - DSP name, can be used for processorName
1539
+ * @param code - the DSP code
1540
+ * @param sp - whether to compile a ScriptProcessorNode or an AudioWorkletNode
1541
+ * @param bufferSize - the buffer size in frames to be used in ScriptProcessorNode only, since AudioWorkletNode always uses 128 frames
1542
+ * @returns the compiled monophonic or polyphonic WebAudio node or 'null' if failure
1543
+ */
1544
+ createFaustNode(context: BaseAudioContext, name: string, code: string, sp?: boolean, bufferSize?: number): Promise<IFaustMonoWebAudioNode | IFaustPolyWebAudioNode | null>;
1545
+ }
1534
1546
  export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
1535
1547
  /**
1536
1548
  * Compile a monophonic DSP factory from given code.
@@ -1704,6 +1716,16 @@ export declare class FaustPolyDspGenerator implements IFaustPolyDspGenerator {
1704
1716
  getJSON(): string;
1705
1717
  getUI(): FaustUIDescriptor;
1706
1718
  }
1719
+ export declare class FaustDspGenerator implements IFaustDspGenerator {
1720
+ private static compilerPromise;
1721
+ private extractMidiAndNvoices;
1722
+ /**
1723
+ * Compile DSP code, inspect metadata for [nvoices:] (and optionally [midi:on]), and build either a mono
1724
+ * or poly WebAudio node (ScriptProcessor or AudioWorklet depending on `sp`). Compilation uses a shared,
1725
+ * lazily-created libfaust instance to avoid repeatedly instantiating the WASM compiler.
1726
+ */
1727
+ createFaustNode(context: BaseAudioContext, name: string, code: string, sp?: boolean, bufferSize?: number): Promise<IFaustMonoWebAudioNode | IFaustPolyWebAudioNode | null>;
1728
+ }
1707
1729
 
1708
1730
  export {
1709
1731
  AudioData$1 as AudioData,