@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.
- package/assets/standalone/faustwasm/index.d.ts +10 -4
- package/assets/standalone/faustwasm/index.js +18 -10
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.d.ts +10 -4
- package/dist/cjs/index.js +18 -10
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +10 -4
- package/dist/cjs-bundle/index.js +18 -10
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +10 -4
- package/dist/esm/index.js +18 -10
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +10 -4
- package/dist/esm-bundle/index.js +18 -10
- package/dist/esm-bundle/index.js.map +2 -2
- package/package.json +1 -1
- package/src/FaustWebAudioDsp.ts +37 -19
- package/test/faustlive-wasm/faustwasm/index.d.ts +10 -4
- package/test/faustlive-wasm/faustwasm/index.js +18 -10
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
package/package.json
CHANGED
package/src/FaustWebAudioDsp.ts
CHANGED
|
@@ -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
|
}
|
|
@@ -830,21 +831,38 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
|
830
831
|
// Split the string into an array of strings and remove first and last characters
|
|
831
832
|
return trimmed.split(";").map(str => str.length <= 2 ? '' : str.substring(1, str.length - 1));
|
|
832
833
|
}
|
|
834
|
+
|
|
835
|
+
private extractURLsFromJSON(): string[] {
|
|
836
|
+
// Find the entry with the "soundfiles" key
|
|
837
|
+
const soundfilesEntry = this.fJSONDsp.meta.find(entry => entry.soundfiles !== undefined);
|
|
838
|
+
// If the entry is found, split the string by semicolon to get the URLs
|
|
839
|
+
if (soundfilesEntry) {
|
|
840
|
+
return soundfilesEntry.soundfiles.split(';').filter(url => url !== '');
|
|
841
|
+
} else {
|
|
842
|
+
return [];
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
|
|
833
846
|
/**
|
|
834
|
-
*
|
|
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.
|
|
835
851
|
*
|
|
836
852
|
* @param sfReader : the soundfile reader
|
|
837
|
-
* @param
|
|
853
|
+
* @param baseDSP : the base DSP in the wasm memory
|
|
838
854
|
* @param name : the name of the soundfile
|
|
839
855
|
* @param url : the url of the soundfile
|
|
840
856
|
*/
|
|
841
|
-
private async loadSoundfile(sfReader: SoundfileReader,
|
|
857
|
+
private async loadSoundfile(sfReader: SoundfileReader, baseDSP: number, name: string, url: string): Promise<void> {
|
|
842
858
|
|
|
843
859
|
console.log(`Soundfile ${name} paths: ${url}`);
|
|
844
860
|
|
|
845
|
-
|
|
846
|
-
|
|
861
|
+
const sfReaderURLs = this.extractURLsFromJSON();
|
|
862
|
+
console.log(`sfReaderURLs ${sfReaderURLs}`);
|
|
847
863
|
|
|
864
|
+
const sfDirectories: string[] = ["", ".", "http://127.0.0.1:8000"];
|
|
865
|
+
sfDirectories.push(...sfReaderURLs);
|
|
848
866
|
console.log(`sfDirectories ${sfDirectories}`);
|
|
849
867
|
|
|
850
868
|
// Check if the soundfile exists in the given directories and return the real path
|
|
@@ -856,30 +874,31 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
|
856
874
|
if (item) {
|
|
857
875
|
// Use the cached Soundfile
|
|
858
876
|
if (item.basePtr !== -1) {
|
|
877
|
+
|
|
859
878
|
// Update HEAP32 after soundfile creation
|
|
860
879
|
const HEAP32 = sfReader.getHEAP32();
|
|
861
880
|
|
|
862
881
|
// Fill the soundfile structure in wasm memory, sounfiles are at the beginning of the DSP memory
|
|
863
|
-
console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with
|
|
864
|
-
|
|
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;
|
|
865
886
|
|
|
866
|
-
HEAP32[sfOffset >> 2] = item.basePtr;
|
|
867
887
|
} else {
|
|
868
888
|
|
|
869
889
|
// Create the soundfiles
|
|
870
890
|
const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN, this.fSampleSize === 8);
|
|
871
891
|
if (soundfile) {
|
|
872
892
|
|
|
873
|
-
//soundfile.displayMemory("After createSoundfile");
|
|
874
|
-
|
|
875
893
|
// Update HEAP32 after soundfile creation
|
|
876
894
|
const HEAP32 = soundfile.getHEAP32();
|
|
877
895
|
|
|
878
|
-
//
|
|
896
|
+
// Get the soundfile pointer in wasm memory
|
|
879
897
|
item.basePtr = soundfile.getPtr();
|
|
880
|
-
console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with
|
|
898
|
+
console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
|
|
881
899
|
|
|
882
|
-
|
|
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;
|
|
883
902
|
|
|
884
903
|
} else {
|
|
885
904
|
console.log(`Soundfile ${name} for ${url} cannot be created !}`);
|
|
@@ -893,15 +912,14 @@ export class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
|
893
912
|
/**
|
|
894
913
|
* Init soundfiles memory.
|
|
895
914
|
*
|
|
896
|
-
*
|
|
897
|
-
*
|
|
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
|
|
898
918
|
*/
|
|
899
919
|
protected async initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void> {
|
|
900
920
|
// Create and fill the soundfile structure
|
|
901
|
-
let sfOffset: number = baseDSP;
|
|
902
921
|
for (const { name, url } of this.fSoundfiles) {
|
|
903
|
-
await this.loadSoundfile(sfReader,
|
|
904
|
-
sfOffset += this.fPtrSize;
|
|
922
|
+
await this.loadSoundfile(sfReader, baseDSP, name, url);
|
|
905
923
|
};
|
|
906
924
|
}
|
|
907
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 {
|
|
@@ -710,11 +711,15 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
|
710
711
|
static parseItems(items: FaustUIItem[], callback: (item: FaustUIItem) => any): void;
|
|
711
712
|
static parseItem(item: FaustUIItem, callback: (item: FaustUIItem) => any): void;
|
|
712
713
|
static splitNames(input: string): string[];
|
|
714
|
+
private extractURLsFromJSON;
|
|
713
715
|
/**
|
|
714
|
-
*
|
|
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.
|
|
715
720
|
*
|
|
716
721
|
* @param sfReader : the soundfile reader
|
|
717
|
-
* @param
|
|
722
|
+
* @param baseDSP : the base DSP in the wasm memory
|
|
718
723
|
* @param name : the name of the soundfile
|
|
719
724
|
* @param url : the url of the soundfile
|
|
720
725
|
*/
|
|
@@ -722,8 +727,9 @@ export declare class FaustBaseWebAudioDsp implements IFaustBaseWebAudioDsp {
|
|
|
722
727
|
/**
|
|
723
728
|
* Init soundfiles memory.
|
|
724
729
|
*
|
|
725
|
-
*
|
|
726
|
-
*
|
|
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
|
|
727
733
|
*/
|
|
728
734
|
protected initSoundfileMemory(allocator: WasmAllocator, sfReader: SoundfileReader, baseDSP: number): Promise<void>;
|
|
729
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
|
}
|
|
@@ -2306,9 +2306,20 @@ var FaustBaseWebAudioDsp = class {
|
|
|
2306
2306
|
let trimmed = input.replace(/^\{|\}$/g, "");
|
|
2307
2307
|
return trimmed.split(";").map((str) => str.length <= 2 ? "" : str.substring(1, str.length - 1));
|
|
2308
2308
|
}
|
|
2309
|
-
|
|
2309
|
+
extractURLsFromJSON() {
|
|
2310
|
+
const soundfilesEntry = this.fJSONDsp.meta.find((entry) => entry.soundfiles !== void 0);
|
|
2311
|
+
if (soundfilesEntry) {
|
|
2312
|
+
return soundfilesEntry.soundfiles.split(";").filter((url) => url !== "");
|
|
2313
|
+
} else {
|
|
2314
|
+
return [];
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
async loadSoundfile(sfReader, baseDSP, name, url) {
|
|
2310
2318
|
console.log(`Soundfile ${name} paths: ${url}`);
|
|
2319
|
+
const sfReaderURLs = this.extractURLsFromJSON();
|
|
2320
|
+
console.log(`sfReaderURLs ${sfReaderURLs}`);
|
|
2311
2321
|
const sfDirectories = ["", ".", "http://127.0.0.1:8000"];
|
|
2322
|
+
sfDirectories.push(...sfReaderURLs);
|
|
2312
2323
|
console.log(`sfDirectories ${sfDirectories}`);
|
|
2313
2324
|
const sfPathNames = await sfReader.checkFiles(sfDirectories, FaustBaseWebAudioDsp.splitNames(url));
|
|
2314
2325
|
console.log(`Soundfile ${name} paths: ${sfPathNames}`);
|
|
@@ -2316,16 +2327,15 @@ var FaustBaseWebAudioDsp = class {
|
|
|
2316
2327
|
if (item) {
|
|
2317
2328
|
if (item.basePtr !== -1) {
|
|
2318
2329
|
const HEAP32 = sfReader.getHEAP32();
|
|
2319
|
-
console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with
|
|
2320
|
-
|
|
2321
|
-
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;
|
|
2322
2332
|
} else {
|
|
2323
2333
|
const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN, this.fSampleSize === 8);
|
|
2324
2334
|
if (soundfile) {
|
|
2325
2335
|
const HEAP32 = soundfile.getHEAP32();
|
|
2326
2336
|
item.basePtr = soundfile.getPtr();
|
|
2327
|
-
console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with
|
|
2328
|
-
HEAP32[
|
|
2337
|
+
console.log(`Soundfile ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
|
|
2338
|
+
HEAP32[baseDSP + item.index >> 2] = item.basePtr;
|
|
2329
2339
|
} else {
|
|
2330
2340
|
console.log(`Soundfile ${name} for ${url} cannot be created !}`);
|
|
2331
2341
|
}
|
|
@@ -2335,10 +2345,8 @@ var FaustBaseWebAudioDsp = class {
|
|
|
2335
2345
|
}
|
|
2336
2346
|
}
|
|
2337
2347
|
async initSoundfileMemory(allocator, sfReader, baseDSP) {
|
|
2338
|
-
let sfOffset = baseDSP;
|
|
2339
2348
|
for (const { name, url } of this.fSoundfiles) {
|
|
2340
|
-
await this.loadSoundfile(sfReader,
|
|
2341
|
-
sfOffset += this.fPtrSize;
|
|
2349
|
+
await this.loadSoundfile(sfReader, baseDSP, name, url);
|
|
2342
2350
|
}
|
|
2343
2351
|
;
|
|
2344
2352
|
}
|