@grame/faustwasm 0.2.1 → 0.2.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -87,12 +87,14 @@ export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
87
87
  * @param sampleRate - the sample rate in Hz
88
88
  * @param bufferSize - the buffer size in frames
89
89
  * @param factory - default is the compiled factory
90
+ * @param context - if this exists, will be used to fetch soundfiles online
90
91
  * @returns the compiled processor or 'null' if failure
91
92
  */
92
93
  createOfflineProcessor(
93
94
  sampleRate: number,
94
95
  bufferSize: number,
95
- factory?: LooseFaustDspFactory
96
+ factory?: LooseFaustDspFactory,
97
+ context?: BaseAudioContext
96
98
  ): Promise<IFaustMonoOfflineProcessor | null>;
97
99
 
98
100
  /**
@@ -166,6 +168,7 @@ export interface IFaustPolyDspGenerator extends GeneratorSupportingSoundfiles {
166
168
  * @param voiceFactory - the Faust factory for voices, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
167
169
  * @param mixerModule - the wasm Mixer module (loaded from 'mixer32.wasm' or 'mixer64.wasm' files)
168
170
  * @param effectFactory - the Faust factory for the effect, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
171
+ * @param context - if this exists, will be used to fetch soundfiles online
169
172
  * @returns the compiled processor or 'null' if failure
170
173
  */
171
174
  createOfflineProcessor(
@@ -175,7 +178,7 @@ export interface IFaustPolyDspGenerator extends GeneratorSupportingSoundfiles {
175
178
  voiceFactory?: LooseFaustDspFactory,
176
179
  mixerModule?: WebAssembly.Module,
177
180
  effectFactory?: LooseFaustDspFactory | null,
178
- processorName?: string
181
+ context?: BaseAudioContext
179
182
  ): Promise<IFaustPolyOfflineProcessor | null>;
180
183
 
181
184
  /**
@@ -422,13 +425,15 @@ const dependencies = {
422
425
  async createOfflineProcessor(
423
426
  sampleRate: number,
424
427
  bufferSize: number,
425
- factory = this.factory as LooseFaustDspFactory
428
+ factory = this.factory as LooseFaustDspFactory,
429
+ context?: BaseAudioContext
426
430
  ) {
427
431
  if (!factory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
428
432
 
429
433
  const meta = JSON.parse(factory.json);
430
434
  const instance = await FaustWasmInstantiator.createAsyncMonoDSPInstance(factory);
431
435
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
436
+ if (context) factory.soundfiles = await SoundfileReader.loadSoundfiles(meta, factory.soundfiles || {}, context);
432
437
  const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
433
438
  return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
434
439
  }
@@ -675,7 +680,8 @@ const dependencies = {
675
680
  voices: number,
676
681
  voiceFactory = this.voiceFactory as LooseFaustDspFactory,
677
682
  mixerModule = this.mixerModule,
678
- effectFactory = this.effectFactory as LooseFaustDspFactory | null
683
+ effectFactory = this.effectFactory as LooseFaustDspFactory | null,
684
+ context?: BaseAudioContext
679
685
  ) {
680
686
  if (!voiceFactory) throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
681
687
 
@@ -683,6 +689,10 @@ const dependencies = {
683
689
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : undefined;
684
690
  const instance = await FaustWasmInstantiator.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || undefined);
685
691
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
692
+ if (context) {
693
+ voiceFactory.soundfiles = await SoundfileReader.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
694
+ if (effectFactory) effectFactory.soundfiles = await SoundfileReader.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
695
+ }
686
696
  const soundfiles = { ...effectFactory?.soundfiles, ...voiceFactory.soundfiles };
687
697
  const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
688
698
  return new FaustPolyOfflineProcessor(polyDsp, bufferSize);
@@ -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;
@@ -3715,12 +3715,14 @@ const dependencies = {
3715
3715
  throw e;
3716
3716
  }
3717
3717
  }
3718
- async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory) {
3718
+ async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory, context) {
3719
3719
  if (!factory)
3720
3720
  throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3721
3721
  const meta = JSON.parse(factory.json);
3722
3722
  const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
3723
3723
  const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
3724
+ if (context)
3725
+ factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
3724
3726
  const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
3725
3727
  return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
3726
3728
  }
@@ -3922,13 +3924,18 @@ const dependencies = {
3922
3924
  throw e;
3923
3925
  }
3924
3926
  }
3925
- async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory) {
3927
+ async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, context) {
3926
3928
  if (!voiceFactory)
3927
3929
  throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
3928
3930
  const voiceMeta = JSON.parse(voiceFactory.json);
3929
3931
  const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
3930
3932
  const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
3931
3933
  const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
3934
+ if (context) {
3935
+ voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
3936
+ if (effectFactory)
3937
+ effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
3938
+ }
3932
3939
  const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
3933
3940
  const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
3934
3941
  return new FaustPolyOfflineProcessor(polyDsp, bufferSize);