Revert "Revert "Extensions for peak controller. Fulfills request 144.""
Now that we solved the problem with wrong default values in newly
introduced models when loading older projects we can safely implement
the new PeakController features.
This reverts commit 9cb52ccf0d.
This commit is contained in:
1 parent
44d0e7a48f
commit
7644d2c559
6 files changed
+76
-11
No files matched your search
@@ -64,6 +64,7 @@ PeakControllerEffect::PeakControllerEffect(
|
||||
m_peakControls( this ),
|
||||
m_lastSample( 0 ),
|
||||
m_lastRMS( -1 ),
|
||||
m_lastRMSavail(false),
|
||||
m_autoController( NULL )
|
||||
{
|
||||
m_autoController = new PeakController( engine::getSong(), this );
|
||||
@@ -83,13 +84,19 @@ PeakControllerEffect::~PeakControllerEffect()
|
||||
}
|
||||
}
|
||||
|
||||
//! returns 1.0f if val > 0.0f, -1.0 else
|
||||
inline float my_sign(float val) { return -1.0f + 2.0f * (val > 0.0f); }
|
||||
|
||||
//! if val >= 0.0f, returns sqrtf(val), else: -sqrtf(-val)
|
||||
inline float sqrt_neg(float val) {
|
||||
return sqrtf(fabs(val)) * my_sign(val);
|
||||
}
|
||||
|
||||
bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
|
||||
const fpp_t _frames )
|
||||
{
|
||||
PeakControllerEffectControls & c = m_peakControls;
|
||||
|
||||
|
||||
// This appears to be used for determining whether or not to continue processing
|
||||
// audio with this effect
|
||||
if( !isEnabled() || !isRunning() )
|
||||
@@ -101,7 +108,12 @@ bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
|
||||
double sum = 0;
|
||||
for( int i = 0; i < _frames; ++i )
|
||||
{
|
||||
sum += _buf[i][0]*_buf[i][0] + _buf[i][1]*_buf[i][1];
|
||||
float sign_0 = (c.m_absModel.value())
|
||||
? 1.0f : my_sign(_buf[i][0]);
|
||||
float sign_1 = (c.m_absModel.value())
|
||||
? 1.0f : my_sign(_buf[i][1]);
|
||||
sum += _buf[i][0]*_buf[i][0]*sign_0
|
||||
+ _buf[i][1]*_buf[i][1]*sign_1;
|
||||
}
|
||||
|
||||
if( c.m_muteModel.value() )
|
||||
@@ -112,19 +124,22 @@ bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
|
||||
}
|
||||
}
|
||||
|
||||
float curRMS = sqrtf( sum / _frames );
|
||||
float curRMS = sqrt_neg( sum / _frames );
|
||||
const float origRMS = curRMS;
|
||||
if( m_lastRMS < 0 )
|
||||
|
||||
if( !m_lastRMSavail )
|
||||
{
|
||||
m_lastRMSavail = true;
|
||||
m_lastRMS = curRMS;
|
||||
}
|
||||
const float v = ( curRMS >= m_lastRMS ) ?
|
||||
c.m_attackModel.value() :
|
||||
c.m_decayModel.value();
|
||||
const float a = sqrtf( sqrtf( v ) );
|
||||
const float a = sqrt_neg( sqrt_neg( v ) );
|
||||
curRMS = (1-a)*curRMS + a*m_lastRMS;
|
||||
|
||||
m_lastSample = c.m_baseModel.value() + c.m_amountModel.value()*curRMS;
|
||||
const float amount = c.m_amountModel.value() * c.m_amountMultModel.value();
|
||||
m_lastSample = c.m_baseModel.value() + amount*curRMS;
|
||||
m_lastRMS = curRMS;
|
||||
|
||||
// on greater buffer sizes our LP is updated less frequently, therfore
|
||||
@@ -138,6 +153,16 @@ bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
|
||||
|
||||
//checkGate( out_sum / _frames );
|
||||
|
||||
// finally, mute the output if wanted
|
||||
// TODO: avoid clips?
|
||||
if( c.m_muteOutputModel.value() )
|
||||
{
|
||||
for( int i = 0; i < _frames; ++i )
|
||||
{
|
||||
_buf[i][0] = _buf[i][1] = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
return isRunning();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user