@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.
- package/README.md +181 -0
- package/assets/standalone/faust-ui/index.css +414 -0
- package/assets/standalone/faust-ui/index.css.map +1 -0
- package/assets/standalone/faust-ui/index.d.ts +1 -0
- package/assets/standalone/faust-ui/index.js +3478 -0
- package/assets/standalone/faust-ui/index.js.map +1 -0
- package/assets/standalone/faustwasm/index.d.ts +1252 -0
- package/assets/standalone/faustwasm/index.js +3772 -0
- package/assets/standalone/faustwasm/index.js.map +7 -0
- package/assets/standalone/index.html +73 -0
- package/assets/standalone/index.js +198 -0
- package/assets/standalone/types.d.ts +9 -0
- package/dist/cjs/index.d.ts +1252 -0
- package/dist/cjs/index.js +3752 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs-bundle/index.d.ts +1259 -0
- package/dist/cjs-bundle/index.js +11507 -0
- package/dist/cjs-bundle/index.js.map +7 -0
- package/dist/esm/index.d.ts +1252 -0
- package/dist/esm/index.js +3772 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm-bundle/index.d.ts +1259 -0
- package/dist/esm-bundle/index.js +11495 -0
- package/dist/esm-bundle/index.js.map +7 -0
- package/fileutils.js +40 -0
- package/libfaust-wasm/libfaust-wasm.d.cts +3 -0
- package/libfaust-wasm/libfaust-wasm.d.ts +3 -0
- package/libfaust-wasm/libfaust-wasm.data +0 -0
- package/libfaust-wasm/libfaust-wasm.data.d.ts +2 -0
- package/libfaust-wasm/libfaust-wasm.js +21 -0
- package/libfaust-wasm/libfaust-wasm.wasm +0 -0
- package/libfaust-wasm/libfaust-wasm.wasm.d.ts +2 -0
- package/library.md +91 -0
- package/package.json +43 -0
- package/postbuild-bundled.js +11 -0
- package/postbuild.js +63 -0
- package/prebuild-bundled.js +11 -0
- package/rsrc/overview.png +0 -0
- package/rsrc/overview.xlsx +0 -0
- package/scripts/faust2sndfile.js +43 -0
- package/scripts/faust2svg.js +17 -0
- package/scripts/faust2wasm.js +29 -0
- package/src/FaustAudioWorkletNode.ts +264 -0
- package/src/FaustAudioWorkletProcessor.ts +273 -0
- package/src/FaustCompiler.ts +252 -0
- package/src/FaustDspGenerator.ts +498 -0
- package/src/FaustDspInstance.ts +141 -0
- package/src/FaustFFTAudioWorkletProcessor.ts +554 -0
- package/src/FaustOfflineProcessor.ts +141 -0
- package/src/FaustScriptProcessorNode.ts +80 -0
- package/src/FaustSvgDiagrams.ts +37 -0
- package/src/FaustWasmInstantiator.ts +202 -0
- package/src/FaustWebAudioDsp.ts +1060 -0
- package/src/LibFaust.ts +57 -0
- package/src/WavDecoder.ts +207 -0
- package/src/WavEncoder.ts +204 -0
- package/src/copyWebStandaloneAssets.d.ts +3 -0
- package/src/copyWebStandaloneAssets.js +20 -0
- package/src/exports-bundle.ts +5 -0
- package/src/exports.ts +24 -0
- package/src/faust2svgFiles.d.ts +3 -0
- package/src/faust2svgFiles.js +43 -0
- package/src/faust2wasmFiles.d.ts +5 -0
- package/src/faust2wasmFiles.js +93 -0
- package/src/faust2wavFiles.d.ts +3 -0
- package/src/faust2wavFiles.js +58 -0
- package/src/index-bundle-iife.ts +7 -0
- package/src/index-bundle.ts +5 -0
- package/src/index.ts +5 -0
- package/src/instantiateFaustModule.ts +32 -0
- package/src/instantiateFaustModuleFromFile.ts +57 -0
- package/src/types.ts +234 -0
- package/test/clarinet.dsp +1 -0
- package/test/faustlive-wasm/faust-ui/index.css +414 -0
- package/test/faustlive-wasm/faust-ui/index.css.map +1 -0
- package/test/faustlive-wasm/faust-ui/index.d.ts +1 -0
- package/test/faustlive-wasm/faust-ui/index.js +3478 -0
- package/test/faustlive-wasm/faust-ui/index.js.map +1 -0
- package/test/faustlive-wasm/faustwasm/index.d.ts +1252 -0
- package/test/faustlive-wasm/faustwasm/index.js +3772 -0
- package/test/faustlive-wasm/faustwasm/index.js.map +7 -0
- package/test/faustlive-wasm/index.css +97 -0
- package/test/faustlive-wasm/index.html +130 -0
- package/test/faustlive-wasm/index.js +638 -0
- package/test/guitar.dsp +1 -0
- package/test/guitar1.dsp +2 -0
- package/test/libfaust-in-worklet/index.html +13 -0
- package/test/libfaust-in-worklet/index.js +40 -0
- package/test/mono.dsp +8 -0
- package/test/node/test.js +17 -0
- package/test/noise.dsp +3 -0
- package/test/organ.dsp +5 -0
- package/test/organ1.dsp +6 -0
- package/test/osc.dsp +4 -0
- package/test/osc2.dsp +5 -0
- package/test/osc3.dsp +4 -0
- package/test/p-dj.dsp +4 -0
- package/test/poly.dsp +13 -0
- package/test/rev.dsp +2 -0
- package/test/t1.dsp +1 -0
- package/test/web/fft.html +87 -0
- package/test/web/fft1.html +88 -0
- package/test/web/fft2.html +114 -0
- package/test/web/fftw.js +1907 -0
- package/test/web/index.html +12 -0
- package/test/web/index.js +235 -0
- package/test/web/kissfft.js +904 -0
- package/test/web/mono.html +46 -0
- package/test/web/poly-key.html +62 -0
- package/test/web/poly.html +59 -0
- 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
|
+
})();
|