@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;
@@ -8303,7 +8303,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8303
8303
  }
8304
8304
  });
8305
8305
  } else if (item.type === "soundfile") {
8306
- this.fSoundfiles.push({ name: item.label, url: item.url, basePtr: -1 });
8306
+ this.fSoundfiles.push({ name: item.label, url: item.url, index: item.index, basePtr: -1 });
8307
8307
  }
8308
8308
  };
8309
8309
  }
@@ -8332,9 +8332,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8332
8332
  let trimmed = input.replace(/^\{|\}$/g, "");
8333
8333
  return trimmed.split(";").map((str) => str.length <= 2 ? "" : str.substring(1, str.length - 1));
8334
8334
  }
8335
- async loadSoundfile(sfReader, sfOffset, name, url) {
8335
+ extractURLsFromJSON() {
8336
+ const soundfilesEntry = this.fJSONDsp.meta.find((entry) => entry.soundfiles !== void 0);
8337
+ if (soundfilesEntry) {
8338
+ return soundfilesEntry.soundfiles.split(";").filter((url) => url !== "");
8339
+ } else {
8340
+ return [];
8341
+ }
8342
+ }
8343
+ async loadSoundfile(sfReader, baseDSP, name, url) {
8336
8344
  console.log(`Soundfile ${name} paths: ${url}`);
8345
+ const sfReaderURLs = this.extractURLsFromJSON();
8346
+ console.log(`sfReaderURLs ${sfReaderURLs}`);
8337
8347
  const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
8348
+ sfDirectories.push(...sfReaderURLs);
8338
8349
  console.log(`sfDirectories ${sfDirectories}`);
8339
8350
  const sfPathNames = await sfReader.checkFiles(sfDirectories, FaustBaseWebAudioDsp.splitNames(url));
8340
8351
  console.log(`Soundfile ${name} paths: ${sfPathNames}`);
@@ -8342,16 +8353,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8342
8353
  if (item) {
8343
8354
  if (item.basePtr !== -1) {
8344
8355
  const HEAP32 = sfReader.getHEAP32();
8345
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
8346
- console.log(`Soundfile CACHE ${url}}`);
8347
- HEAP32[sfOffset >> 2] = item.basePtr;
8356
+ console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
8357
+ HEAP32[baseDSP + item.index >> 2] = item.basePtr;
8348
8358
  } else {
8349
8359
  const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN, this.fSampleSize === 8);
8350
8360
  if (soundfile) {
8351
8361
  const HEAP32 = soundfile.getHEAP32();
8352
8362
  item.basePtr = soundfile.getPtr();
8353
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
8354
- HEAP32[sfOffset >> 2] = item.basePtr;
8363
+ console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
8364
+ HEAP32[baseDSP + item.index >> 2] = item.basePtr;
8355
8365
  } else {
8356
8366
  console.log(`Soundfile ${name} for ${url} cannot be created !}`);
8357
8367
  }
@@ -8361,10 +8371,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8361
8371
  }
8362
8372
  }
8363
8373
  async initSoundfileMemory(allocator, sfReader, baseDSP) {
8364
- let sfOffset = baseDSP;
8365
8374
  for (const { name, url } of this.fSoundfiles) {
8366
- await this.loadSoundfile(sfReader, sfOffset, name, url);
8367
- sfOffset += this.fPtrSize;
8375
+ await this.loadSoundfile(sfReader, baseDSP, name, url);
8368
8376
  }
8369
8377
  ;
8370
8378
  }