@grame/faustwasm 0.5.0 → 0.5.1
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.
|
@@ -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);
|