Skip to content

Commit

Permalink
Reduce code repetition
Browse files Browse the repository at this point in the history
Reduce code repetition in `EqEffect::setBandPeaks` by introducing a lambda. Adjust code formatting.
  • Loading branch information
michaelgregorius committed Apr 3, 2024
1 parent 6d7e7c4 commit f2d63ec
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions plugins/Eq/EqEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,45 +311,37 @@ float EqEffect::linearPeakBand(float minF, float maxF, EqAnalyser* fft, int sr)

void EqEffect::setBandPeaks( EqAnalyser *fft, int samplerate )
{
auto computePeakBand = [this, fft, samplerate](FloatModel const & freqModel, FloatModel const & bwModel)
{
float const freq = freqModel.value();
float const bw = bwModel.value();

return linearPeakBand(freq * (1 - bw * 0.5), freq * (1 + bw * 0.5), fft, samplerate);
};

m_eqControls.m_lowShelfPeakR = m_eqControls.m_lowShelfPeakL =
linearPeakBand( m_eqControls.m_lowShelfFreqModel.value()
* ( 1 - m_eqControls.m_lowShelfResModel.value() * 0.5 ),
linearPeakBand(m_eqControls.m_lowShelfFreqModel.value()
* (1 - m_eqControls.m_lowShelfResModel.value() * 0.5),
m_eqControls.m_lowShelfFreqModel.value(),
fft , samplerate );
fft , samplerate);

m_eqControls.m_para1PeakL = m_eqControls.m_para1PeakR =
linearPeakBand( m_eqControls.m_para1FreqModel.value()
* ( 1 - m_eqControls.m_para1BwModel.value() * 0.5 ),
m_eqControls.m_para1FreqModel.value()
* ( 1 + m_eqControls.m_para1BwModel.value() * 0.5 ),
fft , samplerate );
computePeakBand(m_eqControls.m_para1FreqModel, m_eqControls.m_para1BwModel);

m_eqControls.m_para2PeakL = m_eqControls.m_para2PeakR =
linearPeakBand( m_eqControls.m_para2FreqModel.value()
* ( 1 - m_eqControls.m_para2BwModel.value() * 0.5 ),
m_eqControls.m_para2FreqModel.value()
* ( 1 + m_eqControls.m_para2BwModel.value() * 0.5 ),
fft , samplerate );
computePeakBand(m_eqControls.m_para2FreqModel, m_eqControls.m_para2BwModel);

m_eqControls.m_para3PeakL = m_eqControls.m_para3PeakR =
linearPeakBand( m_eqControls.m_para3FreqModel.value()
* ( 1 - m_eqControls.m_para3BwModel.value() * 0.5 ),
m_eqControls.m_para3FreqModel.value()
* ( 1 + m_eqControls.m_para3BwModel.value() * 0.5 ),
fft , samplerate );
computePeakBand(m_eqControls.m_para3FreqModel, m_eqControls.m_para3BwModel);

m_eqControls.m_para4PeakL = m_eqControls.m_para4PeakR =
linearPeakBand( m_eqControls.m_para4FreqModel.value()
* ( 1 - m_eqControls.m_para4BwModel.value() * 0.5 ),
m_eqControls.m_para4FreqModel.value()
* ( 1 + m_eqControls.m_para4BwModel.value() * 0.5 ),
fft , samplerate );
computePeakBand(m_eqControls.m_para4FreqModel, m_eqControls.m_para4BwModel);

m_eqControls.m_highShelfPeakL = m_eqControls.m_highShelfPeakR =
linearPeakBand( m_eqControls.m_highShelfFreqModel.value(),
linearPeakBand(m_eqControls.m_highShelfFreqModel.value(),
m_eqControls.m_highShelfFreqModel.value()
* ( 1 + m_eqControls.m_highShelfResModel.value() * 0.5 ),
fft, samplerate );
* (1 + m_eqControls.m_highShelfResModel.value() * 0.5),
fft, samplerate);
}

extern "C"
Expand Down

0 comments on commit f2d63ec

Please sign in to comment.