Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion include/PeakController.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public slots:
static int m_loadCount;
static bool m_buggedFile;

float m_coeff;
float m_attackCoeff;
float m_decayCoeff;
bool m_coeffNeedsUpdate;
} ;

Expand Down
12 changes: 1 addition & 11 deletions plugins/PeakControllerEffect/PeakControllerEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,8 @@ Effect::ProcessStatus PeakControllerEffect::processImpl(SampleFrame* buf, const
float curRMS = sqrt_neg(sum / frames);
const float tres = c.m_tresholdModel.value();
const float amount = c.m_amountModel.value() * c.m_amountMultModel.value();
const float attack = 1.0f - c.m_attackModel.value();
const float decay = 1.0f - c.m_decayModel.value();

curRMS = qAbs( curRMS ) < tres ? 0.0f : curRMS;
float target = c.m_baseModel.value() + amount * curRMS;
// Use decay when the volume is decreasing, attack otherwise.
// Since direction can change as often as every sampleBuffer, it's difficult
// to witness attack/decay working in isolation unless using large buffer sizes.
const float t = target < m_lastSample ? decay : attack;
// Set m_lastSample to the interpolation between itself and target.
// When t is 1.0, m_lastSample snaps to target. When t is 0.0, m_lastSample shouldn't change.
m_lastSample = std::clamp(m_lastSample + t * (target - m_lastSample), 0.0f, 1.0f);
m_lastSample = qBound( 0.0f, c.m_baseModel.value() + amount * curRMS, 1.0f );

return ProcessStatus::Continue;
}
Expand Down
13 changes: 11 additions & 2 deletions src/core/PeakController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ void PeakController::updateValueBuffer()
{
if( m_coeffNeedsUpdate )
{
m_coeff = 100.0f / Engine::audioEngine()->outputSampleRate();
const float ratio = 44100.0f / Engine::audioEngine()->outputSampleRate();
m_attackCoeff = 1.0f - powf( 2.0f, -0.3f * ( 1.0f - m_peakEffect->attackModel()->value() ) * ratio );
m_decayCoeff = 1.0f - powf( 2.0f, -0.3f * ( 1.0f - m_peakEffect->decayModel()->value() ) * ratio );
m_coeffNeedsUpdate = false;
}

Expand All @@ -95,7 +97,14 @@ void PeakController::updateValueBuffer()
for( f_cnt_t f = 0; f < frames; ++f )
{
const float diff = ( targetSample - m_currentSample );
m_currentSample += diff * m_coeff;
if( m_currentSample < targetSample ) // going up...
{
m_currentSample += diff * m_attackCoeff;
}
else if( m_currentSample > targetSample ) // going down
{
m_currentSample += diff * m_decayCoeff;
}
values[f] = m_currentSample;
}
}
Expand Down
Loading