How to connect to microphone using the Web Renderer #32
-
I started experimenting with elementary today and was able to generate a tone using the example from the web renderer documentation; however, I have no idea how to send a microphone signal to the renderer. Here is what I have so far within a React component: import WebRenderer from "@elemaudio/web-renderer";
import { el } from "@elemaudio/core";
export default function ElementaryTest(props) {
// connects to microphone signal
async function connectInputSignal(context) {
if (context.state === "suspended") {
await context.resume();
}
let stream = await navigator.mediaDevices.getUserMedia({
audio: {
echoCancellation: false,
autoGainControl: false,
noiseSuppression: false,
latency: 0,
},
});
return context.createMediaStreamSource(stream);
}
// attach to web renderer
// this is where I get lost
async function attachWebRenderer(inputSignal) {
const core = new WebRenderer();
console.log("inputSignal", inputSignal);
core.on("load", function () {
core.render(
el.lowpass(800, 1.414, el.in({ channel: 0 })),
el.lowpass(800, 1.414, el.in({ channel: 1 })),
);
});
let node = await core.initialize(inputSignal.context, {
numberOfInputs: 1,
numberOfOutputs: 1,
outputChannelCount: [2],
});
node.connect(inputSignal.context.destination);
}
// creates context and connects things together
async function startSound() {
if (navigator.mediaDevices) {
let context = new AudioContext();
let inputSignal = await connectInputSignal(context);
inputSignal.connect(context.destination);
await attachWebRenderer(inputSignal);
}
}
return (
<>
<button onClick={startSound}>Start</button>
</>
);
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hey @rajangdavis, you're so close!
Right here you basically would want something like: inputSignal.connect(node);
node.connect(inputSignal.context.destination); So the
This would render a stereo pass-through graph from input to output. In order for stereo in to work, you have to make sure you configure elementary's
Of course if you're just using a mono input then your configuration is already correct and you can just use Let me know if that helps |
Beta Was this translation helpful? Give feedback.
Hey @rajangdavis, you're so close!
Right here you basically would want something like:
So the
inputSignal
which is your MediaStreamSourceNode connects to the AudioNode returned fromWebRenderer.initialize
, which then connects to the destination. Once you have that wired up, you can reference the input signals in your elementary graph usingel.in({channel: 0})
. For example,This would render a stereo pass-through graph from input to output. In order for stereo in to work, you have to make sure you configure e…