Browse Source

Clear output audio only if no Ports are subscribed to Device.

tags/v2.2.0
Andrew Belt 2 years ago
parent
commit
f97308edfb
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      src/audio.cpp

+ 5
- 3
src/audio.cpp View File

@@ -31,9 +31,6 @@ void Device::unsubscribe(Port* port) {
} }


void Device::processBuffer(const float* input, int inputStride, float* output, int outputStride, int frames) { 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<std::mutex> lock(processMutex); std::lock_guard<std::mutex> lock(processMutex);
for (Port* port : subscribed) { 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. // 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); contextSet(port->context);
port->processOutput(output + port->outputOffset, outputStride, frames); 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() { void Device::onStartStream() {


Loading…
Cancel
Save