Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small bug fix to the StereoEnhancer effect and Gain knob #5956

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 21 additions & 8 deletions plugins/StereoEnhancer/StereoEnhancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ StereoEnhancerEffect::StereoEnhancerEffect(
m_seFX( DspEffectLibrary::StereoEnhancer( 0.0f ) ),
m_delayBuffer( new sampleFrame[DEFAULT_BUFFER_SIZE] ),
m_currFrame( 0 ),
m_bbControls( this )
m_bbControls(this),
m_bufferIsClear(true)
{
// TODO: Make m_delayBuffer customizable?
clearMyBuffer();
Expand Down Expand Up @@ -90,16 +91,31 @@ bool StereoEnhancerEffect::processAudioBuffer( sampleFrame * _buf,
// audio with this effect
double out_sum = 0.0;

if (!isRunning() && !m_bufferIsClear)
{
clearMyBuffer();
}

if( !isEnabled() || !isRunning() )
{
return( false );
}

// We are affecting the buffer, so we mark it as not clear
m_bufferIsClear = false;

const float d = dryLevel();
const float w = wetLevel();
float gain = m_bbControls.m_outputGain.value();
const ValueBuffer* gainBuffer = m_bbControls.m_outputGain.valueBuffer();

for( fpp_t f = 0; f < _frames; ++f )
{
// If we have a sample exact buffer, use it
if (gainBuffer)
{
gain = gainBuffer->value(f);
}

// copy samples into the delay buffer
m_delayBuffer[m_currFrame][0] = _buf[f][0];
Expand All @@ -122,8 +138,8 @@ bool StereoEnhancerEffect::processAudioBuffer( sampleFrame * _buf,

m_seFX.nextSample( s[0], s[1] );

_buf[f][0] = d * _buf[f][0] + w * s[0];
_buf[f][1] = d * _buf[f][1] + w * s[1];
_buf[f][0] = (d * _buf[f][0] + w * s[0]) * gain;
_buf[f][1] = (d * _buf[f][1] + w * s[1]) * gain;
out_sum += _buf[f][0]*_buf[f][0] + _buf[f][1]*_buf[f][1];

// Update currFrame
Expand All @@ -132,10 +148,6 @@ bool StereoEnhancerEffect::processAudioBuffer( sampleFrame * _buf,
}

checkGate( out_sum / _frames );
if( !isRunning() )
{
clearMyBuffer();
}

return( isRunning() );
}
Expand All @@ -152,6 +164,7 @@ void StereoEnhancerEffect::clearMyBuffer()
}

m_currFrame = 0;
m_bufferIsClear = true;
}


Expand All @@ -172,4 +185,4 @@ PLUGIN_EXPORT Plugin * lmms_plugin_main( Model * _parent, void * _data )
}


} // namespace lmms
} // namespace lmms
4 changes: 4 additions & 0 deletions plugins/StereoEnhancer/StereoEnhancer.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class StereoEnhancerEffect : public Effect

StereoEnhancerControls m_bbControls;

// Variable that holds whether the buffer
// needs to be cleared
bool m_bufferIsClear;

friend class StereoEnhancerControls;
} ;

Expand Down
6 changes: 6 additions & 0 deletions plugins/StereoEnhancer/StereoEnhancerControlDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ StereoEnhancerControlDialog::StereoEnhancerControlDialog(
widthKnob->setLabel( tr( "WIDTH" ) );
widthKnob->setHintText( tr( "Width:" ) , " samples" );

Knob* outputKnob = new Knob(KnobType::Bright26, this);
outputKnob->setModel(&_controls->m_outputGain);
outputKnob->setLabel(tr("GAIN"));
outputKnob->setHintText(tr("Gain:"), "");

l->addWidget( widthKnob );
l->addWidget(outputKnob);

this->setLayout(l);
}
Expand Down
5 changes: 4 additions & 1 deletion plugins/StereoEnhancer/StereoEnhancerControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ namespace lmms
StereoEnhancerControls::StereoEnhancerControls( StereoEnhancerEffect * _eff ) :
EffectControls( _eff ),
m_effect( _eff ),
m_widthModel(0.0f, 0.0f, 180.0f, 1.0f, this, tr( "Width" ) )
m_widthModel(0.0f, 0.0f, 180.0f, 1.0f, this, tr("Width")),
m_outputGain(1.0f, 0.1f, 7.0f, 0.01f, this, tr("Output Gain"))
{
connect( &m_widthModel, SIGNAL( dataChanged() ),
this, SLOT( changeWideCoeff() ) );
Expand All @@ -55,6 +56,7 @@ void StereoEnhancerControls::changeWideCoeff()
void StereoEnhancerControls::loadSettings( const QDomElement & _this )
{
m_widthModel.loadSettings( _this, "width" );
m_outputGain.loadSettings(_this, "gain");
}


Expand All @@ -64,6 +66,7 @@ void StereoEnhancerControls::saveSettings( QDomDocument & _doc,
QDomElement & _this )
{
m_widthModel.saveSettings( _doc, _this, "width" );
m_outputGain.saveSettings(_doc, _this, "gain");
}


Expand Down
5 changes: 3 additions & 2 deletions plugins/StereoEnhancer/StereoEnhancerControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class StereoEnhancerControls : public EffectControls

int controlCount() override
{
return( 1 );
return 2;
}

gui::EffectControlDialog* createView() override
Expand All @@ -66,9 +66,10 @@ private slots:
private:
StereoEnhancerEffect * m_effect;
FloatModel m_widthModel;
FloatModel m_outputGain;

friend class gui::StereoEnhancerControlDialog;

friend class StereoEnhancerEffect;
} ;


Expand Down
Loading