Skip to content

Commit

Permalink
Fix audio processing to work with any number of channels
Browse files Browse the repository at this point in the history
  • Loading branch information
sakertooth committed Jan 31, 2025
1 parent 34efa35 commit ce08aa5
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/core/audio/AudioPortAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,20 @@ int AudioPortAudio::processCallback(const float* inputBuffer, float* outputBuffe
if (err == 0) { return paComplete; }
}

const auto minLen = std::min(framesPerBuffer, m_outBuf.size() - m_outBufPos);
for (auto sample = std::size_t{0}; sample < framesPerBuffer * channels(); ++sample)
for (auto frame = std::size_t{0}; frame < framesPerBuffer; ++frame)
{
if (channels() == 1)
{
outputBuffer[sample] = m_outBuf[sample].average();
outputBuffer[frame] = m_outBuf[frame].average();
}
else
else
{
outputBuffer[sample] = m_outBuf[sample / channels()][sample % channels()];
outputBuffer[frame * channels()] = m_outBuf[frame][0];
outputBuffer[frame * channels() + 1] = m_outBuf[frame][1];
}
}

const auto minLen = std::min(framesPerBuffer, m_outBuf.size() - m_outBufPos);
outputBuffer += minLen * channels();
framesPerBuffer -= minLen;
m_outBufPos += minLen;
Expand Down

0 comments on commit ce08aa5

Please sign in to comment.