@grame/faustwasm 0.1.2 → 0.1.4
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 +17 -5
- package/assets/standalone/faustwasm/index.js +69 -47
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.d.ts +17 -5
- package/dist/cjs/index.js +69 -47
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +17 -5
- package/dist/cjs-bundle/index.js +71 -49
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +17 -5
- package/dist/esm/index.js +69 -47
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +17 -5
- package/dist/esm-bundle/index.js +71 -49
- package/dist/esm-bundle/index.js.map +2 -2
- package/libfaust-wasm/libfaust-wasm.js +1 -1
- package/libfaust-wasm/libfaust-wasm.wasm +0 -0
- package/package.json +1 -1
- package/src/FaustWasmInstantiator.ts +14 -5
- package/src/FaustWebAudioDsp.ts +97 -46
- package/test/faustlive-wasm/faustwasm/index.d.ts +17 -5
- package/test/faustlive-wasm/faustwasm/index.js +69 -47
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
package/dist/cjs/index.d.ts
CHANGED
|
@@ -395,6 +395,12 @@ declare class WasmAllocator {
|
|
|
395
395
|
* @returns The view of the memory buffer as Int32Array.
|
|
396
396
|
*/
|
|
397
397
|
getInt32Array(): Int32Array;
|
|
398
|
+
/**
|
|
399
|
+
* Returns the Int64 view of the underlying buffer object.
|
|
400
|
+
*
|
|
401
|
+
* @returns The view of the memory buffer as BigInt64Array.
|
|
402
|
+
*/
|
|
403
|
+
getInt64Array(): BigInt64Array;
|
|
398
404
|
/**
|
|
399
405
|
* Returns the Float32 view of the underlying buffer object.
|
|
400
406
|
*
|
|
@@ -416,8 +422,9 @@ declare class Soundfile {
|
|
|
416
422
|
private readonly fOffset;
|
|
417
423
|
private readonly fSampleSize;
|
|
418
424
|
private readonly fPtrSize;
|
|
425
|
+
private readonly fIntSize;
|
|
419
426
|
private readonly fAllocator;
|
|
420
|
-
constructor(allocator: WasmAllocator,
|
|
427
|
+
constructor(allocator: WasmAllocator, sampleSize: number, curChan: number, length: number, maxChan: number, totalParts: number);
|
|
421
428
|
private allocBuffers;
|
|
422
429
|
shareBuffers(curChan: number, maxChan: number): void;
|
|
423
430
|
copyToOut(part: number, maxChannels: number, offset: number, buffer: AudioBuffer): void;
|
|
@@ -432,11 +439,17 @@ declare class Soundfile {
|
|
|
432
439
|
}
|
|
433
440
|
declare class SoundfileReader {
|
|
434
441
|
private readonly fAllocator;
|
|
435
|
-
private readonly fPtrSize;
|
|
436
442
|
private readonly fSampleSize;
|
|
437
443
|
private readonly fContext;
|
|
438
444
|
private readonly fAudioBuffers;
|
|
439
|
-
constructor(allocator: WasmAllocator, context: BaseAudioContext,
|
|
445
|
+
constructor(allocator: WasmAllocator, context: BaseAudioContext, sampleSize: number);
|
|
446
|
+
/**
|
|
447
|
+
* Check if the file exists.
|
|
448
|
+
*
|
|
449
|
+
* @param url : the url of the file to check
|
|
450
|
+
* @returns : true if the file exists, otherwise false
|
|
451
|
+
*/
|
|
452
|
+
private checkFileExists;
|
|
440
453
|
/**
|
|
441
454
|
* Check if the file exists in the given directories.
|
|
442
455
|
*
|
|
@@ -476,9 +489,8 @@ declare class SoundfileReader {
|
|
|
476
489
|
* Crate a soundfile, load all parts and copy audio data to the wasm soundfile buffer.
|
|
477
490
|
* @param pathNameList : list of soundfile paths
|
|
478
491
|
* @param maxChan : maximum number of channels
|
|
479
|
-
* @param isDouble : whether the soundfile will be copied as double
|
|
480
492
|
*/
|
|
481
|
-
createSoundfile(pathNameList: string[], maxChan: number
|
|
493
|
+
createSoundfile(pathNameList: string[], maxChan: number): Promise<Soundfile | null>;
|
|
482
494
|
getHEAP32(): Int32Array;
|
|
483
495
|
}
|
|
484
496
|
/**
|
package/dist/cjs/index.js
CHANGED
|
@@ -1890,11 +1890,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
1890
1890
|
}
|
|
1891
1891
|
}
|
|
1892
1892
|
static async createAsyncMonoDSPInstance(factory) {
|
|
1893
|
-
const
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
return (_a = group.items) == null ? void 0 : _a.some((item) => item.type === "soundfile");
|
|
1897
|
-
})) {
|
|
1893
|
+
const pattern = /"type":\s*"soundfile"/;
|
|
1894
|
+
const isDetected = pattern.test(factory.json);
|
|
1895
|
+
if (isDetected) {
|
|
1898
1896
|
const memory = this.createMemoryMono(factory);
|
|
1899
1897
|
const instance = await WebAssembly.instantiate(factory.module, this.createWasmImport(memory));
|
|
1900
1898
|
return this.createMonoDSPInstanceAux(instance, factory.json, memory);
|
|
@@ -1904,11 +1902,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
1904
1902
|
}
|
|
1905
1903
|
}
|
|
1906
1904
|
static createSyncMonoDSPInstance(factory) {
|
|
1907
|
-
const
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
return (_a = group.items) == null ? void 0 : _a.some((item) => item.type === "soundfile");
|
|
1911
|
-
})) {
|
|
1905
|
+
const pattern = /"type":\s*"soundfile"/;
|
|
1906
|
+
const isDetected = pattern.test(factory.json);
|
|
1907
|
+
if (isDetected) {
|
|
1912
1908
|
const memory = this.createMemoryMono(factory);
|
|
1913
1909
|
const instance = new WebAssembly.Instance(factory.module, this.createWasmImport(memory));
|
|
1914
1910
|
return this.createMonoDSPInstanceAux(instance, factory.json, memory);
|
|
@@ -2002,6 +1998,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2002
1998
|
getInt32Array() {
|
|
2003
1999
|
return new Int32Array(this.memory.buffer);
|
|
2004
2000
|
}
|
|
2001
|
+
getInt64Array() {
|
|
2002
|
+
return new BigInt64Array(this.memory.buffer);
|
|
2003
|
+
}
|
|
2005
2004
|
getFloat32Array() {
|
|
2006
2005
|
return new Float32Array(this.memory.buffer);
|
|
2007
2006
|
}
|
|
@@ -2013,22 +2012,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2013
2012
|
var MAX_CHAN = 64;
|
|
2014
2013
|
var BUFFER_SIZE = 1024;
|
|
2015
2014
|
var SAMPLE_RATE = 44100;
|
|
2016
|
-
var intSize = 4;
|
|
2017
2015
|
var Soundfile = class {
|
|
2018
|
-
constructor(allocator,
|
|
2016
|
+
constructor(allocator, sampleSize, curChan, length2, maxChan, totalParts) {
|
|
2019
2017
|
this.fSampleSize = sampleSize;
|
|
2020
|
-
this.
|
|
2018
|
+
this.fIntSize = this.fSampleSize;
|
|
2019
|
+
this.fPtrSize = 4;
|
|
2021
2020
|
this.fAllocator = allocator;
|
|
2022
|
-
|
|
2023
|
-
this.
|
|
2024
|
-
this.
|
|
2025
|
-
this.
|
|
2021
|
+
console.log(`Soundfile constructor: curChan: ${curChan}, length: ${length2}, maxChan: ${maxChan}, totalParts: ${totalParts}`);
|
|
2022
|
+
this.fPtr = allocator.alloc(4 * this.fPtrSize);
|
|
2023
|
+
this.fLength = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
|
|
2024
|
+
this.fSR = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
|
|
2025
|
+
this.fOffset = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
|
|
2026
2026
|
this.fBuffers = this.allocBuffers(curChan, length2, maxChan);
|
|
2027
2027
|
const HEAP32 = this.fAllocator.getInt32Array();
|
|
2028
2028
|
HEAP32[this.fPtr >> 2] = this.fBuffers;
|
|
2029
|
-
HEAP32[this.fPtr +
|
|
2030
|
-
HEAP32[this.fPtr + 2 *
|
|
2031
|
-
HEAP32[this.fPtr + 3 *
|
|
2029
|
+
HEAP32[this.fPtr + this.fPtrSize >> 2] = this.fLength;
|
|
2030
|
+
HEAP32[this.fPtr + 2 * this.fPtrSize >> 2] = this.fSR;
|
|
2031
|
+
HEAP32[this.fPtr + 3 * this.fPtrSize >> 2] = this.fOffset;
|
|
2032
2032
|
for (let chan = 0; chan < curChan; chan++) {
|
|
2033
2033
|
const buffer = HEAP32[(this.fBuffers >> 2) + chan];
|
|
2034
2034
|
console.log(`allocBuffers AFTER: ${chan} - ${buffer}`);
|
|
@@ -2051,10 +2051,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2051
2051
|
}
|
|
2052
2052
|
}
|
|
2053
2053
|
copyToOut(part, maxChannels, offset, buffer) {
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2054
|
+
if (this.fIntSize === 4) {
|
|
2055
|
+
const HEAP32 = this.fAllocator.getInt32Array();
|
|
2056
|
+
HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = buffer.length;
|
|
2057
|
+
HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = buffer.sampleRate;
|
|
2058
|
+
HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
|
|
2059
|
+
} else {
|
|
2060
|
+
const HEAP64 = this.fAllocator.getInt64Array();
|
|
2061
|
+
HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(buffer.length);
|
|
2062
|
+
HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(buffer.sampleRate);
|
|
2063
|
+
HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
|
|
2064
|
+
}
|
|
2065
|
+
console.log(`copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${buffer}`);
|
|
2058
2066
|
if (this.fSampleSize === 8) {
|
|
2059
2067
|
this.copyToOutReal64(maxChannels, offset, buffer);
|
|
2060
2068
|
} else {
|
|
@@ -2067,6 +2075,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2067
2075
|
for (let chan = 0; chan < buffer.numberOfChannels; chan++) {
|
|
2068
2076
|
const input = buffer.getChannelData(chan);
|
|
2069
2077
|
const output = HEAP32[(this.fBuffers >> 2) + chan];
|
|
2078
|
+
const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
2079
|
+
const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
2080
|
+
console.log(`copyToOutReal32 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
|
|
2070
2081
|
const outputReal = HEAPF.subarray(
|
|
2071
2082
|
output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
|
|
2072
2083
|
output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
|
|
@@ -2082,6 +2093,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2082
2093
|
for (let chan = 0; chan < buffer.numberOfChannels; chan++) {
|
|
2083
2094
|
const input = buffer.getChannelData(chan);
|
|
2084
2095
|
const output = HEAP32[(this.fBuffers >> 2) + chan];
|
|
2096
|
+
const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
2097
|
+
const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
2098
|
+
console.log(`copyToOutReal64 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
|
|
2085
2099
|
const outputReal = HEAPF.subarray(
|
|
2086
2100
|
output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
|
|
2087
2101
|
output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
|
|
@@ -2092,10 +2106,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2092
2106
|
}
|
|
2093
2107
|
}
|
|
2094
2108
|
emptyFile(part, offset) {
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2109
|
+
if (this.fIntSize === 4) {
|
|
2110
|
+
const HEAP32 = this.fAllocator.getInt32Array();
|
|
2111
|
+
HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = BUFFER_SIZE;
|
|
2112
|
+
HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = SAMPLE_RATE;
|
|
2113
|
+
HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
|
|
2114
|
+
} else {
|
|
2115
|
+
const HEAP64 = this.fAllocator.getInt64Array();
|
|
2116
|
+
HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(BUFFER_SIZE);
|
|
2117
|
+
HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(SAMPLE_RATE);
|
|
2118
|
+
HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
|
|
2119
|
+
}
|
|
2099
2120
|
return offset + BUFFER_SIZE;
|
|
2100
2121
|
}
|
|
2101
2122
|
displayMemory(where = "", mem = false) {
|
|
@@ -2127,30 +2148,29 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2127
2148
|
}
|
|
2128
2149
|
};
|
|
2129
2150
|
var SoundfileReader = class {
|
|
2130
|
-
constructor(allocator, context,
|
|
2151
|
+
constructor(allocator, context, sampleSize) {
|
|
2131
2152
|
this.fAllocator = allocator;
|
|
2132
|
-
this.fPtrSize = ptrSize;
|
|
2133
2153
|
this.fSampleSize = sampleSize;
|
|
2134
2154
|
this.fContext = context;
|
|
2135
2155
|
this.fAudioBuffers = [];
|
|
2136
2156
|
}
|
|
2137
|
-
async
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
return false;
|
|
2146
|
-
}
|
|
2157
|
+
async checkFileExists(url) {
|
|
2158
|
+
try {
|
|
2159
|
+
console.log(`"checkFileExists" url: ${url}`);
|
|
2160
|
+
const response = await fetch(url, { method: "HEAD" });
|
|
2161
|
+
return response.ok;
|
|
2162
|
+
} catch (error) {
|
|
2163
|
+
console.error("Fetch error:", error);
|
|
2164
|
+
return false;
|
|
2147
2165
|
}
|
|
2148
|
-
|
|
2166
|
+
}
|
|
2167
|
+
async checkFile(directories, fileName) {
|
|
2168
|
+
if (await this.checkFileExists(fileName)) {
|
|
2149
2169
|
return fileName;
|
|
2150
2170
|
} else {
|
|
2151
2171
|
for (let i = 0; i < directories.length; i++) {
|
|
2152
2172
|
const pathName = directories[i] + "/" + fileName;
|
|
2153
|
-
if (await checkFileExists(pathName)) {
|
|
2173
|
+
if (await this.checkFileExists(pathName)) {
|
|
2154
2174
|
return pathName;
|
|
2155
2175
|
}
|
|
2156
2176
|
}
|
|
@@ -2196,7 +2216,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2196
2216
|
return offset + BUFFER_SIZE;
|
|
2197
2217
|
}
|
|
2198
2218
|
}
|
|
2199
|
-
async createSoundfile(pathNameList, maxChan
|
|
2219
|
+
async createSoundfile(pathNameList, maxChan) {
|
|
2200
2220
|
try {
|
|
2201
2221
|
let curChan = 1;
|
|
2202
2222
|
let totalLength = 0;
|
|
@@ -2214,7 +2234,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2214
2234
|
totalLength += len;
|
|
2215
2235
|
}
|
|
2216
2236
|
totalLength += (MAX_SOUNDFILE_PARTS - pathNameList.length) * BUFFER_SIZE;
|
|
2217
|
-
let soundfile = new Soundfile(this.fAllocator, this.
|
|
2237
|
+
let soundfile = new Soundfile(this.fAllocator, this.fSampleSize, curChan, totalLength, maxChan, pathNameList.length);
|
|
2218
2238
|
let offset = 0;
|
|
2219
2239
|
for (let part = 0; part < pathNameList.length; part++) {
|
|
2220
2240
|
if (pathNameList[part] === "__empty_sound__") {
|
|
@@ -2338,7 +2358,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2338
2358
|
console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
|
|
2339
2359
|
HEAP32[baseDSP + item.index >> 2] = item.basePtr;
|
|
2340
2360
|
} else {
|
|
2341
|
-
const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN
|
|
2361
|
+
const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN);
|
|
2342
2362
|
if (soundfile) {
|
|
2343
2363
|
const HEAP32 = soundfile.getHEAP32();
|
|
2344
2364
|
item.basePtr = soundfile.getPtr();
|
|
@@ -2472,6 +2492,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2472
2492
|
constructor(instance, sampleRate, sampleSize, bufferSize) {
|
|
2473
2493
|
super(sampleSize, bufferSize);
|
|
2474
2494
|
this.fInstance = instance;
|
|
2495
|
+
console.log("sampleSize: " + sampleSize + " bufferSize: " + bufferSize);
|
|
2475
2496
|
this.fJSONDsp = JSON.parse(this.fInstance.json);
|
|
2476
2497
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
2477
2498
|
this.fEndMemory = this.initMemory();
|
|
@@ -2480,7 +2501,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2480
2501
|
async init(context) {
|
|
2481
2502
|
if (this.fSoundfiles.length > 0 && context) {
|
|
2482
2503
|
const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
|
|
2483
|
-
const sfReader = new SoundfileReader(allocator, context, this.
|
|
2504
|
+
const sfReader = new SoundfileReader(allocator, context, this.fSampleSize);
|
|
2484
2505
|
await this.initSoundfileMemory(allocator, sfReader, this.fDSP);
|
|
2485
2506
|
}
|
|
2486
2507
|
}
|
|
@@ -2684,6 +2705,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2684
2705
|
constructor(instance, sampleRate, sampleSize, bufferSize) {
|
|
2685
2706
|
super(sampleSize, bufferSize);
|
|
2686
2707
|
this.fInstance = instance;
|
|
2708
|
+
console.log("sampleSize: " + sampleSize + " bufferSize: " + bufferSize);
|
|
2687
2709
|
this.fJSONDsp = JSON.parse(this.fInstance.voiceJSON);
|
|
2688
2710
|
this.fJSONEffect = this.fInstance.effectAPI && this.fInstance.effectJSON ? JSON.parse(this.fInstance.effectJSON) : null;
|
|
2689
2711
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
@@ -2706,7 +2728,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
2706
2728
|
async init(context) {
|
|
2707
2729
|
if (this.fSoundfiles.length > 0 && context) {
|
|
2708
2730
|
const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
|
|
2709
|
-
const sfReader = new SoundfileReader(allocator, context, this.
|
|
2731
|
+
const sfReader = new SoundfileReader(allocator, context, this.fSampleSize);
|
|
2710
2732
|
for (let voice = 0; voice < this.fInstance.voices; voice++) {
|
|
2711
2733
|
await this.initSoundfileMemory(allocator, sfReader, this.fJSONDsp.size * voice);
|
|
2712
2734
|
}
|