From 908517c890c2959355a75582c48db3e1b70ef731 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Sat, 24 Dec 2022 02:10:07 -0500 Subject: [PATCH] Clear audio output in Device before Ports process buffers. --- src/audio.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 44120cd4..9cfecfb3 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -31,6 +31,9 @@ void Device::unsubscribe(Port* port) { } void Device::processBuffer(const float* input, int inputStride, float* output, int outputStride, int frames) { + // Zero output since Ports might not write to all elements, or no Ports exist + std::fill_n(output, frames * outputStride, 0.f); + std::lock_guard lock(processMutex); for (Port* port : subscribed) { // Setting the thread context should probably be the responsibility of Port, but because processInput() etc are overridden, this is the only good place for it. @@ -45,11 +48,6 @@ void Device::processBuffer(const float* input, int inputStride, float* output, i contextSet(port->context); port->processOutput(output + port->outputOffset, outputStride, frames); } - - if (subscribed.empty()) { - // Clear output if no Port writes values to it. - std::fill_n(output, frames * outputStride, 0.f); - } } void Device::onStartStream() {