@grame/faustwasm 0.0.59 → 0.0.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grame/faustwasm",
3
- "version": "0.0.59",
3
+ "version": "0.0.60",
4
4
  "description": "WebAssembly version of Faust Compiler",
5
5
  "main": "dist/cjs/index.js",
6
6
  "types": "dist/esm/index.d.ts",
package/test/node/test.js CHANGED
@@ -11,7 +11,6 @@ const wasmBuf = fs.readFileSync(path.join(__dirname, "../../libfaust-wasm/libfau
11
11
  (async () => {
12
12
  // const w = await WebAssembly.instantiate(wasmBuf, {env:{},wasi_snapshot_preview1:{}});
13
13
  // console.log(w);
14
-
15
14
  const faustModule = await FaustWasm.instantiateFaustModuleFromFile(path.join(__dirname, "../../libfaust-wasm/libfaust-wasm.js"));
16
15
  console.log(faustModule);
17
16
  })();
package/test/bug/bug.html DELETED
@@ -1,84 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <head>
5
- <meta charset="UTF-8">
6
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
8
- <title>Faust DSP</title>
9
- <style>
10
- body {
11
- color: #b0b0b0;
12
- background-color: #1f1f1f;
13
- display: flex;
14
- top: 0;
15
- left: 0;
16
- width: 100%;
17
- height: 100%;
18
- margin: 0;
19
- position: absolute;
20
- }
21
-
22
- main {
23
- margin: 20px;
24
- display: flex;
25
- flex-direction: column;
26
- flex: 1 1 100%;
27
- }
28
-
29
- main span {
30
- position: relative;
31
- display: flex;
32
- }
33
-
34
- main span[hidden] {
35
- display: none;
36
- }
37
-
38
- main span span {
39
- margin: 0px 10px;
40
- flex: 1;
41
- }
42
-
43
- main span select {
44
- flex: 2;
45
- }
46
-
47
- #dsp-switch {
48
- margin: 20px auto;
49
- }
50
-
51
- #button-dsp {
52
- padding: 10px;
53
- }
54
-
55
- #div-faust-ui {
56
- flex: 1 1 auto;
57
- display: flex;
58
- position: relative;
59
- flex-direction: column;
60
- }
61
- </style>
62
- <link rel="stylesheet" href="./faust-ui/index.css">
63
- </head>
64
-
65
- <body>
66
- <main>
67
- <span id="audio-input">
68
- <span>Select Audio Input Device</span>
69
- <select id="select-audio-input"></select>
70
- </span>
71
- <span id="midi-input">
72
- <span>Select MIDI Input Device</span>
73
- <select id="select-midi-input"></select>
74
- </span>
75
- <span id="dsp-switch">
76
- <button id="button-dsp">Activate DSP</button>
77
- </span>
78
- <div id="div-faust-ui">
79
- </div>
80
- </main>
81
- <script src="./bug.js"></script>
82
- </body>
83
-
84
- </html>
package/test/bug/bug.js DELETED
@@ -1,216 +0,0 @@
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({ latencyHint: 0.00001 });
26
- audioContext.destination.channelInterpretation = "discrete";
27
- audioContext.suspend();
28
-
29
- /**
30
- * @param {FaustAudioWorkletNode} faustNode
31
- */
32
- const buildAudioDeviceMenu = async (faustNode) => {
33
- /** @type {MediaStreamAudioSourceNode} */
34
- let inputStreamNode;
35
- const handleDeviceChange = async () => {
36
- const devicesInfo = await navigator.mediaDevices.enumerateDevices();
37
- $selectAudioInput.innerHTML = '';
38
- devicesInfo.forEach((deviceInfo, i) => {
39
- const { kind, deviceId, label } = deviceInfo;
40
- if (kind === "audioinput") {
41
- const option = new Option(label || `microphone ${i + 1}`, deviceId);
42
- $selectAudioInput.add(option);
43
- }
44
- });
45
- }
46
- await handleDeviceChange();
47
- navigator.mediaDevices.addEventListener("devicechange", handleDeviceChange)
48
- $selectAudioInput.onchange = async () => {
49
- const id = $selectAudioInput.value;
50
- const constraints = {
51
- audio: {
52
- echoCancellation: false,
53
- mozNoiseSuppression: false,
54
- mozAutoGainControl: false,
55
- deviceId: id ? { exact: id } : undefined,
56
- },
57
- };
58
- const stream = await navigator.mediaDevices.getUserMedia(constraints);
59
- if (inputStreamNode) inputStreamNode.disconnect();
60
- inputStreamNode = audioContext.createMediaStreamSource(stream);
61
- inputStreamNode.connect(faustNode);
62
- };
63
-
64
- const defaultConstraints = {
65
- audio: {
66
- echoCancellation: false,
67
- mozNoiseSuppression: false,
68
- mozAutoGainControl: false
69
- }
70
- };
71
- const defaultStream = await navigator.mediaDevices.getUserMedia(defaultConstraints);
72
- if (defaultStream) {
73
- inputStreamNode = audioContext.createMediaStreamSource(defaultStream);
74
- inputStreamNode.connect(faustNode);
75
- }
76
- };
77
-
78
- /**
79
- * @param {FaustAudioWorkletNode} faustNode
80
- */
81
- const buildMidiDeviceMenu = async (faustNode) => {
82
- const midiAccess = await navigator.requestMIDIAccess();
83
- /** @type {WebMidi.MIDIInput} */
84
- let currentInput;
85
- /**
86
- * @param {WebMidi.MIDIMessageEvent} e
87
- */
88
- const handleMidiMessage = e => faustNode.midiMessage(e.data);
89
- const handleStateChange = () => {
90
- const { inputs } = midiAccess;
91
- if ($selectMidiInput.options.length === inputs.size + 1) return;
92
- if (currentInput) currentInput.removeEventListener("midimessage", handleMidiMessage);
93
- $selectMidiInput.innerHTML = '<option value="-1" disabled selected>Select...</option>';
94
- inputs.forEach((midiInput) => {
95
- const { name, id } = midiInput;
96
- const option = new Option(name, id);
97
- $selectMidiInput.add(option);
98
- });
99
- };
100
- handleStateChange();
101
- midiAccess.addEventListener("statechange", handleStateChange);
102
- $selectMidiInput.onchange = () => {
103
- if (currentInput) currentInput.removeEventListener("midimessage", handleMidiMessage);
104
- const id = $selectMidiInput.value;
105
- currentInput = midiAccess.inputs.get(id);
106
- currentInput.addEventListener("midimessage", handleMidiMessage);
107
- };
108
- };
109
-
110
- $buttonDsp.disabled = true;
111
- $buttonDsp.onclick = () => {
112
- if (audioContext.state === "running") {
113
- $buttonDsp.textContent = "Suspended";
114
- audioContext.suspend();
115
- } else if (audioContext.state === "suspended") {
116
- $buttonDsp.textContent = "Running";
117
- audioContext.resume();
118
- }
119
- }
120
-
121
- /**
122
- * Creates a Faust audio node for use in the Web Audio API.
123
- *
124
- * @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node will be connected.
125
- * @param {string} dspName - The name of the DSP to be loaded.
126
- * @param {number} voices - The number of voices to be used for polyphonic DSPs.
127
- * @returns {Object} - An object containing the Faust audio node and the DSP metadata.
128
- */
129
- const createFaustNode = async (audioContext, dspName = "template", voices = 0) => {
130
- // Import necessary Faust modules and data
131
- const { FaustMonoDspGenerator, FaustPolyDspGenerator } = await import("./faustwasm/index.js");
132
-
133
- // Load DSP metadata from JSON
134
- /** @type {FaustDspMeta} */
135
- const dspMeta = await (await fetch(`./${dspName}.json`)).json();
136
-
137
- // Compile the DSP module from WebAssembly binary data
138
- const dspModule = await WebAssembly.compileStreaming(await fetch(`./${dspName}.wasm`));
139
-
140
- // Create an object representing Faust DSP with metadata and module
141
- /** @type {FaustDspDistribution} */
142
- const faustDsp = { dspMeta, dspModule };
143
-
144
- /** @type {FaustAudioWorkletNode} */
145
- let faustNode;
146
-
147
- // Create either a polyphonic or monophonic Faust audio node based on the number of voices
148
- if (voices > 0) {
149
-
150
- // Try to load optional mixer and effect modules
151
- try {
152
- faustDsp.mixerModule = await WebAssembly.compileStreaming(await fetch("./mixerModule.wasm"));
153
- faustDsp.effectMeta = await (await fetch(`./${dspName}_effect.json`)).json();
154
- faustDsp.effectModule = await WebAssembly.compileStreaming(await fetch(`./${dspName}_effect.wasm`));
155
- } catch (e) { }
156
-
157
- const generator = new FaustPolyDspGenerator();
158
- faustNode = await generator.createNode(
159
- audioContext,
160
- voices,
161
- "FaustPolyDSP",
162
- { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) },
163
- faustDsp.mixerModule,
164
- faustDsp.effectModule ? { module: faustDsp.effectModule, json: JSON.stringify(faustDsp.effectMeta) } : undefined
165
- );
166
- } else {
167
- const generator = new FaustMonoDspGenerator();
168
- faustNode = await generator.createNode(
169
- audioContext,
170
- "FaustMonoDSP",
171
- { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) }
172
- );
173
- }
174
-
175
- // Return an object with the Faust audio node and the DSP metadata
176
- return { faustNode, dspMeta };
177
- }
178
-
179
- /**
180
- * @param {FaustAudioWorkletNode} faustNode
181
- */
182
- const createFaustUI = async (faustNode) => {
183
- const { FaustUI } = await import("./faust-ui/index.js");
184
- const $container = document.createElement("div");
185
- $container.style.margin = "0";
186
- $container.style.position = "absolute";
187
- $container.style.overflow = "auto";
188
- $container.style.display = "flex";
189
- $container.style.flexDirection = "column";
190
- $container.style.width = "100%";
191
- $container.style.height = "100%";
192
- $divFaustUI.appendChild($container);
193
- const faustUI = new FaustUI({
194
- ui: faustNode.getUI(),
195
- root: $container,
196
- listenWindowMessage: false,
197
- listenWindowResize: true,
198
- });
199
- faustUI.paramChangeByUI = (path, value) => faustNode.setParamValue(path, value);
200
- faustNode.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value));
201
- $container.style.minWidth = `${faustUI.minWidth}px`;
202
- $container.style.minHeight = `${faustUI.minHeight}px`;
203
- faustUI.resize();
204
- };
205
-
206
- (async () => {
207
- const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "bug", 16);
208
- await createFaustUI(faustNode);
209
- faustNode.connect(audioContext.destination);
210
- if (faustNode.numberOfInputs) await buildAudioDeviceMenu(faustNode);
211
- else $spanAudioInput.hidden = true;
212
- if (navigator.requestMIDIAccess) await buildMidiDeviceMenu(faustNode);
213
- else $spanMidiInput.hidden = true;
214
- $buttonDsp.disabled = false;
215
- document.title = name;
216
- })();
package/test/bug/bug.json DELETED
@@ -1,124 +0,0 @@
1
- {
2
- "name": "bug",
3
- "filename": "bug",
4
- "version": "2.72.4",
5
- "compile_options": "-lang wasm-e -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2",
6
- "library_list": [
7
- "/usr/share/faust/stdfaust.lib",
8
- "/usr/share/faust/oscillators.lib",
9
- "/usr/share/faust/maths.lib",
10
- "/usr/share/faust/platform.lib",
11
- "/usr/share/faust/envelopes.lib"
12
- ],
13
- "include_pathnames": [
14
- "/share/faust",
15
- "/usr/local/share/faust",
16
- "/usr/share/faust",
17
- "."
18
- ],
19
- "size": 76,
20
- "inputs": 0,
21
- "outputs": 2,
22
- "meta": [
23
- {
24
- "compile_options": "-lang wasm-e -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2"
25
- },
26
- {
27
- "envelopes.lib/adsr:author": "Yann Orlarey and Andrey Bundin"
28
- },
29
- {
30
- "envelopes.lib/author": "GRAME"
31
- },
32
- {
33
- "envelopes.lib/copyright": "GRAME"
34
- },
35
- {
36
- "envelopes.lib/license": "LGPL with exception"
37
- },
38
- {
39
- "envelopes.lib/name": "Faust Envelope Library"
40
- },
41
- {
42
- "envelopes.lib/version": "1.3.0"
43
- },
44
- {
45
- "filename": "bug"
46
- },
47
- {
48
- "maths.lib/author": "GRAME"
49
- },
50
- {
51
- "maths.lib/copyright": "GRAME"
52
- },
53
- {
54
- "maths.lib/license": "LGPL with exception"
55
- },
56
- {
57
- "maths.lib/name": "Faust Math Library"
58
- },
59
- {
60
- "maths.lib/version": "2.7.0"
61
- },
62
- {
63
- "name": "bug"
64
- },
65
- {
66
- "options": "[midi:on][nvoices:12]"
67
- },
68
- {
69
- "oscillators.lib/name": "Faust Oscillator Library"
70
- },
71
- {
72
- "oscillators.lib/saw2ptr:author": "Julius O. Smith III"
73
- },
74
- {
75
- "oscillators.lib/saw2ptr:license": "STK-4.3"
76
- },
77
- {
78
- "oscillators.lib/version": "1.5.0"
79
- },
80
- {
81
- "platform.lib/name": "Generic Platform Library"
82
- },
83
- {
84
- "platform.lib/version": "1.3.0"
85
- }
86
- ],
87
- "ui": [
88
- {
89
- "type": "vgroup",
90
- "label": "bug",
91
- "items": [
92
- {
93
- "type": "hslider",
94
- "label": "freq",
95
- "shortname": "freq",
96
- "address": "/bug/freq",
97
- "index": 16,
98
- "init": 200,
99
- "min": 50,
100
- "max": 1000,
101
- "step": 0.01
102
- },
103
- {
104
- "type": "hslider",
105
- "label": "gain",
106
- "shortname": "gain",
107
- "address": "/bug/gain",
108
- "index": 0,
109
- "init": 0.5,
110
- "min": 0,
111
- "max": 1,
112
- "step": 0.01
113
- },
114
- {
115
- "type": "button",
116
- "label": "gate",
117
- "shortname": "gate",
118
- "address": "/bug/gate",
119
- "index": 32
120
- }
121
- ]
122
- }
123
- ]
124
- }
package/test/bug/bug.wasm DELETED
Binary file
@@ -1,95 +0,0 @@
1
- {
2
- "name": "bug",
3
- "filename": "bug",
4
- "version": "2.72.4",
5
- "compile_options": "-lang wasm-e -inpl -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2",
6
- "library_list": [
7
- "/usr/share/faust/stdfaust.lib",
8
- "/usr/share/faust/oscillators.lib",
9
- "/usr/share/faust/maths.lib",
10
- "/usr/share/faust/platform.lib",
11
- "/usr/share/faust/envelopes.lib"
12
- ],
13
- "include_pathnames": [
14
- "/share/faust",
15
- "/usr/local/share/faust",
16
- "/usr/share/faust",
17
- "."
18
- ],
19
- "size": 4,
20
- "code": "xI8e",
21
- "inputs": 2,
22
- "outputs": 2,
23
- "meta": [
24
- {
25
- "compile_options": "-lang wasm-e -inpl -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2"
26
- },
27
- {
28
- "envelopes.lib/adsr:author": "Yann Orlarey and Andrey Bundin"
29
- },
30
- {
31
- "envelopes.lib/author": "GRAME"
32
- },
33
- {
34
- "envelopes.lib/copyright": "GRAME"
35
- },
36
- {
37
- "envelopes.lib/license": "LGPL with exception"
38
- },
39
- {
40
- "envelopes.lib/name": "Faust Envelope Library"
41
- },
42
- {
43
- "envelopes.lib/version": "1.3.0"
44
- },
45
- {
46
- "filename": "bug"
47
- },
48
- {
49
- "maths.lib/author": "GRAME"
50
- },
51
- {
52
- "maths.lib/copyright": "GRAME"
53
- },
54
- {
55
- "maths.lib/license": "LGPL with exception"
56
- },
57
- {
58
- "maths.lib/name": "Faust Math Library"
59
- },
60
- {
61
- "maths.lib/version": "2.7.0"
62
- },
63
- {
64
- "name": "bug"
65
- },
66
- {
67
- "options": "[midi:on][nvoices:12]"
68
- },
69
- {
70
- "oscillators.lib/name": "Faust Oscillator Library"
71
- },
72
- {
73
- "oscillators.lib/saw2ptr:author": "Julius O. Smith III"
74
- },
75
- {
76
- "oscillators.lib/saw2ptr:license": "STK-4.3"
77
- },
78
- {
79
- "oscillators.lib/version": "1.5.0"
80
- },
81
- {
82
- "platform.lib/name": "Generic Platform Library"
83
- },
84
- {
85
- "platform.lib/version": "1.3.0"
86
- }
87
- ],
88
- "ui": [
89
- {
90
- "type": "vgroup",
91
- "label": "bug",
92
- "items": []
93
- }
94
- ]
95
- }
Binary file