@grame/faustwasm 0.0.25
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 +181 -0
- package/assets/standalone/faust-ui/index.css +414 -0
- package/assets/standalone/faust-ui/index.css.map +1 -0
- package/assets/standalone/faust-ui/index.d.ts +1 -0
- package/assets/standalone/faust-ui/index.js +3478 -0
- package/assets/standalone/faust-ui/index.js.map +1 -0
- package/assets/standalone/faustwasm/index.d.ts +1252 -0
- package/assets/standalone/faustwasm/index.js +3772 -0
- package/assets/standalone/faustwasm/index.js.map +7 -0
- package/assets/standalone/index.html +73 -0
- package/assets/standalone/index.js +198 -0
- package/assets/standalone/types.d.ts +9 -0
- package/dist/cjs/index.d.ts +1252 -0
- package/dist/cjs/index.js +3752 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs-bundle/index.d.ts +1259 -0
- package/dist/cjs-bundle/index.js +11507 -0
- package/dist/cjs-bundle/index.js.map +7 -0
- package/dist/esm/index.d.ts +1252 -0
- package/dist/esm/index.js +3772 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm-bundle/index.d.ts +1259 -0
- package/dist/esm-bundle/index.js +11495 -0
- package/dist/esm-bundle/index.js.map +7 -0
- package/fileutils.js +40 -0
- package/libfaust-wasm/libfaust-wasm.d.cts +3 -0
- package/libfaust-wasm/libfaust-wasm.d.ts +3 -0
- package/libfaust-wasm/libfaust-wasm.data +0 -0
- package/libfaust-wasm/libfaust-wasm.data.d.ts +2 -0
- package/libfaust-wasm/libfaust-wasm.js +21 -0
- package/libfaust-wasm/libfaust-wasm.wasm +0 -0
- package/libfaust-wasm/libfaust-wasm.wasm.d.ts +2 -0
- package/library.md +91 -0
- package/package.json +43 -0
- package/postbuild-bundled.js +11 -0
- package/postbuild.js +63 -0
- package/prebuild-bundled.js +11 -0
- package/rsrc/overview.png +0 -0
- package/rsrc/overview.xlsx +0 -0
- package/scripts/faust2sndfile.js +43 -0
- package/scripts/faust2svg.js +17 -0
- package/scripts/faust2wasm.js +29 -0
- package/src/FaustAudioWorkletNode.ts +264 -0
- package/src/FaustAudioWorkletProcessor.ts +273 -0
- package/src/FaustCompiler.ts +252 -0
- package/src/FaustDspGenerator.ts +498 -0
- package/src/FaustDspInstance.ts +141 -0
- package/src/FaustFFTAudioWorkletProcessor.ts +554 -0
- package/src/FaustOfflineProcessor.ts +141 -0
- package/src/FaustScriptProcessorNode.ts +80 -0
- package/src/FaustSvgDiagrams.ts +37 -0
- package/src/FaustWasmInstantiator.ts +202 -0
- package/src/FaustWebAudioDsp.ts +1060 -0
- package/src/LibFaust.ts +57 -0
- package/src/WavDecoder.ts +207 -0
- package/src/WavEncoder.ts +204 -0
- package/src/copyWebStandaloneAssets.d.ts +3 -0
- package/src/copyWebStandaloneAssets.js +20 -0
- package/src/exports-bundle.ts +5 -0
- package/src/exports.ts +24 -0
- package/src/faust2svgFiles.d.ts +3 -0
- package/src/faust2svgFiles.js +43 -0
- package/src/faust2wasmFiles.d.ts +5 -0
- package/src/faust2wasmFiles.js +93 -0
- package/src/faust2wavFiles.d.ts +3 -0
- package/src/faust2wavFiles.js +58 -0
- package/src/index-bundle-iife.ts +7 -0
- package/src/index-bundle.ts +5 -0
- package/src/index.ts +5 -0
- package/src/instantiateFaustModule.ts +32 -0
- package/src/instantiateFaustModuleFromFile.ts +57 -0
- package/src/types.ts +234 -0
- package/test/clarinet.dsp +1 -0
- package/test/faustlive-wasm/faust-ui/index.css +414 -0
- package/test/faustlive-wasm/faust-ui/index.css.map +1 -0
- package/test/faustlive-wasm/faust-ui/index.d.ts +1 -0
- package/test/faustlive-wasm/faust-ui/index.js +3478 -0
- package/test/faustlive-wasm/faust-ui/index.js.map +1 -0
- package/test/faustlive-wasm/faustwasm/index.d.ts +1252 -0
- package/test/faustlive-wasm/faustwasm/index.js +3772 -0
- package/test/faustlive-wasm/faustwasm/index.js.map +7 -0
- package/test/faustlive-wasm/index.css +97 -0
- package/test/faustlive-wasm/index.html +130 -0
- package/test/faustlive-wasm/index.js +638 -0
- package/test/guitar.dsp +1 -0
- package/test/guitar1.dsp +2 -0
- package/test/libfaust-in-worklet/index.html +13 -0
- package/test/libfaust-in-worklet/index.js +40 -0
- package/test/mono.dsp +8 -0
- package/test/node/test.js +17 -0
- package/test/noise.dsp +3 -0
- package/test/organ.dsp +5 -0
- package/test/organ1.dsp +6 -0
- package/test/osc.dsp +4 -0
- package/test/osc2.dsp +5 -0
- package/test/osc3.dsp +4 -0
- package/test/p-dj.dsp +4 -0
- package/test/poly.dsp +13 -0
- package/test/rev.dsp +2 -0
- package/test/t1.dsp +1 -0
- package/test/web/fft.html +87 -0
- package/test/web/fft1.html +88 -0
- package/test/web/fft2.html +114 -0
- package/test/web/fftw.js +1907 -0
- package/test/web/index.html +12 -0
- package/test/web/index.js +235 -0
- package/test/web/kissfft.js +904 -0
- package/test/web/mono.html +46 -0
- package/test/web/poly-key.html +62 -0
- package/test/web/poly.html +59 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<html lang="en">
|
|
2
|
+
<head>
|
|
3
|
+
<meta charset="UTF-8" />
|
|
4
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
5
|
+
<title>Faust Wasm Generator Demo</title>
|
|
6
|
+
</head>
|
|
7
|
+
|
|
8
|
+
<body>
|
|
9
|
+
<p id="log">...<br /></p>
|
|
10
|
+
|
|
11
|
+
<script type="module" src="index.js"></script>
|
|
12
|
+
</body>
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
//@ts-check
|
|
2
|
+
const div = document.getElementById("log");
|
|
3
|
+
const log = (/** @type {string} */str) => div.innerHTML += str.replace("\n", "<br />") + "<br />";
|
|
4
|
+
const svg = (/** @type {string} */str, /** @type {string} */name) => log(str);
|
|
5
|
+
const options = "-ftz 0 -I libraries/";
|
|
6
|
+
const errCode = "foo";
|
|
7
|
+
const effectCode = 'process = _*(hslider("Left", 0.1, 0, 1, 0.01)), _*(hslider("Right", 0.0, 0, 1, 0.01));';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
(async () => {
|
|
11
|
+
const {
|
|
12
|
+
instantiateFaustModule,
|
|
13
|
+
LibFaust,
|
|
14
|
+
WavEncoder,
|
|
15
|
+
FaustWasmInstantiator,
|
|
16
|
+
FaustMonoDspGenerator,
|
|
17
|
+
FaustPolyDspGenerator,
|
|
18
|
+
FaustMonoWebAudioDsp,
|
|
19
|
+
FaustOfflineProcessor,
|
|
20
|
+
FaustCompiler,
|
|
21
|
+
FaustSvgDiagrams
|
|
22
|
+
} = await import("../../dist/esm-bundle/index.js");
|
|
23
|
+
const faustModule = await instantiateFaustModule();
|
|
24
|
+
|
|
25
|
+
const libFaust = new LibFaust(faustModule);
|
|
26
|
+
globalThis.libFaust = libFaust;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {InstanceType<FaustCompiler>} faust
|
|
30
|
+
* @param {(msg: string) => any} log
|
|
31
|
+
* @param {string} code
|
|
32
|
+
*/
|
|
33
|
+
const misc = (faust, log, code) => {
|
|
34
|
+
let exp;
|
|
35
|
+
try {
|
|
36
|
+
exp = faust.expandDSP(code, options);
|
|
37
|
+
} catch (e) {
|
|
38
|
+
log(" expandDSP " + exp || e.message);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let res;
|
|
42
|
+
try {
|
|
43
|
+
res = faust.generateAuxFiles("test", code, options + " -svg");
|
|
44
|
+
} catch (e) {
|
|
45
|
+
log(" generateAuxFiles " + res ? "done" : e.message);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param {InstanceType<FaustCompiler>} faust
|
|
50
|
+
* @param {(msg: string) => any} log
|
|
51
|
+
* @param {string} code
|
|
52
|
+
*/
|
|
53
|
+
const createDsp = async (faust, log, code) => {
|
|
54
|
+
log("createMonoDSPFactory: ");
|
|
55
|
+
let factory = await faust.createMonoDSPFactory("test", code, options);
|
|
56
|
+
if (factory) {
|
|
57
|
+
log("factory JSON: " + factory.json);
|
|
58
|
+
log("factory poly: " + factory.poly);
|
|
59
|
+
} else {
|
|
60
|
+
log("factory is null");
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
log("deleteDSPFactory");
|
|
64
|
+
faust.deleteDSPFactory(factory);
|
|
65
|
+
|
|
66
|
+
log("createSyncMonoDSPInstance: ");
|
|
67
|
+
let instance1 = FaustWasmInstantiator.createSyncMonoDSPInstance(factory);
|
|
68
|
+
if (instance1) {
|
|
69
|
+
log(" getNumInputs : " + instance1.api.getNumInputs(0));
|
|
70
|
+
log(" getNumOutputs: " + instance1.api.getNumOutputs(0));
|
|
71
|
+
log(" JSON: " + instance1.json);
|
|
72
|
+
} else {
|
|
73
|
+
log("instance1 is null");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
log("createAsyncMonoDSPInstance: ");
|
|
77
|
+
let instance2 = await FaustWasmInstantiator.createAsyncMonoDSPInstance(factory);
|
|
78
|
+
if (instance2) {
|
|
79
|
+
log(" getNumInputs : " + instance2.api.getNumInputs(0));
|
|
80
|
+
log(" getNumOutputs: " + instance2.api.getNumOutputs(0));
|
|
81
|
+
log(" JSON: " + instance2.json);
|
|
82
|
+
} else {
|
|
83
|
+
log("instance2 is null");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @param {InstanceType<FaustCompiler>} faust
|
|
88
|
+
* @param {(msg: string) => any} log
|
|
89
|
+
* @param {string} voiceCode
|
|
90
|
+
* @param {string} effectCode
|
|
91
|
+
*/
|
|
92
|
+
const createPolyDsp = async (faust, log, voiceCode, effectCode) => {
|
|
93
|
+
const { mixerModule } = await faust.getAsyncInternalMixerModule();
|
|
94
|
+
log("createPolyDSPFactory for voice: ");
|
|
95
|
+
let voiceFactory = await faust.createPolyDSPFactory("voice", voiceCode, options);
|
|
96
|
+
if (voiceFactory) {
|
|
97
|
+
log("voice factory JSON: " + voiceFactory.json);
|
|
98
|
+
log("voice factory poly: " + voiceFactory.poly);
|
|
99
|
+
} else {
|
|
100
|
+
log("voice_factory is null");
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
log("createPolyDSPFactory for effect: ");
|
|
104
|
+
let effectFactory = await faust.createPolyDSPFactory("effect", effectCode, options);
|
|
105
|
+
if (effectFactory) {
|
|
106
|
+
log("effect factory JSON: " + effectFactory.json);
|
|
107
|
+
log("effect factory poly: " + effectFactory.poly);
|
|
108
|
+
} else {
|
|
109
|
+
log("effect_factory is null");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
log("createSyncPolyDSPInstance: ");
|
|
113
|
+
let polyInstance1 = FaustWasmInstantiator.createSyncPolyDSPInstance(voiceFactory, mixerModule, 8, effectFactory);
|
|
114
|
+
if (polyInstance1) {
|
|
115
|
+
log(" voice_api getNumInputs : " + polyInstance1.voiceAPI.getNumInputs(0));
|
|
116
|
+
log(" voice_api getNumOutputs: " + polyInstance1.voiceAPI.getNumOutputs(0));
|
|
117
|
+
log(" JSON: " + polyInstance1.voiceJSON);
|
|
118
|
+
log(" effect_api getNumInputs : " + polyInstance1.voiceAPI.getNumInputs(0));
|
|
119
|
+
log(" effect_api getNumOutputs: " + polyInstance1.voiceAPI.getNumOutputs(0));
|
|
120
|
+
log(" JSON: " + polyInstance1.effectJSON);
|
|
121
|
+
} else {
|
|
122
|
+
log("poly_instance1 is null");
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
log("createAsyncPolyDSPInstance: ");
|
|
126
|
+
let polyInstance2 = await FaustWasmInstantiator.createAsyncPolyDSPInstance(voiceFactory, mixerModule, 8, effectFactory);
|
|
127
|
+
if (polyInstance2) {
|
|
128
|
+
log(" voice_api getNumInputs : " + polyInstance2.voiceAPI.getNumInputs(0));
|
|
129
|
+
log(" voice_api getNumOutputs: " + polyInstance2.voiceAPI.getNumOutputs(0));
|
|
130
|
+
log(" JSON: " + polyInstance2.voiceJSON);
|
|
131
|
+
log(" effect_api getNumInputs : " + polyInstance2.effectAPI.getNumInputs(0));
|
|
132
|
+
log(" effect_api getNumOutputs: " + polyInstance2.effectAPI.getNumOutputs(0));
|
|
133
|
+
log(" JSON: " + polyInstance2.effectJSON);
|
|
134
|
+
} else {
|
|
135
|
+
log("poly_instance2 is null");
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* @param {InstanceType<FaustCompiler>} compiler
|
|
141
|
+
* @param {(msg: string) => any} log
|
|
142
|
+
* @param {string} code
|
|
143
|
+
*/
|
|
144
|
+
const svgdiagrams = (compiler, log, code) => {
|
|
145
|
+
const filter = "import(\"stdfaust.lib\");\nprocess = dm.oscrs_demo;";
|
|
146
|
+
const SvgDiagrams = new FaustSvgDiagrams(compiler);
|
|
147
|
+
|
|
148
|
+
let svg1 = SvgDiagrams.from("TestSVG1", code, options);
|
|
149
|
+
log(`<div>${svg1["process.svg"]}</div>`);
|
|
150
|
+
|
|
151
|
+
let svg2 = SvgDiagrams.from("TestSVG2", filter, options)
|
|
152
|
+
log(`<div>${svg2["process.svg"]}</div>`);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @param {InstanceType<FaustCompiler>} faust
|
|
157
|
+
* @param {(msg: string) => any} log
|
|
158
|
+
*/
|
|
159
|
+
const offlineProcessor = async (faust, log) => {
|
|
160
|
+
|
|
161
|
+
let signal = "import(\"stdfaust.lib\");\nprocess = 0.25,0.33, 0.6;";
|
|
162
|
+
let factory = await faust.createMonoDSPFactory("test", signal, options);
|
|
163
|
+
const instance = await FaustWasmInstantiator.createAsyncMonoDSPInstance(factory);
|
|
164
|
+
const dsp = new FaustMonoWebAudioDsp(instance, 48000, 4, 33);
|
|
165
|
+
|
|
166
|
+
log("offlineProcessor");
|
|
167
|
+
let offline = new FaustOfflineProcessor(dsp, 33);
|
|
168
|
+
let plotted = offline.render(null, 100);
|
|
169
|
+
for (let chan = 0; chan < plotted.length; chan++) {
|
|
170
|
+
for (let frame = 0; frame < 100; frame++) {
|
|
171
|
+
console.log("Chan %d sample %f\n", chan, plotted[chan][frame])
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
*
|
|
177
|
+
* @param {InstanceType<LibFaust>} libFaust
|
|
178
|
+
* @param {(msg: string) => any} log
|
|
179
|
+
* @param {string} code
|
|
180
|
+
* @param {AudioContext} context
|
|
181
|
+
*/
|
|
182
|
+
const run = async (libFaust, log, code, context) => {
|
|
183
|
+
const compiler = new FaustCompiler(libFaust);
|
|
184
|
+
log("libfaust version: " + compiler.version());
|
|
185
|
+
|
|
186
|
+
log("\n-----------------\nMisc tests" + compiler.version());
|
|
187
|
+
misc(compiler, log, code);
|
|
188
|
+
log("\n-----------------\nMisc tests with error code");
|
|
189
|
+
misc(compiler, log, errCode);
|
|
190
|
+
|
|
191
|
+
log("\n-----------------\nCreating DSP instance:");
|
|
192
|
+
await createDsp(compiler, log, code);
|
|
193
|
+
|
|
194
|
+
log("\n-----------------\nCreating Poly DSP instance:");
|
|
195
|
+
await createPolyDsp(compiler, log, code, effectCode);
|
|
196
|
+
|
|
197
|
+
log("\n-----------------\nCreating DSP instance with error code:");
|
|
198
|
+
await createDsp(compiler, log, errCode).catch(e => { log(e.message); });
|
|
199
|
+
|
|
200
|
+
log("\n-----------------\nCreating Poly DSP instance with error code:");
|
|
201
|
+
await createPolyDsp(compiler, log, errCode, effectCode).catch(e => { log(e.message); });
|
|
202
|
+
|
|
203
|
+
log("\n-----------------\nTest SVG diagrams: ");
|
|
204
|
+
svgdiagrams(compiler, log, code);
|
|
205
|
+
|
|
206
|
+
log("\n-----------------\nTest Offline processor ");
|
|
207
|
+
offlineProcessor(compiler, log);
|
|
208
|
+
|
|
209
|
+
const gen = new FaustPolyDspGenerator()
|
|
210
|
+
await gen.compile(compiler, "mydsp2", code, options, effectCode);
|
|
211
|
+
const node = await gen.createNode(ctx, 8);
|
|
212
|
+
console.log(node);
|
|
213
|
+
console.log(node.getParams());
|
|
214
|
+
console.log(node.getMeta());
|
|
215
|
+
node.connect(ctx.destination);
|
|
216
|
+
node.keyOn(0, 60, 50);
|
|
217
|
+
node.keyOn(0, 64, 50);
|
|
218
|
+
node.keyOn(0, 67, 50);
|
|
219
|
+
node.keyOn(0, 71, 50);
|
|
220
|
+
node.keyOn(0, 76, 50);
|
|
221
|
+
|
|
222
|
+
log("\nEnd of API tests");
|
|
223
|
+
};
|
|
224
|
+
const sampleRate = 48000;
|
|
225
|
+
const code1Fetch = await fetch("../organ.dsp");
|
|
226
|
+
const code1 = await code1Fetch.text();
|
|
227
|
+
const name1 = "pdj";
|
|
228
|
+
const code2Fetch = await fetch("../rev.dsp");
|
|
229
|
+
const code2 = await code2Fetch.text();
|
|
230
|
+
|
|
231
|
+
const ctx = new AudioContext();
|
|
232
|
+
|
|
233
|
+
await run(libFaust, log, code1, ctx);
|
|
234
|
+
globalThis.ctx = ctx;
|
|
235
|
+
})();
|