From d5669cd31d297ecbbb349105d6dc4453bff3e42b Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Mon, 30 Jul 2018 20:05:48 +0200 Subject: [PATCH] Remove peak value references from Mixer::getPeakValues Adjust Mixer::getPeakValues so client do not have to allocate the variables that will store the peak values. Adjust both existing clients: FxMixer and VisualizationWidget. --- include/Mixer.h | 8 +++++++- src/core/FxMixer.cpp | 8 +++----- src/core/Mixer.cpp | 8 +++++--- src/gui/widgets/VisualizationWidget.cpp | 6 ++---- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/include/Mixer.h b/include/Mixer.h index bd057753ac6..743547b0f82 100644 --- a/include/Mixer.h +++ b/include/Mixer.h @@ -273,7 +273,13 @@ class LMMS_EXPORT Mixer : public QObject } - void getPeakValues( sampleFrame * _ab, const f_cnt_t _frames, float & peakLeft, float & peakRight ) const; + struct StereoSample + { + StereoSample(sample_t _left, sample_t _right) : left(_left), right(_right) {} + sample_t left; + sample_t right; + }; + StereoSample getPeakValues(sampleFrame * _ab, const f_cnt_t _frames) const; bool criticalXRuns() const; diff --git a/src/core/FxMixer.cpp b/src/core/FxMixer.cpp index 51e66939aad..0e5f200d6d5 100644 --- a/src/core/FxMixer.cpp +++ b/src/core/FxMixer.cpp @@ -170,11 +170,9 @@ void FxChannel::doProcessing() m_stillRunning = m_fxChain.processAudioBuffer( m_buffer, fpp, m_hasInput ); - float peakLeft = 0.; - float peakRight = 0.; - Engine::mixer()->getPeakValues( m_buffer, fpp, peakLeft, peakRight ); - m_peakLeft = qMax( m_peakLeft, peakLeft * v ); - m_peakRight = qMax( m_peakRight, peakRight * v ); + Mixer::StereoSample peakSamples = Engine::mixer()->getPeakValues(m_buffer, fpp); + m_peakLeft = qMax( m_peakLeft, peakSamples.left * v ); + m_peakRight = qMax( m_peakRight, peakSamples.right * v ); } else { diff --git a/src/core/Mixer.cpp b/src/core/Mixer.cpp index 07a9d592f2c..f34f9dbbc42 100644 --- a/src/core/Mixer.cpp +++ b/src/core/Mixer.cpp @@ -534,10 +534,10 @@ void Mixer::clearInternal() -void Mixer::getPeakValues( sampleFrame * _ab, const f_cnt_t _frames, float & peakLeft, float & peakRight ) const +Mixer::StereoSample Mixer::getPeakValues(sampleFrame * _ab, const f_cnt_t _frames) const { - peakLeft = 0.0f; - peakRight = 0.0f; + sample_t peakLeft = 0.0f; + sample_t peakRight = 0.0f; for( f_cnt_t f = 0; f < _frames; ++f ) { @@ -553,6 +553,8 @@ void Mixer::getPeakValues( sampleFrame * _ab, const f_cnt_t _frames, float & pea peakRight = absRight; } } + + return StereoSample(peakLeft, peakRight); } diff --git a/src/gui/widgets/VisualizationWidget.cpp b/src/gui/widgets/VisualizationWidget.cpp index 00521f7bcc9..df001281679 100644 --- a/src/gui/widgets/VisualizationWidget.cpp +++ b/src/gui/widgets/VisualizationWidget.cpp @@ -131,10 +131,8 @@ void VisualizationWidget::paintEvent( QPaintEvent * ) const fpp_t frames = mixer->framesPerPeriod(); - float peakLeft; - float peakRight; - mixer->getPeakValues( m_buffer, frames, peakLeft, peakRight ); - const float max_level = qMax( peakLeft, peakRight ); + Mixer::StereoSample peakValues = mixer->getPeakValues(m_buffer, frames); + const float max_level = qMax( peakValues.left, peakValues.right ); // and set color according to that... if( max_level * master_output < 0.9 )