@grame/faustwasm 0.0.63 → 0.0.64

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.
Binary file
@@ -1,86 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
-
4
- <link rel="manifest" href="/manifest.json">
5
-
6
- <head>
7
- <meta charset="UTF-8">
8
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
9
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
10
- <title>Faust DSP</title>
11
- <style>
12
- body {
13
- color: #b0b0b0;
14
- background-color: #1f1f1f;
15
- display: flex;
16
- top: 0;
17
- left: 0;
18
- width: 100%;
19
- height: 100%;
20
- margin: 0;
21
- position: absolute;
22
- }
23
-
24
- main {
25
- margin: 20px;
26
- display: flex;
27
- flex-direction: column;
28
- flex: 1 1 100%;
29
- }
30
-
31
- main span {
32
- position: relative;
33
- display: flex;
34
- }
35
-
36
- main span[hidden] {
37
- display: none;
38
- }
39
-
40
- main span span {
41
- margin: 0px 10px;
42
- flex: 1;
43
- }
44
-
45
- main span select {
46
- flex: 2;
47
- }
48
-
49
- #dsp-switch {
50
- margin: 20px auto;
51
- }
52
-
53
- #button-dsp {
54
- padding: 10px;
55
- }
56
-
57
- #div-faust-ui {
58
- flex: 1 1 auto;
59
- display: flex;
60
- position: relative;
61
- flex-direction: column;
62
- }
63
- </style>
64
- <link rel="stylesheet" href="./faust-ui/index.css">
65
- </head>
66
-
67
- <body>
68
- <main>
69
- <span id="audio-input">
70
- <span>Select Audio Input Device</span>
71
- <select id="select-audio-input"></select>
72
- </span>
73
- <span id="midi-input">
74
- <span>Select MIDI Input Device</span>
75
- <select id="select-midi-input"></select>
76
- </span>
77
- <span id="dsp-switch">
78
- <button id="button-dsp">Activate DSP</button>
79
- </span>
80
- <div id="div-faust-ui">
81
- </div>
82
- </main>
83
- <script src="./organ.js"></script>
84
- </body>
85
-
86
- </html>
@@ -1,15 +0,0 @@
1
- {
2
- "name": "Faust organ",
3
- "short_name": "organ",
4
- "start_url": "/",
5
- "display": "standalone",
6
- "background_color": "#ffffff",
7
- "theme_color": "#000000",
8
- "icons": [
9
- {
10
- "src": "icon.png",
11
- "sizes": "390x390",
12
- "type": "image/png"
13
- }
14
- ]
15
- }
@@ -1,227 +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
- /**
11
- * Registers the service worker.
12
- */
13
- if ('serviceWorker' in navigator) {
14
- window.addEventListener('load', () => {
15
- navigator.serviceWorker.register('/service-worker.js')
16
- .then(reg => console.log('Service Worker registered', reg))
17
- .catch(err => console.log('Service Worker registration failed', err));
18
- });
19
- }
20
-
21
- /** @type {HTMLSpanElement} */
22
- const $spanAudioInput = document.getElementById("audio-input");
23
- /** @type {HTMLSpanElement} */
24
- const $spanMidiInput = document.getElementById("midi-input");
25
- /** @type {HTMLSelectElement} */
26
- const $selectAudioInput = document.getElementById("select-audio-input");
27
- /** @type {HTMLSelectElement} */
28
- const $selectMidiInput = document.getElementById("select-midi-input");
29
- /** @type {HTMLSelectElement} */
30
- const $buttonDsp = document.getElementById("button-dsp");
31
- /** @type {HTMLDivElement} */
32
- const $divFaustUI = document.getElementById("div-faust-ui");
33
-
34
- /** @type {typeof AudioContext} */
35
- const AudioCtx = window.AudioContext || window.webkitAudioContext;
36
- const audioContext = new AudioCtx({ latencyHint: 0.00001 });
37
- audioContext.destination.channelInterpretation = "discrete";
38
- audioContext.suspend();
39
-
40
- /**
41
- * @param {FaustAudioWorkletNode} faustNode
42
- */
43
- const buildAudioDeviceMenu = async (faustNode) => {
44
- /** @type {MediaStreamAudioSourceNode} */
45
- let inputStreamNode;
46
- const handleDeviceChange = async () => {
47
- const devicesInfo = await navigator.mediaDevices.enumerateDevices();
48
- $selectAudioInput.innerHTML = '';
49
- devicesInfo.forEach((deviceInfo, i) => {
50
- const { kind, deviceId, label } = deviceInfo;
51
- if (kind === "audioinput") {
52
- const option = new Option(label || `microphone ${i + 1}`, deviceId);
53
- $selectAudioInput.add(option);
54
- }
55
- });
56
- }
57
- await handleDeviceChange();
58
- navigator.mediaDevices.addEventListener("devicechange", handleDeviceChange)
59
- $selectAudioInput.onchange = async () => {
60
- const id = $selectAudioInput.value;
61
- const constraints = {
62
- audio: {
63
- echoCancellation: false,
64
- mozNoiseSuppression: false,
65
- mozAutoGainControl: false,
66
- deviceId: id ? { exact: id } : undefined,
67
- },
68
- };
69
- const stream = await navigator.mediaDevices.getUserMedia(constraints);
70
- if (inputStreamNode) inputStreamNode.disconnect();
71
- inputStreamNode = audioContext.createMediaStreamSource(stream);
72
- inputStreamNode.connect(faustNode);
73
- };
74
-
75
- const defaultConstraints = {
76
- audio: {
77
- echoCancellation: false,
78
- mozNoiseSuppression: false,
79
- mozAutoGainControl: false
80
- }
81
- };
82
- const defaultStream = await navigator.mediaDevices.getUserMedia(defaultConstraints);
83
- if (defaultStream) {
84
- inputStreamNode = audioContext.createMediaStreamSource(defaultStream);
85
- inputStreamNode.connect(faustNode);
86
- }
87
- };
88
-
89
- /**
90
- * @param {FaustAudioWorkletNode} faustNode
91
- */
92
- const buildMidiDeviceMenu = async (faustNode) => {
93
- const midiAccess = await navigator.requestMIDIAccess();
94
- /** @type {WebMidi.MIDIInput} */
95
- let currentInput;
96
- /**
97
- * @param {WebMidi.MIDIMessageEvent} e
98
- */
99
- const handleMidiMessage = e => faustNode.midiMessage(e.data);
100
- const handleStateChange = () => {
101
- const { inputs } = midiAccess;
102
- if ($selectMidiInput.options.length === inputs.size + 1) return;
103
- if (currentInput) currentInput.removeEventListener("midimessage", handleMidiMessage);
104
- $selectMidiInput.innerHTML = '<option value="-1" disabled selected>Select...</option>';
105
- inputs.forEach((midiInput) => {
106
- const { name, id } = midiInput;
107
- const option = new Option(name, id);
108
- $selectMidiInput.add(option);
109
- });
110
- };
111
- handleStateChange();
112
- midiAccess.addEventListener("statechange", handleStateChange);
113
- $selectMidiInput.onchange = () => {
114
- if (currentInput) currentInput.removeEventListener("midimessage", handleMidiMessage);
115
- const id = $selectMidiInput.value;
116
- currentInput = midiAccess.inputs.get(id);
117
- currentInput.addEventListener("midimessage", handleMidiMessage);
118
- };
119
- };
120
-
121
- $buttonDsp.disabled = true;
122
- $buttonDsp.onclick = () => {
123
- if (audioContext.state === "running") {
124
- $buttonDsp.textContent = "Suspended";
125
- audioContext.suspend();
126
- } else if (audioContext.state === "suspended") {
127
- $buttonDsp.textContent = "Running";
128
- audioContext.resume();
129
- }
130
- }
131
-
132
- /**
133
- * Creates a Faust audio node for use in the Web Audio API.
134
- *
135
- * @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node will be connected.
136
- * @param {string} dspName - The name of the DSP to be loaded.
137
- * @param {number} voices - The number of voices to be used for polyphonic DSPs.
138
- * @returns {Object} - An object containing the Faust audio node and the DSP metadata.
139
- */
140
- const createFaustNode = async (audioContext, dspName = "template", voices = 0) => {
141
- // Import necessary Faust modules and data
142
- const { FaustMonoDspGenerator, FaustPolyDspGenerator } = await import("./faustwasm/index.js");
143
-
144
- // Load DSP metadata from JSON
145
- /** @type {FaustDspMeta} */
146
- const dspMeta = await (await fetch(`./${dspName}.json`)).json();
147
-
148
- // Compile the DSP module from WebAssembly binary data
149
- const dspModule = await WebAssembly.compileStreaming(await fetch(`./${dspName}.wasm`));
150
-
151
- // Create an object representing Faust DSP with metadata and module
152
- /** @type {FaustDspDistribution} */
153
- const faustDsp = { dspMeta, dspModule };
154
-
155
- /** @type {FaustAudioWorkletNode} */
156
- let faustNode;
157
-
158
- // Create either a polyphonic or monophonic Faust audio node based on the number of voices
159
- if (voices > 0) {
160
-
161
- // Try to load optional mixer and effect modules
162
- try {
163
- faustDsp.mixerModule = await WebAssembly.compileStreaming(await fetch("./mixerModule.wasm"));
164
- faustDsp.effectMeta = await (await fetch(`./${dspName}_effect.json`)).json();
165
- faustDsp.effectModule = await WebAssembly.compileStreaming(await fetch(`./${dspName}_effect.wasm`));
166
- } catch (e) { }
167
-
168
- const generator = new FaustPolyDspGenerator();
169
- faustNode = await generator.createNode(
170
- audioContext,
171
- voices,
172
- "FaustPolyDSP",
173
- { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) },
174
- faustDsp.mixerModule,
175
- faustDsp.effectModule ? { module: faustDsp.effectModule, json: JSON.stringify(faustDsp.effectMeta) } : undefined
176
- );
177
- } else {
178
- const generator = new FaustMonoDspGenerator();
179
- faustNode = await generator.createNode(
180
- audioContext,
181
- "FaustMonoDSP",
182
- { module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta) }
183
- );
184
- }
185
-
186
- // Return an object with the Faust audio node and the DSP metadata
187
- return { faustNode, dspMeta };
188
- }
189
-
190
- /**
191
- * @param {FaustAudioWorkletNode} faustNode
192
- */
193
- const createFaustUI = async (faustNode) => {
194
- const { FaustUI } = await import("./faust-ui/index.js");
195
- const $container = document.createElement("div");
196
- $container.style.margin = "0";
197
- $container.style.position = "absolute";
198
- $container.style.overflow = "auto";
199
- $container.style.display = "flex";
200
- $container.style.flexDirection = "column";
201
- $container.style.width = "100%";
202
- $container.style.height = "100%";
203
- $divFaustUI.appendChild($container);
204
- const faustUI = new FaustUI({
205
- ui: faustNode.getUI(),
206
- root: $container,
207
- listenWindowMessage: false,
208
- listenWindowResize: true,
209
- });
210
- faustUI.paramChangeByUI = (path, value) => faustNode.setParamValue(path, value);
211
- faustNode.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value));
212
- $container.style.minWidth = `${faustUI.minWidth}px`;
213
- $container.style.minHeight = `${faustUI.minHeight}px`;
214
- faustUI.resize();
215
- };
216
-
217
- (async () => {
218
- const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "organ");
219
- await createFaustUI(faustNode);
220
- faustNode.connect(audioContext.destination);
221
- if (faustNode.numberOfInputs) await buildAudioDeviceMenu(faustNode);
222
- else $spanAudioInput.hidden = true;
223
- if (navigator.requestMIDIAccess) await buildMidiDeviceMenu(faustNode);
224
- else $spanMidiInput.hidden = true;
225
- $buttonDsp.disabled = false;
226
- document.title = name;
227
- })();
@@ -1,126 +0,0 @@
1
- {
2
- "name": "organ",
3
- "filename": "organ",
4
- "version": "2.72.4",
5
- "compile_options": "-lang wasm-i -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/platform.lib",
10
- "/usr/share/faust/maths.lib",
11
- "/usr/share/faust/basics.lib",
12
- "/usr/share/faust/envelopes.lib"
13
- ],
14
- "include_pathnames": [
15
- "/share/faust",
16
- "/usr/local/share/faust",
17
- "/usr/share/faust",
18
- "."
19
- ],
20
- "size": 262256,
21
- "code": "IMic",
22
- "inputs": 0,
23
- "outputs": 1,
24
- "meta": [
25
- {
26
- "basics.lib/name": "Faust Basic Element Library"
27
- },
28
- {
29
- "basics.lib/tabulateNd": "Copyright (C) 2023 Bart Brouns <bart@magnetophon.nl>"
30
- },
31
- {
32
- "basics.lib/version": "1.12.0"
33
- },
34
- {
35
- "compile_options": "-lang wasm-i -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2"
36
- },
37
- {
38
- "envelopes.lib/adsr:author": "Yann Orlarey and Andrey Bundin"
39
- },
40
- {
41
- "envelopes.lib/author": "GRAME"
42
- },
43
- {
44
- "envelopes.lib/copyright": "GRAME"
45
- },
46
- {
47
- "envelopes.lib/license": "LGPL with exception"
48
- },
49
- {
50
- "envelopes.lib/name": "Faust Envelope Library"
51
- },
52
- {
53
- "envelopes.lib/version": "1.3.0"
54
- },
55
- {
56
- "filename": "organ"
57
- },
58
- {
59
- "maths.lib/author": "GRAME"
60
- },
61
- {
62
- "maths.lib/copyright": "GRAME"
63
- },
64
- {
65
- "maths.lib/license": "LGPL with exception"
66
- },
67
- {
68
- "maths.lib/name": "Faust Math Library"
69
- },
70
- {
71
- "maths.lib/version": "2.7.0"
72
- },
73
- {
74
- "name": "organ"
75
- },
76
- {
77
- "oscillators.lib/name": "Faust Oscillator Library"
78
- },
79
- {
80
- "oscillators.lib/version": "1.5.0"
81
- },
82
- {
83
- "platform.lib/name": "Generic Platform Library"
84
- },
85
- {
86
- "platform.lib/version": "1.3.0"
87
- }
88
- ],
89
- "ui": [
90
- {
91
- "type": "vgroup",
92
- "label": "organ",
93
- "items": [
94
- {
95
- "type": "hslider",
96
- "label": "freq",
97
- "shortname": "freq",
98
- "address": "/organ/freq",
99
- "index": 262164,
100
- "init": 440,
101
- "min": 20,
102
- "max": 10000,
103
- "step": 1
104
- },
105
- {
106
- "type": "hslider",
107
- "label": "gain",
108
- "shortname": "gain",
109
- "address": "/organ/gain",
110
- "index": 262144,
111
- "init": 0,
112
- "min": 0,
113
- "max": 1,
114
- "step": 0.01
115
- },
116
- {
117
- "type": "button",
118
- "label": "gate",
119
- "shortname": "gate",
120
- "address": "/organ/gate",
121
- "index": 262204
122
- }
123
- ]
124
- }
125
- ]
126
- }
Binary file
@@ -1,35 +0,0 @@
1
- self.addEventListener('install', event => {
2
- event.waitUntil(
3
- caches.open('organ-static-v1').then(cache => {
4
- return cache.addAll([
5
- '/faust-ui/index.js',
6
- '/faustwasm/index.js',
7
- '/faustwasm/styles.css',
8
- '/index.html',
9
- '/organ.js',
10
- '/organ.wasm',
11
- '/organ.json',
12
- ]).catch(error => {
13
- // Catch and log any errors during the caching process
14
- console.error('Failed to cache resources during install:', error);
15
- });
16
- })
17
- );
18
- });
19
-
20
- self.addEventListener('activate', event => {
21
- // This ensures that the new service worker takes control immediately
22
- event.waitUntil(self.clients.claim());
23
- });
24
-
25
- self.addEventListener('fetch', event => {
26
- event.respondWith(
27
- caches.match(event.request).then(response => {
28
- // Return the cached response if found, else fetch from network
29
- return response || fetch(event.request).catch(() => {
30
- // Fallback content or page for failed network requests
31
- return caches.match('/offline.html');
32
- });
33
- })
34
- );
35
- });