Skip to content

Commit

Permalink
EngineBuffer: Improve calculation of m_slipPosition in processSlip()
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Sep 8, 2021
1 parent 1d9490d commit bc616cc
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,8 +1199,16 @@ void EngineBuffer::processSlip(int iBufferSize) {

// Increment slip position even if it was just toggled -- this ensures the position is correct.
if (enabled) {
m_slipPosition += static_cast<double>(iBufferSize) * m_dSlipRate /
mixxx::kEngineChannelCount;
// `iBufferSize` originates from `SoundManager::onDeviceOutputCallback`
// and is always a multiple of 2, so we can safely use integer division
// to find the number of frames per buffer here.
//
// TODO: Check if we can replace `iBufferSize` with the number of
// frames per buffer in most engine method signatures to avoid this
// back and forth calculations.
const int bufferFrameCount = iBufferSize / mixxx::kEngineChannelCount;
DEBUG_ASSERT(bufferFrameCount * mixxx::kEngineChannelCount == iBufferSize);
m_slipPosition += static_cast<mixxx::audio::FrameDiff_t>(bufferFrameCount) * m_dSlipRate;
}
}

Expand Down

0 comments on commit bc616cc

Please sign in to comment.