@grame/faustwasm 0.1.1 → 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 {
@@ -719,10 +720,13 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
719
720
  static splitNames(input: string): string[];
720
721
  private extractURLsFromJSON;
721
722
  /**
722
- * 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.
723
727
  *
724
728
  * @param sfReader : the soundfile reader
725
- * @param sfOffset : the offset in the wasm memory
729
+ * @param baseDSP : the base DSP in the wasm memory
726
730
  * @param name : the name of the soundfile
727
731
  * @param url : the url of the soundfile
728
732
  */
@@ -730,8 +734,9 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
730
734
  /**
731
735
  * Init soundfiles memory.
732
736
  *
733
- * Soundfile pointers are located at the beginning of the DSP struct memory (one after the other),
734
- * 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
735
740
  */
736
741
  protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
737
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
  }
@@ -8340,11 +8340,11 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8340
8340
  return [];
8341
8341
  }
8342
8342
  }
8343
- async loadSoundfile(sfReader, sfOffset, name, url) {
8343
+ async loadSoundfile(sfReader, baseDSP, name, url) {
8344
8344
  console.log(`Soundfile ${name} paths: ${url}`);
8345
- const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
8346
8345
  const sfReaderURLs = this.extractURLsFromJSON();
8347
8346
  console.log(`sfReaderURLs ${sfReaderURLs}`);
8347
+ const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
8348
8348
  sfDirectories.push(...sfReaderURLs);
8349
8349
  console.log(`sfDirectories ${sfDirectories}`);
8350
8350
  const sfPathNames = await sfReader.checkFiles(sfDirectories, FaustBaseWebAudioDsp.splitNames(url));
@@ -8353,16 +8353,15 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8353
8353
  if (item) {
8354
8354
  if (item.basePtr !== -1) {
8355
8355
  const HEAP32 = sfReader.getHEAP32();
8356
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
8357
- console.log(`Soundfile CACHE ${url}}`);
8358
- 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;
8359
8358
  } else {
8360
8359
  const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN, this.fSampleSize === 8);
8361
8360
  if (soundfile) {
8362
8361
  const HEAP32 = soundfile.getHEAP32();
8363
8362
  item.basePtr = soundfile.getPtr();
8364
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
8365
- 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;
8366
8365
  } else {
8367
8366
  console.log(`Soundfile ${name} for ${url} cannot be created !}`);
8368
8367
  }
@@ -8372,10 +8371,8 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
8372
8371
  }
8373
8372
  }
8374
8373
  async initSoundfileMemory(allocator, sfReader, baseDSP) {
8375
- let sfOffset = baseDSP;
8376
8374
  for (const { name, url } of this.fSoundfiles) {
8377
- await this.loadSoundfile(sfReader, sfOffset, name, url);
8378
- sfOffset += this.fPtrSize;
8375
+ await this.loadSoundfile(sfReader, baseDSP, name, url);
8379
8376
  }
8380
8377
  ;
8381
8378
  }