The delay buffer now resizes on sample rate change.
tidy up formatting
This commit is contained in:
@@ -29,21 +29,21 @@
|
||||
#include "engine.h"
|
||||
#include "song.h"
|
||||
|
||||
DelayControls::DelayControls(DelayEffect* effect):
|
||||
DelayControls::DelayControls( DelayEffect* effect ):
|
||||
EffectControls( effect ),
|
||||
m_effect ( effect ),
|
||||
m_delayTimeModel( 2.0, 0.01, 20.0, 0.0001, 20000.0, this, tr( "Delay Samples" )) ,
|
||||
m_feedbackModel(0.0f,0.0f,1.0f,0.01f,this,tr( "Feedback" ) ),
|
||||
m_lfoTimeModel(2.0, 0.01, 20.0, 0.0001, 20000.0, this, tr( "Lfo Frequency" ) ),
|
||||
m_lfoAmountModel(0.0f,0.0f,0.5f,0.01f, this, tr ( "Lfo Amount" ) )
|
||||
m_lfoAmountModel(0.0f,0.0f,0.1f,0.0001f, this, tr ( "Lfo Amount" ) )
|
||||
{
|
||||
//used to setup the controls
|
||||
connect( engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( changeSampleRate() ) );
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DelayControls::loadSettings(const QDomElement &_this)
|
||||
void DelayControls::loadSettings( const QDomElement &_this )
|
||||
{
|
||||
m_delayTimeModel.loadSettings(_this, "DelayTimeSamples" );
|
||||
m_feedbackModel.loadSettings( _this, "FeebackAmount" );
|
||||
@@ -54,12 +54,19 @@ void DelayControls::loadSettings(const QDomElement &_this)
|
||||
|
||||
|
||||
|
||||
void DelayControls::saveSettings(QDomDocument& doc, QDomElement& _this)
|
||||
void DelayControls::saveSettings( QDomDocument& doc, QDomElement& _this )
|
||||
{
|
||||
m_delayTimeModel.saveSettings( doc, _this, "DelayTimeSamples");
|
||||
m_feedbackModel.saveSettings( doc, _this ,"FeebackAmount");
|
||||
m_lfoTimeModel.saveSettings( doc, _this, "LfoFrequency");
|
||||
m_lfoAmountModel.saveSettings( doc, _this ,"LfoAmount");
|
||||
m_delayTimeModel.saveSettings( doc, _this, "DelayTimeSamples" );
|
||||
m_feedbackModel.saveSettings( doc, _this ,"FeebackAmount" );
|
||||
m_lfoTimeModel.saveSettings( doc, _this, "LfoFrequency" );
|
||||
m_lfoAmountModel.saveSettings( doc, _this ,"LfoAmount" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DelayControls::changeSampleRate()
|
||||
{
|
||||
m_effect->changeSampleRate();
|
||||
}
|
||||
|
||||
#include "moc_delaycontrols.cxx"
|
||||
|
||||
@@ -55,6 +55,9 @@ public:
|
||||
return new DelayControlsDialog( this );
|
||||
}
|
||||
|
||||
private slots:
|
||||
void changeSampleRate();
|
||||
|
||||
private:
|
||||
DelayEffect* m_effect;
|
||||
TempoSyncKnobModel m_delayTimeModel;
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
|
||||
|
||||
DelayControlsDialog::DelayControlsDialog(DelayControls *controls) :
|
||||
DelayControlsDialog::DelayControlsDialog( DelayControls *controls ) :
|
||||
EffectControlDialog( controls )
|
||||
{
|
||||
setAutoFillBackground( true );
|
||||
@@ -46,25 +46,25 @@ DelayControlsDialog::DelayControlsDialog(DelayControls *controls) :
|
||||
sampleDelayKnob->setLabel( tr( "Delay" ) );
|
||||
sampleDelayKnob->setHintText( tr( "Delay Time Samples:" ) + " ", "" );
|
||||
|
||||
knob * feedbackKnob = new knob( knobBright_26, this);
|
||||
knob * feedbackKnob = new knob( knobBright_26, this );
|
||||
feedbackKnob->move( 60,30 );
|
||||
feedbackKnob->setVolumeKnob(true);
|
||||
feedbackKnob->setVolumeKnob( true) ;
|
||||
feedbackKnob->setModel( &controls->m_feedbackModel);
|
||||
feedbackKnob->setLabel( tr( "Feedback" ) );
|
||||
feedbackKnob->setHintText( tr ( "Feedback Amount:" ) + " ", "");
|
||||
feedbackKnob->setHintText( tr ( "Feedback Amount:" ) + " ", "" );
|
||||
|
||||
TempoSyncKnob * lfoFreqKnob = new TempoSyncKnob( knobBright_26, this);
|
||||
TempoSyncKnob * lfoFreqKnob = new TempoSyncKnob( knobBright_26, this );
|
||||
lfoFreqKnob->move( 20,80 );
|
||||
lfoFreqKnob->setVolumeKnob(false);
|
||||
lfoFreqKnob->setModel( &controls->m_lfoTimeModel);
|
||||
lfoFreqKnob->setVolumeKnob( false );
|
||||
lfoFreqKnob->setModel( &controls->m_lfoTimeModel );
|
||||
lfoFreqKnob->setLabel( tr( "Lfo Hz" ) );
|
||||
lfoFreqKnob->setHintText( tr ( "Lfo Hz:" ) + " ", "");
|
||||
lfoFreqKnob->setHintText( tr ( "Lfo Hz:" ) + " ", "" );
|
||||
|
||||
knob * lfoAmtKnob = new knob( knobBright_26, this);
|
||||
knob * lfoAmtKnob = new knob( knobBright_26, this );
|
||||
lfoAmtKnob->move( 60,80 );
|
||||
lfoAmtKnob->setVolumeKnob(true);
|
||||
lfoAmtKnob->setModel( &controls->m_lfoAmountModel);
|
||||
lfoAmtKnob->setVolumeKnob( true );
|
||||
lfoAmtKnob->setModel( &controls->m_lfoAmountModel );
|
||||
lfoAmtKnob->setLabel( tr( "Lfo Amt" ) );
|
||||
lfoAmtKnob->setHintText( tr ( "Lfo Amt:" ) + " ", "");
|
||||
lfoAmtKnob->setHintText( tr ( "Lfo Amt:" ) + " ", "" );
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class DelayControls;
|
||||
class DelayControlsDialog : public EffectControlDialog
|
||||
{
|
||||
public:
|
||||
DelayControlsDialog(DelayControls* controls );
|
||||
DelayControlsDialog( DelayControls* controls );
|
||||
virtual ~DelayControlsDialog()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -51,9 +51,8 @@ DelayEffect::DelayEffect( Model* parent, const Plugin::Descriptor::SubPluginFeat
|
||||
m_delayControls( this )
|
||||
{
|
||||
m_delay = 0;
|
||||
m_delay = new StereoDelay( 192000 * 20 );
|
||||
m_delay = new StereoDelay( 20, engine::mixer()->processingSampleRate() );
|
||||
m_lfo = new Lfo( engine::mixer()->processingSampleRate() );
|
||||
connect( engine::mixer(), SIGNAL( sampleRateChanged() ), this, SLOT( sampleRateChanged() ) );
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +73,7 @@ DelayEffect::~DelayEffect()
|
||||
|
||||
|
||||
|
||||
bool DelayEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frames)
|
||||
bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
|
||||
{
|
||||
if( !isEnabled() || !isRunning () )
|
||||
{
|
||||
@@ -103,12 +102,10 @@ bool DelayEffect::processAudioBuffer(sampleFrame* buf, const fpp_t frames)
|
||||
return isRunning();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DelayEffect::sampleRateChanged()
|
||||
void DelayEffect::changeSampleRate()
|
||||
{
|
||||
m_lfo->setSamplerate(engine::mixer()->processingSampleRate());
|
||||
m_lfo->setSampleRate( engine::mixer()->processingSampleRate() );
|
||||
m_delay->setSampleRate( engine::mixer()->processingSampleRate() );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -35,14 +35,12 @@ class DelayEffect : public Effect
|
||||
public:
|
||||
DelayEffect(Model* parent , const Descriptor::SubPluginFeatures::Key* key );
|
||||
virtual ~DelayEffect();
|
||||
virtual bool processAudioBuffer( sampleFrame* buf, const fpp_t frames);
|
||||
virtual bool processAudioBuffer( sampleFrame* buf, const fpp_t frames );
|
||||
virtual EffectControls* controls()
|
||||
{
|
||||
return &m_delayControls;
|
||||
}
|
||||
|
||||
private slots:
|
||||
void sampleRateChanged();
|
||||
void changeSampleRate();
|
||||
|
||||
private:
|
||||
DelayControls m_delayControls;
|
||||
|
||||
@@ -44,7 +44,7 @@ float Lfo::tick()
|
||||
|
||||
if( m_amplitude > 0.0001 )
|
||||
{
|
||||
return ( ( output + 1.0 ) * 0.5 ) * m_amplitude;
|
||||
return ( ( output * m_amplitude + 1.0 ) * 0.5 ) ;
|
||||
} else
|
||||
{
|
||||
return 1;
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
|
||||
|
||||
|
||||
inline void setSamplerate ( int samplerate )
|
||||
inline void setSampleRate ( int samplerate )
|
||||
{
|
||||
m_samplerate = samplerate;
|
||||
m_twoPiOverSr = F_2PI / samplerate;
|
||||
|
||||
@@ -27,15 +27,15 @@
|
||||
#include "lmms_basics.h"
|
||||
|
||||
|
||||
StereoDelay::StereoDelay( int maxLength )
|
||||
StereoDelay::StereoDelay( int maxLength, int sampleRate )
|
||||
{
|
||||
m_buffer = 0;
|
||||
m_buffer = new sampleFrame[maxLength];
|
||||
m_maxLength = maxLength;
|
||||
m_maxLength = maxLength * sampleRate;
|
||||
m_length = m_maxLength;
|
||||
|
||||
m_index = 0;
|
||||
m_feedback = 0.0f;
|
||||
// setLength( 0 );
|
||||
setSampleRate( sampleRate );
|
||||
}
|
||||
|
||||
|
||||
@@ -67,5 +67,19 @@ void StereoDelay::tick( sampleFrame frame )
|
||||
|
||||
|
||||
|
||||
void StereoDelay::setSampleRate( int sampleRate )
|
||||
{
|
||||
if( m_buffer )
|
||||
{
|
||||
delete m_buffer;
|
||||
}
|
||||
|
||||
|
||||
m_buffer = new sampleFrame[sampleRate * m_maxLength];
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
class StereoDelay
|
||||
{
|
||||
public:
|
||||
StereoDelay( int maxLength );
|
||||
StereoDelay( int maxLength, int sampleRate );
|
||||
~StereoDelay();
|
||||
inline void setLength( int length )
|
||||
{
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
}
|
||||
|
||||
void tick( sampleFrame frame );
|
||||
void setSampleRate( int sampleRate );
|
||||
|
||||
private:
|
||||
sampleFrame* m_buffer;
|
||||
int m_maxLength;
|
||||
|
||||
Reference in New Issue
Block a user