@grame/faustwasm 0.1.0 → 0.1.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.
@@ -668,6 +668,7 @@ export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode
668
668
  export type SoundfileItem = {
669
669
  name: string;
670
670
  url: string;
671
+ index: number;
671
672
  basePtr: number;
672
673
  };
673
674
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
@@ -717,11 +718,15 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
717
718
  static parseItems(items: FaustUIItem[], callback: (item: FaustUIItem) => any): void;
718
719
  static parseItem(item: FaustUIItem, callback: (item: FaustUIItem) => any): void;
719
720
  static splitNames(input: string): string[];
721
+ private extractURLsFromJSON;
720
722
  /**
721
- * Load a soundfile possibly containing several parts.
723
+ * Load a soundfile possibly containing several parts in the DSP struct.
724
+ * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
725
+ * The DSP struct is located at baseDSP in the wasm memory,
726
+ * either a monophonic DSP, or a voice in a polyphonic context.
722
727
  *
723
728
  * @param sfReader : the soundfile reader
724
- * @param sfOffset : the offset in the wasm memory
729
+ * @param baseDSP : the base DSP in the wasm memory
725
730
  * @param name : the name of the soundfile
726
731
  * @param url : the url of the soundfile
727
732
  */
@@ -729,8 +734,9 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
729
734
  /**
730
735
  * Init soundfiles memory.
731
736
  *
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.
737
+ * @param allocator : the wasm memory allocator
738
+ * @param sfReader : the soundfile reader
739
+ * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
734
740
  */
735
741
  protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
736
742
  protected updateOutputs(): void;
@@ -8265,7 +8265,7 @@ var FaustBaseWebAudioDsp = class {
8265
8265
  }
8266
8266
  });
8267
8267
  } else if (item.type === "soundfile") {
8268
- this.fSoundfiles.push({ name: item.label, url: item.url, basePtr: -1 });
8268
+ this.fSoundfiles.push({ name: item.label, url: item.url, index: item.index, basePtr: -1 });
8269
8269
  }
8270
8270
  };
8271
8271
  }
@@ -8294,9 +8294,20 @@ var FaustBaseWebAudioDsp = class {
8294
8294
  let trimmed = input.replace(/^\{|\}$/g, "");
8295
8295
  return trimmed.split(";").map((str) => str.length <= 2 ? "" : str.substring(1, str.length - 1));
8296
8296
  }
8297
- async loadSoundfile(sfReader, sfOffset, name, url) {
8297
+ extractURLsFromJSON() {
8298
+ const soundfilesEntry = this.fJSONDsp.meta.find((entry) => entry.soundfiles !== void 0);
8299
+ if (soundfilesEntry) {
8300
+ return soundfilesEntry.soundfiles.split(";").filter((url) => url !== "");
8301
+ } else {
8302
+ return [];
8303
+ }
8304
+ }
8305
+ async loadSoundfile(sfReader, baseDSP, name, url) {
8298
8306
  console.log(`Soundfile ${name} paths: ${url}`);
8307
+ const sfReaderURLs = this.extractURLsFromJSON();
8308
+ console.log(`sfReaderURLs ${sfReaderURLs}`);
8299
8309
  const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
8310
+ sfDirectories.push(...sfReaderURLs);
8300
8311
  console.log(`sfDirectories ${sfDirectories}`);
8301
8312
  const sfPathNames = await sfReader.checkFiles(sfDirectories, FaustBaseWebAudioDsp.splitNames(url));
8302
8313
  console.log(`Soundfile ${name} paths: ${sfPathNames}`);
@@ -8304,16 +8315,15 @@ var FaustBaseWebAudioDsp = class {
8304
8315
  if (item) {
8305
8316
  if (item.basePtr !== -1) {
8306
8317
  const HEAP32 = sfReader.getHEAP32();
8307
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
8308
- console.log(`Soundfile CACHE ${url}}`);
8309
- HEAP32[sfOffset >> 2] = item.basePtr;
8318
+ console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
8319
+ HEAP32[baseDSP + item.index >> 2] = item.basePtr;
8310
8320
  } else {
8311
8321
  const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN, this.fSampleSize === 8);
8312
8322
  if (soundfile) {
8313
8323
  const HEAP32 = soundfile.getHEAP32();
8314
8324
  item.basePtr = soundfile.getPtr();
8315
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
8316
- HEAP32[sfOffset >> 2] = item.basePtr;
8325
+ console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
8326
+ HEAP32[baseDSP + item.index >> 2] = item.basePtr;
8317
8327
  } else {
8318
8328
  console.log(`Soundfile ${name} for ${url} cannot be created !}`);
8319
8329
  }
@@ -8323,10 +8333,8 @@ var FaustBaseWebAudioDsp = class {
8323
8333
  }
8324
8334
  }
8325
8335
  async initSoundfileMemory(allocator, sfReader, baseDSP) {
8326
- let sfOffset = baseDSP;
8327
8336
  for (const { name, url } of this.fSoundfiles) {
8328
- await this.loadSoundfile(sfReader, sfOffset, name, url);
8329
- sfOffset += this.fPtrSize;
8337
+ await this.loadSoundfile(sfReader, baseDSP, name, url);
8330
8338
  }
8331
8339
  ;
8332
8340
  }