@grame/faustwasm 0.0.28 → 0.0.29

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/test/t1.cjs ADDED
@@ -0,0 +1,46 @@
1
+ const FaustWasm = require("@grame/faustwasm");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+
5
+ const {
6
+ instantiateFaustModuleFromFile,
7
+ LibFaust,
8
+ WavEncoder,
9
+ FaustMonoDspGenerator,
10
+ FaustCompiler,
11
+ FaustSvgDiagrams
12
+ } = FaustWasm;
13
+
14
+ (async () => {
15
+ const faustModulePath = path.join(__dirname, "../node_modules/@grame/faustwasm/libfaust-wasm/libfaust-wasm.js");
16
+
17
+ // initialize the libfaust wasm
18
+ const faustModule = await instantiateFaustModuleFromFile(faustModulePath);
19
+
20
+ // Get the Faust compiler
21
+ const libFaust = new LibFaust(faustModule);
22
+ console.log(libFaust.version());
23
+ const compiler = new FaustCompiler(libFaust);
24
+ const generator = new FaustMonoDspGenerator();
25
+ const sampleRate = 48000;
26
+ const name = "Djembe"
27
+ const argv = ["-I", "libraries/"];
28
+ const code = `
29
+ import("stdfaust.lib");
30
+ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
31
+ `;
32
+ // Compile the DSP
33
+ await generator.compile(compiler, name, code, argv.join(" "));
34
+ const processor = await generator.createOfflineProcessor(sampleRate, 1024);
35
+
36
+ // Generate SVG diagrams.
37
+ const svgDiagrams = new FaustSvgDiagrams(compiler);
38
+ const svgs = svgDiagrams.from(name, code, argv.join(" "));
39
+ console.log(Object.keys(svgs));
40
+
41
+ const out = processor.render(null, 192000);
42
+ const wav = WavEncoder.encode(out, { sampleRate, bitDepth: 24 });
43
+
44
+ // The wav file is generated
45
+ fs.writeFileSync(`${__dirname}/out.wav`, new Uint8Array(wav));
46
+ })();
package/test/t1.js ADDED
@@ -0,0 +1,46 @@
1
+ const FaustWasm = require("@grame/faustwasm");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+
5
+ const {
6
+ instantiateFaustModuleFromFile,
7
+ LibFaust,
8
+ WavEncoder,
9
+ FaustMonoDspGenerator,
10
+ FaustCompiler,
11
+ FaustSvgDiagrams
12
+ } = FaustWasm;
13
+
14
+ (async () => {
15
+ const faustModulePath = path.join(__dirname, "../node_modules/@grame/faustwasm/libfaust-wasm/libfaust-wasm.js");
16
+
17
+ // initialize the libfaust wasm
18
+ const faustModule = await instantiateFaustModuleFromFile(faustModulePath);
19
+
20
+ // Get the Faust compiler
21
+ const libFaust = new LibFaust(faustModule);
22
+ console.log(libFaust.version());
23
+ const compiler = new FaustCompiler(libFaust);
24
+ const generator = new FaustMonoDspGenerator();
25
+ const sampleRate = 48000;
26
+ const name = "Djembe"
27
+ const argv = ["-I", "libraries/"];
28
+ const code = `
29
+ import("stdfaust.lib");
30
+ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
31
+ `;
32
+ // Compile the DSP
33
+ await generator.compile(compiler, name, code, argv.join(" "));
34
+ const processor = await generator.createOfflineProcessor(sampleRate, 1024);
35
+
36
+ // Generate SVG diagrams.
37
+ const svgDiagrams = new FaustSvgDiagrams(compiler);
38
+ const svgs = svgDiagrams.from(name, code, argv.join(" "));
39
+ console.log(Object.keys(svgs));
40
+
41
+ const out = processor.render(null, 192000);
42
+ const wav = WavEncoder.encode(out, { sampleRate, bitDepth: 24 });
43
+
44
+ // The wav file is generated
45
+ fs.writeFileSync(`${__dirname}/out.wav`, new Uint8Array(wav));
46
+ })();