@grame/faustwasm 0.7.3 → 0.7.4
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/dist/cjs-bundle/index.js +1 -1
- package/dist/esm-bundle/index.js +1 -1
- package/libfaust-wasm/libfaust-wasm.wasm +0 -0
- package/package.json +1 -1
- package/test/max_bug/create-node.js +140 -0
- package/test/max_bug/dsp-meta.json +247 -0
- package/test/max_bug/dsp-module.wasm +0 -0
- package/test/max_bug/faust-ui/index.css +442 -0
- package/test/max_bug/faust-ui/index.css.map +1 -0
- package/test/max_bug/faust-ui/index.d.ts +1 -0
- package/test/max_bug/faust-ui/index.js +3844 -0
- package/test/max_bug/faust-ui/index.js.map +1 -0
- package/test/max_bug/faustwasm/index.d.ts +1585 -0
- package/test/max_bug/faustwasm/index.js +4646 -0
- package/test/max_bug/faustwasm/index.js.map +7 -0
- package/test/max_bug/icon.png +0 -0
- package/test/max_bug/index.html +76 -0
- package/test/max_bug/index.js +149 -0
- package/test/max_bug/manifest.json +17 -0
- package/test/max_bug/service-worker.js +73 -0
- package/test/max_bug.dsp +13 -0
|
Binary file
|
package/package.json
CHANGED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @typedef {{ dspModule: WebAssembly.Module; dspMeta: FaustDspMeta; effectModule?: WebAssembly.Module; effectMeta?: FaustDspMeta; mixerModule?: WebAssembly.Module }} FaustDspDistribution
|
|
5
|
+
* @typedef {import("./faustwasm").FaustDspMeta} FaustDspMeta
|
|
6
|
+
* @typedef {import("./faustwasm").FaustMonoAudioWorkletNode} FaustMonoAudioWorkletNode
|
|
7
|
+
* @typedef {import("./faustwasm").FaustPolyAudioWorkletNode} FaustPolyAudioWorkletNode
|
|
8
|
+
* @typedef {import("./faustwasm").FaustMonoScriptProcessorNode} FaustMonoScriptProcessorNode
|
|
9
|
+
* @typedef {import("./faustwasm").FaustPolyScriptProcessorNode} FaustPolyScriptProcessorNode
|
|
10
|
+
* @typedef {FaustMonoAudioWorkletNode | FaustPolyAudioWorkletNode | FaustMonoScriptProcessorNode | FaustPolyScriptProcessorNode} FaustNode
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Creates a Faust audio node for use in the Web Audio API.
|
|
15
|
+
*
|
|
16
|
+
* @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node will be connected.
|
|
17
|
+
* @param {string} [dspName] - The name of the DSP to be loaded.
|
|
18
|
+
* @param {number} [voices] - The number of voices to be used for polyphonic DSPs.
|
|
19
|
+
* @param {boolean} [sp] - Whether to create a ScriptProcessorNode instead of an AudioWorkletNode.
|
|
20
|
+
* @returns {Promise<{ faustNode: FaustNode | null; dspMeta: FaustDspMeta }>} - An object containing the Faust audio node and the DSP metadata.
|
|
21
|
+
*/
|
|
22
|
+
const createFaustNode = async (audioContext, dspName = "template", voices = 0, sp = false, bufferSize = 512) => {
|
|
23
|
+
// Set to true if the DSP has an effect
|
|
24
|
+
const FAUST_DSP_HAS_EFFECT = false;
|
|
25
|
+
|
|
26
|
+
// Import necessary Faust modules and data
|
|
27
|
+
const { FaustMonoDspGenerator, FaustPolyDspGenerator } = await import("./faustwasm/index.js");
|
|
28
|
+
|
|
29
|
+
// Load DSP metadata from JSON
|
|
30
|
+
/** @type {FaustDspMeta} */
|
|
31
|
+
const dspMeta = await (await fetch("./dsp-meta.json")).json();
|
|
32
|
+
|
|
33
|
+
// Compile the DSP module from WebAssembly binary data
|
|
34
|
+
const dspModule = await WebAssembly.compileStreaming(await fetch("./dsp-module.wasm"));
|
|
35
|
+
|
|
36
|
+
// Create an object representing Faust DSP with metadata and module
|
|
37
|
+
/** @type {FaustDspDistribution} */
|
|
38
|
+
const faustDsp = { dspMeta, dspModule };
|
|
39
|
+
|
|
40
|
+
/** @type {FaustNode | null} */
|
|
41
|
+
let faustNode = null;
|
|
42
|
+
|
|
43
|
+
// Create either a polyphonic or monophonic Faust audio node based on the number of voices
|
|
44
|
+
if (voices > 0) {
|
|
45
|
+
|
|
46
|
+
// Try to load optional mixer and effect modules
|
|
47
|
+
faustDsp.mixerModule = await WebAssembly.compileStreaming(await fetch("./mixer-module.wasm"));
|
|
48
|
+
|
|
49
|
+
if (FAUST_DSP_HAS_EFFECT) {
|
|
50
|
+
faustDsp.effectMeta = await (await fetch("./effect-meta.json")).json();
|
|
51
|
+
faustDsp.effectModule = await WebAssembly.compileStreaming(await fetch("./effect-module.wasm"));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Create a polyphonic Faust audio node
|
|
55
|
+
const generator = new FaustPolyDspGenerator();
|
|
56
|
+
faustNode = await generator.createNode(
|
|
57
|
+
audioContext,
|
|
58
|
+
voices,
|
|
59
|
+
dspName,
|
|
60
|
+
{ module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta), soundfiles: {} },
|
|
61
|
+
faustDsp.mixerModule,
|
|
62
|
+
faustDsp.effectModule ? { module: faustDsp.effectModule, json: JSON.stringify(faustDsp.effectMeta), soundfiles: {} } : undefined,
|
|
63
|
+
sp,
|
|
64
|
+
bufferSize
|
|
65
|
+
);
|
|
66
|
+
} else {
|
|
67
|
+
// Create a standard Faust audio node
|
|
68
|
+
const generator = new FaustMonoDspGenerator();
|
|
69
|
+
faustNode = await generator.createNode(
|
|
70
|
+
audioContext,
|
|
71
|
+
dspName,
|
|
72
|
+
{ module: faustDsp.dspModule, json: JSON.stringify(faustDsp.dspMeta), soundfiles: {} },
|
|
73
|
+
sp,
|
|
74
|
+
bufferSize
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Return an object with the Faust audio node and the DSP metadata
|
|
79
|
+
return { faustNode, dspMeta };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Connects an audio input stream to a Faust audio node.
|
|
84
|
+
*
|
|
85
|
+
* @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node is connected.
|
|
86
|
+
* @param {string} id - The ID of the audio input device to connect.
|
|
87
|
+
* @param {FaustNode} faustNode - The Faust audio node to which the audio input stream will be connected.
|
|
88
|
+
* @param {MediaStreamAudioSourceNode} inputStreamNode - The audio input stream node to be disconnected from the Faust audio node.
|
|
89
|
+
* @returns {Promise<MediaStreamAudioSourceNode>} - The audio input stream node connected to the Faust audio node.
|
|
90
|
+
*/
|
|
91
|
+
async function connectToAudioInput(audioContext, id, faustNode, inputStreamNode) {
|
|
92
|
+
// Create an audio input stream node
|
|
93
|
+
const constraints = {
|
|
94
|
+
audio: {
|
|
95
|
+
echoCancellation: false,
|
|
96
|
+
noiseSuppression: false,
|
|
97
|
+
autoGainControl: false,
|
|
98
|
+
deviceId: id ? { exact: id } : undefined,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
// Get the audio input stream
|
|
102
|
+
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
103
|
+
if (stream) {
|
|
104
|
+
if (inputStreamNode) inputStreamNode.disconnect();
|
|
105
|
+
inputStreamNode = audioContext.createMediaStreamSource(stream);
|
|
106
|
+
inputStreamNode.connect(faustNode);
|
|
107
|
+
}
|
|
108
|
+
return inputStreamNode;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {FaustAudioWorkletNode} faustNode
|
|
113
|
+
*/
|
|
114
|
+
async function createFaustUI(divFaustUI, faustNode) {
|
|
115
|
+
const { FaustUI } = await import("./faust-ui/index.js");
|
|
116
|
+
const $container = document.createElement("div");
|
|
117
|
+
$container.style.margin = "0";
|
|
118
|
+
$container.style.position = "absolute";
|
|
119
|
+
$container.style.overflow = "auto";
|
|
120
|
+
$container.style.display = "flex";
|
|
121
|
+
$container.style.flexDirection = "column";
|
|
122
|
+
$container.style.width = "100%";
|
|
123
|
+
$container.style.height = "100%";
|
|
124
|
+
divFaustUI.appendChild($container);
|
|
125
|
+
const faustUI = new FaustUI({
|
|
126
|
+
ui: faustNode.getUI(),
|
|
127
|
+
root: $container,
|
|
128
|
+
listenWindowMessage: false,
|
|
129
|
+
listenWindowResize: true,
|
|
130
|
+
});
|
|
131
|
+
faustUI.paramChangeByUI = (path, value) => faustNode.setParamValue(path, value);
|
|
132
|
+
faustNode.setOutputParamHandler((path, value) => faustUI.paramChangeByDSP(path, value));
|
|
133
|
+
$container.style.minWidth = `${faustUI.minWidth}px`;
|
|
134
|
+
$container.style.minHeight = `${faustUI.minHeight}px`;
|
|
135
|
+
faustUI.resize();
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Export the functions
|
|
139
|
+
export { createFaustNode, createFaustUI, connectToAudioInput };
|
|
140
|
+
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "max_bug",
|
|
3
|
+
"filename": "max_bug",
|
|
4
|
+
"version": "2.75.16",
|
|
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/filters.lib",
|
|
9
|
+
"/usr/share/faust/analyzers.lib",
|
|
10
|
+
"/usr/share/faust/basics.lib",
|
|
11
|
+
"/usr/share/faust/maths.lib",
|
|
12
|
+
"/usr/share/faust/platform.lib"
|
|
13
|
+
],
|
|
14
|
+
"include_pathnames": [
|
|
15
|
+
"/share/faust",
|
|
16
|
+
"/usr/local/share/faust",
|
|
17
|
+
"/usr/share/faust",
|
|
18
|
+
"."
|
|
19
|
+
],
|
|
20
|
+
"size": 352,
|
|
21
|
+
"code": "gKg8ASQWHw==",
|
|
22
|
+
"inputs": 2,
|
|
23
|
+
"outputs": 1,
|
|
24
|
+
"meta": [
|
|
25
|
+
{
|
|
26
|
+
"analyzers.lib/name": "Faust Analyzer Library"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"analyzers.lib/version": "1.2.0"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"basics.lib/name": "Faust Basic Element Library"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"basics.lib/tabulateNd": "Copyright (C) 2023 Bart Brouns <bart@magnetophon.nl>"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"basics.lib/version": "1.19.1"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"compile_options": "-lang wasm-i -ct 1 -es 1 -mcd 16 -mdd 1024 -mdy 33 -single -ftz 2"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"filename": "max_bug"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"filters.lib/filterbank:author": "Julius O. Smith III"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"filters.lib/filterbank:copyright": "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"filters.lib/filterbank:license": "MIT-style STK-4.3 license"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"filters.lib/highpass:author": "Julius O. Smith III"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"filters.lib/highpass:copyright": "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"filters.lib/highpass_plus_lowpass:author": "Julius O. Smith III"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"filters.lib/highpass_plus_lowpass:copyright": "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"filters.lib/highpass_plus_lowpass:license": "MIT-style STK-4.3 license"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"filters.lib/lowpass0_highpass1": "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"filters.lib/lowpass0_highpass1:author": "Julius O. Smith III"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
"filters.lib/lowpass:author": "Julius O. Smith III"
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
"filters.lib/lowpass:copyright": "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"filters.lib/lowpass:license": "MIT-style STK-4.3 license"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
"filters.lib/name": "Faust Filters Library"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
"filters.lib/tf1:author": "Julius O. Smith III"
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"filters.lib/tf1:copyright": "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
"filters.lib/tf1:license": "MIT-style STK-4.3 license"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"filters.lib/tf1s:author": "Julius O. Smith III"
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"filters.lib/tf1s:copyright": "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"filters.lib/tf1s:license": "MIT-style STK-4.3 license"
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
"filters.lib/version": "1.3.0"
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
"maths.lib/author": "GRAME"
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
"maths.lib/copyright": "GRAME"
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
"maths.lib/license": "LGPL with exception"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"maths.lib/name": "Faust Math Library"
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
"maths.lib/version": "2.8.0"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"name": "max_bug"
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
"platform.lib/name": "Generic Platform Library"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
"platform.lib/version": "1.3.0"
|
|
132
|
+
}
|
|
133
|
+
],
|
|
134
|
+
"ui": [
|
|
135
|
+
{
|
|
136
|
+
"type": "vgroup",
|
|
137
|
+
"label": "max_bug",
|
|
138
|
+
"items": [
|
|
139
|
+
{
|
|
140
|
+
"type": "hbargraph",
|
|
141
|
+
"label": "max",
|
|
142
|
+
"shortname": "max",
|
|
143
|
+
"address": "/max_bug/max",
|
|
144
|
+
"index": 348,
|
|
145
|
+
"min": 0,
|
|
146
|
+
"max": 2
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
"type": "hgroup",
|
|
150
|
+
"label": "peaks",
|
|
151
|
+
"items": [
|
|
152
|
+
{
|
|
153
|
+
"type": "vbargraph",
|
|
154
|
+
"label": "1",
|
|
155
|
+
"shortname": "1",
|
|
156
|
+
"address": "/max_bug/peaks/1",
|
|
157
|
+
"index": 56,
|
|
158
|
+
"min": 0,
|
|
159
|
+
"max": 1
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"type": "vbargraph",
|
|
163
|
+
"label": "2",
|
|
164
|
+
"shortname": "2",
|
|
165
|
+
"address": "/max_bug/peaks/2",
|
|
166
|
+
"index": 88,
|
|
167
|
+
"min": 0,
|
|
168
|
+
"max": 1
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
"type": "vbargraph",
|
|
172
|
+
"label": "3",
|
|
173
|
+
"shortname": "3",
|
|
174
|
+
"address": "/max_bug/peaks/3",
|
|
175
|
+
"index": 120,
|
|
176
|
+
"min": 0,
|
|
177
|
+
"max": 1
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"type": "vbargraph",
|
|
181
|
+
"label": "4",
|
|
182
|
+
"shortname": "4",
|
|
183
|
+
"address": "/max_bug/peaks/4",
|
|
184
|
+
"index": 152,
|
|
185
|
+
"min": 0,
|
|
186
|
+
"max": 1
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
"type": "vbargraph",
|
|
190
|
+
"label": "5",
|
|
191
|
+
"shortname": "5",
|
|
192
|
+
"address": "/max_bug/peaks/5",
|
|
193
|
+
"index": 184,
|
|
194
|
+
"min": 0,
|
|
195
|
+
"max": 1
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"type": "vbargraph",
|
|
199
|
+
"label": "6",
|
|
200
|
+
"shortname": "6",
|
|
201
|
+
"address": "/max_bug/peaks/6",
|
|
202
|
+
"index": 216,
|
|
203
|
+
"min": 0,
|
|
204
|
+
"max": 1
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"type": "vbargraph",
|
|
208
|
+
"label": "7",
|
|
209
|
+
"shortname": "7",
|
|
210
|
+
"address": "/max_bug/peaks/7",
|
|
211
|
+
"index": 248,
|
|
212
|
+
"min": 0,
|
|
213
|
+
"max": 1
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"type": "vbargraph",
|
|
217
|
+
"label": "8",
|
|
218
|
+
"shortname": "8",
|
|
219
|
+
"address": "/max_bug/peaks/8",
|
|
220
|
+
"index": 280,
|
|
221
|
+
"min": 0,
|
|
222
|
+
"max": 1
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"type": "vbargraph",
|
|
226
|
+
"label": "9",
|
|
227
|
+
"shortname": "9",
|
|
228
|
+
"address": "/max_bug/peaks/9",
|
|
229
|
+
"index": 312,
|
|
230
|
+
"min": 0,
|
|
231
|
+
"max": 1
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
"type": "vbargraph",
|
|
235
|
+
"label": "10",
|
|
236
|
+
"shortname": "10",
|
|
237
|
+
"address": "/max_bug/peaks/10",
|
|
238
|
+
"index": 344,
|
|
239
|
+
"min": 0,
|
|
240
|
+
"max": 1
|
|
241
|
+
}
|
|
242
|
+
]
|
|
243
|
+
}
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
Binary file
|