@grame/faustwasm 0.2.0 → 0.2.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 +25 -7
- package/assets/standalone/faustwasm/index.js +42 -3
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.d.ts +25 -7
- package/dist/cjs/index.js +42 -3
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.d.ts +25 -7
- package/dist/cjs-bundle/index.js +42 -3
- package/dist/cjs-bundle/index.js.map +2 -2
- package/dist/esm/index.d.ts +25 -7
- package/dist/esm/index.js +42 -3
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.d.ts +25 -7
- package/dist/esm-bundle/index.js +42 -3
- package/dist/esm-bundle/index.js.map +2 -2
- package/package.json +1 -1
- package/src/FaustDspGenerator.ts +61 -7
- package/src/SoundfileReader.ts +2 -2
- package/test/faustlive-wasm/faustwasm/index.d.ts +25 -7
- package/test/faustlive-wasm/faustwasm/index.js +42 -3
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
- package/test/web/soundfile.html +1 -1
|
@@ -1203,7 +1203,7 @@ export declare class SoundfileReader {
|
|
|
1203
1203
|
* @param dspMeta : the metadata
|
|
1204
1204
|
* @returns : the URLs
|
|
1205
1205
|
*/
|
|
1206
|
-
|
|
1206
|
+
static findSoundfilesFromMeta(dspMeta: FaustDspMeta): LooseFaustDspFactory["soundfiles"];
|
|
1207
1207
|
/**
|
|
1208
1208
|
* Check if the file exists.
|
|
1209
1209
|
*
|
|
@@ -1343,7 +1343,19 @@ export declare class FaustPolyScriptProcessorNode extends FaustScriptProcessorNo
|
|
|
1343
1343
|
keyOff(channel: number, pitch: number, velocity: number): void;
|
|
1344
1344
|
allNotesOff(hard: boolean): void;
|
|
1345
1345
|
}
|
|
1346
|
-
export interface
|
|
1346
|
+
export interface GeneratorSupportingSoundfiles {
|
|
1347
|
+
/**
|
|
1348
|
+
* Attach a map of id - audio data, call after `compile()` before `createNode()`
|
|
1349
|
+
*
|
|
1350
|
+
* @param soundfileMap a map of id - `AudioData` as an object where `AudioData` contains channel data as `audioBuffer: Float32Array[]` and `sampleRate: number`
|
|
1351
|
+
*/
|
|
1352
|
+
addSoundfiles(soundfileMap: Record<string, AudioData>): void;
|
|
1353
|
+
/**
|
|
1354
|
+
* Get a list of soundfiles needed, call after `compile()`
|
|
1355
|
+
*/
|
|
1356
|
+
getSoundfileList(): string[];
|
|
1357
|
+
}
|
|
1358
|
+
export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
|
|
1347
1359
|
/**
|
|
1348
1360
|
* Compile a monophonic DSP factory from given code.
|
|
1349
1361
|
*
|
|
@@ -1388,9 +1400,10 @@ export interface IFaustMonoDspGenerator {
|
|
|
1388
1400
|
* @param sampleRate - the sample rate in Hz
|
|
1389
1401
|
* @param bufferSize - the buffer size in frames
|
|
1390
1402
|
* @param factory - default is the compiled factory
|
|
1403
|
+
* @param context - if this exists, will be used to fetch soundfiles online
|
|
1391
1404
|
* @returns the compiled processor or 'null' if failure
|
|
1392
1405
|
*/
|
|
1393
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<IFaustMonoOfflineProcessor | null>;
|
|
1406
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, context?: BaseAudioContext): Promise<IFaustMonoOfflineProcessor | null>;
|
|
1394
1407
|
/**
|
|
1395
1408
|
* Get DSP JSON description with its UI and metadata as object.
|
|
1396
1409
|
*
|
|
@@ -1410,7 +1423,7 @@ export interface IFaustMonoDspGenerator {
|
|
|
1410
1423
|
*/
|
|
1411
1424
|
getUI(): FaustUIDescriptor;
|
|
1412
1425
|
}
|
|
1413
|
-
export interface IFaustPolyDspGenerator {
|
|
1426
|
+
export interface IFaustPolyDspGenerator extends GeneratorSupportingSoundfiles {
|
|
1414
1427
|
/**
|
|
1415
1428
|
* Compile a monophonic DSP factory from given code.
|
|
1416
1429
|
*
|
|
@@ -1447,9 +1460,10 @@ export interface IFaustPolyDspGenerator {
|
|
|
1447
1460
|
* @param voiceFactory - the Faust factory for voices, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
|
|
1448
1461
|
* @param mixerModule - the wasm Mixer module (loaded from 'mixer32.wasm' or 'mixer64.wasm' files)
|
|
1449
1462
|
* @param effectFactory - the Faust factory for the effect, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
|
|
1463
|
+
* @param context - if this exists, will be used to fetch soundfiles online
|
|
1450
1464
|
* @returns the compiled processor or 'null' if failure
|
|
1451
1465
|
*/
|
|
1452
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null,
|
|
1466
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, context?: BaseAudioContext): Promise<IFaustPolyOfflineProcessor | null>;
|
|
1453
1467
|
/**
|
|
1454
1468
|
* Get DSP JSON description with its UI and metadata as object.
|
|
1455
1469
|
*
|
|
@@ -1475,6 +1489,8 @@ export declare class FaustMonoDspGenerator implements IFaustMonoDspGenerator {
|
|
|
1475
1489
|
factory: FaustDspFactory | null;
|
|
1476
1490
|
constructor();
|
|
1477
1491
|
compile(compiler: IFaustCompiler, name: string, code: string, args: string): Promise<this | null>;
|
|
1492
|
+
addSoundfiles(soundfileMap: Record<string, AudioData>): void;
|
|
1493
|
+
getSoundfileList(): string[];
|
|
1478
1494
|
createNode<SP extends boolean = false>(context: BaseAudioContext, name?: string, factory?: LooseFaustDspFactory, sp?: SP, bufferSize?: number, processorName?: string): Promise<SP extends true ? FaustMonoScriptProcessorNode | null : FaustMonoAudioWorkletNode | null>;
|
|
1479
1495
|
createFFTNode(context: BaseAudioContext, fftUtils: typeof FFTUtils, name?: string, factory?: LooseFaustDspFactory, fftOptions?: Partial<FaustFFTOptionsData>, processorName?: string): Promise<FaustMonoAudioWorkletNode | null>;
|
|
1480
1496
|
createAudioWorkletProcessor(name?: string, factory?: LooseFaustDspFactory, processorName?: string): Promise<{
|
|
@@ -1482,7 +1498,7 @@ export declare class FaustMonoDspGenerator implements IFaustMonoDspGenerator {
|
|
|
1482
1498
|
prototype: AudioWorkletProcessor;
|
|
1483
1499
|
parameterDescriptors: AudioParamDescriptor[];
|
|
1484
1500
|
}>;
|
|
1485
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<FaustMonoOfflineProcessor>;
|
|
1501
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, context?: BaseAudioContext): Promise<FaustMonoOfflineProcessor>;
|
|
1486
1502
|
getMeta(): any;
|
|
1487
1503
|
getJSON(): string;
|
|
1488
1504
|
getUI(): any;
|
|
@@ -1496,13 +1512,15 @@ export declare class FaustPolyDspGenerator implements IFaustPolyDspGenerator {
|
|
|
1496
1512
|
mixerModule: WebAssembly.Module;
|
|
1497
1513
|
constructor();
|
|
1498
1514
|
compile(compiler: IFaustCompiler, name: string, dspCodeAux: string, args: string, effectCodeAux?: string): Promise<this | null>;
|
|
1515
|
+
addSoundfiles(soundfileMap: Record<string, AudioData>): void;
|
|
1516
|
+
getSoundfileList(): string[];
|
|
1499
1517
|
createNode<SP extends boolean = false>(context: BaseAudioContext, voices: number, name?: string, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, sp?: SP, bufferSize?: number, processorName?: string): Promise<SP extends true ? FaustPolyScriptProcessorNode | null : FaustPolyAudioWorkletNode | null>;
|
|
1500
1518
|
createAudioWorkletProcessor(name?: string, voiceFactory?: LooseFaustDspFactory, effectFactory?: LooseFaustDspFactory | null, processorName?: string): Promise<{
|
|
1501
1519
|
new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
|
|
1502
1520
|
prototype: AudioWorkletProcessor;
|
|
1503
1521
|
parameterDescriptors: AudioParamDescriptor[];
|
|
1504
1522
|
}>;
|
|
1505
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null): Promise<FaustPolyOfflineProcessor>;
|
|
1523
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, context?: BaseAudioContext): Promise<FaustPolyOfflineProcessor>;
|
|
1506
1524
|
getMeta(): FaustDspMeta;
|
|
1507
1525
|
getJSON(): string;
|
|
1508
1526
|
getUI(): FaustUIDescriptor;
|
package/dist/cjs-bundle/index.js
CHANGED
|
@@ -9159,7 +9159,7 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9159
9159
|
// src/SoundfileReader.ts
|
|
9160
9160
|
var SoundfileReader = class {
|
|
9161
9161
|
static get fallbackPaths() {
|
|
9162
|
-
return [location.href, location.origin
|
|
9162
|
+
return [location.href, location.origin];
|
|
9163
9163
|
}
|
|
9164
9164
|
/**
|
|
9165
9165
|
* Convert an audio buffer to audio data.
|
|
@@ -9592,6 +9592,20 @@ export default ${(_b = jsCode.match(jsCodeHead)) == null ? void 0 : _b[1]};
|
|
|
9592
9592
|
return null;
|
|
9593
9593
|
}
|
|
9594
9594
|
}
|
|
9595
|
+
addSoundfiles(soundfileMap) {
|
|
9596
|
+
if (!this.factory)
|
|
9597
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
9598
|
+
for (const id in soundfileMap) {
|
|
9599
|
+
this.factory.soundfiles[id] = soundfileMap[id];
|
|
9600
|
+
}
|
|
9601
|
+
}
|
|
9602
|
+
getSoundfileList() {
|
|
9603
|
+
if (!this.factory)
|
|
9604
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
9605
|
+
const meta = JSON.parse(this.factory.json);
|
|
9606
|
+
const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
|
|
9607
|
+
return Object.keys(map);
|
|
9608
|
+
}
|
|
9595
9609
|
async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
|
|
9596
9610
|
var _a, _b;
|
|
9597
9611
|
if (!factory)
|
|
@@ -9749,12 +9763,14 @@ const dependencies = {
|
|
|
9749
9763
|
throw e;
|
|
9750
9764
|
}
|
|
9751
9765
|
}
|
|
9752
|
-
async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory) {
|
|
9766
|
+
async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory, context) {
|
|
9753
9767
|
if (!factory)
|
|
9754
9768
|
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
9755
9769
|
const meta = JSON.parse(factory.json);
|
|
9756
9770
|
const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
|
|
9757
9771
|
const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
|
|
9772
|
+
if (context)
|
|
9773
|
+
factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
|
|
9758
9774
|
const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
|
|
9759
9775
|
return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
|
|
9760
9776
|
}
|
|
@@ -9844,6 +9860,24 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
|
|
|
9844
9860
|
return null;
|
|
9845
9861
|
}
|
|
9846
9862
|
}
|
|
9863
|
+
addSoundfiles(soundfileMap) {
|
|
9864
|
+
if (!this.voiceFactory)
|
|
9865
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
9866
|
+
for (const id in soundfileMap) {
|
|
9867
|
+
this.voiceFactory.soundfiles[id] = soundfileMap[id];
|
|
9868
|
+
}
|
|
9869
|
+
}
|
|
9870
|
+
getSoundfileList() {
|
|
9871
|
+
if (!this.voiceFactory)
|
|
9872
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
9873
|
+
const meta = JSON.parse(this.voiceFactory.json);
|
|
9874
|
+
const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
|
|
9875
|
+
if (!this.effectFactory)
|
|
9876
|
+
return Object.keys(map);
|
|
9877
|
+
const effectMeta = JSON.parse(this.effectFactory.json);
|
|
9878
|
+
const effectMap = SoundfileReader_default.findSoundfilesFromMeta(effectMeta);
|
|
9879
|
+
return Object.keys({ ...effectMap, ...map });
|
|
9880
|
+
}
|
|
9847
9881
|
async createNode(context, voices, name = this.name, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, sp = false, bufferSize = 1024, processorName = ((voiceFactory == null ? void 0 : voiceFactory.shaKey) || "") + ((effectFactory == null ? void 0 : effectFactory.shaKey) || "") || `${name}_poly`) {
|
|
9848
9882
|
var _a, _b;
|
|
9849
9883
|
if (!voiceFactory)
|
|
@@ -9938,13 +9972,18 @@ const dependencies = {
|
|
|
9938
9972
|
throw e;
|
|
9939
9973
|
}
|
|
9940
9974
|
}
|
|
9941
|
-
async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory) {
|
|
9975
|
+
async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, context) {
|
|
9942
9976
|
if (!voiceFactory)
|
|
9943
9977
|
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
9944
9978
|
const voiceMeta = JSON.parse(voiceFactory.json);
|
|
9945
9979
|
const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
|
|
9946
9980
|
const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
|
|
9947
9981
|
const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
|
|
9982
|
+
if (context) {
|
|
9983
|
+
voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
|
|
9984
|
+
if (effectFactory)
|
|
9985
|
+
effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
|
|
9986
|
+
}
|
|
9948
9987
|
const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
|
|
9949
9988
|
const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
|
|
9950
9989
|
return new FaustPolyOfflineProcessor(polyDsp, bufferSize);
|