@grame/faustwasm 0.1.3 → 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 +69 -47
- 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 +69 -47
- package/dist/esm-bundle/index.js.map +2 -2
- 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
|
@@ -402,6 +402,12 @@ declare class WasmAllocator {
|
|
|
402
402
|
* @returns The view of the memory buffer as Int32Array.
|
|
403
403
|
*/
|
|
404
404
|
getInt32Array(): Int32Array;
|
|
405
|
+
/**
|
|
406
|
+
* Returns the Int64 view of the underlying buffer object.
|
|
407
|
+
*
|
|
408
|
+
* @returns The view of the memory buffer as BigInt64Array.
|
|
409
|
+
*/
|
|
410
|
+
getInt64Array(): BigInt64Array;
|
|
405
411
|
/**
|
|
406
412
|
* Returns the Float32 view of the underlying buffer object.
|
|
407
413
|
*
|
|
@@ -423,8 +429,9 @@ declare class Soundfile {
|
|
|
423
429
|
private readonly fOffset;
|
|
424
430
|
private readonly fSampleSize;
|
|
425
431
|
private readonly fPtrSize;
|
|
432
|
+
private readonly fIntSize;
|
|
426
433
|
private readonly fAllocator;
|
|
427
|
-
constructor(allocator: WasmAllocator,
|
|
434
|
+
constructor(allocator: WasmAllocator, sampleSize: number, curChan: number, length: number, maxChan: number, totalParts: number);
|
|
428
435
|
private allocBuffers;
|
|
429
436
|
shareBuffers(curChan: number, maxChan: number): void;
|
|
430
437
|
copyToOut(part: number, maxChannels: number, offset: number, buffer: AudioBuffer): void;
|
|
@@ -439,11 +446,17 @@ declare class Soundfile {
|
|
|
439
446
|
}
|
|
440
447
|
declare class SoundfileReader {
|
|
441
448
|
private readonly fAllocator;
|
|
442
|
-
private readonly fPtrSize;
|
|
443
449
|
private readonly fSampleSize;
|
|
444
450
|
private readonly fContext;
|
|
445
451
|
private readonly fAudioBuffers;
|
|
446
|
-
constructor(allocator: WasmAllocator, context: BaseAudioContext,
|
|
452
|
+
constructor(allocator: WasmAllocator, context: BaseAudioContext, sampleSize: number);
|
|
453
|
+
/**
|
|
454
|
+
* Check if the file exists.
|
|
455
|
+
*
|
|
456
|
+
* @param url : the url of the file to check
|
|
457
|
+
* @returns : true if the file exists, otherwise false
|
|
458
|
+
*/
|
|
459
|
+
private checkFileExists;
|
|
447
460
|
/**
|
|
448
461
|
* Check if the file exists in the given directories.
|
|
449
462
|
*
|
|
@@ -483,9 +496,8 @@ declare class SoundfileReader {
|
|
|
483
496
|
* Crate a soundfile, load all parts and copy audio data to the wasm soundfile buffer.
|
|
484
497
|
* @param pathNameList : list of soundfile paths
|
|
485
498
|
* @param maxChan : maximum number of channels
|
|
486
|
-
* @param isDouble : whether the soundfile will be copied as double
|
|
487
499
|
*/
|
|
488
|
-
createSoundfile(pathNameList: string[], maxChan: number
|
|
500
|
+
createSoundfile(pathNameList: string[], maxChan: number): Promise<Soundfile | null>;
|
|
489
501
|
getHEAP32(): Int32Array;
|
|
490
502
|
}
|
|
491
503
|
/**
|
package/dist/cjs-bundle/index.js
CHANGED
|
@@ -7908,11 +7908,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
7908
7908
|
}
|
|
7909
7909
|
}
|
|
7910
7910
|
static async createAsyncMonoDSPInstance(factory) {
|
|
7911
|
-
const
|
|
7912
|
-
|
|
7913
|
-
|
|
7914
|
-
return (_a = group.items) == null ? void 0 : _a.some((item) => item.type === "soundfile");
|
|
7915
|
-
})) {
|
|
7911
|
+
const pattern = /"type":\s*"soundfile"/;
|
|
7912
|
+
const isDetected = pattern.test(factory.json);
|
|
7913
|
+
if (isDetected) {
|
|
7916
7914
|
const memory = this.createMemoryMono(factory);
|
|
7917
7915
|
const instance = await WebAssembly.instantiate(factory.module, this.createWasmImport(memory));
|
|
7918
7916
|
return this.createMonoDSPInstanceAux(instance, factory.json, memory);
|
|
@@ -7922,11 +7920,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
7922
7920
|
}
|
|
7923
7921
|
}
|
|
7924
7922
|
static createSyncMonoDSPInstance(factory) {
|
|
7925
|
-
const
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
return (_a = group.items) == null ? void 0 : _a.some((item) => item.type === "soundfile");
|
|
7929
|
-
})) {
|
|
7923
|
+
const pattern = /"type":\s*"soundfile"/;
|
|
7924
|
+
const isDetected = pattern.test(factory.json);
|
|
7925
|
+
if (isDetected) {
|
|
7930
7926
|
const memory = this.createMemoryMono(factory);
|
|
7931
7927
|
const instance = new WebAssembly.Instance(factory.module, this.createWasmImport(memory));
|
|
7932
7928
|
return this.createMonoDSPInstanceAux(instance, factory.json, memory);
|
|
@@ -8020,6 +8016,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8020
8016
|
getInt32Array() {
|
|
8021
8017
|
return new Int32Array(this.memory.buffer);
|
|
8022
8018
|
}
|
|
8019
|
+
getInt64Array() {
|
|
8020
|
+
return new BigInt64Array(this.memory.buffer);
|
|
8021
|
+
}
|
|
8023
8022
|
getFloat32Array() {
|
|
8024
8023
|
return new Float32Array(this.memory.buffer);
|
|
8025
8024
|
}
|
|
@@ -8031,22 +8030,23 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8031
8030
|
var MAX_CHAN = 64;
|
|
8032
8031
|
var BUFFER_SIZE = 1024;
|
|
8033
8032
|
var SAMPLE_RATE = 44100;
|
|
8034
|
-
var intSize = 4;
|
|
8035
8033
|
var Soundfile = class {
|
|
8036
|
-
constructor(allocator,
|
|
8034
|
+
constructor(allocator, sampleSize, curChan, length2, maxChan, totalParts) {
|
|
8037
8035
|
this.fSampleSize = sampleSize;
|
|
8038
|
-
this.
|
|
8036
|
+
this.fIntSize = this.fSampleSize;
|
|
8037
|
+
this.fPtrSize = 4;
|
|
8039
8038
|
this.fAllocator = allocator;
|
|
8040
|
-
|
|
8041
|
-
this.
|
|
8042
|
-
this.
|
|
8043
|
-
this.
|
|
8039
|
+
console.log(`Soundfile constructor: curChan: ${curChan}, length: ${length2}, maxChan: ${maxChan}, totalParts: ${totalParts}`);
|
|
8040
|
+
this.fPtr = allocator.alloc(4 * this.fPtrSize);
|
|
8041
|
+
this.fLength = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
|
|
8042
|
+
this.fSR = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
|
|
8043
|
+
this.fOffset = allocator.alloc(MAX_SOUNDFILE_PARTS * this.fIntSize);
|
|
8044
8044
|
this.fBuffers = this.allocBuffers(curChan, length2, maxChan);
|
|
8045
8045
|
const HEAP32 = this.fAllocator.getInt32Array();
|
|
8046
8046
|
HEAP32[this.fPtr >> 2] = this.fBuffers;
|
|
8047
|
-
HEAP32[this.fPtr +
|
|
8048
|
-
HEAP32[this.fPtr + 2 *
|
|
8049
|
-
HEAP32[this.fPtr + 3 *
|
|
8047
|
+
HEAP32[this.fPtr + this.fPtrSize >> 2] = this.fLength;
|
|
8048
|
+
HEAP32[this.fPtr + 2 * this.fPtrSize >> 2] = this.fSR;
|
|
8049
|
+
HEAP32[this.fPtr + 3 * this.fPtrSize >> 2] = this.fOffset;
|
|
8050
8050
|
for (let chan = 0; chan < curChan; chan++) {
|
|
8051
8051
|
const buffer = HEAP32[(this.fBuffers >> 2) + chan];
|
|
8052
8052
|
console.log(`allocBuffers AFTER: ${chan} - ${buffer}`);
|
|
@@ -8069,10 +8069,18 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8069
8069
|
}
|
|
8070
8070
|
}
|
|
8071
8071
|
copyToOut(part, maxChannels, offset, buffer) {
|
|
8072
|
-
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8072
|
+
if (this.fIntSize === 4) {
|
|
8073
|
+
const HEAP32 = this.fAllocator.getInt32Array();
|
|
8074
|
+
HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = buffer.length;
|
|
8075
|
+
HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = buffer.sampleRate;
|
|
8076
|
+
HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
|
|
8077
|
+
} else {
|
|
8078
|
+
const HEAP64 = this.fAllocator.getInt64Array();
|
|
8079
|
+
HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(buffer.length);
|
|
8080
|
+
HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(buffer.sampleRate);
|
|
8081
|
+
HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
|
|
8082
|
+
}
|
|
8083
|
+
console.log(`copyToOut: part: ${part}, maxChannels: ${maxChannels}, offset: ${offset}, buffer: ${buffer}`);
|
|
8076
8084
|
if (this.fSampleSize === 8) {
|
|
8077
8085
|
this.copyToOutReal64(maxChannels, offset, buffer);
|
|
8078
8086
|
} else {
|
|
@@ -8085,6 +8093,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8085
8093
|
for (let chan = 0; chan < buffer.numberOfChannels; chan++) {
|
|
8086
8094
|
const input = buffer.getChannelData(chan);
|
|
8087
8095
|
const output = HEAP32[(this.fBuffers >> 2) + chan];
|
|
8096
|
+
const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
8097
|
+
const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
8098
|
+
console.log(`copyToOutReal32 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
|
|
8088
8099
|
const outputReal = HEAPF.subarray(
|
|
8089
8100
|
output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
|
|
8090
8101
|
output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
|
|
@@ -8100,6 +8111,9 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8100
8111
|
for (let chan = 0; chan < buffer.numberOfChannels; chan++) {
|
|
8101
8112
|
const input = buffer.getChannelData(chan);
|
|
8102
8113
|
const output = HEAP32[(this.fBuffers >> 2) + chan];
|
|
8114
|
+
const begin = output + offset * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
8115
|
+
const end = output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize);
|
|
8116
|
+
console.log(`copyToOutReal64 begin: ${begin}, end: ${end}, delta: ${end - begin}`);
|
|
8103
8117
|
const outputReal = HEAPF.subarray(
|
|
8104
8118
|
output + offset * this.fSampleSize >> Math.log2(this.fSampleSize),
|
|
8105
8119
|
output + (offset + input.length) * this.fSampleSize >> Math.log2(this.fSampleSize)
|
|
@@ -8110,10 +8124,17 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8110
8124
|
}
|
|
8111
8125
|
}
|
|
8112
8126
|
emptyFile(part, offset) {
|
|
8113
|
-
|
|
8114
|
-
|
|
8115
|
-
|
|
8116
|
-
|
|
8127
|
+
if (this.fIntSize === 4) {
|
|
8128
|
+
const HEAP32 = this.fAllocator.getInt32Array();
|
|
8129
|
+
HEAP32[(this.fLength >> Math.log2(this.fIntSize)) + part] = BUFFER_SIZE;
|
|
8130
|
+
HEAP32[(this.fSR >> Math.log2(this.fIntSize)) + part] = SAMPLE_RATE;
|
|
8131
|
+
HEAP32[(this.fOffset >> Math.log2(this.fIntSize)) + part] = offset;
|
|
8132
|
+
} else {
|
|
8133
|
+
const HEAP64 = this.fAllocator.getInt64Array();
|
|
8134
|
+
HEAP64[(this.fLength >> Math.log2(this.fIntSize)) + part] = BigInt(BUFFER_SIZE);
|
|
8135
|
+
HEAP64[(this.fSR >> Math.log2(this.fIntSize)) + part] = BigInt(SAMPLE_RATE);
|
|
8136
|
+
HEAP64[(this.fOffset >> Math.log2(this.fIntSize)) + part] = BigInt(offset);
|
|
8137
|
+
}
|
|
8117
8138
|
return offset + BUFFER_SIZE;
|
|
8118
8139
|
}
|
|
8119
8140
|
displayMemory(where = "", mem = false) {
|
|
@@ -8145,30 +8166,29 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8145
8166
|
}
|
|
8146
8167
|
};
|
|
8147
8168
|
var SoundfileReader = class {
|
|
8148
|
-
constructor(allocator, context,
|
|
8169
|
+
constructor(allocator, context, sampleSize) {
|
|
8149
8170
|
this.fAllocator = allocator;
|
|
8150
|
-
this.fPtrSize = ptrSize;
|
|
8151
8171
|
this.fSampleSize = sampleSize;
|
|
8152
8172
|
this.fContext = context;
|
|
8153
8173
|
this.fAudioBuffers = [];
|
|
8154
8174
|
}
|
|
8155
|
-
async
|
|
8156
|
-
|
|
8157
|
-
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
return false;
|
|
8164
|
-
}
|
|
8175
|
+
async checkFileExists(url) {
|
|
8176
|
+
try {
|
|
8177
|
+
console.log(`"checkFileExists" url: ${url}`);
|
|
8178
|
+
const response = await fetch(url, { method: "HEAD" });
|
|
8179
|
+
return response.ok;
|
|
8180
|
+
} catch (error) {
|
|
8181
|
+
console.error("Fetch error:", error);
|
|
8182
|
+
return false;
|
|
8165
8183
|
}
|
|
8166
|
-
|
|
8184
|
+
}
|
|
8185
|
+
async checkFile(directories, fileName) {
|
|
8186
|
+
if (await this.checkFileExists(fileName)) {
|
|
8167
8187
|
return fileName;
|
|
8168
8188
|
} else {
|
|
8169
8189
|
for (let i = 0; i < directories.length; i++) {
|
|
8170
8190
|
const pathName = directories[i] + "/" + fileName;
|
|
8171
|
-
if (await checkFileExists(pathName)) {
|
|
8191
|
+
if (await this.checkFileExists(pathName)) {
|
|
8172
8192
|
return pathName;
|
|
8173
8193
|
}
|
|
8174
8194
|
}
|
|
@@ -8214,7 +8234,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8214
8234
|
return offset + BUFFER_SIZE;
|
|
8215
8235
|
}
|
|
8216
8236
|
}
|
|
8217
|
-
async createSoundfile(pathNameList, maxChan
|
|
8237
|
+
async createSoundfile(pathNameList, maxChan) {
|
|
8218
8238
|
try {
|
|
8219
8239
|
let curChan = 1;
|
|
8220
8240
|
let totalLength = 0;
|
|
@@ -8232,7 +8252,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8232
8252
|
totalLength += len;
|
|
8233
8253
|
}
|
|
8234
8254
|
totalLength += (MAX_SOUNDFILE_PARTS - pathNameList.length) * BUFFER_SIZE;
|
|
8235
|
-
let soundfile = new Soundfile(this.fAllocator, this.
|
|
8255
|
+
let soundfile = new Soundfile(this.fAllocator, this.fSampleSize, curChan, totalLength, maxChan, pathNameList.length);
|
|
8236
8256
|
let offset = 0;
|
|
8237
8257
|
for (let part = 0; part < pathNameList.length; part++) {
|
|
8238
8258
|
if (pathNameList[part] === "__empty_sound__") {
|
|
@@ -8356,7 +8376,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8356
8376
|
console.log(`Soundfile CACHE ${url}} : ${name} loaded at ${item.basePtr} in wasm memory with index ${item.index}`);
|
|
8357
8377
|
HEAP32[baseDSP + item.index >> 2] = item.basePtr;
|
|
8358
8378
|
} else {
|
|
8359
|
-
const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN
|
|
8379
|
+
const soundfile = await sfReader.createSoundfile(sfPathNames, MAX_CHAN);
|
|
8360
8380
|
if (soundfile) {
|
|
8361
8381
|
const HEAP32 = soundfile.getHEAP32();
|
|
8362
8382
|
item.basePtr = soundfile.getPtr();
|
|
@@ -8490,6 +8510,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8490
8510
|
constructor(instance, sampleRate, sampleSize, bufferSize) {
|
|
8491
8511
|
super(sampleSize, bufferSize);
|
|
8492
8512
|
this.fInstance = instance;
|
|
8513
|
+
console.log("sampleSize: " + sampleSize + " bufferSize: " + bufferSize);
|
|
8493
8514
|
this.fJSONDsp = JSON.parse(this.fInstance.json);
|
|
8494
8515
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
8495
8516
|
this.fEndMemory = this.initMemory();
|
|
@@ -8498,7 +8519,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8498
8519
|
async init(context) {
|
|
8499
8520
|
if (this.fSoundfiles.length > 0 && context) {
|
|
8500
8521
|
const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
|
|
8501
|
-
const sfReader = new SoundfileReader(allocator, context, this.
|
|
8522
|
+
const sfReader = new SoundfileReader(allocator, context, this.fSampleSize);
|
|
8502
8523
|
await this.initSoundfileMemory(allocator, sfReader, this.fDSP);
|
|
8503
8524
|
}
|
|
8504
8525
|
}
|
|
@@ -8702,6 +8723,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8702
8723
|
constructor(instance, sampleRate, sampleSize, bufferSize) {
|
|
8703
8724
|
super(sampleSize, bufferSize);
|
|
8704
8725
|
this.fInstance = instance;
|
|
8726
|
+
console.log("sampleSize: " + sampleSize + " bufferSize: " + bufferSize);
|
|
8705
8727
|
this.fJSONDsp = JSON.parse(this.fInstance.voiceJSON);
|
|
8706
8728
|
this.fJSONEffect = this.fInstance.effectAPI && this.fInstance.effectJSON ? JSON.parse(this.fInstance.effectJSON) : null;
|
|
8707
8729
|
FaustBaseWebAudioDsp.parseUI(this.fJSONDsp.ui, this.fUICallback);
|
|
@@ -8724,7 +8746,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
8724
8746
|
async init(context) {
|
|
8725
8747
|
if (this.fSoundfiles.length > 0 && context) {
|
|
8726
8748
|
const allocator = new WasmAllocator(this.fInstance.memory, this.fEndMemory);
|
|
8727
|
-
const sfReader = new SoundfileReader(allocator, context, this.
|
|
8749
|
+
const sfReader = new SoundfileReader(allocator, context, this.fSampleSize);
|
|
8728
8750
|
for (let voice = 0; voice < this.fInstance.voices; voice++) {
|
|
8729
8751
|
await this.initSoundfileMemory(allocator, sfReader, this.fJSONDsp.size * voice);
|
|
8730
8752
|
}
|