@grame/faustwasm 0.1.7 → 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 (35) 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 +1012 -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 +1012 -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 -15
  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
@@ -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
  export declare const FaustModuleFactoryFn: FaustModuleFactory;
221
227
  export declare const FaustModuleFactoryWasm: Uint8Array;
222
228
  export declare const FaustModuleFactoryData: Uint8Array;
@@ -261,14 +267,14 @@ export interface IFaustDspInstance {
261
267
  *
262
268
  * @param $dsp - the DSP pointer
263
269
  * @param index - the parameter index
264
- * @preturn the parameter value
270
+ * @return the parameter value
265
271
  */
266
272
  getParamValue($dsp: number, index: number): number;
267
273
  /**
268
274
  * Give the Faust wasm instance sample rate.
269
275
  *
270
276
  * @param $dsp - the DSP pointer
271
- * @preturn the sample rate
277
+ * @return the sample rate
272
278
  */
273
279
  getSampleRate($dsp: number): number;
274
280
  /**
@@ -377,7 +383,32 @@ export type PlotHandler = (plotted: Float32Array[] | Float64Array[], index: numb
377
383
  }[]) => void;
378
384
  export type MetadataHandler = (key: string, value: string) => void;
379
385
  export type UIHandler = (item: FaustUIItem) => void;
380
- declare class WasmAllocator {
386
+ /** Definition of the AudioBufferItem type */
387
+ export interface AudioBufferItem {
388
+ pathName: string;
389
+ audioBuffer: AudioBuffer;
390
+ }
391
+ /** Definition of the SoundfileItem type */
392
+ export interface SoundfileItem {
393
+ /** Name of the soundfile */
394
+ name: string;
395
+ /** URL of the soundfile */
396
+ url: string;
397
+ /** Index in the DSP struct */
398
+ index: number;
399
+ /** Base pointer in wasm memory */
400
+ basePtr: number;
401
+ }
402
+ /**
403
+ * WasmAllocator is a basic memory management class designed to allocate
404
+ * blocks of memory within a WebAssembly.Memory object. It provides a simple
405
+ * alloc method to allocate a contiguous block of memory of a specified size.
406
+ *
407
+ * The allocator operates by keeping a linear progression through the memory,
408
+ * always allocating the next block at the end of the last. This approach does not
409
+ * handle freeing of memory or reuse of memory spaces.
410
+ */
411
+ export declare class WasmAllocator {
381
412
  private readonly memory;
382
413
  private allocatedBytes;
383
414
  constructor(memory: WebAssembly.Memory, offset: number);
@@ -421,7 +452,19 @@ declare class WasmAllocator {
421
452
  */
422
453
  getFloat64Array(): Float64Array;
423
454
  }
424
- declare class Soundfile {
455
+ /**
456
+ * Soundfile class to handle soundfile data in wasm memory.
457
+ */
458
+ export declare class Soundfile {
459
+ /** Maximum number of soundfile parts. */
460
+ static get MAX_SOUNDFILE_PARTS(): number;
461
+ /** Maximum number of channels. */
462
+ static get MAX_CHAN(): number;
463
+ /** Maximum buffer size in frames. */
464
+ static get BUFFER_SIZE(): number;
465
+ /** Default sample rate. */
466
+ static get SAMPLE_RATE(): number;
467
+ /** Pointer to the soundfile structure in wasm memory */
425
468
  private readonly fPtr;
426
469
  private readonly fBuffers;
427
470
  private readonly fLength;
@@ -434,9 +477,9 @@ declare class Soundfile {
434
477
  constructor(allocator: WasmAllocator, sampleSize: number, curChan: number, length: number, maxChan: number, totalParts: number);
435
478
  private allocBuffers;
436
479
  shareBuffers(curChan: number, maxChan: number): void;
437
- copyToOut(part: number, maxChannels: number, offset: number, buffer: AudioBuffer): void;
438
- copyToOutReal32(maxChannels: number, offset: number, buffer: AudioBuffer): void;
439
- copyToOutReal64(maxChannels: number, offset: number, buffer: AudioBuffer): void;
480
+ copyToOut(part: number, maxChannels: number, offset: number, audioData: AudioData): void;
481
+ copyToOutReal32(maxChannels: number, offset: number, audioData: AudioData): void;
482
+ copyToOutReal64(maxChannels: number, offset: number, audioData: AudioData): void;
440
483
  emptyFile(part: number, offset: number): number;
441
484
  displayMemory(where?: string, mem?: boolean): void;
442
485
  getPtr(): number;
@@ -444,62 +487,6 @@ declare class Soundfile {
444
487
  getHEAPFloat32(): Float32Array;
445
488
  getHEAPFloat64(): Float64Array;
446
489
  }
447
- declare class SoundfileReader {
448
- private readonly fAllocator;
449
- private readonly fSampleSize;
450
- private readonly fContext;
451
- private readonly fAudioBuffers;
452
- constructor(allocator: WasmAllocator, context: BaseAudioContext, sampleSize: number);
453
- /**
454
- * Check if the file exists.
455
- *
456
- * @param url : the url of the file to check
457
- * @returns : true if the file exists, otherwise false
458
- */
459
- private checkFileExists;
460
- /**
461
- * Check if the file exists in the given directories.
462
- *
463
- * @param directories : the list of directories to search for the file
464
- * @param fileName : the name of the file to search for
465
- * @returns : the path of the file if found, otherwise an empty string
466
- */
467
- private checkFile;
468
- /**
469
- * Check if all soundfiles exist and return their real path_name.
470
- *
471
- * @param directories : the list of directories to search for the file
472
- * @param fileNameList : the list of file names to search for
473
- * @returns : the list of path names of the files if found, otherwise an empty string
474
- */
475
- checkFiles(directories: string[], fileNameList: string[]): Promise<string[]>;
476
- /**
477
- * Get the channels and length values of the given sound resource.
478
- *
479
- * @param pathName : the name of the file, or sound resource identified this way
480
- * @returns channels and length of the soundfile
481
- */
482
- private getParamsFile;
483
- /**
484
- * Read one sound resource and fill the 'soundfile' structure accordingly
485
- *
486
- * @param soundfile - the soundfile to be filled
487
- * @param pathName - the name of the file, or sound resource identified this way
488
- * @param part - the part number to be filled in the soundfile
489
- * @param maxChan - the maximum number of mono channels to fill
490
- *
491
- * @returns the offset in the soundfile buffer
492
- *
493
- */
494
- private readFile;
495
- /**
496
- * Crate a soundfile, load all parts and copy audio data to the wasm soundfile buffer.
497
- * @param pathNameList : list of soundfile paths
498
- * @param maxChan : maximum number of channels
499
- */
500
- createSoundfile(pathNameList: string[], maxChan: number): Promise<Soundfile | null>;
501
- getHEAP32(): Int32Array;
502
- }
503
490
  /**
504
491
  * DSP implementation: mimic the C++ 'dsp' class:
505
492
  * - adding MIDI control: metadata are decoded and incoming MIDI messages will control the associated controllers
@@ -677,12 +664,6 @@ export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
677
664
  }
678
665
  export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode {
679
666
  }
680
- export type SoundfileItem = {
681
- name: string;
682
- url: string;
683
- index: number;
684
- basePtr: number;
685
- };
686
667
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
687
668
  protected fOutputHandler: OutputParamHandler | null;
688
669
  protected fComputeHandler: ComputeHandler | null;
@@ -699,6 +680,8 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
699
680
  protected fOutputsItems: string[];
700
681
  protected fDescriptor: FaustUIInputItem[];
701
682
  protected fSoundfiles: SoundfileItem[];
683
+ protected fSoundfileBuffers: LooseFaustDspFactory["soundfiles"];
684
+ /** Keep the end of memory offset before soundfiles */
702
685
  protected fEndMemory: number;
703
686
  protected fAudioInputs: number;
704
687
  protected fAudioOutputs: number;
@@ -723,26 +706,28 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
723
706
  protected fDestroyed: boolean;
724
707
  protected fFirstCall: boolean;
725
708
  protected fJSONDsp: FaustDspMeta;
726
- constructor(sampleSize: number, bufferSize: number);
709
+ constructor(sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
727
710
  static remap(v: number, mn0: number, mx0: number, mn1: number, mx1: number): number;
728
711
  static parseUI(ui: FaustUIDescriptor, callback: (item: FaustUIItem) => any): void;
729
712
  static parseGroup(group: FaustUIGroup, callback: (item: FaustUIItem) => any): void;
730
713
  static parseItems(items: FaustUIItem[], callback: (item: FaustUIItem) => any): void;
731
714
  static parseItem(item: FaustUIItem, callback: (item: FaustUIItem) => any): void;
732
- static splitNames(input: string): string[];
733
- private extractURLsFromJSON;
715
+ /** Split the soundfile names and return an array of names */
716
+ static splitSoundfileNames(input: string): string[];
717
+ static extractUrlsFromMeta(dspMeta: FaustDspMeta): string[];
734
718
  /**
735
719
  * Load a soundfile possibly containing several parts in the DSP struct.
736
720
  * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
737
721
  * The DSP struct is located at baseDSP in the wasm memory,
738
722
  * either a monophonic DSP, or a voice in a polyphonic context.
739
723
  *
740
- * @param sfReader : the soundfile reader
724
+ * @param allocator : the wasm memory allocator
741
725
  * @param baseDSP : the base DSP in the wasm memory
742
726
  * @param name : the name of the soundfile
743
727
  * @param url : the url of the soundfile
744
728
  */
745
729
  private loadSoundfile;
730
+ createSoundfile(allocator: WasmAllocator, soundfileIdList: string[], soundfiles: LooseFaustDspFactory["soundfiles"], maxChan?: number): Soundfile;
746
731
  /**
747
732
  * Init soundfiles memory.
748
733
  *
@@ -750,7 +735,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
750
735
  * @param sfReader : the soundfile reader
751
736
  * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
752
737
  */
753
- protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
738
+ protected initSoundfileMemory(allocator: WasmAllocator, baseDSP: number): void;
754
739
  protected updateOutputs(): void;
755
740
  metadata(handler: MetadataHandler): void;
756
741
  compute(input: Float32Array[], output: Float32Array[]): boolean;
@@ -780,8 +765,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
780
765
  export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implements IFaustMonoWebAudioDsp {
781
766
  private fInstance;
782
767
  private fDSP;
783
- constructor(instance: FaustMonoDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
784
- init(context: BaseAudioContext | null): Promise<void>;
768
+ constructor(instance: FaustMonoDspInstance, sampleRate: number, sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
785
769
  private initMemory;
786
770
  toString(): string;
787
771
  compute(input: Float32Array[] | ((input: Float32Array[] | Float64Array[]) => any), output: Float32Array[] | ((output: Float32Array[] | Float64Array[]) => any)): boolean;
@@ -796,12 +780,12 @@ export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implement
796
780
  getUI(): FaustUIDescriptor;
797
781
  }
798
782
  export declare class FaustWebAudioDspVoice {
799
- static kActiveVoice: number;
800
- static kFreeVoice: number;
801
- static kReleaseVoice: number;
802
- static kLegatoVoice: number;
803
- static kNoVoice: number;
804
- static VOICE_STOP_LEVEL: number;
783
+ static get kActiveVoice(): number;
784
+ static get kFreeVoice(): number;
785
+ static get kReleaseVoice(): number;
786
+ static get kLegatoVoice(): number;
787
+ static get kNoVoice(): number;
788
+ static get VOICE_STOP_LEVEL(): number;
805
789
  private fFreqLabel;
806
790
  private fGateLabel;
807
791
  private fGainLabel;
@@ -835,8 +819,7 @@ export declare class FaustPolyWebAudioDsp extends FaustBaseWebAudioDsp implement
835
819
  private fAudioMixing;
836
820
  private fAudioMixingHalf;
837
821
  private fVoiceTable;
838
- constructor(instance: FaustPolyDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
839
- init(context: BaseAudioContext | null): Promise<void>;
822
+ constructor(instance: FaustPolyDspInstance, sampleRate: number, sampleSize: number, bufferSize: number, soundfiles: LooseFaustDspFactory["soundfiles"]);
840
823
  private initMemory;
841
824
  toString(): string;
842
825
  private allocVoice;
@@ -934,7 +917,6 @@ export interface FaustFFTAudioWorkletProcessorOptions {
934
917
  }
935
918
  export declare const getFaustFFTAudioWorkletProcessor: (dependencies: FaustFFTAudioWorkletProcessorDependencies, faustData: FaustFFTData, register?: boolean) => {
936
919
  new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
937
- /** Generated from the current window function */
938
920
  prototype: AudioWorkletProcessor;
939
921
  parameterDescriptors: AudioParamDescriptor[];
940
922
  };
@@ -1168,8 +1150,8 @@ export interface IFaustCmajor {
1168
1150
  compile(name: string, code: string, args: string): string;
1169
1151
  }
1170
1152
  export declare class FaustCmajor implements IFaustCmajor {
1171
- private fLibFaust;
1172
- constructor(libfaust: LibFaust);
1153
+ private fCompiler;
1154
+ constructor(compiler: FaustCompiler);
1173
1155
  compile(name: string, code: string, args: string): string;
1174
1156
  }
1175
1157
  export interface WavEncoderOptions {
@@ -1205,6 +1187,57 @@ export declare class WavDecoder {
1205
1187
  private static decodeData;
1206
1188
  private static readPCM;
1207
1189
  }
1190
+ /** Read metadata and fetch soundfiles */
1191
+ export declare class SoundfileReader {
1192
+ static get fallbackPaths(): string[];
1193
+ /**
1194
+ * Convert an audio buffer to audio data.
1195
+ *
1196
+ * @param audioBuffer : the audio buffer to convert
1197
+ * @returns : the audio data
1198
+ */
1199
+ private static toAudioData;
1200
+ /**
1201
+ * Extract the URLs from the metadata.
1202
+ *
1203
+ * @param dspMeta : the metadata
1204
+ * @returns : the URLs
1205
+ */
1206
+ private static findSoundfilesFromMeta;
1207
+ /**
1208
+ * Check if the file exists.
1209
+ *
1210
+ * @param url : the url of the file to check
1211
+ * @returns : true if the file exists, otherwise false
1212
+ */
1213
+ private static checkFileExists;
1214
+ /**
1215
+ * Fetch the soundfile.
1216
+ *
1217
+ * @param url : the url of the soundfile
1218
+ * @param audioCtx : the audio context
1219
+ * @returns : the audio data
1220
+ */
1221
+ private static fetchSoundfile;
1222
+ /**
1223
+ * Load the soundfile.
1224
+ *
1225
+ * @param filename : the filename
1226
+ * @param metaUrls : the metadata URLs
1227
+ * @param soundfiles : the soundfiles
1228
+ * @param audioCtx : the audio context
1229
+ */
1230
+ private static loadSoundfile;
1231
+ /**
1232
+ * Load the soundfiles, public API.
1233
+ *
1234
+ * @param dspMeta : the metadata
1235
+ * @param soundfilesIn : the soundfiles
1236
+ * @param audioCtx : the audio context
1237
+ * @returns : the soundfiles
1238
+ */
1239
+ static loadSoundfiles(dspMeta: FaustDspMeta, soundfilesIn: LooseFaustDspFactory["soundfiles"], audioCtx: BaseAudioContext): Promise<LooseFaustDspFactory["soundfiles"]>;
1240
+ }
1208
1241
  declare const FaustAudioWorkletNode_base: {
1209
1242
  new (context: BaseAudioContext, name: string, options?: AudioWorkletNodeOptions | undefined): AudioWorkletNode;
1210
1243
  prototype: AudioWorkletNode;
@@ -1357,7 +1390,7 @@ export interface IFaustMonoDspGenerator {
1357
1390
  * @param factory - default is the compiled factory
1358
1391
  * @returns the compiled processor or 'null' if failure
1359
1392
  */
1360
- createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, meta?: FaustDspMeta): Promise<IFaustMonoOfflineProcessor | null>;
1393
+ createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<IFaustMonoOfflineProcessor | null>;
1361
1394
  /**
1362
1395
  * Get DSP JSON description with its UI and metadata as object.
1363
1396
  *
@@ -1405,7 +1438,7 @@ export interface IFaustPolyDspGenerator {
1405
1438
  * @param bufferSize - the buffer size in frames to be used in ScriptProcessorNode only, since AudioWorkletNode always uses 128 frames
1406
1439
  * @returns the compiled WebAudio node or 'null' if failure
1407
1440
  */
1408
- createNode(context: BaseAudioContext, voices: number, name?: string, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, sp?: boolean, bufferSize?: number): Promise<IFaustPolyWebAudioNode | null>;
1441
+ createNode(context: BaseAudioContext, voices: number, name?: string, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, sp?: boolean, bufferSize?: number, processorName?: string): Promise<IFaustPolyWebAudioNode | null>;
1409
1442
  /**
1410
1443
  * Create a monophonic Offline processor.
1411
1444
  *
@@ -1416,7 +1449,7 @@ export interface IFaustPolyDspGenerator {
1416
1449
  * @param effectFactory - the Faust factory for the effect, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
1417
1450
  * @returns the compiled processor or 'null' if failure
1418
1451
  */
1419
- createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null): Promise<IFaustPolyOfflineProcessor | null>;
1452
+ createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, processorName?: string): Promise<IFaustPolyOfflineProcessor | null>;
1420
1453
  /**
1421
1454
  * Get DSP JSON description with its UI and metadata as object.
1422
1455
  *