@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,73 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
+ <title>Faust DSP</title>
8
+ <style>
9
+ body {
10
+ color: #b0b0b0;
11
+ background-color: #1f1f1f;
12
+ display: flex;
13
+ top: 0;
14
+ left: 0;
15
+ width: 100%;
16
+ height: 100%;
17
+ margin: 0;
18
+ position: absolute;
19
+ }
20
+ main {
21
+ margin: 20px;
22
+ display: flex;
23
+ flex-direction: column;
24
+ flex: 1 1 100%;
25
+ }
26
+ main span {
27
+ position: relative;
28
+ display: flex;
29
+ }
30
+ main span[hidden] {
31
+ display: none;
32
+ }
33
+ main span span {
34
+ margin: 0px 10px;
35
+ flex: 1;
36
+ }
37
+ main span select {
38
+ flex: 2;
39
+ }
40
+ #dsp-switch {
41
+ margin: 20px auto;
42
+ }
43
+ #button-dsp {
44
+ padding: 10px;
45
+ }
46
+ #div-faust-ui {
47
+ flex: 1 1 auto;
48
+ display: flex;
49
+ position: relative;
50
+ flex-direction: column;
51
+ }
52
+ </style>
53
+ <link rel="stylesheet" href="./faust-ui/index.css">
54
+ </head>
55
+ <body>
56
+ <main>
57
+ <span id="audio-input">
58
+ <span>Select Audio Input Device</span>
59
+ <select id="select-audio-input"></select>
60
+ </span>
61
+ <span id="midi-input">
62
+ <span>Select MIDI Input Device</span>
63
+ <select id="select-midi-input"></select>
64
+ </span>
65
+ <span id="dsp-switch">
66
+ <button id="button-dsp">Activate DSP</button>
67
+ </span>
68
+ <div id="div-faust-ui">
69
+ </div>
70
+ </main>
71
+ <script src="./index.js"></script>
72
+ </body>
73
+ </html>
@@ -0,0 +1,198 @@
1
+ /**
2
+ * @typedef {import("./types").FaustDspDistribution} FaustDspDistribution
3
+ * @typedef {import("./faustwasm").FaustAudioWorkletNode} FaustAudioWorkletNode
4
+ * @typedef {import("./faustwasm").FaustDspMeta} FaustDspMeta
5
+ * @typedef {import("./faustwasm").FaustUIDescriptor} FaustUIDescriptor
6
+ * @typedef {import("./faustwasm").FaustUIGroup} FaustUIGroup
7
+ * @typedef {import("./faustwasm").FaustUIItem} FaustUIItem
8
+ */
9
+
10
+ /** @type {HTMLSpanElement} */
11
+ const $spanAudioInput = document.getElementById("audio-input");
12
+ /** @type {HTMLSpanElement} */
13
+ const $spanMidiInput = document.getElementById("midi-input");
14
+ /** @type {HTMLSelectElement} */
15
+ const $selectAudioInput = document.getElementById("select-audio-input");
16
+ /** @type {HTMLSelectElement} */
17
+ const $selectMidiInput = document.getElementById("select-midi-input");
18
+ /** @type {HTMLSelectElement} */
19
+ const $buttonDsp = document.getElementById("button-dsp");
20
+ /** @type {HTMLDivElement} */
21
+ const $divFaustUI = document.getElementById("div-faust-ui");
22
+
23
+ /** @type {typeof AudioContext} */
24
+ const AudioCtx = window.AudioContext || window.webkitAudioContext;
25
+ const audioContext = new AudioCtx();
26
+ audioContext.suspend();
27
+
28
+ /**
29
+ * @param {FaustAudioWorkletNode} faustNode
30
+ */
31
+ const buildAudioDeviceMenu = async (faustNode) => {
32
+ /** @type {MediaStreamAudioSourceNode} */
33
+ let inputStreamNode;
34
+ const handleDeviceChange = async () => {
35
+ const devicesInfo = await navigator.mediaDevices.enumerateDevices();
36
+ $selectAudioInput.innerHTML = '';
37
+ devicesInfo.forEach((deviceInfo, i) => {
38
+ const { kind, deviceId, label } = deviceInfo;
39
+ if (kind === "audioinput") {
40
+ const option = new Option(label || `microphone ${i + 1}`, deviceId);
41
+ $selectAudioInput.add(option);
42
+ }
43
+ });
44
+ }
45
+ await handleDeviceChange();
46
+ navigator.mediaDevices.addEventListener("devicechange", handleDeviceChange)
47
+ $selectAudioInput.onchange = async () => {
48
+ const id = $selectAudioInput.value;
49
+ const constraints = {
50
+ audio: {
51
+ echoCancellation: false,
52
+ mozNoiseSuppression: false,
53
+ mozAutoGainControl: false,
54
+ deviceId: id ? { exact: id } : undefined,
55
+ },
56
+ };
57
+ const stream = await navigator.mediaDevices.getUserMedia(constraints);
58
+ if (inputStreamNode) inputStreamNode.disconnect();
59
+ inputStreamNode = audioContext.createMediaStreamSource(stream);
60
+ inputStreamNode.connect(faustNode);
61
+ };
62
+
63
+ const defaultConstraints = {
64
+ audio: {
65
+ echoCancellation: false,
66
+ mozNoiseSuppression: false,
67
+ mozAutoGainControl: false
68
+ }
69
+ };
70
+ const defaultStream = await navigator.mediaDevices.getUserMedia(defaultConstraints);
71
+ if (defaultStream) {
72
+ inputStreamNode = audioContext.createMediaStreamSource(defaultStream);
73
+ inputStreamNode.connect(faustNode);
74
+ }
75
+ };
76
+
77
+ /**
78
+ * @param {FaustAudioWorkletNode} faustNode
79
+ */
80
+ const buildMidiDeviceMenu = async (faustNode) => {
81
+ const midiAccess = await navigator.requestMIDIAccess();
82
+ /** @type {WebMidi.MIDIInput} */
83
+ let currentInput;
84
+ /**
85
+ * @param {WebMidi.MIDIMessageEvent} e
86
+ */
87
+ const handleMidiMessage = e => faustNode.midiMessage(e.data);
88
+ const handleStateChange = () => {
89
+ const { inputs } = midiAccess;
90
+ if ($selectMidiInput.options.length === inputs.size + 1) return;
91
+ if (currentInput) currentInput.removeEventListener("midimessage", handleMidiMessage);
92
+ $selectMidiInput.innerHTML = '<option value="-1" disabled selected>Select...</option>';
93
+ inputs.forEach((midiInput) => {
94
+ const { name, id } = midiInput;
95
+ const option = new Option(name, id);
96
+ $selectMidiInput.add(option);
97
+ });
98
+ };
99
+ handleStateChange();
100
+ midiAccess.addEventListener("statechange", handleStateChange);
101
+ $selectMidiInput.onchange = () => {
102
+ if (currentInput) currentInput.removeEventListener("midimessage", handleMidiMessage);
103
+ const id = $selectMidiInput.value;
104
+ currentInput = midiAccess.inputs.get(id);
105
+ currentInput.addEventListener("midimessage", handleMidiMessage);
106
+ };
107
+ };
108
+
109
+ $buttonDsp.disabled = true;
110
+ $buttonDsp.onclick = () => {
111
+ if (audioContext.state === "running") {
112
+ $buttonDsp.textContent = "Suspended";
113
+ audioContext.suspend();
114
+ } else if (audioContext.state === "suspended") {
115
+ $buttonDsp.textContent = "Running";
116
+ audioContext.resume();
117
+ }
118
+ }
119
+
120
+ /**
121
+ * @param {AudioContext} audioContext
122
+ */
123
+ const createFaustNode = async (audioContext) => {
124
+ const { FaustMonoDspGenerator, FaustPolyDspGenerator } = await import("./faustwasm/index.js");
125
+
126
+ /** @type {FaustDspMeta} */
127
+ const dspMeta = await (await fetch("./dspMeta.json")).json();
128
+ const dspModule = await WebAssembly.compileStreaming(await fetch("./dspModule.wasm"));
129
+ /** @type {FaustDspDistribution} */
130
+ const faustDsp = { dspMeta, dspModule };
131
+ try {
132
+ faustDsp.mixerModule = await WebAssembly.compileStreaming(await fetch("./mixerModule.wasm"));
133
+ faustDsp.effectMeta = await (await fetch("./effectMeta.json")).json();
134
+ faustDsp.effectModule = await WebAssembly.compileStreaming(await fetch("./effectModule.wasm"));
135
+ } catch (e) {}
136
+ const voices = faustDsp.mixerModule ? 64 : 0;
137
+
138
+ /** @type {FaustAudioWorkletNode} */
139
+ let faustNode;
140
+ if (voices) {
141
+ const generator = new FaustPolyDspGenerator();
142
+ faustNode = await generator.createNode(
143
+ audioContext,
144
+ voices,
145
+ "FaustPolyDSP",
146
+ { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) },
147
+ faustDsp.mixerModule,
148
+ faustDsp.effectModule ? { module: faustDsp.effectModule, json: JSON.stringify(faustDsp.effectMeta) } : undefined
149
+ );
150
+ } else {
151
+ const generator = new FaustMonoDspGenerator();
152
+ faustNode = await generator.createNode(
153
+ audioContext,
154
+ "FaustMonoDSP",
155
+ { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) }
156
+ );
157
+ }
158
+ return { faustNode, voices, dspMeta };
159
+ }
160
+
161
+ /**
162
+ * @param {FaustAudioWorkletNode} faustNode
163
+ */
164
+ const createFaustUI = async (faustNode) => {
165
+ const { FaustUI } = await import("./faust-ui/index.js");
166
+ const $container = document.createElement("div");
167
+ $container.style.margin = "0";
168
+ $container.style.position = "absolute";
169
+ $container.style.overflow = "auto";
170
+ $container.style.display = "flex";
171
+ $container.style.flexDirection = "column";
172
+ $container.style.width = "100%";
173
+ $container.style.height = "100%";
174
+ $divFaustUI.appendChild($container);
175
+ const faustUI = new FaustUI({
176
+ ui: faustNode.getUI(),
177
+ root: $container,
178
+ listenWindowMessage: false,
179
+ listenWindowResize: true,
180
+ });
181
+ faustUI.paramChangeByUI = (path, value) => faustNode.setParamValue(path, value);
182
+ faustNode.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value));
183
+ $container.style.minWidth = `${faustUI.minWidth}px`;
184
+ $container.style.minHeight = `${faustUI.minHeight}px`;
185
+ faustUI.resize();
186
+ };
187
+
188
+ (async () => {
189
+ const { faustNode, voices, dspMeta: { name } } = await createFaustNode(audioContext);
190
+ await createFaustUI(faustNode);
191
+ faustNode.connect(audioContext.destination);
192
+ if (faustNode.numberOfInputs) await buildAudioDeviceMenu(faustNode);
193
+ else $spanAudioInput.hidden = true;
194
+ if (voices && navigator.requestMIDIAccess) await buildMidiDeviceMenu(faustNode);
195
+ else $spanMidiInput.hidden = true;
196
+ $buttonDsp.disabled = false;
197
+ document.title = name;
198
+ })();
@@ -0,0 +1,9 @@
1
+ import { FaustDspMeta } from "./faustwasm";
2
+
3
+ export interface FaustDspDistribution {
4
+ dspModule: WebAssembly.Module;
5
+ dspMeta: FaustDspMeta;
6
+ effectModule?: WebAssembly.Module;
7
+ effectMeta?: FaustDspMeta;
8
+ mixerModule?: WebAssembly.Module;
9
+ }