@grame/faustwasm 0.5.0 → 0.5.2
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/assets/standalone/create-node.js +28 -1
- package/assets/standalone/index-pwa.js +8 -2
- package/assets/standalone/index-template.js +9 -3
- package/assets/standalone/index.js +11 -26
- package/package.json +1 -1
- package/scripts/faust2sndfile.js +0 -1
- package/src/faust2svgFiles.js +0 -1
- package/src/faust2wasmFiles.js +1 -2
- package/src/faust2wavFiles.js +0 -1
- package/build +0 -25
|
@@ -75,4 +75,31 @@ const createFaustNode = async (audioContext, dspName = "template", voices = 0, s
|
|
|
75
75
|
return { faustNode, dspMeta };
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Connects an audio input stream to a Faust audio node.
|
|
80
|
+
*
|
|
81
|
+
* @param {AudioContext} audioContext - The Web Audio API AudioContext to which the Faust audio node is connected.
|
|
82
|
+
* @param {string} id - The ID of the audio input device to connect.
|
|
83
|
+
* @param {FaustNode} faustNode - The Faust audio node to which the audio input stream will be connected.
|
|
84
|
+
* @param {MediaStreamAudioSourceNode} inputStreamNode - The audio input stream node to be connected to the Faust audio node.
|
|
85
|
+
* @returns {Promise<MediaStreamAudioSourceNode>} - The audio input stream node connected to the Faust audio node.
|
|
86
|
+
*/
|
|
87
|
+
async function connectToAudioInput(audioContext, id, faustNode, inputStreamNode) {
|
|
88
|
+
const constraints = {
|
|
89
|
+
audio: {
|
|
90
|
+
echoCancellation: false,
|
|
91
|
+
noiseSuppression: false,
|
|
92
|
+
autoGainControl: false,
|
|
93
|
+
deviceId: id ? { exact: id } : undefined,
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
97
|
+
if (stream) {
|
|
98
|
+
if (inputStreamNode) inputStreamNode.disconnect();
|
|
99
|
+
inputStreamNode = audioContext.createMediaStreamSource(stream);
|
|
100
|
+
inputStreamNode.connect(faustNode);
|
|
101
|
+
}
|
|
102
|
+
return inputStreamNode;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { createFaustNode, connectToAudioInput };
|
|
@@ -58,7 +58,7 @@ const createFaustUI = async (faustNode) => {
|
|
|
58
58
|
|
|
59
59
|
(async () => {
|
|
60
60
|
|
|
61
|
-
const {
|
|
61
|
+
const { createFaustNode } = await import("./create-node.js");
|
|
62
62
|
|
|
63
63
|
// To test the ScriptProcessorNode mode
|
|
64
64
|
// const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "osc", FAUST_DSP_VOICES, true);
|
|
@@ -68,9 +68,15 @@ const createFaustUI = async (faustNode) => {
|
|
|
68
68
|
// Create the Faust UI
|
|
69
69
|
await createFaustUI(faustNode);
|
|
70
70
|
|
|
71
|
-
// Connect the Faust node to the audio
|
|
71
|
+
// Connect the Faust node to the audio output
|
|
72
72
|
faustNode.connect(audioContext.destination);
|
|
73
73
|
|
|
74
|
+
// Connect the Faust node to the audio input
|
|
75
|
+
if (faustNode.getNumInputs() > 0) {
|
|
76
|
+
const { connectToAudioInput } = await import("./create-node.js");
|
|
77
|
+
await connectToAudioInput(audioContext, null, faustNode, null);
|
|
78
|
+
}
|
|
79
|
+
|
|
74
80
|
// Activate sensor listeners
|
|
75
81
|
await faustNode.listenSensors();
|
|
76
82
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const FAUST_DSP_VOICES = 0;
|
|
3
3
|
|
|
4
4
|
(async () => {
|
|
5
|
-
const {
|
|
5
|
+
const { createFaustNode } = await import("./create-node.js");
|
|
6
6
|
|
|
7
7
|
// Create audio context
|
|
8
8
|
const AudioCtx = window.AudioContext || window.webkitAudioContext;
|
|
@@ -37,12 +37,18 @@ const FAUST_DSP_VOICES = 0;
|
|
|
37
37
|
const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP_NAME", FAUST_DSP_VOICES);
|
|
38
38
|
if (!faustNode) throw new Error("Faust DSP not compiled");
|
|
39
39
|
|
|
40
|
-
// Connect Faust node to audio
|
|
40
|
+
// Connect the Faust node to the audio output
|
|
41
41
|
faustNode.connect(audioContext.destination);
|
|
42
42
|
|
|
43
|
+
// Connect the Faust node to the audio input
|
|
44
|
+
if (faustNode.getNumInputs() > 0) {
|
|
45
|
+
const { connectToAudioInput } = await import("./create-node.js");
|
|
46
|
+
await connectToAudioInput(audioContext, null, faustNode, null);
|
|
47
|
+
}
|
|
48
|
+
|
|
43
49
|
// Create Faust node activation button
|
|
44
50
|
$buttonDsp.disabled = false;
|
|
45
|
-
|
|
51
|
+
|
|
46
52
|
// Set page title to the DSP name
|
|
47
53
|
document.title = name;
|
|
48
54
|
})();
|
|
@@ -44,8 +44,10 @@ $buttonDsp.disabled = true;
|
|
|
44
44
|
* @param {FaustAudioWorkletNode} faustNode
|
|
45
45
|
*/
|
|
46
46
|
const buildAudioDeviceMenu = async (faustNode) => {
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
|
|
48
|
+
const { connectToAudioInput } = await import("./create-node.js");
|
|
49
|
+
|
|
50
|
+
let inputStreamNode = null;
|
|
49
51
|
const handleDeviceChange = async () => {
|
|
50
52
|
const devicesInfo = await navigator.mediaDevices.enumerateDevices();
|
|
51
53
|
$selectAudioInput.innerHTML = "";
|
|
@@ -61,31 +63,14 @@ const buildAudioDeviceMenu = async (faustNode) => {
|
|
|
61
63
|
navigator.mediaDevices.addEventListener("devicechange", handleDeviceChange)
|
|
62
64
|
$selectAudioInput.onchange = async () => {
|
|
63
65
|
const id = $selectAudioInput.value;
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
echoCancellation: false,
|
|
67
|
-
noiseSuppression: false,
|
|
68
|
-
autoGainControl: false,
|
|
69
|
-
deviceId: id ? { exact: id } : undefined,
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
const stream = await navigator.mediaDevices.getUserMedia(constraints);
|
|
73
|
-
if (inputStreamNode) inputStreamNode.disconnect();
|
|
74
|
-
inputStreamNode = audioContext.createMediaStreamSource(stream);
|
|
75
|
-
inputStreamNode.connect(faustNode);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const defaultConstraints = {
|
|
79
|
-
audio: {
|
|
80
|
-
echoCancellation: false,
|
|
81
|
-
mozNoiseSuppression: false,
|
|
82
|
-
mozAutoGainControl: false
|
|
66
|
+
if (faustNode.getNumInputs() > 0) {
|
|
67
|
+
inputStreamNode = await connectToAudioInput(audioContext, id, faustNode, inputStreamNode);
|
|
83
68
|
}
|
|
84
69
|
};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
inputStreamNode
|
|
70
|
+
|
|
71
|
+
// Connect to the default audio input device
|
|
72
|
+
if (faustNode.getNumInputs() > 0) {
|
|
73
|
+
inputStreamNode = await connectToAudioInput(audioContext, null, faustNode, inputStreamNode);
|
|
89
74
|
}
|
|
90
75
|
};
|
|
91
76
|
|
|
@@ -149,7 +134,7 @@ const createFaustUI = async (faustNode) => {
|
|
|
149
134
|
};
|
|
150
135
|
|
|
151
136
|
(async () => {
|
|
152
|
-
const {
|
|
137
|
+
const { createFaustNode } = await import("./create-node.js");
|
|
153
138
|
// To test the ScriptProcessorNode mode
|
|
154
139
|
// const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP_NAME", FAUST_DSP_VOICES, true);
|
|
155
140
|
const { faustNode, dspMeta: { name } } = await createFaustNode(audioContext, "FAUST_DSP_NAME", FAUST_DSP_VOICES);
|
package/package.json
CHANGED
package/scripts/faust2sndfile.js
CHANGED
package/src/faust2svgFiles.js
CHANGED
|
@@ -26,7 +26,6 @@ const faust2svgFiles = async (inputFile, outputDir, argv = []) => {
|
|
|
26
26
|
const code = fs.readFileSync(inputFile, { encoding: "utf8" });
|
|
27
27
|
const { name } = path.parse(inputFile);
|
|
28
28
|
const diagram = new FaustSvgDiagrams(compiler);
|
|
29
|
-
if (!argv.find(a => a === "-I")) argv.push("-I", "libraries/");
|
|
30
29
|
const svgs = diagram.from(name, code, argv.join(" "));
|
|
31
30
|
console.log(`Generated ${Object.keys(svgs).length} files.`);
|
|
32
31
|
console.log(`Writing files to ${outputDir}`);
|
package/src/faust2wasmFiles.js
CHANGED
|
@@ -31,8 +31,7 @@ const faust2wasmFiles = async (inputFile, outputDir, argv = [], poly = false) =>
|
|
|
31
31
|
|
|
32
32
|
const fileName = /** @type {string} */(inputFile.split('/').pop());
|
|
33
33
|
const dspName = fileName.replace(/\.dsp$/, '');
|
|
34
|
-
|
|
35
|
-
if (!argv.find(a => a === "-I")) argv.push("-I", "libraries/");
|
|
34
|
+
// Flush to zero to avoid costly denormalized numbers
|
|
36
35
|
argv.push("-ftz", "2");
|
|
37
36
|
const dspModulePath = path.join(outputDir, `dsp-module.wasm`);
|
|
38
37
|
const dspMetaPath = path.join(outputDir, `dsp-meta.json`);
|
package/src/faust2wavFiles.js
CHANGED
|
@@ -32,7 +32,6 @@ const faust2wavFiles = async (inputFile, inputWav, outputWav, bufferSize = 64, s
|
|
|
32
32
|
console.log(`Faust Compiler version: ${compiler.version()}`);
|
|
33
33
|
console.log(`Reading file ${inputFile}`);
|
|
34
34
|
const code = fs.readFileSync(inputFile, { encoding: "utf8" });
|
|
35
|
-
if (!argv.find(a => a === "-I")) argv.push("-I", "libraries/");
|
|
36
35
|
const { name } = path.parse(inputFile);
|
|
37
36
|
const gen = new FaustMonoDspGenerator();
|
|
38
37
|
await gen.compile(compiler, name, code, argv.join(" "));
|
package/build
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/atomicro/atomicro.dsp /Users/letz/Developpements/sletz.github.io/atomicro -pwa
|
|
2
|
-
|
|
3
|
-
node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/attackey/attackey.dsp /Users/letz/Developpements/sletz.github.io/attackey -pwa
|
|
4
|
-
|
|
5
|
-
node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/baliphone/baliphone.dsp /Users/letz/Developpements/sletz.github.io/baliphone -pwa
|
|
6
|
-
|
|
7
|
-
node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/drone/drone.dsp /Users/letz/Developpements/sletz.github.io/drone -pwa
|
|
8
|
-
|
|
9
|
-
node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/sequenceur/sequenceur.dsp /Users/letz/Developpements/sletz.github.io/sequenceur -pwa
|
|
10
|
-
|
|
11
|
-
node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/shakerxy/shakerxy.dsp /Users/letz/Developpements/sletz.github.io/shakerxy -pwa
|
|
12
|
-
|
|
13
|
-
node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/sinusoide/sinusoide.dsp /Users/letz/Developpements/sletz.github.io/sinusoide -pwa
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
#node scripts/faust2wasm.js /Users/letz/Developpements/GameLAN/test.dsp /Users/letz/Developpements/sletz.github.io/out -standalone
|
|
17
|
-
#node scripts/faust2wasm.js test/organ.dsp /Users/letz/Developpements/sletz.github.io/organ -poly -standalone
|
|
18
|
-
|
|
19
|
-
#node scripts/faust2wasm.js test/organ1.dsp /Users/letz/Developpements/sletz.github.io/organ1 -poly -standalone
|
|
20
|
-
|
|
21
|
-
#node scripts/faust2wasm.js test/osc2.dsp /Users/letz/Developpements/sletz.github.io/osc2 -standalone
|
|
22
|
-
|
|
23
|
-
#node scripts/faust2wasm.js /Users/letz/Developpements/faust-sampler/sampler.dsp /Users/letz/Developpements/sletz.github.io/sampler -poly -standalone
|
|
24
|
-
|
|
25
|
-
#node scripts/faust2wasm.js /Users/letz/Developpements/faust-sampler/piano.dsp /Users/letz/Developpements/sletz.github.io/piano -poly -standalone
|