@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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
@@ -687,6 +687,7 @@ export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode
687
687
  type SoundfileItem = {
688
688
  name: string; // Name of the soundfile
689
689
  url: string; // URL of the soundfile
690
+ index: number; // Index in the DSP struct
690
691
  basePtr: number; // Base pointer in wasm memory
691
692
  };
692
693
 
@@ -791,7 +792,7 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
791
792
  }
792
793
  });
793
794
  } else if (item.type === "soundfile") {
794
- this.fSoundfiles.push({ name: item.label, url: item.url, basePtr: -1 });
795
+ this.fSoundfiles.push({ name: item.label, url: item.url, index: item.index, basePtr: -1 });
795
796
  }
796
797
  }
797
798
  }
@@ -843,14 +844,17 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
843
844
  }
844
845
 
845
846
  /**
846
- * Load a soundfile possibly containing several parts.
847
+ * Load a soundfile possibly containing several parts in the DSP struct.
848
+ * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
849
+ * The DSP struct is located at baseDSP in the wasm memory,
850
+ * either a monophonic DSP, or a voice in a polyphonic context.
847
851
  *
848
852
  * @param sfReader : the soundfile reader
849
- * @param sfOffset : the offset in the wasm memory
853
+ * @param baseDSP : the base DSP in the wasm memory
850
854
  * @param name : the name of the soundfile
851
855
  * @param url : the url of the soundfile
852
856
  */
853
- private async loadSoundfile(sfReader: SoundfileReader, sfOffset: number, name: string, url: string): Promise<void> {
857
+ private async loadSoundfile(sfReader: SoundfileReader, baseDSP: number, name: string, url: string): Promise<void> {
854
858
 
855
859
  console.log(`Soundfile ${name} paths: ${url}`);
856
860
 
@@ -870,30 +874,31 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
870
874
  if (item) {
871
875
  // Use the cached Soundfile
872
876
  if (item.basePtr !== -1) {
877
+
873
878
  // Update HEAP32 after soundfile creation
874
879
  const HEAP32 = sfReader.getHEAP32();
875
880
 
876
881
  // Fill the soundfile structure in wasm memory, sounfiles are at the beginning of the DSP memory
877
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
878
- console.log(`Soundfile CACHE ${url}}`);
882
+ console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
883
+
884
+ // Soundfile is located at 'index' in the DSP struct, to be added with baseDSP in the wasm memory
885
+ HEAP32[(baseDSP + item.index) >> 2] = item.basePtr;
879
886
 
880
- HEAP32[sfOffset >> 2] = item.basePtr;
881
887
  } else {
882
888
 
883
889
  // Create the soundfiles
884
890
  const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN, this.fSampleSize === 8);
885
891
  if (soundfile) {
886
892
 
887
- //soundfile.displayMemory("After createSoundfile");
888
-
889
893
  // Update HEAP32 after soundfile creation
890
894
  const HEAP32 = soundfile.getHEAP32();
891
895
 
892
- // Fill the soundfile structure in wasm memory, sounfiles are at the beginning of the DSP memory
896
+ // Get the soundfile pointer in wasm memory
893
897
  item.basePtr = soundfile.getPtr();
894
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
898
+ console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
895
899
 
896
- HEAP32[sfOffset >> 2] = item.basePtr;
900
+ // Soundfile is located at 'index' in the DSP struct, to be added with baseDSP in the wasm memory
901
+ HEAP32[(baseDSP + item.index) >> 2] = item.basePtr;
897
902
 
898
903
  } else {
899
904
  console.log(`Soundfile ${name} for ${url} cannot be created !}`);
@@ -907,15 +912,14 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
907
912
  /**
908
913
  * Init soundfiles memory.
909
914
  *
910
- * Soundfile pointers are located at the beginning of the DSP struct memory (one after the other),
911
- * so that the TS scode can setup them easily.
915
+ * @param allocator : the wasm memory allocator
916
+ * @param sfReader : the soundfile reader
917
+ * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
912
918
  */
913
919
  protected async initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void> {
914
920
  // Create and fill the soundfile structure
915
- let sfOffset: number = baseDSP;
916
921
  for (const { name, url } of this.fSoundfiles) {
917
- await this.loadSoundfile(sfReader, sfOffset, name, url);
918
- sfOffset += this.fPtrSize;
922
+ await this.loadSoundfile(sfReader, baseDSP, name, url);
919
923
  };
920
924
  }
921
925
 
@@ -661,6 +661,7 @@ export interface IFaustPolyWebAudioNode extends IFaustPolyWebAudioDsp, AudioNode
661
661
  export type SoundfileItem = {
662
662
  name: string;
663
663
  url: string;
664
+ index: number;
664
665
  basePtr: number;
665
666
  };
666
667
  export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
@@ -712,10 +713,13 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
712
713
  static splitNames(input: string): string[];
713
714
  private extractURLsFromJSON;
714
715
  /**
715
- * Load a soundfile possibly containing several parts.
716
+ * Load a soundfile possibly containing several parts in the DSP struct.
717
+ * Soundfile pointers are located at 'index' offset, to be read in the JSON file.
718
+ * The DSP struct is located at baseDSP in the wasm memory,
719
+ * either a monophonic DSP, or a voice in a polyphonic context.
716
720
  *
717
721
  * @param sfReader : the soundfile reader
718
- * @param sfOffset : the offset in the wasm memory
722
+ * @param baseDSP : the base DSP in the wasm memory
719
723
  * @param name : the name of the soundfile
720
724
  * @param url : the url of the soundfile
721
725
  */
@@ -723,8 +727,9 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
723
727
  /**
724
728
  * Init soundfiles memory.
725
729
  *
726
- * Soundfile pointers are located at the beginning of the DSP struct memory (one after the other),
727
- * so that the TS scode can setup them easily.
730
+ * @param allocator : the wasm memory allocator
731
+ * @param sfReader : the soundfile reader
732
+ * @param baseDSP : the DSP struct (either a monophonic DSP of polyphonic voice) base DSP in the wasm memory
728
733
  */
729
734
  protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
730
735
  protected updateOutputs(): void;
@@ -2277,7 +2277,7 @@ var FaustBaseWebAudioDsp = class {
2277
2277
  }
2278
2278
  });
2279
2279
  } else if (item.type === "soundfile") {
2280
- this.fSoundfiles.push({ name: item.label, url: item.url, basePtr: -1 });
2280
+ this.fSoundfiles.push({ name: item.label, url: item.url, index: item.index, basePtr: -1 });
2281
2281
  }
2282
2282
  };
2283
2283
  }
@@ -2314,11 +2314,11 @@ var FaustBaseWebAudioDsp = class {
2314
2314
  return [];
2315
2315
  }
2316
2316
  }
2317
- async loadSoundfile(sfReader, sfOffset, name, url) {
2317
+ async loadSoundfile(sfReader, baseDSP, name, url) {
2318
2318
  console.log(`Soundfile ${name} paths: ${url}`);
2319
- const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
2320
2319
  const sfReaderURLs = this.extractURLsFromJSON();
2321
2320
  console.log(`sfReaderURLs ${sfReaderURLs}`);
2321
+ const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
2322
2322
  sfDirectories.push(...sfReaderURLs);
2323
2323
  console.log(`sfDirectories ${sfDirectories}`);
2324
2324
  const sfPathNames = await sfReader.checkFiles(sfDirectories, FaustBaseWebAudioDsp.splitNames(url));
@@ -2327,16 +2327,15 @@ var FaustBaseWebAudioDsp = class {
2327
2327
  if (item) {
2328
2328
  if (item.basePtr !== -1) {
2329
2329
  const HEAP32 = sfReader.getHEAP32();
2330
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
2331
- console.log(`Soundfile CACHE ${url}}`);
2332
- HEAP32[sfOffset >> 2] = item.basePtr;
2330
+ console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
2331
+ HEAP32[baseDSP + item.index >> 2] = item.basePtr;
2333
2332
  } else {
2334
2333
  const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN, this.fSampleSize === 8);
2335
2334
  if (soundfile) {
2336
2335
  const HEAP32 = soundfile.getHEAP32();
2337
2336
  item.basePtr = soundfile.getPtr();
2338
- console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with sfOffset ${sfOffset}`);
2339
- HEAP32[sfOffset >> 2] = item.basePtr;
2337
+ console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
2338
+ HEAP32[baseDSP + item.index >> 2] = item.basePtr;
2340
2339
  } else {
2341
2340
  console.log(`Soundfile ${name} for ${url} cannot be created !}`);
2342
2341
  }
@@ -2346,10 +2345,8 @@ var FaustBaseWebAudioDsp = class {
2346
2345
  }
2347
2346
  }
2348
2347
  async initSoundfileMemory(allocator, sfReader, baseDSP) {
2349
- let sfOffset = baseDSP;
2350
2348
  for (const { name, url } of this.fSoundfiles) {
2351
- await this.loadSoundfile(sfReader, sfOffset, name, url);
2352
- sfOffset += this.fPtrSize;
2349
+ await this.loadSoundfile(sfReader, baseDSP, name, url);
2353
2350
  }
2354
2351
  ;
2355
2352
  }