Fixes and improvements for FR 144 (SF version). Tested and working.

This commit is contained in:
Johannes Lorenz committed 2014-01-22 16:25:54 +01:00
1 parent 419da0715b
commit ebc111e7f7
5 files changed
+36 -38

No files matched your search

@@ -84,12 +84,17 @@ 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); }
namespace helpers
{
//! returns 1.0f if val > 0.0f, -1.0 else
inline float 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)) * helpers::sign(val);
}
//! 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,
@@ -106,16 +111,28 @@ bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
// RMS:
double sum = 0;
for( int i = 0; i < _frames; ++i )
if(c.m_absModel.value())
{
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;
for( int i = 0; i < _frames; ++i )
{
// absolute value is achieved because the squares are > 0
sum += _buf[i][0]*_buf[i][0] + _buf[i][1]*_buf[i][1];
}
}
else
{
for( int i = 0; i < _frames; ++i )
{
// the value is absolute because of squaring,
// so we need to correct it
sum += _buf[i][0]*_buf[i][0]*helpers::sign(_buf[i][0])
+ _buf[i][1]*_buf[i][1]*helpers::sign(_buf[i][1]);
}
}
// TODO: flipping this might cause clipping
// this will mute the output after the values were measured
if( c.m_muteModel.value() )
{
for( int i = 0; i < _frames; ++i )
@@ -124,7 +141,7 @@ bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
}
}
float curRMS = sqrt_neg( sum / _frames );
float curRMS = helpers::sqrt_neg( sum / _frames );
const float origRMS = curRMS;
if( !m_lastRMSavail )
@@ -135,7 +152,7 @@ bool PeakControllerEffect::processAudioBuffer( sampleFrame * _buf,
const float v = ( curRMS >= m_lastRMS ) ?
c.m_attackModel.value() :
c.m_decayModel.value();
const float a = sqrt_neg( sqrt_neg( v ) );
const float a = helpers::sqrt_neg( helpers::sqrt_neg( v ) );
curRMS = (1-a)*curRMS + a*m_lastRMS;
const float amount = c.m_amountModel.value() * c.m_amountMultModel.value();
@@ -153,16 +170,6 @@ 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();
}