Merge pull request #103 from JohannesLorenz/stable-0.4
Fixes and improvements for FR 144 (SF version). Tested and working.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ PeakControllerEffectControlDialog::PeakControllerEffectControlDialog(
|
||||
m_baseKnob->setHintText( tr( "Base amount:" ) + " ", "" );
|
||||
|
||||
m_amountKnob = new knob( knobBright_26, this );
|
||||
m_amountKnob->setLabel( tr( "AMT" ) );
|
||||
m_amountKnob->setLabel( tr( "AMNT" ) );
|
||||
m_amountKnob->setModel( &_controls->m_amountModel );
|
||||
m_amountKnob->setHintText( tr( "Modulation amount:" ) + " ", "" );
|
||||
|
||||
@@ -66,12 +66,12 @@ PeakControllerEffectControlDialog::PeakControllerEffectControlDialog(
|
||||
m_amountMultKnob->setHintText( tr( "Amount Multiplicator:" ) + " ", "" );
|
||||
|
||||
m_attackKnob = new knob( knobBright_26, this );
|
||||
m_attackKnob->setLabel( tr( "ATTCK" ) );
|
||||
m_attackKnob->setLabel( tr( "ATCK" ) );
|
||||
m_attackKnob->setModel( &_controls->m_attackModel );
|
||||
m_attackKnob->setHintText( tr( "Attack:" ) + " ", "" );
|
||||
|
||||
m_decayKnob = new knob( knobBright_26, this );
|
||||
m_decayKnob->setLabel( tr( "DECAY" ) );
|
||||
m_decayKnob->setLabel( tr( "DCAY" ) );
|
||||
m_decayKnob->setModel( &_controls->m_decayModel );
|
||||
m_decayKnob->setHintText( tr( "Release:" ) + " ", "" );
|
||||
|
||||
@@ -88,15 +88,11 @@ PeakControllerEffectControlDialog::PeakControllerEffectControlDialog(
|
||||
m_muteLed = new ledCheckBox( "Mute Effect", this );
|
||||
m_muteLed->setModel( &_controls->m_muteModel );
|
||||
|
||||
m_absLed = new ledCheckBox( "Abs Value", this );
|
||||
m_absLed = new ledCheckBox( "Absolute Value", this );
|
||||
m_absLed->setModel( &_controls->m_absModel );
|
||||
|
||||
m_muteOutputLed = new ledCheckBox( "Mute Output", this );
|
||||
m_muteOutputLed->setModel( &_controls->m_muteOutputModel );
|
||||
|
||||
l2->addWidget( m_muteLed );
|
||||
l2->addWidget( m_absLed );
|
||||
l2->addWidget( m_muteOutputLed );
|
||||
l2->addStretch(); // expand, so other widgets have minimum height
|
||||
tl->addLayout( l2 );
|
||||
|
||||
|
||||
@@ -52,7 +52,6 @@ protected:
|
||||
|
||||
ledCheckBox * m_absLed;
|
||||
knob * m_amountMultKnob;
|
||||
ledCheckBox * m_muteOutputLed;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
@@ -41,8 +41,7 @@ PeakControllerEffectControls( PeakControllerEffect * _eff ) :
|
||||
m_decayModel( 0, 0, 0.999, 0.001, this, tr( "Release" ) ),
|
||||
m_muteModel( false, this, tr( "Mute output" ) ),
|
||||
m_absModel( true, this, tr("Abs Value") ),
|
||||
m_amountMultModel( 1.0, 0, 32, 0.2, this, tr("Amount Multiplicator") ),
|
||||
m_muteOutputModel( false, this, tr("Mute Output") )
|
||||
m_amountMultModel( 1.0, 0, 32, 0.2, this, tr("Amount Multiplicator") )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -59,7 +58,6 @@ void PeakControllerEffectControls::loadSettings( const QDomElement & _this )
|
||||
|
||||
m_absModel.loadSettings( _this, "abs" );
|
||||
m_amountMultModel.loadSettings( _this, "amountmult" );
|
||||
m_muteOutputModel.loadSettings( _this, "muteout" );
|
||||
|
||||
int effectId = _this.attribute( "effectId" ).toInt();
|
||||
if( effectId > PeakController::s_lastEffectId )
|
||||
@@ -92,7 +90,6 @@ void PeakControllerEffectControls::saveSettings( QDomDocument & _doc,
|
||||
|
||||
m_absModel.saveSettings( _doc, _this, "abs" );
|
||||
m_amountMultModel.saveSettings( _doc, _this, "amountmult" );
|
||||
m_muteOutputModel.saveSettings( _doc, _this, "muteout" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ private:
|
||||
BoolModel m_muteModel;
|
||||
BoolModel m_absModel;
|
||||
FloatModel m_amountMultModel;
|
||||
BoolModel m_muteOutputModel;
|
||||
|
||||
friend class PeakControllerEffectControlDialog;
|
||||
friend class PeakControllerEffect;
|
||||
|
||||
Reference in New Issue
Block a user