@grame/faustwasm 0.2.1 → 0.2.3

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.
@@ -481,10 +481,10 @@ export declare class Soundfile {
481
481
  getHEAPFloat64(): Float64Array;
482
482
  }
483
483
  /**
484
- * DSP implementation: mimic the C++ 'dsp' class:
484
+ * DSP implementation that mimic the C++ 'dsp' class:
485
485
  * - adding MIDI control: metadata are decoded and incoming MIDI messages will control the associated controllers
486
486
  * - an output handler can be set to treat produced output controllers (like 'bargraph')
487
- * - regular controllers are handled using setParamValue/getParamValue
487
+ * - regular controllers are handled using setParamValue/getParamValue and getParams methods
488
488
  */
489
489
  export interface IFaustBaseWebAudioDsp {
490
490
  /**
@@ -596,12 +596,6 @@ export interface IFaustBaseWebAudioDsp {
596
596
  * @return the DSP JSON description as object
597
597
  */
598
598
  getMeta(): FaustDspMeta;
599
- /**
600
- * Get DSP JSON description with its UI and metadata.
601
- *
602
- * @return the DSP JSON description
603
- */
604
- getJSON(): string;
605
599
  /**
606
600
  * Get DSP UI description.
607
601
  *
@@ -614,6 +608,12 @@ export interface IFaustBaseWebAudioDsp {
614
608
  * @return the DSP UI items description
615
609
  */
616
610
  getDescriptors(): FaustUIInputItem[];
611
+ /**
612
+ * Get DSP JSON description with its UI and metadata.
613
+ *
614
+ * @return the DSP JSON description
615
+ */
616
+ getJSON(): string;
617
617
  /**
618
618
  * Start the DSP.
619
619
  */
@@ -1393,9 +1393,10 @@ export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
1393
1393
  * @param sampleRate - the sample rate in Hz
1394
1394
  * @param bufferSize - the buffer size in frames
1395
1395
  * @param factory - default is the compiled factory
1396
+ * @param context - if this exists, will be used to fetch soundfiles online
1396
1397
  * @returns the compiled processor or 'null' if failure
1397
1398
  */
1398
- createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<IFaustMonoOfflineProcessor | null>;
1399
+ createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, context?: BaseAudioContext): Promise<IFaustMonoOfflineProcessor | null>;
1399
1400
  /**
1400
1401
  * Get DSP JSON description with its UI and metadata as object.
1401
1402
  *
@@ -1452,9 +1453,10 @@ export interface IFaustPolyDspGenerator extends GeneratorSupportingSoundfiles {
1452
1453
  * @param voiceFactory - the Faust factory for voices, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
1453
1454
  * @param mixerModule - the wasm Mixer module (loaded from 'mixer32.wasm' or 'mixer64.wasm' files)
1454
1455
  * @param effectFactory - the Faust factory for the effect, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
1456
+ * @param context - if this exists, will be used to fetch soundfiles online
1455
1457
  * @returns the compiled processor or 'null' if failure
1456
1458
  */
1457
- createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, processorName?: string): Promise<IFaustPolyOfflineProcessor | null>;
1459
+ createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, context?: BaseAudioContext): Promise<IFaustPolyOfflineProcessor | null>;
1458
1460
  /**
1459
1461
  * Get DSP JSON description with its UI and metadata as object.
1460
1462
  *
@@ -1489,7 +1491,7 @@ export declare class FaustMonoDspGenerator implements IFaustMonoDspGenerator {
1489
1491
  prototype: AudioWorkletProcessor;
1490
1492
  parameterDescriptors: AudioParamDescriptor[];
1491
1493
  }>;
1492
- createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<FaustMonoOfflineProcessor>;
1494
+ createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, context?: BaseAudioContext): Promise<FaustMonoOfflineProcessor>;
1493
1495
  getMeta(): any;
1494
1496
  getJSON(): string;
1495
1497
  getUI(): any;
@@ -1511,7 +1513,7 @@ export declare class FaustPolyDspGenerator implements IFaustPolyDspGenerator {
1511
1513
  prototype: AudioWorkletProcessor;
1512
1514
  parameterDescriptors: AudioParamDescriptor[];
1513
1515
  }>;
1514
- createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null): Promise<FaustPolyOfflineProcessor>;
1516
+ createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, context?: BaseAudioContext): Promise<FaustPolyOfflineProcessor>;
1515
1517
  getMeta(): FaustDspMeta;
1516
1518
  getJSON(): string;
1517
1519
  getUI(): FaustUIDescriptor;
package/dist/cjs/index.js CHANGED
@@ -3746,12 +3746,14 @@ const dependencies = {
3746
3746
  throw e;
3747
3747
  }
3748
3748
  }
3749
- async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory) {
3749
+ async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory, context) {
3750
3750
  if (!factory)
3751
3751
  throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3752
3752
  const meta = JSON.parse(factory.json);
3753
3753
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
3754
3754
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
3755
+ if (context)
3756
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
3755
3757
  const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
3756
3758
  return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
3757
3759
  }
@@ -3953,13 +3955,18 @@ const dependencies = {
3953
3955
  throw e;
3954
3956
  }
3955
3957
  }
3956
- async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory) {
3958
+ async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, context) {
3957
3959
  if (!voiceFactory)
3958
3960
  throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3959
3961
  const voiceMeta = JSON.parse(voiceFactory.json);
3960
3962
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
3961
3963
  const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
3962
3964
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
3965
+ if (context) {
3966
+ voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
3967
+ if (effectFactory)
3968
+ effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
3969
+ }
3963
3970
  const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
3964
3971
  const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
3965
3972
  return new FaustPolyOfflineProcessor(polyDsp, bufferSize);