From 693f0e52f716207aab0912ddb375a070f99426df Mon Sep 17 00:00:00 2001 From: Alexandre Bique Date: Wed, 20 Sep 2023 19:18:58 +0200 Subject: [PATCH] Use kMaxEngineFrames or kMaxEngineSamples when possible --- src/engine/effects/engineeffect.cpp | 4 ++-- src/engine/effects/engineeffectchain.cpp | 6 ++++-- src/soundio/sounddevice.cpp | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/engine/effects/engineeffect.cpp b/src/engine/effects/engineeffect.cpp index 611f79d74428..1d8f53aea34a 100644 --- a/src/engine/effects/engineeffect.cpp +++ b/src/engine/effects/engineeffect.cpp @@ -40,7 +40,7 @@ EngineEffect::EngineEffect(EffectManifestPointer pManifest, // At this point the SoundDevice is not set up so we use the kInitalSampleRate. const mixxx::EngineParameters engineParameters( kInitalSampleRate, - MAX_BUFFER_LEN / mixxx::kEngineChannelCount); + kMaxEngineFrames); m_pProcessor->initialize(activeInputChannels, registeredOutputChannels, engineParameters); m_effectRampsFromDry = pManifest->effectRampsFromDry(); } @@ -62,7 +62,7 @@ void EngineEffect::initalizeInputChannel(ChannelHandle inputChannel) { // At this point the SoundDevice is not set up so we use the kInitalSampleRate. const mixxx::EngineParameters engineParameters( kInitalSampleRate, - MAX_BUFFER_LEN / mixxx::kEngineChannelCount); + kMaxEngineFrames); m_pProcessor->initializeInputChannel(inputChannel, engineParameters); } diff --git a/src/engine/effects/engineeffectchain.cpp b/src/engine/effects/engineeffectchain.cpp index 7996726a12fb..c1005fffd17b 100644 --- a/src/engine/effects/engineeffectchain.cpp +++ b/src/engine/effects/engineeffectchain.cpp @@ -11,8 +11,8 @@ EngineEffectChain::EngineEffectChain(const QString& group, m_enableState(EffectEnableState::Enabled), m_mixMode(EffectChainMixMode::DrySlashWet), m_dMix(0), - m_buffer1(MAX_BUFFER_LEN), - m_buffer2(MAX_BUFFER_LEN) { + m_buffer1(kMaxEngineSamples), + m_buffer2(kMaxEngineSamples) { // Try to prevent memory allocation. m_effects.reserve(256); @@ -179,6 +179,8 @@ bool EngineEffectChain::process(const ChannelHandle& inputHandle, const mixxx::audio::SampleRate sampleRate, const GroupFeatureState& groupFeatures, bool fadeout) { + DEBUG_ASSERT(numSamples <= kMaxEngineFrames); + // Compute the effective enable state from the channel input routing switch and // the chain's enable state. When either of these are turned on/off, send the // effects the intermediate enabling/disabling signal. diff --git a/src/soundio/sounddevice.cpp b/src/soundio/sounddevice.cpp index 0fe875af4a79..3e76259c2f3b 100644 --- a/src/soundio/sounddevice.cpp +++ b/src/soundio/sounddevice.cpp @@ -35,7 +35,7 @@ void SoundDevice::setSampleRate(mixxx::audio::SampleRate sampleRate) { } void SoundDevice::setConfigFramesPerBuffer(unsigned int framesPerBuffer) { - if (framesPerBuffer * 2 > MAX_BUFFER_LEN) { + if (framesPerBuffer > kMaxEngineFrames) { // framesPerBuffer * 2 because a frame will generally end up // being 2 samples and MAX_BUFFER_LEN is a number of samples // this isn't checked elsewhere, so...