Skip to content

Commit

Permalink
EngineBuffer: Use mixxx::audio::SampleRate instead of int/double
Browse files Browse the repository at this point in the history
  • Loading branch information
Holzhaus committed Jul 6, 2021
1 parent 8d75d83 commit 9c33e11
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
23 changes: 10 additions & 13 deletions src/engine/enginebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ EngineBuffer::EngineBuffer(const QString& group,
m_baserate_old(0),
m_rate_old(0.),
m_trackSamplesOld(0),
m_trackSampleRateOld(0),
m_dSlipPosition(0.),
m_dSlipRate(1.0),
m_bSlipEnabledProcessing(false),
Expand All @@ -92,7 +91,6 @@ EngineBuffer::EngineBuffer(const QString& group,
m_iSyncModeQueued(SYNC_INVALID),
m_iTrackLoading(0),
m_bPlayAfterLoading(false),
m_iSampleRate(0),
m_pCrossfadeBuffer(SampleUtil::alloc(MAX_BUFFER_LEN)),
m_bCrossfadeReady(false),
m_iLastBufferSize(0) {
Expand Down Expand Up @@ -790,15 +788,15 @@ void EngineBuffer::slotKeylockEngineChanged(double dIndex) {
}

void EngineBuffer::processTrackLocked(
CSAMPLE* pOutput, const int iBufferSize, int sample_rate) {
CSAMPLE* pOutput, const int iBufferSize, mixxx::audio::SampleRate sampleRate) {
ScopedTimer t("EngineBuffer::process_pauselock");

m_trackSampleRateOld = m_pTrackSampleRate->get();
m_trackSampleRateOld = mixxx::audio::SampleRate::fromDouble(m_pTrackSampleRate->get());
m_trackSamplesOld = m_pTrackSamples->get();

double baserate = 0.0;
if (sample_rate > 0) {
baserate = m_trackSampleRateOld / sample_rate;
if (sampleRate.isValid()) {
baserate = m_trackSampleRateOld / sampleRate;
}

// Sync requests can affect rate, so process those first.
Expand Down Expand Up @@ -1113,19 +1111,18 @@ void EngineBuffer::process(CSAMPLE* pOutput, const int iBufferSize) {
// - Set last sample value (m_fLastSampleValue) so that rampOut works? Other
// miscellaneous upkeep issues.

m_iSampleRate = static_cast<int>(m_pSampleRate->get());
m_sampleRate = mixxx::audio::SampleRate::fromDouble(m_pSampleRate->get());

// If the sample rate has changed, force Rubberband to reset so that
// it doesn't reallocate when the user engages keylock during playback.
// We do this even if rubberband is not active.
const auto sampleRate = mixxx::audio::SampleRate(m_iSampleRate);
m_pScaleLinear->setSampleRate(sampleRate);
m_pScaleST->setSampleRate(sampleRate);
m_pScaleRB->setSampleRate(sampleRate);
m_pScaleLinear->setSampleRate(m_sampleRate);
m_pScaleST->setSampleRate(m_sampleRate);
m_pScaleRB->setSampleRate(m_sampleRate);

bool bTrackLoading = atomicLoadRelaxed(m_iTrackLoading) != 0;
if (!bTrackLoading && m_pause.tryLock()) {
processTrackLocked(pOutput, iBufferSize, m_iSampleRate);
processTrackLocked(pOutput, iBufferSize, m_sampleRate);
// release the pauselock
m_pause.unlock();
} else {
Expand Down Expand Up @@ -1325,7 +1322,7 @@ bool EngineBuffer::getQueuedSeekPosition(double* pSeekPosition) const {
}

void EngineBuffer::updateIndicators(double speed, int iBufferSize) {
if (m_trackSampleRateOld == 0) {
if (!m_trackSampleRateOld.isValid()) {
// This happens if Deck Passthrough is active but no track is loaded.
// We skip indicator updates.
return;
Expand Down
8 changes: 5 additions & 3 deletions src/engine/enginebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ class EngineBuffer : public EngineObject {
bool updateIndicatorsAndModifyPlay(bool newPlay, bool oldPlay);
void verifyPlay();
void notifyTrackLoaded(TrackPointer pNewTrack, TrackPointer pOldTrack);
void processTrackLocked(CSAMPLE* pOutput, const int iBufferSize, int sample_rate);
void processTrackLocked(CSAMPLE* pOutput,
const int iBufferSize,
mixxx::audio::SampleRate sampleRate);

// Holds the name of the control group
const QString m_group;
Expand Down Expand Up @@ -310,7 +312,7 @@ class EngineBuffer : public EngineObject {
double m_trackSamplesOld;

// Copy of file sample rate
double m_trackSampleRateOld;
mixxx::audio::SampleRate m_trackSampleRateOld;

// Mutex controlling whether the process function is in pause mode. This happens
// during seek and loading of a new track
Expand Down Expand Up @@ -397,7 +399,7 @@ class EngineBuffer : public EngineObject {
bool m_bPlayAfterLoading;
// Records the sample rate so we can detect when it changes. Initialized to
// 0 to guarantee we see a change on the first callback.
int m_iSampleRate;
mixxx::audio::SampleRate m_sampleRate;

TrackPointer m_pCurrentTrack;
#ifdef __SCALER_DEBUG__
Expand Down

0 comments on commit 9c33e11

Please sign in to comment.