@grame/faustwasm 0.1.6 → 0.2.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 (42) hide show
  1. package/assets/standalone/faustwasm/index.d.ts +132 -99
  2. package/assets/standalone/faustwasm/index.js +907 -1230
  3. package/assets/standalone/faustwasm/index.js.map +4 -4
  4. package/dist/cjs/index.d.ts +132 -99
  5. package/dist/cjs/index.js +909 -1212
  6. package/dist/cjs/index.js.map +4 -4
  7. package/dist/cjs-bundle/index.d.ts +132 -99
  8. package/dist/cjs-bundle/index.js +1013 -1317
  9. package/dist/cjs-bundle/index.js.map +4 -4
  10. package/dist/esm/index.d.ts +132 -99
  11. package/dist/esm/index.js +907 -1230
  12. package/dist/esm/index.js.map +4 -4
  13. package/dist/esm-bundle/index.d.ts +132 -99
  14. package/dist/esm-bundle/index.js +1013 -1321
  15. package/dist/esm-bundle/index.js.map +4 -4
  16. package/libfaust-wasm/libfaust-wasm.js +1 -1
  17. package/libfaust-wasm/libfaust-wasm.wasm +0 -0
  18. package/package.json +15 -13
  19. package/src/FaustAudioWorkletProcessor.ts +3 -14
  20. package/src/FaustCmajor.ts +6 -6
  21. package/src/FaustCompiler.ts +2 -2
  22. package/src/FaustDspGenerator.ts +109 -75
  23. package/src/FaustDspInstance.ts +2 -2
  24. package/src/FaustFFTAudioWorkletProcessor.ts +3 -1
  25. package/src/FaustWebAudioDsp.ts +224 -449
  26. package/src/SoundfileReader.ts +117 -0
  27. package/src/exports.ts +1 -0
  28. package/src/faust2wasmFiles.js +1 -1
  29. package/src/types.ts +15 -7
  30. package/test/faustlive-wasm/faustwasm/index.d.ts +132 -99
  31. package/test/faustlive-wasm/faustwasm/index.js +907 -1230
  32. package/test/faustlive-wasm/faustwasm/index.js.map +4 -4
  33. package/test/soundfile.dsp +15 -0
  34. package/test/soundfile1.dsp +23 -0
  35. package/test/web/soundfile.html +69 -0
  36. package/out/clarinetMIDI.html +0 -50
  37. package/out/clarinetMIDI.js +0 -63
  38. package/out/clarinetMIDI.json +0 -431
  39. package/out/clarinetMIDI.wasm +0 -0
  40. package/out/faustwasm/index.d.ts +0 -1495
  41. package/out/faustwasm/index.js +0 -4470
  42. package/out/faustwasm/index.js.map +0 -7
@@ -1,7 +1,6 @@
1
- // Generated by dts-bundle-generator v6.13.0
1
+ // Generated by dts-bundle-generator v9.5.1
2
2
 
3
3
  /// <reference types="emscripten" />
4
- /// <reference types="node" />
5
4
 
6
5
  export type FaustModuleFactory = EmscriptenModuleFactory<FaustModule>;
7
6
  export interface FaustModule extends EmscriptenModule {
@@ -92,23 +91,26 @@ export interface LibFaustWasm {
92
91
  */
93
92
  getInfos(what: FaustInfoType): string;
94
93
  }
94
+ export interface FaustDspFactory extends Required<LooseFaustDspFactory> {
95
+ }
95
96
  /**
96
97
  * The Factory structure.
97
- * cfactory: a "pointer" (as an integer) on the internal C++ factory
98
- * code: the WASM code as a binary array
99
- * module: the compule WASM module
100
- * json: the compiled DSP JSON description
101
- * poly: whether the factory is a polyphonic one or not
102
98
  */
103
- export interface FaustDspFactory extends Required<LooseFaustDspFactory> {
104
- }
105
99
  export interface LooseFaustDspFactory {
100
+ /** a "pointer" (as an integer) on the internal C++ factory */
106
101
  cfactory?: number;
102
+ /** the WASM code as a binary array */
107
103
  code?: Uint8Array;
104
+ /** the compule WASM module */
108
105
  module: WebAssembly.Module;
106
+ /** the compiled DSP JSON description */
109
107
  json: string;
108
+ /** whether the factory is a polyphonic one or not */
110
109
  poly?: boolean;
110
+ /** a unique identifier */
111
111
  shaKey?: string;
112
+ /** a map of transferable audio buffers for the `soundfile` function */
113
+ soundfiles: Record<string, (AudioData | null)>;
112
114
  }
113
115
  export interface FaustDspMeta {
114
116
  name: string;
@@ -217,6 +219,10 @@ export declare const FFTUtils: {
217
219
  /** Convert from Faust processor's output to direct audio output, real/imag are readonly, fft length = fftSize = (real/imag length - 1) * 2 */
218
220
  signalToNoFFT: (real: Float32Array | Float64Array, imag: Float32Array | Float64Array, fft: Float32Array | Float64Array) => any;
219
221
  };
222
+ export interface AudioData {
223
+ sampleRate: number;
224
+ audioBuffer: Float32Array[];
225
+ }
220
226
  /**
221
227
  * Load libfaust-wasm files, than instantiate libFaust
222
228
  * @param jsFile path to `libfaust-wasm.js`
@@ -254,14 +260,14 @@ export interface IFaustDspInstance {
254
260
  *
255
261
  * @param $dsp - the DSP pointer
256
262
  * @param index - the parameter index
257
- * @preturn the parameter value
263
+ * @return the parameter value
258
264
  */
259
265
  getParamValue($dsp: number, index: number): number;
260
266
  /**
261
267
  * Give the Faust wasm instance sample rate.
262
268
  *
263
269
  * @param $dsp - the DSP pointer
264
- * @preturn the sample rate
270
+ * @return the sample rate
265
271
  */
266
272
  getSampleRate($dsp: number): number;
267
273
  /**
@@ -370,7 +376,32 @@ export type PlotHandler = (plotted: Float32Array[] | Float64Array[], index: numb
370
376
  }[]) => void;
371
377
  export type MetadataHandler = (key: string, value: string) => void;
372
378
  export type UIHandler = (item: FaustUIItem) => void;
373
- declare class WasmAllocator {
379
+ /** Definition of the AudioBufferItem type */
380
+ export interface AudioBufferItem {
381
+ pathName: string;
382
+ audioBuffer: AudioBuffer;
383
+ }
384
+ /** Definition of the SoundfileItem type */
385
+ export interface SoundfileItem {
386
+ /** Name of the soundfile */
387
+ name: string;
388
+ /** URL of the soundfile */
389
+ url: string;
390
+ /** Index in the DSP struct */
391
+ index: number;
392
+ /** Base pointer in wasm memory */
393
+ basePtr: number;
394
+ }
395
+ /**
396
+ * WasmAllocator is a basic memory management class designed to allocate
397
+ * blocks of memory within a WebAssembly.Memory object. It provides a simple
398
+ * alloc method to allocate a contiguous block of memory of a specified size.
399
+ *
400
+ * The allocator operates by keeping a linear progression through the memory,
401
+ * always allocating the next block at the end of the last. This approach does not
402
+ * handle freeing of memory or reuse of memory spaces.
403
+ */
404
+ export declare class WasmAllocator {
374
405
  private readonly memory;
375
406
  private allocatedBytes;
376
407
  constructor(memory: WebAssembly.Memory, offset: number);
@@ -414,7 +445,19 @@ declare class WasmAllocator {
414
445
  */
415
446
  getFloat64Array(): Float64Array;
416
447
  }
417
- declare class Soundfile {
448
+ /**
449
+ * Soundfile class to handle soundfile data in wasm memory.
450
+ */
451
+ export declare class Soundfile {
452
+ /** Maximum number of soundfile parts. */
453
+ static get MAX_SOUNDFILE_PARTS(): number;
454
+ /** Maximum number of channels. */
455
+ static get MAX_CHAN(): number;
456
+ /** Maximum buffer size in frames. */
457
+ static get BUFFER_SIZE(): number;
458
+ /** Default sample rate. */
459
+ static get SAMPLE_RATE(): number;
460
+ /** Pointer to the soundfile structure in wasm memory */
418
461
  private readonly fPtr;
419
462
  private readonly fBuffers;
420
463
  private readonly fLength;
@@ -427,9 +470,9 @@ declare class Soundfile {
427
470
  constructor(allocator: WasmAllocator, sampleSize: number, curChan: number, length: number, maxChan: number, totalParts: number);
428
471
  private allocBuffers;
429
472
  shareBuffers(curChan: number, maxChan: number): void;
430
- copyToOut(part: number, maxChannels: number, offset: number, buffer: AudioBuffer): void;
431
- copyToOutReal32(maxChannels: number, offset: number, buffer: AudioBuffer): void;
432
- copyToOutReal64(maxChannels: number, offset: number, buffer: AudioBuffer): void;
473
+ copyToOut(part: number, maxChannels: number, offset: number, audioData: AudioData): void;
474
+ copyToOutReal32(maxChannels: number, offset: number, audioData: AudioData): void;
475
+ copyToOutReal64(maxChannels: number, offset: number, audioData: AudioData): void;
433
476
  emptyFile(part: number, offset: number): number;
434
477
  displayMemory(where?: string, mem?: boolean): void;
435
478
  getPtr(): number;
@@ -437,62 +480,6 @@ declare class Soundfile {
437
480
  getHEAPFloat32(): Float32Array;
438
481
  getHEAPFloat64(): Float64Array;
439
482
  }
440
- declare class SoundfileReader {
441
- private readonly fAllocator;
442
- private readonly fSampleSize;
443
- private readonly fContext;
444
- private readonly fAudioBuffers;
445
- constructor(allocator: WasmAllocator, context: BaseAudioContext, sampleSize: number);
446
- /**
447
- * Check if the file exists.
448
- *
449
- * @param url : the url of the file to check
450
- * @returns : true if the file exists, otherwise false
451
- */
452
- private checkFileExists;
453
- /**
454
- * Check if the file exists in the given directories.
455
- *
456
- * @param directories : the list of directories to search for the file
457
- * @param fileName : the name of the file to search for
458
- * @returns : the path of the file if found, otherwise an empty string
459
- */
460
- private checkFile;
461
- /**
462
- * Check if all soundfiles exist and return their real path_name.
463
- *
464
- * @param directories : the list of directories to search for the file
465
- * @param fileNameList : the list of file names to search for
466
- * @returns : the list of path names of the files if found, otherwise an empty string
467
- */
468
- checkFiles(directories: string[], fileNameList: string[]): Promise<string[]>;
469
- /**
470
- * Get the channels and length values of the given sound resource.
471
- *
472
- * @param pathName : the name of the file, or sound resource identified this way
473
- * @returns channels and length of the soundfile
474
- */
475
- private getParamsFile;
476
- /**
477
- * Read one sound resource and fill the 'soundfile' structure accordingly
478
- *
479
- * @param soundfile - the soundfile to be filled
480
- * @param pathName - the name of the file, or sound resource identified this way
481
- * @param part - the part number to be filled in the soundfile
482
- * @param maxChan - the maximum number of mono channels to fill
483
- *
484
- * @returns the offset in the soundfile buffer
485
- *
486
- */
487
- private readFile;
488
- /**
489
- * Crate a soundfile, load all parts and copy audio data to the wasm soundfile buffer.
490
- * @param pathNameList : list of soundfile paths
491
- * @param maxChan : maximum number of channels
492
- */
493
- createSoundfile(pathNameList: string[], maxChan: number): Promise<Soundfile | null>;
494
- getHEAP32(): Int32Array;
495
- }
496
483
  /**
497
484
  * DSP implementation: mimic the C++ 'dsp' class:
498
485
  * - adding MIDI control: metadata are decoded and incoming MIDI messages will control the associated controllers
@@ -670,12 +657,6 @@ export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
670
657
  }
671
658
  export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode {
672
659
  }
673
- export type SoundfileItem = {
674
- name: string;
675
- url: string;
676
- index: number;
677
- basePtr: number;
678
- };
679
660
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
680
661
  protected fOutputHandler: OutputParamHandler | null;
681
662
  protected fComputeHandler: ComputeHandler | null;
@@ -692,6 +673,8 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
692
673
  protected fOutputsItems: string[];
693
674
  protected fDescriptor: FaustUIInputItem[];
694
675
  protected fSoundfiles: SoundfileItem[];
676
+ protected fSoundfileBuffers: LooseFaustDspFactory["soundfiles"];
677
+ /** Keep the end of memory offset before soundfiles */
695
678
  protected fEndMemory: number;
696
679
  protected fAudioInputs: number;
697
680
  protected fAudioOutputs: number;
@@ -716,26 +699,28 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
716
699
  protected fDestroyed: boolean;
717
700
  protected fFirstCall: boolean;
718
701
  protected fJSONDsp: FaustDspMeta;
719
- constructor(sampleSize: number, bufferSize: number);
702
+ constructor(sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
720
703
  static remap(v: number, mn0: number, mx0: number, mn1: number, mx1: number): number;
721
704
  static parseUI(ui: FaustUIDescriptor, callback: (item: FaustUIItem) => any): void;
722
705
  static parseGroup(group: FaustUIGroup, callback: (item: FaustUIItem) => any): void;
723
706
  static parseItems(items: FaustUIItem[], callback: (item: FaustUIItem) => any): void;
724
707
  static parseItem(item: FaustUIItem, callback: (item: FaustUIItem) => any): void;
725
- static splitNames(input: string): string[];
726
- private extractURLsFromJSON;
708
+ /** Split the soundfile names and return an array of names */
709
+ static splitSoundfileNames(input: string): string[];
710
+ static extractUrlsFromMeta(dspMeta: FaustDspMeta): string[];
727
711
  /**
728
712
  * Load a soundfile possibly containing several parts in the DSP struct.
729
713
  * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
730
714
  * The DSP struct is located at baseDSP in the wasm memory,
731
715
  * either a monophonic DSP, or a voice in a polyphonic context.
732
716
  *
733
- * @param sfReader : the soundfile reader
717
+ * @param allocator : the wasm memory allocator
734
718
  * @param baseDSP : the base DSP in the wasm memory
735
719
  * @param name : the name of the soundfile
736
720
  * @param url : the url of the soundfile
737
721
  */
738
722
  private loadSoundfile;
723
+ createSoundfile(allocator: WasmAllocator, soundfileIdList: string[], soundfiles: LooseFaustDspFactory["soundfiles"], maxChan?: number): Soundfile;
739
724
  /**
740
725
  * Init soundfiles memory.
741
726
  *
@@ -743,7 +728,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
743
728
  * @param sfReader : the soundfile reader
744
729
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
745
730
  */
746
- protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
731
+ protected initSoundfileMemory(allocator: WasmAllocator, baseDSP: number): void;
747
732
  protected updateOutputs(): void;
748
733
  metadata(handler: MetadataHandler): void;
749
734
  compute(input: Float32Array[], output: Float32Array[]): boolean;
@@ -773,8 +758,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
773
758
  export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implements IFaustMonoWebAudioDsp {
774
759
  private fInstance;
775
760
  private fDSP;
776
- constructor(instance: FaustMonoDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
777
- init(context: BaseAudioContext | null): Promise<void>;
761
+ constructor(instance: FaustMonoDspInstance, sampleRate: number, sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
778
762
  private initMemory;
779
763
  toString(): string;
780
764
  compute(input: Float32Array[] | ((input: Float32Array[] | Float64Array[]) => any), output: Float32Array[] | ((output: Float32Array[] | Float64Array[]) => any)): boolean;
@@ -789,12 +773,12 @@ export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implement
789
773
  getUI(): FaustUIDescriptor;
790
774
  }
791
775
  export declare class FaustWebAudioDspVoice {
792
- static kActiveVoice: number;
793
- static kFreeVoice: number;
794
- static kReleaseVoice: number;
795
- static kLegatoVoice: number;
796
- static kNoVoice: number;
797
- static VOICE_STOP_LEVEL: number;
776
+ static get kActiveVoice(): number;
777
+ static get kFreeVoice(): number;
778
+ static get kReleaseVoice(): number;
779
+ static get kLegatoVoice(): number;
780
+ static get kNoVoice(): number;
781
+ static get VOICE_STOP_LEVEL(): number;
798
782
  private fFreqLabel;
799
783
  private fGateLabel;
800
784
  private fGainLabel;
@@ -828,8 +812,7 @@ export declare class FaustPolyWebAudioDsp extends FaustBaseWebAudioDsp implement
828
812
  private fAudioMixing;
829
813
  private fAudioMixingHalf;
830
814
  private fVoiceTable;
831
- constructor(instance: FaustPolyDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
832
- init(context: BaseAudioContext | null): Promise<void>;
815
+ constructor(instance: FaustPolyDspInstance, sampleRate: number, sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
833
816
  private initMemory;
834
817
  toString(): string;
835
818
  private allocVoice;
@@ -927,7 +910,6 @@ export interface FaustFFTAudioWorkletProcessorOptions {
927
910
  }
928
911
  export declare const getFaustFFTAudioWorkletProcessor: (dependencies: FaustFFTAudioWorkletProcessorDependencies, faustData: FaustFFTData, register?: boolean) => {
929
912
  new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
930
- /** Generated from the current window function */
931
913
  prototype: AudioWorkletProcessor;
932
914
  parameterDescriptors: AudioParamDescriptor[];
933
915
  };
@@ -1161,8 +1143,8 @@ export interface IFaustCmajor {
1161
1143
  compile(name: string, code: string, args: string): string;
1162
1144
  }
1163
1145
  export declare class FaustCmajor implements IFaustCmajor {
1164
- private fLibFaust;
1165
- constructor(libfaust: LibFaust);
1146
+ private fCompiler;
1147
+ constructor(compiler: FaustCompiler);
1166
1148
  compile(name: string, code: string, args: string): string;
1167
1149
  }
1168
1150
  export interface WavEncoderOptions {
@@ -1198,6 +1180,57 @@ export declare class WavDecoder {
1198
1180
  private static decodeData;
1199
1181
  private static readPCM;
1200
1182
  }
1183
+ /** Read metadata and fetch soundfiles */
1184
+ export declare class SoundfileReader {
1185
+ static get fallbackPaths(): string[];
1186
+ /**
1187
+ * Convert an audio buffer to audio data.
1188
+ *
1189
+ * @param audioBuffer : the audio buffer to convert
1190
+ * @returns : the audio data
1191
+ */
1192
+ private static toAudioData;
1193
+ /**
1194
+ * Extract the URLs from the metadata.
1195
+ *
1196
+ * @param dspMeta : the metadata
1197
+ * @returns : the URLs
1198
+ */
1199
+ private static findSoundfilesFromMeta;
1200
+ /**
1201
+ * Check if the file exists.
1202
+ *
1203
+ * @param url : the url of the file to check
1204
+ * @returns : true if the file exists, otherwise false
1205
+ */
1206
+ private static checkFileExists;
1207
+ /**
1208
+ * Fetch the soundfile.
1209
+ *
1210
+ * @param url : the url of the soundfile
1211
+ * @param audioCtx : the audio context
1212
+ * @returns : the audio data
1213
+ */
1214
+ private static fetchSoundfile;
1215
+ /**
1216
+ * Load the soundfile.
1217
+ *
1218
+ * @param filename : the filename
1219
+ * @param metaUrls : the metadata URLs
1220
+ * @param soundfiles : the soundfiles
1221
+ * @param audioCtx : the audio context
1222
+ */
1223
+ private static loadSoundfile;
1224
+ /**
1225
+ * Load the soundfiles, public API.
1226
+ *
1227
+ * @param dspMeta : the metadata
1228
+ * @param soundfilesIn : the soundfiles
1229
+ * @param audioCtx : the audio context
1230
+ * @returns : the soundfiles
1231
+ */
1232
+ static loadSoundfiles(dspMeta: FaustDspMeta, soundfilesIn: LooseFaustDspFactory["soundfiles"], audioCtx: BaseAudioContext): Promise<LooseFaustDspFactory["soundfiles"]>;
1233
+ }
1201
1234
  declare const FaustAudioWorkletNode_base: {
1202
1235
  new (context: BaseAudioContext, name: string, options?: AudioWorkletNodeOptions | undefined): AudioWorkletNode;
1203
1236
  prototype: AudioWorkletNode;
@@ -1350,7 +1383,7 @@ export interface IFaustMonoDspGenerator {
1350
1383
  * @param factory - default is the compiled factory
1351
1384
  * @returns the compiled processor or 'null' if failure
1352
1385
  */
1353
- createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, meta?: FaustDspMeta): Promise<IFaustMonoOfflineProcessor | null>;
1386
+ createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<IFaustMonoOfflineProcessor | null>;
1354
1387
  /**
1355
1388
  * Get DSP JSON description with its UI and metadata as object.
1356
1389
  *
@@ -1398,7 +1431,7 @@ export interface IFaustPolyDspGenerator {
1398
1431
  * @param bufferSize - the buffer size in frames to be used in ScriptProcessorNode only, since AudioWorkletNode always uses 128 frames
1399
1432
  * @returns the compiled WebAudio node or 'null' if failure
1400
1433
  */
1401
- createNode(context: BaseAudioContext, voices: number, name?: string, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, sp?: boolean, bufferSize?: number): Promise<IFaustPolyWebAudioNode | null>;
1434
+ createNode(context: BaseAudioContext, voices: number, name?: string, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, sp?: boolean, bufferSize?: number, processorName?: string): Promise<IFaustPolyWebAudioNode | null>;
1402
1435
  /**
1403
1436
  * Create a monophonic Offline processor.
1404
1437
  *
@@ -1409,7 +1442,7 @@ export interface IFaustPolyDspGenerator {
1409
1442
  * @param effectFactory - the Faust factory for the effect, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
1410
1443
  * @returns the compiled processor or 'null' if failure
1411
1444
  */
1412
- createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null): Promise<IFaustPolyOfflineProcessor | null>;
1445
+ createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, processorName?: string): Promise<IFaustPolyOfflineProcessor | null>;
1413
1446
  /**
1414
1447
  * Get DSP JSON description with its UI and metadata as object.
1415
1448
  *