Skip to content

Commit

Permalink
Remove peak value references from Mixer::getPeakValues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelgregorius committed Aug 16, 2018
1 parent c44bc4e commit 8d00e90
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
8 changes: 7 additions & 1 deletion include/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions src/core/FxMixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
8 changes: 5 additions & 3 deletions src/core/Mixer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand All @@ -553,6 +553,8 @@ void Mixer::getPeakValues( sampleFrame * _ab, const f_cnt_t _frames, float & pea
peakRight = absRight;
}
}

return StereoSample(peakLeft, peakRight);
}


Expand Down
6 changes: 2 additions & 4 deletions src/gui/widgets/VisualizationWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>( peakLeft, peakRight );
Mixer::StereoSample peakValues = mixer->getPeakValues(m_buffer, frames);
const float max_level = qMax<float>( peakValues.left, peakValues.right );

// and set color according to that...
if( max_level * master_output < 0.9 )
Expand Down

0 comments on commit 8d00e90

Please sign in to comment.