@grame/faustwasm 0.13.7 → 0.14.1

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.
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Smoke test: ensure setParamValue/getParamValue accept path, shortname, and label.
3
+ */
4
+ import * as FaustWasm from "../../dist/esm/index.js";
5
+ import * as path from "path";
6
+ import { fileURLToPath } from "url";
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ const dspCode = `
11
+ import("stdfaust.lib");
12
+
13
+ freq = hslider("Freq[Hz]", 440, 20, 20000, 1);
14
+ gain = hslider("Gain[dB]", -6, -60, 6, 0.1) : ba.db2linear;
15
+
16
+ process = os.osc(freq) * gain;
17
+ `;
18
+
19
+ const assertClose = (actual, expected, label) => {
20
+ const delta = Math.abs(actual - expected);
21
+ if (delta > 1e-4) {
22
+ throw new Error(`${label} expected ${expected} got ${actual}`);
23
+ }
24
+ };
25
+
26
+ const faustModule = await FaustWasm.instantiateFaustModuleFromFile(
27
+ path.join(__dirname, "../../libfaust-wasm/libfaust-wasm.js")
28
+ );
29
+ const libFaust = new FaustWasm.LibFaust(faustModule);
30
+ const compiler = new FaustWasm.FaustCompiler(libFaust);
31
+
32
+ const factory = await compiler.createMonoDSPFactory(
33
+ "alias-test",
34
+ dspCode,
35
+ "-ftz 2"
36
+ );
37
+ if (!factory) {
38
+ throw new Error("Faust compilation failed");
39
+ }
40
+
41
+ const instance = await FaustWasm.FaustWasmInstantiator.createAsyncMonoDSPInstance(factory);
42
+ const monoDsp = new FaustWasm.FaustMonoWebAudioDsp(
43
+ instance,
44
+ 48000,
45
+ 4,
46
+ 128,
47
+ factory.soundfiles || {}
48
+ );
49
+
50
+ const descriptors = monoDsp.getDescriptors();
51
+ const control = descriptors.find((item) =>
52
+ ["hslider", "vslider", "nentry"].includes(item.type)
53
+ );
54
+ if (!control) {
55
+ throw new Error("No control parameter found");
56
+ }
57
+
58
+ if (!control.address || !control.shortname || !control.label) {
59
+ throw new Error("Missing address/shortname/label in descriptor");
60
+ }
61
+
62
+ monoDsp.setParamValue(control.address, 0.123);
63
+ assertClose(monoDsp.getParamValue(control.address), 0.123, "address");
64
+
65
+ monoDsp.setParamValue(control.shortname, 0.456);
66
+ assertClose(monoDsp.getParamValue(control.address), 0.456, "shortname->address");
67
+ assertClose(monoDsp.getParamValue(control.shortname), 0.456, "shortname");
68
+
69
+ monoDsp.setParamValue(control.label, 0.789);
70
+ assertClose(monoDsp.getParamValue(control.address), 0.789, "label->address");
71
+ assertClose(monoDsp.getParamValue(control.label), 0.789, "label");
72
+
73
+ console.log("Param alias test passed.");