@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
|
@@ -1196,7 +1196,7 @@ export declare class SoundfileReader {
|
|
|
1196
1196
|
* @param dspMeta : the metadata
|
|
1197
1197
|
* @returns : the URLs
|
|
1198
1198
|
*/
|
|
1199
|
-
|
|
1199
|
+
static findSoundfilesFromMeta(dspMeta: FaustDspMeta): LooseFaustDspFactory["soundfiles"];
|
|
1200
1200
|
/**
|
|
1201
1201
|
* Check if the file exists.
|
|
1202
1202
|
*
|
|
@@ -1336,7 +1336,19 @@ export declare class FaustPolyScriptProcessorNode extends FaustScriptProcessorNo
|
|
|
1336
1336
|
keyOff(channel: number, pitch: number, velocity: number): void;
|
|
1337
1337
|
allNotesOff(hard: boolean): void;
|
|
1338
1338
|
}
|
|
1339
|
-
export interface
|
|
1339
|
+
export interface GeneratorSupportingSoundfiles {
|
|
1340
|
+
/**
|
|
1341
|
+
* Attach a map of id - audio data, call after `compile()` before `createNode()`
|
|
1342
|
+
*
|
|
1343
|
+
* @param soundfileMap a map of id - `AudioData` as an object where `AudioData` contains channel data as `audioBuffer: Float32Array[]` and `sampleRate: number`
|
|
1344
|
+
*/
|
|
1345
|
+
addSoundfiles(soundfileMap: Record<string, AudioData>): void;
|
|
1346
|
+
/**
|
|
1347
|
+
* Get a list of soundfiles needed, call after `compile()`
|
|
1348
|
+
*/
|
|
1349
|
+
getSoundfileList(): string[];
|
|
1350
|
+
}
|
|
1351
|
+
export interface IFaustMonoDspGenerator extends GeneratorSupportingSoundfiles {
|
|
1340
1352
|
/**
|
|
1341
1353
|
* Compile a monophonic DSP factory from given code.
|
|
1342
1354
|
*
|
|
@@ -1381,9 +1393,10 @@ export interface IFaustMonoDspGenerator {
|
|
|
1381
1393
|
* @param sampleRate - the sample rate in Hz
|
|
1382
1394
|
* @param bufferSize - the buffer size in frames
|
|
1383
1395
|
* @param factory - default is the compiled factory
|
|
1396
|
+
* @param context - if this exists, will be used to fetch soundfiles online
|
|
1384
1397
|
* @returns the compiled processor or 'null' if failure
|
|
1385
1398
|
*/
|
|
1386
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<IFaustMonoOfflineProcessor | null>;
|
|
1399
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, context?: BaseAudioContext): Promise<IFaustMonoOfflineProcessor | null>;
|
|
1387
1400
|
/**
|
|
1388
1401
|
* Get DSP JSON description with its UI and metadata as object.
|
|
1389
1402
|
*
|
|
@@ -1403,7 +1416,7 @@ export interface IFaustMonoDspGenerator {
|
|
|
1403
1416
|
*/
|
|
1404
1417
|
getUI(): FaustUIDescriptor;
|
|
1405
1418
|
}
|
|
1406
|
-
export interface IFaustPolyDspGenerator {
|
|
1419
|
+
export interface IFaustPolyDspGenerator extends GeneratorSupportingSoundfiles {
|
|
1407
1420
|
/**
|
|
1408
1421
|
* Compile a monophonic DSP factory from given code.
|
|
1409
1422
|
*
|
|
@@ -1440,9 +1453,10 @@ export interface IFaustPolyDspGenerator {
|
|
|
1440
1453
|
* @param voiceFactory - the Faust factory for voices, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
|
|
1441
1454
|
* @param mixerModule - the wasm Mixer module (loaded from 'mixer32.wasm' or 'mixer64.wasm' files)
|
|
1442
1455
|
* @param effectFactory - the Faust factory for the effect, either obtained with a compiler (createDSPFactory) or loaded from files (loadDSPFactory)
|
|
1456
|
+
* @param context - if this exists, will be used to fetch soundfiles online
|
|
1443
1457
|
* @returns the compiled processor or 'null' if failure
|
|
1444
1458
|
*/
|
|
1445
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null,
|
|
1459
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, context?: BaseAudioContext): Promise<IFaustPolyOfflineProcessor | null>;
|
|
1446
1460
|
/**
|
|
1447
1461
|
* Get DSP JSON description with its UI and metadata as object.
|
|
1448
1462
|
*
|
|
@@ -1468,6 +1482,8 @@ export declare class FaustMonoDspGenerator implements IFaustMonoDspGenerator {
|
|
|
1468
1482
|
factory: FaustDspFactory | null;
|
|
1469
1483
|
constructor();
|
|
1470
1484
|
compile(compiler: IFaustCompiler, name: string, code: string, args: string): Promise<this | null>;
|
|
1485
|
+
addSoundfiles(soundfileMap: Record<string, AudioData>): void;
|
|
1486
|
+
getSoundfileList(): string[];
|
|
1471
1487
|
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>;
|
|
1472
1488
|
createFFTNode(context: BaseAudioContext, fftUtils: typeof FFTUtils, name?: string, factory?: LooseFaustDspFactory, fftOptions?: Partial<FaustFFTOptionsData>, processorName?: string): Promise<FaustMonoAudioWorkletNode | null>;
|
|
1473
1489
|
createAudioWorkletProcessor(name?: string, factory?: LooseFaustDspFactory, processorName?: string): Promise<{
|
|
@@ -1475,7 +1491,7 @@ export declare class FaustMonoDspGenerator implements IFaustMonoDspGenerator {
|
|
|
1475
1491
|
prototype: AudioWorkletProcessor;
|
|
1476
1492
|
parameterDescriptors: AudioParamDescriptor[];
|
|
1477
1493
|
}>;
|
|
1478
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory): Promise<FaustMonoOfflineProcessor>;
|
|
1494
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, factory?: LooseFaustDspFactory, context?: BaseAudioContext): Promise<FaustMonoOfflineProcessor>;
|
|
1479
1495
|
getMeta(): any;
|
|
1480
1496
|
getJSON(): string;
|
|
1481
1497
|
getUI(): any;
|
|
@@ -1489,13 +1505,15 @@ export declare class FaustPolyDspGenerator implements IFaustPolyDspGenerator {
|
|
|
1489
1505
|
mixerModule: WebAssembly.Module;
|
|
1490
1506
|
constructor();
|
|
1491
1507
|
compile(compiler: IFaustCompiler, name: string, dspCodeAux: string, args: string, effectCodeAux?: string): Promise<this | null>;
|
|
1508
|
+
addSoundfiles(soundfileMap: Record<string, AudioData>): void;
|
|
1509
|
+
getSoundfileList(): string[];
|
|
1492
1510
|
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>;
|
|
1493
1511
|
createAudioWorkletProcessor(name?: string, voiceFactory?: LooseFaustDspFactory, effectFactory?: LooseFaustDspFactory | null, processorName?: string): Promise<{
|
|
1494
1512
|
new (options: AudioWorkletNodeOptions): AudioWorkletProcessor;
|
|
1495
1513
|
prototype: AudioWorkletProcessor;
|
|
1496
1514
|
parameterDescriptors: AudioParamDescriptor[];
|
|
1497
1515
|
}>;
|
|
1498
|
-
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null): Promise<FaustPolyOfflineProcessor>;
|
|
1516
|
+
createOfflineProcessor(sampleRate: number, bufferSize: number, voices: number, voiceFactory?: LooseFaustDspFactory, mixerModule?: WebAssembly.Module, effectFactory?: LooseFaustDspFactory | null, context?: BaseAudioContext): Promise<FaustPolyOfflineProcessor>;
|
|
1499
1517
|
getMeta(): FaustDspMeta;
|
|
1500
1518
|
getJSON(): string;
|
|
1501
1519
|
getUI(): FaustUIDescriptor;
|
|
@@ -3111,7 +3111,7 @@ var WavDecoder_default = WavDecoder;
|
|
|
3111
3111
|
// src/SoundfileReader.ts
|
|
3112
3112
|
var SoundfileReader = class {
|
|
3113
3113
|
static get fallbackPaths() {
|
|
3114
|
-
return [location.href, location.origin
|
|
3114
|
+
return [location.href, location.origin];
|
|
3115
3115
|
}
|
|
3116
3116
|
/**
|
|
3117
3117
|
* Convert an audio buffer to audio data.
|
|
@@ -3544,6 +3544,20 @@ var _FaustMonoDspGenerator = class _FaustMonoDspGenerator {
|
|
|
3544
3544
|
return null;
|
|
3545
3545
|
}
|
|
3546
3546
|
}
|
|
3547
|
+
addSoundfiles(soundfileMap) {
|
|
3548
|
+
if (!this.factory)
|
|
3549
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
3550
|
+
for (const id in soundfileMap) {
|
|
3551
|
+
this.factory.soundfiles[id] = soundfileMap[id];
|
|
3552
|
+
}
|
|
3553
|
+
}
|
|
3554
|
+
getSoundfileList() {
|
|
3555
|
+
if (!this.factory)
|
|
3556
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
3557
|
+
const meta = JSON.parse(this.factory.json);
|
|
3558
|
+
const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
|
|
3559
|
+
return Object.keys(map);
|
|
3560
|
+
}
|
|
3547
3561
|
async createNode(context, name = this.name, factory = this.factory, sp = false, bufferSize = 1024, processorName = (factory == null ? void 0 : factory.shaKey) || name) {
|
|
3548
3562
|
var _a, _b;
|
|
3549
3563
|
if (!factory)
|
|
@@ -3701,12 +3715,14 @@ const dependencies = {
|
|
|
3701
3715
|
throw e;
|
|
3702
3716
|
}
|
|
3703
3717
|
}
|
|
3704
|
-
async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory) {
|
|
3718
|
+
async createOfflineProcessor(sampleRate, bufferSize, factory = this.factory, context) {
|
|
3705
3719
|
if (!factory)
|
|
3706
3720
|
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
3707
3721
|
const meta = JSON.parse(factory.json);
|
|
3708
3722
|
const instance = await FaustWasmInstantiator_default.createAsyncMonoDSPInstance(factory);
|
|
3709
3723
|
const sampleSize = meta.compile_options.match("-double") ? 8 : 4;
|
|
3724
|
+
if (context)
|
|
3725
|
+
factory.soundfiles = await SoundfileReader_default.loadSoundfiles(meta, factory.soundfiles || {}, context);
|
|
3710
3726
|
const monoDsp = new FaustMonoWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, factory.soundfiles);
|
|
3711
3727
|
return new FaustMonoOfflineProcessor(monoDsp, bufferSize);
|
|
3712
3728
|
}
|
|
@@ -3796,6 +3812,24 @@ process = adaptorIns(dsp_code.process) : dsp_code.effect : adaptorOuts;
|
|
|
3796
3812
|
return null;
|
|
3797
3813
|
}
|
|
3798
3814
|
}
|
|
3815
|
+
addSoundfiles(soundfileMap) {
|
|
3816
|
+
if (!this.voiceFactory)
|
|
3817
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
3818
|
+
for (const id in soundfileMap) {
|
|
3819
|
+
this.voiceFactory.soundfiles[id] = soundfileMap[id];
|
|
3820
|
+
}
|
|
3821
|
+
}
|
|
3822
|
+
getSoundfileList() {
|
|
3823
|
+
if (!this.voiceFactory)
|
|
3824
|
+
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
3825
|
+
const meta = JSON.parse(this.voiceFactory.json);
|
|
3826
|
+
const map = SoundfileReader_default.findSoundfilesFromMeta(meta);
|
|
3827
|
+
if (!this.effectFactory)
|
|
3828
|
+
return Object.keys(map);
|
|
3829
|
+
const effectMeta = JSON.parse(this.effectFactory.json);
|
|
3830
|
+
const effectMap = SoundfileReader_default.findSoundfilesFromMeta(effectMeta);
|
|
3831
|
+
return Object.keys({ ...effectMap, ...map });
|
|
3832
|
+
}
|
|
3799
3833
|
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`) {
|
|
3800
3834
|
var _a, _b;
|
|
3801
3835
|
if (!voiceFactory)
|
|
@@ -3890,13 +3924,18 @@ const dependencies = {
|
|
|
3890
3924
|
throw e;
|
|
3891
3925
|
}
|
|
3892
3926
|
}
|
|
3893
|
-
async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory) {
|
|
3927
|
+
async createOfflineProcessor(sampleRate, bufferSize, voices, voiceFactory = this.voiceFactory, mixerModule = this.mixerModule, effectFactory = this.effectFactory, context) {
|
|
3894
3928
|
if (!voiceFactory)
|
|
3895
3929
|
throw new Error("Code is not compiled, please define the factory or call `await this.compile()` first.");
|
|
3896
3930
|
const voiceMeta = JSON.parse(voiceFactory.json);
|
|
3897
3931
|
const effectMeta = effectFactory ? JSON.parse(effectFactory.json) : void 0;
|
|
3898
3932
|
const instance = await FaustWasmInstantiator_default.createAsyncPolyDSPInstance(voiceFactory, mixerModule, voices, effectFactory || void 0);
|
|
3899
3933
|
const sampleSize = voiceMeta.compile_options.match("-double") ? 8 : 4;
|
|
3934
|
+
if (context) {
|
|
3935
|
+
voiceFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(voiceMeta, voiceFactory.soundfiles || {}, context);
|
|
3936
|
+
if (effectFactory)
|
|
3937
|
+
effectFactory.soundfiles = await SoundfileReader_default.loadSoundfiles(effectMeta, effectFactory.soundfiles || {}, context);
|
|
3938
|
+
}
|
|
3900
3939
|
const soundfiles = { ...effectFactory == null ? void 0 : effectFactory.soundfiles, ...voiceFactory.soundfiles };
|
|
3901
3940
|
const polyDsp = new FaustPolyWebAudioDsp(instance, sampleRate, sampleSize, bufferSize, soundfiles);
|
|
3902
3941
|
return new FaustPolyOfflineProcessor(polyDsp, bufferSize);
|