@grame/faustwasm 0.0.28 → 0.0.30
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/README.md +32 -10
- package/assets/standalone/faustwasm/index.js +18 -19
- package/assets/standalone/faustwasm/index.js.map +2 -2
- package/dist/cjs/index.js +17 -18
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs-bundle/index.js +1287 -3016
- package/dist/cjs-bundle/index.js.map +3 -3
- package/dist/esm/index.js +18 -19
- package/dist/esm/index.js.map +2 -2
- package/dist/esm-bundle/index.js +1287 -3016
- package/dist/esm-bundle/index.js.map +3 -3
- package/libfaust-wasm/libfaust-wasm.data +0 -0
- package/libfaust-wasm/libfaust-wasm.js +3 -4
- package/libfaust-wasm/libfaust-wasm.wasm +0 -0
- package/package.json +1 -1
- package/src/FaustDspGenerator.ts +13 -13
- package/src/FaustDspInstance.ts +1 -3
- package/src/FaustWasmInstantiator.ts +1 -1
- package/src/exports.ts +24 -24
- package/test/faustlive-wasm/faustwasm/index.js +18 -19
- package/test/faustlive-wasm/faustwasm/index.js.map +2 -2
- package/test/greyhole.dsp +8 -0
- package/test/jprev.dsp +8 -0
- package/test/soundmachine.dsp +52 -0
- package/test/t1.cjs +46 -0
- package/test/t1.js +46 -0
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# FaustWasm
|
|
2
2
|
|
|
3
|
-
The
|
|
3
|
+
The FaustWasm library presents a convenient, high-level API that wraps around [Faust](https://faust.grame.fr) compiler. This library's interface is primarily designed for [TypeScript](https://www.typescriptlang.org/) usage, although it also provides API descriptions and documentation for pure JavaScript. The WebAssembly version of the Faust Compiler, compatible with both [Node.js](https://nodejs.org) and web browsers, has been compiled using [Emscripten](https://emscripten.org/) 3.1.31.
|
|
4
|
+
|
|
5
|
+
The library offers functionality for compiling Faust DSP code into WebAssembly, enabling its utilization as WebAudio nodes within a standard WebAudio node graph. Moreover, it supports offline rendering scenarios. Furthermore, supplementary tools can be employed for generating SVGs from Faust DSP programs.
|
|
4
6
|
|
|
5
7
|
## Usage
|
|
6
8
|
|
|
@@ -14,12 +16,29 @@ git clone https://github.com/grame-cncm/faustwasm.git
|
|
|
14
16
|
cd faustwasm
|
|
15
17
|
```
|
|
16
18
|
|
|
19
|
+
Install development dependencies:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Possibly:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm update
|
|
29
|
+
```
|
|
30
|
+
|
|
17
31
|
Build the files:
|
|
18
32
|
```bash
|
|
19
33
|
npm run build
|
|
20
34
|
```
|
|
21
35
|
|
|
36
|
+
### Versioning
|
|
37
|
+
|
|
38
|
+
You'll have to raise the package version number in `package.json` before `npm run build` to properly work.
|
|
39
|
+
|
|
22
40
|
#### Generate WebAssembly version of a Faust DSP
|
|
41
|
+
|
|
23
42
|
For example:
|
|
24
43
|
```bash
|
|
25
44
|
rm -rf test/out # make sure you are under the faustwasm directory.
|
|
@@ -37,6 +56,7 @@ node scripts/faust2wasm.js test/rev.dsp test/out -standalone
|
|
|
37
56
|
```
|
|
38
57
|
|
|
39
58
|
#### Generate SVG Diagrams of a Faust DSP
|
|
59
|
+
|
|
40
60
|
For example:
|
|
41
61
|
```bash
|
|
42
62
|
rm -rf test/out # make sure you are under the faustwasm directory.
|
|
@@ -45,6 +65,7 @@ node scripts/faust2svg.js test/mono.dsp test/out
|
|
|
45
65
|
The main diagram should be in `test/out/process.svg`.
|
|
46
66
|
|
|
47
67
|
#### Generate or process audio files
|
|
68
|
+
|
|
48
69
|
Options:
|
|
49
70
|
- `-bs <num>` to setup the rendering buffer size in frames (default: 64)
|
|
50
71
|
- `-bd 16|24|32` to setup the output file bit-depth (default: 16)
|
|
@@ -126,6 +147,7 @@ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
|
|
|
126
147
|
```
|
|
127
148
|
|
|
128
149
|
### Use in a web browser
|
|
150
|
+
|
|
129
151
|
```JavaScript
|
|
130
152
|
|
|
131
153
|
(async () => {
|
|
@@ -193,13 +215,13 @@ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
|
|
|
193
215
|
- [Important note](#note)
|
|
194
216
|
|
|
195
217
|
|
|
196
|
-
|
|
218
|
+
### Organisation of the API <a name="org"></a>
|
|
197
219
|
|
|
198
220
|
The API is organised from low to high level as illustrated by the figure below.
|
|
199
221
|
|
|
200
222
|
<img src="rsrc/overview.png" class="mx-auto d-block" width="60%">
|
|
201
223
|
|
|
202
|
-
|
|
224
|
+
#### Faust Compiler WebAssembly module <a name="module"></a>
|
|
203
225
|
|
|
204
226
|
The first level is the Faust compiler compiled as a wasm library named `libfaust-wasm`.
|
|
205
227
|
It consists in 3 different files:
|
|
@@ -217,11 +239,11 @@ It provides *classic* Faust compilation services, which output is a raw WebAssem
|
|
|
217
239
|
|
|
218
240
|
### Faust Wasm Instance <a name="wasm"></a>
|
|
219
241
|
|
|
220
|
-
This level takes a WebAssembly module produced by the Faust compiler or a precompiled module loaded from a file, and builds an instance of this module with the proper Wasm memory layout, ready to run
|
|
242
|
+
This level takes a WebAssembly module produced by the Faust compiler or a precompiled module loaded from a file, and builds an instance of this module with the proper Wasm memory layout, ready to run. It is described in `FaustDspGenerator.ts`, `FaustWasmInstantiator.ts`, `FaustWebAudioDsp.ts` and `FaustDspInstance.ts` files.
|
|
221
243
|
|
|
222
|
-
|
|
244
|
+
#### Faust Audio Nodes Instances and Offline Processor <a name="audio"></a>
|
|
223
245
|
|
|
224
|
-
This level takes a Faust Wasm instance to build an audio node. [AudioWorklet](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) and [ScriptProcessor](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode) nodes are supported.
|
|
246
|
+
This level takes a Faust Wasm instance to build an audio node. [AudioWorklet](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) and [ScriptProcessor](https://developer.mozilla.org/en-US/docs/Web/API/ScriptProcessorNode) nodes are supported. It is described in `FaustAudioWorkletNode.ts` and `FaustAudioWorkletProcessor.ts` files.
|
|
225
247
|
|
|
226
248
|
**Warning**: AudioWorklet is a recent technology and may not be supported by all the browsers. Check the [compatibility](https://developer.mozilla.org/fr/docs/Web/API/AudioWorklet) chart.
|
|
227
249
|
|
|
@@ -231,18 +253,18 @@ By default, and to save CPU, created audio nodes are not processing audio buffer
|
|
|
231
253
|
|
|
232
254
|
An offline processor to render a DSP in a non real-time context and get the computed frames is available. It is described in `FaustOfflineProcessor.ts`. It will automatically use the `start` and `stop` methods internally to activate actual rendering in its `plot` method.
|
|
233
255
|
|
|
234
|
-
|
|
256
|
+
#### High-level API <a name="high"></a>
|
|
235
257
|
|
|
236
258
|
A high-level API is available to compile a DSP program and create the audio node, either monophonic or polyphonic using `createNode`. Offline processing monophonic or polyphonic nodes can be created using `createOfflineProcessor`. FFT processing nodes can be created using `createFFTNode`. It is described in `FaustDspGenerator.ts`.
|
|
237
259
|
|
|
238
|
-
|
|
260
|
+
#### How to use with typescript <a name="tsuse"></a>
|
|
239
261
|
|
|
240
262
|
Simply include the following to get access to types and functions:
|
|
241
263
|
~~~~~~~~~~~~~~~
|
|
242
264
|
///<reference types="@grame/faustwasm"/>
|
|
243
265
|
~~~~~~~~~~~~~~~
|
|
244
266
|
|
|
245
|
-
|
|
267
|
+
### Dynamic and Static Instances <a name="ds"></a>
|
|
246
268
|
|
|
247
269
|
The Faust Wasm and Audio Node levels make it possible to generate instances from Faust dsp code as well as from pre-compiled WebAssembly modules.
|
|
248
270
|
In the latter case, it is not necessary to include the `libfaust-wasm.js` library, `index.js` is sufficient to provide the required services.
|
|
@@ -253,7 +275,7 @@ This allows to generate lighter and faster-loading HTML pages.
|
|
|
253
275
|
- `FaustSvgDiagrams.ts`: provides facilities to browse Faust generated SVG diagrams
|
|
254
276
|
- `FaustFFTAudioWorkletProcessor`: provides FFT processing
|
|
255
277
|
|
|
256
|
-
|
|
278
|
+
### Important note <a name="note"></a>
|
|
257
279
|
|
|
258
280
|
Html pages embedding the Faust compiler must be served using https, unless using http://localhost.
|
|
259
281
|
|
|
@@ -1723,7 +1723,6 @@ var FaustDspInstance = class {
|
|
|
1723
1723
|
this.fExports.setParamValue($dsp, index, value);
|
|
1724
1724
|
}
|
|
1725
1725
|
};
|
|
1726
|
-
var FaustDspInstance_default = FaustDspInstance;
|
|
1727
1726
|
|
|
1728
1727
|
// src/FaustWasmInstantiator.ts
|
|
1729
1728
|
var FaustWasmInstantiator = class {
|
|
@@ -1813,7 +1812,7 @@ var FaustWasmInstantiator = class {
|
|
|
1813
1812
|
}
|
|
1814
1813
|
static createMonoDSPInstanceAux(instance, json) {
|
|
1815
1814
|
const functions = instance.exports;
|
|
1816
|
-
const api = new
|
|
1815
|
+
const api = new FaustDspInstance(functions);
|
|
1817
1816
|
const memory = instance.exports.memory;
|
|
1818
1817
|
return { memory, api, json };
|
|
1819
1818
|
}
|
|
@@ -1876,12 +1875,12 @@ var FaustWasmInstantiator = class {
|
|
|
1876
1875
|
const memory = this.createMemoryAux(voices, voiceFactory, effectFactory);
|
|
1877
1876
|
const voiceInstance = await WebAssembly.instantiate(voiceFactory.module, this.createWasmImport(memory));
|
|
1878
1877
|
const voiceFunctions = voiceInstance.exports;
|
|
1879
|
-
const voiceAPI = new
|
|
1878
|
+
const voiceAPI = new FaustDspInstance(voiceFunctions);
|
|
1880
1879
|
const mixerAPI = this.createMixerAux(mixerModule, memory);
|
|
1881
1880
|
if (effectFactory) {
|
|
1882
1881
|
const effectInstance = await WebAssembly.instantiate(effectFactory.module, this.createWasmImport(memory));
|
|
1883
1882
|
const effectFunctions = effectInstance.exports;
|
|
1884
|
-
const effectAPI = new
|
|
1883
|
+
const effectAPI = new FaustDspInstance(effectFunctions);
|
|
1885
1884
|
return {
|
|
1886
1885
|
memory,
|
|
1887
1886
|
voices,
|
|
@@ -1905,12 +1904,12 @@ var FaustWasmInstantiator = class {
|
|
|
1905
1904
|
const memory = this.createMemoryAux(voices, voiceFactory, effectFactory);
|
|
1906
1905
|
const voiceInstance = new WebAssembly.Instance(voiceFactory.module, this.createWasmImport(memory));
|
|
1907
1906
|
const voiceFunctions = voiceInstance.exports;
|
|
1908
|
-
const voiceAPI = new
|
|
1907
|
+
const voiceAPI = new FaustDspInstance(voiceFunctions);
|
|
1909
1908
|
const mixerAPI = this.createMixerAux(mixerModule, memory);
|
|
1910
1909
|
if (effectFactory) {
|
|
1911
1910
|
const effectInstance = new WebAssembly.Instance(effectFactory.module, this.createWasmImport(memory));
|
|
1912
1911
|
const effectFunctions = effectInstance.exports;
|
|
1913
|
-
const effectAPI = new
|
|
1912
|
+
const effectAPI = new FaustDspInstance(effectFunctions);
|
|
1914
1913
|
return {
|
|
1915
1914
|
memory,
|
|
1916
1915
|
voices,
|
|
@@ -3499,15 +3498,15 @@ const faustData = ${JSON.stringify({
|
|
|
3499
3498
|
poly: false
|
|
3500
3499
|
})};
|
|
3501
3500
|
// Implementation needed classes of functions
|
|
3502
|
-
const ${
|
|
3501
|
+
const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
|
|
3503
3502
|
const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
|
|
3504
3503
|
const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
|
|
3505
3504
|
const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
|
|
3506
3505
|
// Put them in dependencies
|
|
3507
3506
|
const dependencies = {
|
|
3508
|
-
${FaustBaseWebAudioDsp.name},
|
|
3509
|
-
${FaustMonoWebAudioDsp.name},
|
|
3510
|
-
${FaustWasmInstantiator_default.name}
|
|
3507
|
+
FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
|
|
3508
|
+
FaustMonoWebAudioDsp: ${FaustMonoWebAudioDsp.name},
|
|
3509
|
+
FaustWasmInstantiator: ${FaustWasmInstantiator_default.name}
|
|
3511
3510
|
};
|
|
3512
3511
|
// Generate the actual AudioWorkletProcessor code
|
|
3513
3512
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -3542,16 +3541,16 @@ const faustData = ${JSON.stringify({
|
|
|
3542
3541
|
fftOptions
|
|
3543
3542
|
})};
|
|
3544
3543
|
// Implementation needed classes of functions
|
|
3545
|
-
const ${
|
|
3544
|
+
const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
|
|
3546
3545
|
const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
|
|
3547
3546
|
const ${FaustMonoWebAudioDsp.name} = ${FaustMonoWebAudioDsp.toString()}
|
|
3548
3547
|
const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
|
|
3549
3548
|
const FFTUtils = ${fftUtils.toString()}
|
|
3550
3549
|
// Put them in dependencies
|
|
3551
3550
|
const dependencies = {
|
|
3552
|
-
${FaustBaseWebAudioDsp.name},
|
|
3553
|
-
${FaustMonoWebAudioDsp.name},
|
|
3554
|
-
${FaustWasmInstantiator_default.name},
|
|
3551
|
+
FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
|
|
3552
|
+
FaustMonoWebAudioDsp: ${FaustMonoWebAudioDsp.name},
|
|
3553
|
+
FaustWasmInstantiator: ${FaustWasmInstantiator_default.name},
|
|
3555
3554
|
FFTUtils
|
|
3556
3555
|
};
|
|
3557
3556
|
// Generate the actual AudioWorkletProcessor code
|
|
@@ -3678,16 +3677,16 @@ const faustData = ${JSON.stringify({
|
|
|
3678
3677
|
effectMeta
|
|
3679
3678
|
})};
|
|
3680
3679
|
// Implementation needed classes of functions
|
|
3681
|
-
const ${
|
|
3680
|
+
const ${FaustDspInstance.name} = ${FaustDspInstance.toString()}
|
|
3682
3681
|
const ${FaustBaseWebAudioDsp.name} = ${FaustBaseWebAudioDsp.toString()}
|
|
3683
3682
|
const ${FaustPolyWebAudioDsp.name} = ${FaustPolyWebAudioDsp.toString()}
|
|
3684
3683
|
const ${FaustWebAudioDspVoice.name} = ${FaustWebAudioDspVoice.toString()}
|
|
3685
3684
|
const ${FaustWasmInstantiator_default.name} = ${FaustWasmInstantiator_default.toString()}
|
|
3686
3685
|
// Put them in dependencies
|
|
3687
3686
|
const dependencies = {
|
|
3688
|
-
${FaustBaseWebAudioDsp.name},
|
|
3689
|
-
${FaustPolyWebAudioDsp.name},
|
|
3690
|
-
${FaustWasmInstantiator_default.name}
|
|
3687
|
+
FaustBaseWebAudioDsp: ${FaustBaseWebAudioDsp.name},
|
|
3688
|
+
FaustPolyWebAudioDsp: ${FaustPolyWebAudioDsp.name},
|
|
3689
|
+
FaustWasmInstantiator: ${FaustWasmInstantiator_default.name}
|
|
3691
3690
|
};
|
|
3692
3691
|
// Generate the actual AudioWorkletProcessor code
|
|
3693
3692
|
(${FaustAudioWorkletProcessor_default.toString()})(dependencies, faustData);
|
|
@@ -3747,7 +3746,7 @@ export {
|
|
|
3747
3746
|
FaustAudioWorkletNode,
|
|
3748
3747
|
FaustBaseWebAudioDsp,
|
|
3749
3748
|
FaustCompiler_default as FaustCompiler,
|
|
3750
|
-
|
|
3749
|
+
FaustDspInstance,
|
|
3751
3750
|
FaustMonoAudioWorkletNode,
|
|
3752
3751
|
FaustMonoDspGenerator,
|
|
3753
3752
|
FaustMonoOfflineProcessor,
|