@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;
@@ -355,9 +356,11 @@ export declare class FaustDspInstance implements IFaustDspInstance {
355
356
  }
356
357
  export declare class FaustWasmInstantiator {
357
358
  private static createWasmImport;
358
- private static createWasmMemory;
359
+ private static createWasmMemoryPoly;
360
+ private static createWasmMemoryMono;
359
361
  private static createMonoDSPInstanceAux;
360
- private static createMemoryAux;
362
+ private static createMemoryMono;
363
+ private static createMemoryPoly;
361
364
  private static createMixerAux;
362
365
  static loadDSPFactory(wasmPath: string, jsonPath: string): Promise<FaustDspFactory>;
363
366
  static loadDSPMixer(mixerPath: string, fs?: typeof FS): Promise<WebAssembly.Module>;
@@ -374,6 +377,117 @@ export type PlotHandler = (plotted: Float32Array[] | Float64Array[], index: numb
374
377
  }[]) => void;
375
378
  export type MetadataHandler = (key: string, value: string) => void;
376
379
  export type UIHandler = (item: FaustUIItem) => void;
380
+ declare class WasmAllocator {
381
+ private readonly memory;
382
+ private allocatedBytes;
383
+ constructor(memory: WebAssembly.Memory, offset: number);
384
+ /**
385
+ * Allocates a block of memory of the specified size, returning the pointer to the
386
+ * beginning of the block. The block is allocated at the current offset and the
387
+ * offset is incremented by the size of the block.
388
+ *
389
+ * @param sizeInBytes The size of the block to allocate in bytes.
390
+ * @returns The offset (pointer) to the beginning of the allocated block.
391
+ */
392
+ alloc(sizeInBytes: number): number;
393
+ /**
394
+ * Returns the underlying buffer object.
395
+ *
396
+ * @returns The buffer object.
397
+ */
398
+ getBuffer(): ArrayBuffer;
399
+ /**
400
+ * Returns the Int32 view of the underlying buffer object.
401
+ *
402
+ * @returns The view of the memory buffer as Int32Array.
403
+ */
404
+ getInt32Array(): Int32Array;
405
+ /**
406
+ * Returns the Float32 view of the underlying buffer object.
407
+ *
408
+ * @returns The view of the memory buffer as Float32Array.
409
+ */
410
+ getFloat32Array(): Float32Array;
411
+ /**
412
+ * Returns the Float64 view of the underlying buffer object..
413
+ *
414
+ * @returns The view of the memory buffer as Float64Array.
415
+ */
416
+ getFloat64Array(): Float64Array;
417
+ }
418
+ declare class Soundfile {
419
+ private readonly fPtr;
420
+ private readonly fBuffers;
421
+ private readonly fLength;
422
+ private readonly fSR;
423
+ private readonly fOffset;
424
+ private readonly fSampleSize;
425
+ private readonly fPtrSize;
426
+ private readonly fAllocator;
427
+ constructor(allocator: WasmAllocator, ptrSize: number, sampleSize: number, curChan: number, length: number, maxChan: number, totalParts: number);
428
+ private allocBuffers;
429
+ 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;
433
+ emptyFile(part: number, offset: number): number;
434
+ displayMemory(where?: string, mem?: boolean): void;
435
+ getPtr(): number;
436
+ getHEAP32(): Int32Array;
437
+ getHEAPFloat32(): Float32Array;
438
+ getHEAPFloat64(): Float64Array;
439
+ }
440
+ declare class SoundfileReader {
441
+ private readonly fAllocator;
442
+ private readonly fPtrSize;
443
+ private readonly fSampleSize;
444
+ private readonly fContext;
445
+ private readonly fAudioBuffers;
446
+ constructor(allocator: WasmAllocator, context: BaseAudioContext, ptrSize: number, sampleSize: number);
447
+ /**
448
+ * Check if the file exists in the given directories.
449
+ *
450
+ * @param directories : the list of directories to search for the file
451
+ * @param fileName : the name of the file to search for
452
+ * @returns : the path of the file if found, otherwise an empty string
453
+ */
454
+ private checkFile;
455
+ /**
456
+ * Check if all soundfiles exist and return their real path_name.
457
+ *
458
+ * @param directories : the list of directories to search for the file
459
+ * @param fileNameList : the list of file names to search for
460
+ * @returns : the list of path names of the files if found, otherwise an empty string
461
+ */
462
+ checkFiles(directories: string[], fileNameList: string[]): Promise<string[]>;
463
+ /**
464
+ * Get the channels and length values of the given sound resource.
465
+ *
466
+ * @param pathName : the name of the file, or sound resource identified this way
467
+ * @returns channels and length of the soundfile
468
+ */
469
+ private getParamsFile;
470
+ /**
471
+ * Read one sound resource and fill the 'soundfile' structure accordingly
472
+ *
473
+ * @param soundfile - the soundfile to be filled
474
+ * @param pathName - the name of the file, or sound resource identified this way
475
+ * @param part - the part number to be filled in the soundfile
476
+ * @param maxChan - the maximum number of mono channels to fill
477
+ *
478
+ * @returns the offset in the soundfile buffer
479
+ *
480
+ */
481
+ private readFile;
482
+ /**
483
+ * Crate a soundfile, load all parts and copy audio data to the wasm soundfile buffer.
484
+ * @param pathNameList : list of soundfile paths
485
+ * @param maxChan : maximum number of channels
486
+ * @param isDouble : whether the soundfile will be copied as double
487
+ */
488
+ createSoundfile(pathNameList: string[], maxChan: number, isDouble: boolean): Promise<Soundfile | null>;
489
+ getHEAP32(): Int32Array;
490
+ }
377
491
  /**
378
492
  * DSP implementation: mimic the C++ 'dsp' class:
379
493
  * - adding MIDI control: metadata are decoded and incoming MIDI messages will control the associated controllers
@@ -551,6 +665,11 @@ export interface IFaustPolyWebAudioDsp extends IFaustBaseWebAudioDsp {
551
665
  }
552
666
  export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode {
553
667
  }
668
+ export type SoundfileItem = {
669
+ name: string;
670
+ url: string;
671
+ basePtr: number;
672
+ };
554
673
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
555
674
  protected fOutputHandler: OutputParamHandler | null;
556
675
  protected fComputeHandler: ComputeHandler | null;
@@ -566,11 +685,13 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
566
685
  protected fInputsItems: string[];
567
686
  protected fOutputsItems: string[];
568
687
  protected fDescriptor: FaustUIInputItem[];
688
+ protected fSoundfiles: SoundfileItem[];
689
+ protected fEndMemory: number;
569
690
  protected fAudioInputs: number;
570
691
  protected fAudioOutputs: number;
571
692
  protected fBufferSize: number;
572
- protected gPtrSize: number;
573
- protected gSampleSize: number;
693
+ protected fPtrSize: number;
694
+ protected fSampleSize: number;
574
695
  protected fPitchwheelLabel: {
575
696
  path: string;
576
697
  min: number;
@@ -587,6 +708,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
587
708
  protected fUICallback: UIHandler;
588
709
  protected fProcessing: boolean;
589
710
  protected fDestroyed: boolean;
711
+ protected fFirstCall: boolean;
590
712
  protected fJSONDsp: FaustDspMeta;
591
713
  constructor(sampleSize: number, bufferSize: number);
592
714
  static remap(v: number, mn0: number, mx0: number, mn1: number, mx1: number): number;
@@ -594,6 +716,23 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
594
716
  static parseGroup(group: FaustUIGroup, callback: (item: FaustUIItem) => any): void;
595
717
  static parseItems(items: FaustUIItem[], callback: (item: FaustUIItem) => any): void;
596
718
  static parseItem(item: FaustUIItem, callback: (item: FaustUIItem) => any): void;
719
+ static splitNames(input: string): string[];
720
+ /**
721
+ * Load a soundfile possibly containing several parts.
722
+ *
723
+ * @param sfReader : the soundfile reader
724
+ * @param sfOffset : the offset in the wasm memory
725
+ * @param name : the name of the soundfile
726
+ * @param url : the url of the soundfile
727
+ */
728
+ private loadSoundfile;
729
+ /**
730
+ * Init soundfiles memory.
731
+ *
732
+ * Soundfile pointers are located at the beginning of the DSP struct memory (one after the other),
733
+ * so that the TS scode can setup them easily.
734
+ */
735
+ protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
597
736
  protected updateOutputs(): void;
598
737
  metadata(handler: MetadataHandler): void;
599
738
  compute(input: Float32Array[], output: Float32Array[]): boolean;
@@ -615,6 +754,7 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
615
754
  getJSON(): string;
616
755
  getUI(): FaustUIDescriptor;
617
756
  getDescriptors(): FaustUIInputItem[];
757
+ hasSoundfiles(): boolean;
618
758
  start(): void;
619
759
  stop(): void;
620
760
  destroy(): void;
@@ -623,6 +763,7 @@ export declare class FaustMonoWebAudioDsp extends FaustBaseWebAudioDsp implement
623
763
  private fInstance;
624
764
  private fDSP;
625
765
  constructor(instance: FaustMonoDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
766
+ init(context: BaseAudioContext | null): Promise<void>;
626
767
  private initMemory;
627
768
  toString(): string;
628
769
  compute(input: Float32Array[] | ((input: Float32Array[] | Float64Array[]) => any), output: Float32Array[] | ((output: Float32Array[] | Float64Array[]) => any)): boolean;
@@ -677,6 +818,7 @@ export declare class FaustPolyWebAudioDsp extends FaustBaseWebAudioDsp implement
677
818
  private fAudioMixingHalf;
678
819
  private fVoiceTable;
679
820
  constructor(instance: FaustPolyDspInstance, sampleRate: number, sampleSize: number, bufferSize: number);
821
+ init(context: BaseAudioContext | null): Promise<void>;
680
822
  private initMemory;
681
823
  toString(): string;
682
824
  private allocVoice;
@@ -774,7 +916,8 @@ export interface FaustFFTAudioWorkletProcessorOptions {
774
916
  }
775
917
  export declare const getFaustFFTAudioWorkletProcessor: (dependencies: FaustFFTAudioWorkletProcessorDependencies, faustData: FaustFFTData, register?: boolean) => {
776
918
  new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
777
- prototype: AudioWorkletProcessor; /** Generated from the current window function */
919
+ /** Generated from the current window function */
920
+ prototype: AudioWorkletProcessor;
778
921
  parameterDescriptors: AudioParamDescriptor[];
779
922
  };
780
923
  export interface ILibFaust extends LibFaustWasm {