@grame/faustwasm 0.0.66 → 0.1.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 (39) hide show
  1. package/README.md +1 -1
  2. package/assets/standalone/faust-ui/index.css +17 -0
  3. package/assets/standalone/faust-ui/index.css.map +1 -1
  4. package/assets/standalone/faust-ui/index.js +294 -47
  5. package/assets/standalone/faust-ui/index.js.map +1 -1
  6. package/assets/standalone/faustwasm/index.d.ts +149 -6
  7. package/assets/standalone/faustwasm/index.js +449 -73
  8. package/assets/standalone/faustwasm/index.js.map +3 -3
  9. package/assets/standalone/index-poly.js +9 -6
  10. package/assets/standalone/index.js +9 -6
  11. package/dist/cjs/index.d.ts +149 -6
  12. package/dist/cjs/index.js +449 -73
  13. package/dist/cjs/index.js.map +3 -3
  14. package/dist/cjs-bundle/index.d.ts +149 -6
  15. package/dist/cjs-bundle/index.js +550 -174
  16. package/dist/cjs-bundle/index.js.map +3 -3
  17. package/dist/esm/index.d.ts +149 -6
  18. package/dist/esm/index.js +449 -73
  19. package/dist/esm/index.js.map +3 -3
  20. package/dist/esm-bundle/index.d.ts +149 -6
  21. package/dist/esm-bundle/index.js +550 -174
  22. package/dist/esm-bundle/index.js.map +3 -3
  23. package/libfaust-wasm/libfaust-wasm.data +0 -0
  24. package/libfaust-wasm/libfaust-wasm.js +1 -1
  25. package/libfaust-wasm/libfaust-wasm.wasm +0 -0
  26. package/package.json +2 -2
  27. package/src/FaustAudioWorkletProcessor.ts +16 -3
  28. package/src/FaustDspGenerator.ts +18 -3
  29. package/src/FaustWasmInstantiator.ts +62 -26
  30. package/src/FaustWebAudioDsp.ts +682 -51
  31. package/src/faust2wasmFiles.js +6 -4
  32. package/src/types.ts +5 -4
  33. package/test/faustlive-wasm/faust-ui/index.css +17 -0
  34. package/test/faustlive-wasm/faust-ui/index.css.map +1 -1
  35. package/test/faustlive-wasm/faust-ui/index.js +294 -47
  36. package/test/faustlive-wasm/faust-ui/index.js.map +1 -1
  37. package/test/faustlive-wasm/faustwasm/index.d.ts +149 -6
  38. package/test/faustlive-wasm/faustwasm/index.js +449 -73
  39. package/test/faustlive-wasm/faustwasm/index.js.map +3 -3
@@ -131,6 +131,7 @@ export interface FaustUIInputItem {
131
131
  type: FaustUIInputType;
132
132
  label: string;
133
133
  address: string;
134
+ url: string;
134
135
  index: number;
135
136
  init?: number;
136
137
  min?: number;
@@ -158,7 +159,7 @@ export interface FaustUIMeta {
158
159
  }
159
160
  export type FaustUIGroupType = "vgroup" | "hgroup" | "tgroup";
160
161
  export type FaustUIOutputType = "hbargraph" | "vbargraph";
161
- export type FaustUIInputType = "vslider" | "hslider" | "button" | "checkbox" | "nentry";
162
+ export type FaustUIInputType = "vslider" | "hslider" | "button" | "checkbox" | "nentry" | "soundfile";
162
163
  export interface FaustUIGroup {
163
164
  type: FaustUIGroupType;
164
165
  label: string;
@@ -348,9 +349,11 @@ export declare class FaustDspInstance implements IFaustDspInstance {
348
349
  }
349
350
  export declare class FaustWasmInstantiator {
350
351
  private static createWasmImport;
351
- private static createWasmMemory;
352
+ private static createWasmMemoryPoly;
353
+ private static createWasmMemoryMono;
352
354
  private static createMonoDSPInstanceAux;
353
- private static createMemoryAux;
355
+ private static createMemoryMono;
356
+ private static createMemoryPoly;
354
357
  private static createMixerAux;
355
358
  static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<FaustDspFactory>;
356
359
  static loadDSPMixer(mixerPath: string, fs?: typeof FS): Promise<WebAssembly.Module>;
@@ -367,6 +370,117 @@ export type PlotHandler = (plotted: Float32Array[] | Float64Array[], index: numb
367
370
  }[]) => void;
368
371
  export type MetadataHandler = (key: string, value: string) => void;
369
372
  export type UIHandler = (item: FaustUIItem) => void;
373
+ declare class WasmAllocator {
374
+ private readonly memory;
375
+ private allocatedBytes;
376
+ constructor(memory: WebAssembly.Memory, offset: number);
377
+ /**
378
+ * Allocates a block of memory of the specified size, returning the pointer to the
379
+ * beginning of the block. The block is allocated at the current offset and the
380
+ * offset is incremented by the size of the block.
381
+ *
382
+ * @param sizeInBytes The size of the block to allocate in bytes.
383
+ * @returns The offset (pointer) to the beginning of the allocated block.
384
+ */
385
+ alloc(sizeInBytes: number): number;
386
+ /**
387
+ * Returns the underlying buffer object.
388
+ *
389
+ * @returns The buffer object.
390
+ */
391
+ getBuffer(): ArrayBuffer;
392
+ /**
393
+ * Returns the Int32 view of the underlying buffer object.
394
+ *
395
+ * @returns The view of the memory buffer as Int32Array.
396
+ */
397
+ getInt32Array(): Int32Array;
398
+ /**
399
+ * Returns the Float32 view of the underlying buffer object.
400
+ *
401
+ * @returns The view of the memory buffer as Float32Array.
402
+ */
403
+ getFloat32Array(): Float32Array;
404
+ /**
405
+ * Returns the Float64 view of the underlying buffer object..
406
+ *
407
+ * @returns The view of the memory buffer as Float64Array.
408
+ */
409
+ getFloat64Array(): Float64Array;
410
+ }
411
+ declare class Soundfile {
412
+ private readonly fPtr;
413
+ private readonly fBuffers;
414
+ private readonly fLength;
415
+ private readonly fSR;
416
+ private readonly fOffset;
417
+ private readonly fSampleSize;
418
+ private readonly fPtrSize;
419
+ private readonly fAllocator;
420
+ constructor(allocator: WasmAllocator, ptrSize: number, sampleSize: number, curChan: number, length: number, maxChan: number, totalParts: number);
421
+ private allocBuffers;
422
+ shareBuffers(curChan: number, maxChan: number): void;
423
+ copyToOut(part: number, maxChannels: number, offset: number, buffer: AudioBuffer): void;
424
+ copyToOutReal32(maxChannels: number, offset: number, buffer: AudioBuffer): void;
425
+ copyToOutReal64(maxChannels: number, offset: number, buffer: AudioBuffer): void;
426
+ emptyFile(part: number, offset: number): number;
427
+ displayMemory(where?: string, mem?: boolean): void;
428
+ getPtr(): number;
429
+ getHEAP32(): Int32Array;
430
+ getHEAPFloat32(): Float32Array;
431
+ getHEAPFloat64(): Float64Array;
432
+ }
433
+ declare class SoundfileReader {
434
+ private readonly fAllocator;
435
+ private readonly fPtrSize;
436
+ private readonly fSampleSize;
437
+ private readonly fContext;
438
+ private readonly fAudioBuffers;
439
+ constructor(allocator: WasmAllocator, context: BaseAudioContext, ptrSize: number, sampleSize: number);
440
+ /**
441
+ * Check if the file exists in the given directories.
442
+ *
443
+ * @param directories : the list of directories to search for the file
444
+ * @param fileName : the name of the file to search for
445
+ * @returns : the path of the file if found, otherwise an empty string
446
+ */
447
+ private checkFile;
448
+ /**
449
+ * Check if all soundfiles exist and return their real path_name.
450
+ *
451
+ * @param directories : the list of directories to search for the file
452
+ * @param fileNameList : the list of file names to search for
453
+ * @returns : the list of path names of the files if found, otherwise an empty string
454
+ */
455
+ checkFiles(directories: string[], fileNameList: string[]): Promise<string[]>;
456
+ /**
457
+ * Get the channels and length values of the given sound resource.
458
+ *
459
+ * @param pathName : the name of the file, or sound resource identified this way
460
+ * @returns channels and length of the soundfile
461
+ */
462
+ private getParamsFile;
463
+ /**
464
+ * Read one sound resource and fill the 'soundfile' structure accordingly
465
+ *
466
+ * @param soundfile - the soundfile to be filled
467
+ * @param pathName - the name of the file, or sound resource identified this way
468
+ * @param part - the part number to be filled in the soundfile
469
+ * @param maxChan - the maximum number of mono channels to fill
470
+ *
471
+ * @returns the offset in the soundfile buffer
472
+ *
473
+ */
474
+ private readFile;
475
+ /**
476
+ * Crate a soundfile, load all parts and copy audio data to the wasm soundfile buffer.
477
+ * @param pathNameList : list of soundfile paths
478
+ * @param maxChan : maximum number of channels
479
+ * @param isDouble : whether the soundfile will be copied as double
480
+ */
481
+ createSoundfile(pathNameList: string[], maxChan: number, isDouble: boolean): Promise<Soundfile | null>;
482
+ getHEAP32(): Int32Array;
483
+ }
370
484
  /**
371
485
  * DSP implementation: mimic the C++ 'dsp' class:
372
486
  * - adding MIDI control: metadata are decoded and incoming MIDI messages will control the associated controllers
@@ -544,6 +658,11 @@ export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
544
658
  }
545
659
  export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode {
546
660
  }
661
+ export type SoundfileItem = {
662
+ name: string;
663
+ url: string;
664
+ basePtr: number;
665
+ };
547
666
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
548
667
  protected fOutputHandler: OutputParamHandler | null;
549
668
  protected fComputeHandler: ComputeHandler | null;
@@ -559,11 +678,13 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
559
678
  protected fInputsItems: string[];
560
679
  protected fOutputsItems: string[];
561
680
  protected fDescriptor: FaustUIInputItem[];
681
+ protected fSoundfiles: SoundfileItem[];
682
+ protected fEndMemory: number;
562
683
  protected fAudioInputs: number;
563
684
  protected fAudioOutputs: number;
564
685
  protected fBufferSize: number;
565
- protected gPtrSize: number;
566
- protected gSampleSize: number;
686
+ protected fPtrSize: number;
687
+ protected fSampleSize: number;
567
688
  protected fPitchwheelLabel: {
568
689
  path: string;
569
690
  min: number;
@@ -580,6 +701,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
580
701
  protected fUICallback: UIHandler;
581
702
  protected fProcessing: boolean;
582
703
  protected fDestroyed: boolean;
704
+ protected fFirstCall: boolean;
583
705
  protected fJSONDsp: FaustDspMeta;
584
706
  constructor(sampleSize: number, bufferSize: number);
585
707
  static remap(v: number, mn0: number, mx0: number, mn1: number, mx1: number): number;
@@ -587,6 +709,23 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
587
709
  static parseGroup(group: FaustUIGroup, callback: (item: FaustUIItem) => any): void;
588
710
  static parseItems(items: FaustUIItem[], callback: (item: FaustUIItem) => any): void;
589
711
  static parseItem(item: FaustUIItem, callback: (item: FaustUIItem) => any): void;
712
+ static splitNames(input: string): string[];
713
+ /**
714
+ * Load a soundfile possibly containing several parts.
715
+ *
716
+ * @param sfReader : the soundfile reader
717
+ * @param sfOffset : the offset in the wasm memory
718
+ * @param name : the name of the soundfile
719
+ * @param url : the url of the soundfile
720
+ */
721
+ private loadSoundfile;
722
+ /**
723
+ * Init soundfiles memory.
724
+ *
725
+ * Soundfile pointers are located at the beginning of the DSP struct memory (one after the other),
726
+ * so that the TS scode can setup them easily.
727
+ */
728
+ protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
590
729
  protected updateOutputs(): void;
591
730
  metadata(handler: MetadataHandler): void;
592
731
  compute(input: Float32Array[], output: Float32Array[]): boolean;
@@ -608,6 +747,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
608
747
  getJSON(): string;
609
748
  getUI(): FaustUIDescriptor;
610
749
  getDescriptors(): FaustUIInputItem[];
750
+ hasSoundfiles(): boolean;
611
751
  start(): void;
612
752
  stop(): void;
613
753
  destroy(): void;
@@ -616,6 +756,7 @@ export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implement
616
756
  private fInstance;
617
757
  private fDSP;
618
758
  constructor(instance: FaustMonoDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
759
+ init(context: BaseAudioContext | null): Promise<void>;
619
760
  private initMemory;
620
761
  toString(): string;
621
762
  compute(input: Float32Array[] | ((input: Float32Array[] | Float64Array[]) => any), output: Float32Array[] | ((output: Float32Array[] | Float64Array[]) => any)): boolean;
@@ -670,6 +811,7 @@ export declare class FaustPolyWebAudioDsp extends FaustBaseWebAudioDsp implement
670
811
  private fAudioMixingHalf;
671
812
  private fVoiceTable;
672
813
  constructor(instance: FaustPolyDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
814
+ init(context: BaseAudioContext | null): Promise<void>;
673
815
  private initMemory;
674
816
  toString(): string;
675
817
  private allocVoice;
@@ -767,7 +909,8 @@ export interface FaustFFTAudioWorkletProcessorOptions {
767
909
  }
768
910
  export declare const getFaustFFTAudioWorkletProcessor: (dependencies: FaustFFTAudioWorkletProcessorDependencies, faustData: FaustFFTData, register?: boolean) => {
769
911
  new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
770
- prototype: AudioWorkletProcessor; /** Generated from the current window function */
912
+ /** Generated from the current window function */
913
+ prototype: AudioWorkletProcessor;
771
914
  parameterDescriptors: AudioParamDescriptor[];
772
915
  };
773
916
  export interface ILibFaust extends LibFaustWasm {