From f97308edfb29e907c6abffadae1ddd49155f8d88 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 11 Nov 2022 05:11:36 -0500 Subject: [PATCH] Clear output audio only if no Ports are subscribed to Device. --- src/audio.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 1f0b023f..44120cd4 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -31,9 +31,6 @@ void Device::unsubscribe(Port* port) { } void Device::processBuffer(const float* input, int inputStride, float* output, int outputStride, int frames) { - // Zero output in case no Port writes values to it. - std::memset(output, 0, frames * outputStride * sizeof(float)); - 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. @@ -48,6 +45,11 @@ 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() {