@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.
Files changed (111) hide show
  1. package/README.md +181 -0
  2. package/assets/standalone/faust-ui/index.css +414 -0
  3. package/assets/standalone/faust-ui/index.css.map +1 -0
  4. package/assets/standalone/faust-ui/index.d.ts +1 -0
  5. package/assets/standalone/faust-ui/index.js +3478 -0
  6. package/assets/standalone/faust-ui/index.js.map +1 -0
  7. package/assets/standalone/faustwasm/index.d.ts +1252 -0
  8. package/assets/standalone/faustwasm/index.js +3772 -0
  9. package/assets/standalone/faustwasm/index.js.map +7 -0
  10. package/assets/standalone/index.html +73 -0
  11. package/assets/standalone/index.js +198 -0
  12. package/assets/standalone/types.d.ts +9 -0
  13. package/dist/cjs/index.d.ts +1252 -0
  14. package/dist/cjs/index.js +3752 -0
  15. package/dist/cjs/index.js.map +7 -0
  16. package/dist/cjs-bundle/index.d.ts +1259 -0
  17. package/dist/cjs-bundle/index.js +11507 -0
  18. package/dist/cjs-bundle/index.js.map +7 -0
  19. package/dist/esm/index.d.ts +1252 -0
  20. package/dist/esm/index.js +3772 -0
  21. package/dist/esm/index.js.map +7 -0
  22. package/dist/esm-bundle/index.d.ts +1259 -0
  23. package/dist/esm-bundle/index.js +11495 -0
  24. package/dist/esm-bundle/index.js.map +7 -0
  25. package/fileutils.js +40 -0
  26. package/libfaust-wasm/libfaust-wasm.d.cts +3 -0
  27. package/libfaust-wasm/libfaust-wasm.d.ts +3 -0
  28. package/libfaust-wasm/libfaust-wasm.data +0 -0
  29. package/libfaust-wasm/libfaust-wasm.data.d.ts +2 -0
  30. package/libfaust-wasm/libfaust-wasm.js +21 -0
  31. package/libfaust-wasm/libfaust-wasm.wasm +0 -0
  32. package/libfaust-wasm/libfaust-wasm.wasm.d.ts +2 -0
  33. package/library.md +91 -0
  34. package/package.json +43 -0
  35. package/postbuild-bundled.js +11 -0
  36. package/postbuild.js +63 -0
  37. package/prebuild-bundled.js +11 -0
  38. package/rsrc/overview.png +0 -0
  39. package/rsrc/overview.xlsx +0 -0
  40. package/scripts/faust2sndfile.js +43 -0
  41. package/scripts/faust2svg.js +17 -0
  42. package/scripts/faust2wasm.js +29 -0
  43. package/src/FaustAudioWorkletNode.ts +264 -0
  44. package/src/FaustAudioWorkletProcessor.ts +273 -0
  45. package/src/FaustCompiler.ts +252 -0
  46. package/src/FaustDspGenerator.ts +498 -0
  47. package/src/FaustDspInstance.ts +141 -0
  48. package/src/FaustFFTAudioWorkletProcessor.ts +554 -0
  49. package/src/FaustOfflineProcessor.ts +141 -0
  50. package/src/FaustScriptProcessorNode.ts +80 -0
  51. package/src/FaustSvgDiagrams.ts +37 -0
  52. package/src/FaustWasmInstantiator.ts +202 -0
  53. package/src/FaustWebAudioDsp.ts +1060 -0
  54. package/src/LibFaust.ts +57 -0
  55. package/src/WavDecoder.ts +207 -0
  56. package/src/WavEncoder.ts +204 -0
  57. package/src/copyWebStandaloneAssets.d.ts +3 -0
  58. package/src/copyWebStandaloneAssets.js +20 -0
  59. package/src/exports-bundle.ts +5 -0
  60. package/src/exports.ts +24 -0
  61. package/src/faust2svgFiles.d.ts +3 -0
  62. package/src/faust2svgFiles.js +43 -0
  63. package/src/faust2wasmFiles.d.ts +5 -0
  64. package/src/faust2wasmFiles.js +93 -0
  65. package/src/faust2wavFiles.d.ts +3 -0
  66. package/src/faust2wavFiles.js +58 -0
  67. package/src/index-bundle-iife.ts +7 -0
  68. package/src/index-bundle.ts +5 -0
  69. package/src/index.ts +5 -0
  70. package/src/instantiateFaustModule.ts +32 -0
  71. package/src/instantiateFaustModuleFromFile.ts +57 -0
  72. package/src/types.ts +234 -0
  73. package/test/clarinet.dsp +1 -0
  74. package/test/faustlive-wasm/faust-ui/index.css +414 -0
  75. package/test/faustlive-wasm/faust-ui/index.css.map +1 -0
  76. package/test/faustlive-wasm/faust-ui/index.d.ts +1 -0
  77. package/test/faustlive-wasm/faust-ui/index.js +3478 -0
  78. package/test/faustlive-wasm/faust-ui/index.js.map +1 -0
  79. package/test/faustlive-wasm/faustwasm/index.d.ts +1252 -0
  80. package/test/faustlive-wasm/faustwasm/index.js +3772 -0
  81. package/test/faustlive-wasm/faustwasm/index.js.map +7 -0
  82. package/test/faustlive-wasm/index.css +97 -0
  83. package/test/faustlive-wasm/index.html +130 -0
  84. package/test/faustlive-wasm/index.js +638 -0
  85. package/test/guitar.dsp +1 -0
  86. package/test/guitar1.dsp +2 -0
  87. package/test/libfaust-in-worklet/index.html +13 -0
  88. package/test/libfaust-in-worklet/index.js +40 -0
  89. package/test/mono.dsp +8 -0
  90. package/test/node/test.js +17 -0
  91. package/test/noise.dsp +3 -0
  92. package/test/organ.dsp +5 -0
  93. package/test/organ1.dsp +6 -0
  94. package/test/osc.dsp +4 -0
  95. package/test/osc2.dsp +5 -0
  96. package/test/osc3.dsp +4 -0
  97. package/test/p-dj.dsp +4 -0
  98. package/test/poly.dsp +13 -0
  99. package/test/rev.dsp +2 -0
  100. package/test/t1.dsp +1 -0
  101. package/test/web/fft.html +87 -0
  102. package/test/web/fft1.html +88 -0
  103. package/test/web/fft2.html +114 -0
  104. package/test/web/fftw.js +1907 -0
  105. package/test/web/index.html +12 -0
  106. package/test/web/index.js +235 -0
  107. package/test/web/kissfft.js +904 -0
  108. package/test/web/mono.html +46 -0
  109. package/test/web/poly-key.html +62 -0
  110. package/test/web/poly.html +59 -0
  111. package/tsconfig.json +22 -0
@@ -0,0 +1,17 @@
1
+ import * as FaustWasm from "../../dist/esm/index.js";
2
+ import * as path from "path";
3
+ import * as fs from "fs";
4
+ import { fileURLToPath, pathToFileURL } from "url";
5
+
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const __filename = fileURLToPath(import.meta.url);
8
+
9
+ const wasmBuf = fs.readFileSync(path.join(__dirname, "../../libfaust-wasm/libfaust-wasm.wasm")).buffer;
10
+
11
+ (async () => {
12
+ // const w = await WebAssembly.instantiate(wasmBuf, {env:{},wasi_snapshot_preview1:{}});
13
+ // console.log(w);
14
+
15
+ const faustModule = await FaustWasm.instantiateFaustModuleFromFile(path.join(__dirname, "../../libfaust-wasm/libfaust-wasm.js"));
16
+ console.log(faustModule);
17
+ })();
package/test/noise.dsp ADDED
@@ -0,0 +1,3 @@
1
+ random = +(12345)~*(1103515245);
2
+ noise = random/2147483647.0;
3
+ process = noise * vslider("Volume", 0.2, 0, 1, 0.1) <: (*(0.01),*(0.01));
package/test/organ.dsp ADDED
@@ -0,0 +1,5 @@
1
+ import("stdfaust.lib");
2
+ timbre(f) = os.osc(f)*0.5 + os.osc(f*2)*0.25 + os.osc(f*3)*0.125;
3
+ process = timbre(hslider("freq", 440, 20, 10000, 1))
4
+ * hslider("gain", 0.0, 0, 1, 0.01)
5
+ * (button("gate") : en.adsr(0.1,0.1,0.98,1.5));
@@ -0,0 +1,6 @@
1
+ import("stdfaust.lib");
2
+ timbre(f) = os.osc(f)*0.5 + os.osc(f*2)*0.25 + os.osc(f*3)*0.125;
3
+ effect = _*(hslider("Left", 0.1, 0, 1, 0.01)), _*(hslider("Right", 0.0, 0, 1, 0.01));
4
+ process = timbre(hslider("freq", 440, 20, 10000, 1))
5
+ * hslider("gain", 0.0, 0, 1, 0.01)
6
+ * (button("gate") : en.adsr(0.1,0.1,0.98,1.5));
package/test/osc.dsp ADDED
@@ -0,0 +1,4 @@
1
+ import("stdfaust.lib");
2
+ vol = hslider("volume [unit:dB]", 0, -96, 0, 0.1) : ba.db2linear : si.smoo;
3
+ freq = hslider("freq [unit:Hz]", 500, 20, 24000, 1);
4
+ process = vgroup("Oscillator", os.osc(freq) * vol);
package/test/osc2.dsp ADDED
@@ -0,0 +1,5 @@
1
+ import("stdfaust.lib");
2
+ f = hslider("freq [midi:ctrl 7]",440,50,2000,0.01);
3
+ phasor(freq) = (+(freq/ma.SR) ~ ma.decimal);
4
+ osc(freq) = sin(phasor(freq)*2*ma.PI);
5
+ process = osc(f);
package/test/osc3.dsp ADDED
@@ -0,0 +1,4 @@
1
+ import("stdfaust.lib");
2
+ f = hslider("freq",440,50,2000,0.01);
3
+ phasor(freq) = (+(freq/ma.SR) ~ ma.decimal);
4
+ process = phasor(f);
package/test/p-dj.dsp ADDED
@@ -0,0 +1,4 @@
1
+
2
+ import("stdfaust.lib");
3
+
4
+ process = ba.pulsen(1, 10000) : pm.djembe(60, 0.3, 0.4, 1);
package/test/poly.dsp ADDED
@@ -0,0 +1,13 @@
1
+ declare name "FluteMIDI";
2
+ declare version "1.0";
3
+ declare author "Romain Michon";
4
+ declare description "Simple MIDI-controllable flute physical model with physical parameters.";
5
+ declare license "MIT";
6
+ declare copyright "(c)Romain Michon, CCRMA (Stanford University), GRAME";
7
+ declare isInstrument "true";
8
+
9
+ import("stdfaust.lib");
10
+
11
+ process = pm.flute_ui_MIDI <: _,_;
12
+
13
+ effect = dm.freeverb_demo;
package/test/rev.dsp ADDED
@@ -0,0 +1,2 @@
1
+ import("stdfaust.lib");
2
+ process = _ <: dm.freeverb_demo;
package/test/t1.dsp ADDED
@@ -0,0 +1 @@
1
+ process = 0.125,0.3,0.4,0.8;
@@ -0,0 +1,87 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <script src="../../dist/cjs-bundle/index.js"></script>
6
+ </head>
7
+ <body style="position: absolute; width: 100%; height: 100%; margin: 0px">
8
+ <button id="start">Start</button>
9
+ </body>
10
+ <script>
11
+ code = `
12
+ import("stdfaust.lib");
13
+ process(r, i, b) = a, a, a, a with {
14
+ k = (b == 0) : + ~ %(20);
15
+ a = (b == k) * 0.01;
16
+ };`;
17
+ let t0 = performance.now();
18
+ const time = (str) => {
19
+ const t = performance.now();
20
+ if (str) console.log(str, t - t0);
21
+ t0 = t;
22
+ }
23
+ const { instantiateFaustModule, LibFaust, FaustCompiler, FaustMonoDspGenerator } = faustwasm;
24
+
25
+ // Use KissFFT implementation
26
+ const FFTUtils = class {
27
+ static windowFunctions = [
28
+ (i, N) => {
29
+ const a0 = 0.42, a1 = 0.5, a2 = 0.08, f = 6.283185307179586*i/(N-1);
30
+ return a0 - a1 * Math.cos(f) + a2 * Math.cos(2 * f);
31
+ },
32
+ (i, N) => 1 - Math.abs(2 * (i - 0.5 * (N - 1)) / N)
33
+ ];
34
+ static getFFT = async () => {
35
+ const { instantiateKissFFTModule, KissFFT } = globalThis.kissfftwasm;
36
+ const Module = await instantiateKissFFTModule();
37
+ const kissFFT = new KissFFT(Module);
38
+ return kissFFT.FFTR;
39
+ };
40
+ static fftToSignal = (f, r, i, b) => {
41
+ const fftSize = f.length - 2;
42
+ const len = fftSize / 2 + 1;
43
+ const invFFTSize = 1 / fftSize;
44
+ for (let j = 0; j < len; j++) {
45
+ r[j] = f[2 * j] * invFFTSize;
46
+ if (i) i[j] = f[2 * j + 1] * invFFTSize;
47
+ if (b) b[j] = j;
48
+ }
49
+ };
50
+ static signalToFFT = (r, i, f) => {
51
+ const len = r.length * 2;
52
+ for (let j = 0; j < r.length; j++) {
53
+ f[2 * j] = r[j];
54
+ f[2 * j + 1] = i[j];
55
+ }
56
+ };
57
+ static signalToNoFFT = (r, i, f) => {
58
+ const len = (r.length - 1) * 2;
59
+ f.set(r.subarray(1, r.length));
60
+ f.set(i.subarray(0, i.length - 1), r.length - 1);
61
+ };
62
+ }
63
+ document.getElementById("start").onclick = async () => {
64
+ audioCtx = new (window.AudioContext || window.webkitAudioContext)();
65
+ await audioCtx.audioWorklet.addModule("./kissfft.js");
66
+ await audioCtx.resume();
67
+ // const osc = audioCtx.createOscillator();
68
+ // osc.frequency.value = 440;
69
+ // osc.start();
70
+ time();
71
+ faustModule = await instantiateFaustModule();
72
+ time("Faust WASM Module ready");
73
+ libFaust = new LibFaust(faustModule);
74
+ compiler = new FaustCompiler(libFaust);
75
+ generator = new FaustMonoDspGenerator();
76
+ time("Faust DSP Generator ready");
77
+ await generator.compile(compiler, "dsp", code, "");
78
+ time("Faust DSP compiled");
79
+ node = await generator.createFFTNode(audioCtx, FFTUtils);
80
+ time("Faust FFT AW Node generated");
81
+ // osc.connect(node);
82
+ node.parameters.get("windowFunction").value = 1;
83
+ node.parameters.get("fftOverlap").value = 2;
84
+ node.connect(audioCtx.destination);
85
+ };
86
+ </script>
87
+ </html>
@@ -0,0 +1,88 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <script src="../../dist/cjs-bundle/index.js"></script>
6
+ </head>
7
+ <body style="position: absolute; width: 100%; height: 100%; margin: 0px">
8
+ <button id="start">Start</button>
9
+ </body>
10
+ <script>
11
+ code = `
12
+ import("stdfaust.lib");
13
+ process(r, i, b) = a, a, a, a with {
14
+ k = (b == 0) : + ~ %(20);
15
+ a = (b == k) * 0.01;
16
+ };`;
17
+ let t0 = performance.now();
18
+ const time = (str) => {
19
+ const t = performance.now();
20
+ if (str) console.log(str, t - t0);
21
+ t0 = t;
22
+ }
23
+ const { instantiateFaustModule, LibFaust, FaustCompiler, FaustMonoDspGenerator } = faustwasm;
24
+
25
+ // Use FFTW implementation
26
+ const FFTUtils = class {
27
+ static windowFunctions = [
28
+ (i, N) => {
29
+ const a0 = 0.42, a1 = 0.5, a2 = 0.08, f = 6.283185307179586*i/(N-1);
30
+ return a0 - a1 * Math.cos(f) + a2 * Math.cos(2 * f);
31
+ },
32
+ (i, N) => 1 - Math.abs(2 * (i - 0.5 * (N - 1)) / N)
33
+ ];
34
+ static getFFT = async () => {
35
+ const { instantiateFFTWModule, FFTW } = globalThis.fftwwasm;
36
+ const Module = await instantiateFFTWModule();
37
+ const fftw = new FFTW(Module);
38
+ return fftw.r2r.FFT1D;
39
+ };
40
+ static fftToSignal = (f, r, i, b) => {
41
+ const fftSize = f.length;
42
+ const len = fftSize / 2 + 1;
43
+ const invFFTSize = 1 / fftSize;
44
+ for (let j = 0; j < len; j++) {
45
+ r[j] = f[j] * invFFTSize;
46
+ i[j] = (j === 0 || j === len - 1) ? 0 : f[fftSize - j] * invFFTSize;
47
+ b[j] = j;
48
+ }
49
+ };
50
+ static signalToFFT = (r, i, f) => {
51
+ const len = (r.length - 1) * 2;
52
+ f.set(r);
53
+ for (let j = 0; j < r.length; j++) {
54
+ if (j === 0 || j === r.length - 1) continue;
55
+ f[len - j] = i[j];
56
+ }
57
+ };
58
+ static signalToNoFFT = (r, i, f) => {
59
+ const len = (r.length - 1) * 2;
60
+ f.set(r.subarray(1, r.length));
61
+ f.set(i.subarray(0, i.length - 1), r.length - 1);
62
+ };
63
+ }
64
+ document.getElementById("start").onclick = async () => {
65
+ audioCtx = new (window.AudioContext || window.webkitAudioContext)();
66
+ await audioCtx.audioWorklet.addModule("./fftw.js");
67
+ await audioCtx.resume();
68
+ // const osc = audioCtx.createOscillator();
69
+ // osc.frequency.value = 440;
70
+ // osc.start();
71
+ time();
72
+ faustModule = await instantiateFaustModule();
73
+ time("Faust WASM Module ready");
74
+ libFaust = new LibFaust(faustModule);
75
+ compiler = new FaustCompiler(libFaust);
76
+ generator = new FaustMonoDspGenerator();
77
+ time("Faust DSP Generator ready");
78
+ await generator.compile(compiler, "dsp", code, "");
79
+ time("Faust DSP compiled");
80
+ node = await generator.createFFTNode(audioCtx, FFTUtils);
81
+ time("Faust FFT AW Node generated");
82
+ // osc.connect(node);
83
+ node.parameters.get("windowFunction").value = 1;
84
+ node.parameters.get("fftOverlap").value = 2;
85
+ node.connect(audioCtx.destination);
86
+ };
87
+ </script>
88
+ </html>
@@ -0,0 +1,114 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <script src="../../dist/cjs-bundle/index.js"></script>
6
+ </head>
7
+ <body style="position: absolute; width: 100%; height: 100%; margin: 0px">
8
+ <button id="start">Start</button>
9
+ </body>
10
+ <script>
11
+ code = `
12
+ import("stdfaust.lib");
13
+
14
+ fftSize = hslider("fftSize", 1024, 2, 16384, 1); // global variable set by the processor itself
15
+ fftHopSize = hslider("fftHopSize", 1024, 2, 16384, 1); // global variable set by the processor itself
16
+ bufferSize = fftSize / 2 + 1; // Bins from 0Hz to Nyquist freq
17
+ freqPerBin = ma.SR / fftSize;
18
+
19
+ cartopol(x, y) = x * x + y * y : sqrt, atan2(y, x); // cartesian to polar
20
+ poltocar(r, theta) = r * cos(theta), r * sin(theta); // polar to cartesian
21
+
22
+ feedback = hslider("feedback", 0, 0, 1, 0.01);
23
+ delay = hslider("Delay", 1, 0, 10, 0.01);
24
+ delayFrames = int(ma.SR * delay / fftHopSize) : max(1);
25
+ delaySmps = delayFrames * bufferSize : min(ma.SR * 10);
26
+
27
+ delayLine = + ~ (@(delaySmps - 1) : *(feedback));
28
+
29
+ fftproc(rIn, iIn, bin) = out with { // 3 inputs for each audio channel: real, imaginary, current bin
30
+
31
+ out = (rIn : delayLine), (iIn : delayLine);
32
+ };
33
+ process = fftproc;
34
+
35
+ `;
36
+ let t0 = performance.now();
37
+ const time = (str) => {
38
+ const t = performance.now();
39
+ if (str) console.log(str, t - t0);
40
+ t0 = t;
41
+ }
42
+ const { instantiateFaustModule, LibFaust, FaustCompiler, FaustMonoDspGenerator } = faustwasm;
43
+
44
+ const FFTUtils = class {
45
+ static windowFunctions = [
46
+ (i, N) => {
47
+ const a0 = 0.42, a1 = 0.5, a2 = 0.08, f = 6.283185307179586*i/(N-1);
48
+ return a0 - a1 * Math.cos(f) + a2 * Math.cos(2 * f);
49
+ },
50
+ (i, N) => 1 - Math.abs(2 * (i - 0.5 * (N - 1)) / N)
51
+ ];
52
+ static getFFT = async () => {
53
+ const { instantiateKissFFTModule, KissFFT } = globalThis.kissfftwasm;
54
+ const Module = await instantiateKissFFTModule();
55
+ const kissFFT = new KissFFT(Module);
56
+ return kissFFT.FFTR;
57
+ };
58
+ static fftToSignal = (f, r, i, b) => {
59
+ const fftSize = f.length - 2;
60
+ const len = fftSize / 2 + 1;
61
+ const invFFTSize = 1 / fftSize;
62
+ for (let j = 0; j < len; j++) {
63
+ r[j] = f[2 * j] * invFFTSize;
64
+ if (i) i[j] = f[2 * j + 1] * invFFTSize;
65
+ if (b) b[j] = j;
66
+ }
67
+ };
68
+ static signalToFFT = (r, i, f) => {
69
+ const len = r.length * 2;
70
+ for (let j = 0; j < r.length; j++) {
71
+ f[2 * j] = r[j];
72
+ f[2 * j + 1] = i[j];
73
+ }
74
+ };
75
+ static signalToNoFFT = (r, i, f) => {
76
+ const len = (r.length - 1) * 2;
77
+ f.set(r.subarray(1, r.length));
78
+ f.set(i.subarray(0, i.length - 1), r.length - 1);
79
+ };
80
+ }
81
+ document.getElementById("start").onclick = async () => {
82
+ audioCtx = new (window.AudioContext || window.webkitAudioContext)();
83
+ await audioCtx.audioWorklet.addModule("./kissfft.js");
84
+ await audioCtx.resume();
85
+ osc = audioCtx.createOscillator();
86
+ osc.frequency.value = 440;
87
+ osc.start();
88
+ gain = audioCtx.createGain();
89
+ gain.gain.value = 1;
90
+ osc.connect(gain);
91
+ time();
92
+ faustModule = await instantiateFaustModule();
93
+ time("Faust WASM Module ready");
94
+ libFaust = new LibFaust(faustModule);
95
+ compiler = new FaustCompiler(libFaust);
96
+ generator = new FaustMonoDspGenerator();
97
+ time("Faust DSP Generator ready");
98
+ await generator.compile(compiler, "dsp", code, "");
99
+ time("Faust DSP compiled");
100
+ node = await generator.createFFTNode(audioCtx, FFTUtils);
101
+ time("Faust FFT AW Node generated");
102
+ gain.connect(node);
103
+ setTimeout(() => gain.gain.value = 0, 300);
104
+ setInterval(() => {
105
+ gain.gain.value = 1;
106
+ setTimeout(() => gain.gain.value = 0, 300);
107
+ }, 2500);
108
+ node.parameters.get("windowFunction").value = 1;
109
+ node.parameters.get("fftOverlap").value = 2;
110
+ node.parameters.get("/dsp/feedback").value = 0.8;
111
+ node.connect(audioCtx.destination);
112
+ };
113
+ </script>
114
+ </html>