About latency on Linux machines #2582
-
Hi, I have these simple codes: class LibPd extends AudioWorkletProcessor {
process(inputs, outputs, parameters) {
console.log("LibPd");
for (let i = 0; i < outputs[0].length; ++i) {
outputs[0][i].set(inputs[0][i]);
}
return true;
}
}
registerProcessor("libpd", LibPd); and this <!doctype html>
<html lang="en">
<body>
<h1>Audio Processor Demo</h1>
<button id="button" onclick="audioOn()">Process Audio</button>
<script>
function audioOn() {
const audioContext = new window.AudioContext({
latencyHint: "interactive",
sampleRate: 48000,
});
console.log(audioContext);
console.log(audioContext.baseLatency * 1000);
audioContext.audioWorklet
.addModule("latency.js")
.then(() => {
const myProcessorNode = new AudioWorkletNode(audioContext, "libpd");
console.log(myProcessorNode);
navigator.mediaDevices
.getUserMedia({ audio: true })
.then((stream) => {
const micSource = audioContext.createMediaStreamSource(stream);
micSource.connect(myProcessorNode);
myProcessorNode.connect(audioContext.destination);
})
.catch((err) => {
console.error("getUserMedia error:", err);
});
})
.catch((err) => {
console.error("Error loading audio worklet module:", err);
});
}
</script>
</body>
</html> Yet I have a big latency. About 0.05 seconds. I am using Linux, it is because of Linux? There is something that I can do to make it at least below 20ms? I am trying to develop something for live-electronics music using a software called PureData, realtime is veryyyy important.... Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This repository is home to the Web Audio API specification. Questions on the Web Audio API are better suited to either Stack Overflow or the Web Audio API slack. That said, I'd try different browsers, they aren't all equal in terms of latency, and at least Firefox can be configured to use Jack to have minimal latency (although Pipewire usually suffices these days). Feel free to pop in #media on chat.mozilla.org or send an email to padenot@mozilla.com (me) to try that, with informations about your setup. |
Beta Was this translation helpful? Give feedback.
-
To follow up on Paul's note: Chromium unfortunately doesn't support JACK but there are some experimental command-line switches that can give better output latency. If you are interested in trying them, with the understanding that they are not intended for general use and may stop working sometime in the future, please email me at mjwilson@google.com |
Beta Was this translation helpful? Give feedback.
This repository is home to the Web Audio API specification.
Questions on the Web Audio API are better suited to either Stack Overflow or the Web Audio API slack.
That said, I'd try different browsers, they aren't all equal in terms of latency, and at least Firefox can be configured to use Jack to have minimal latency (although Pipewire usually suffices these days). Feel free to pop in #media on chat.mozilla.org or send an email to padenot@mozilla.com (me) to try that, with informations about your setup.