Skip to content

Commit

Permalink
Merge pull request LMMS#1787 from curlymorphic/xydelay
Browse files Browse the repository at this point in the history
smoothed the time parameter of the delay pluging
  • Loading branch information
diizy committed Mar 13, 2015
2 parents da66205 + 8a588d4 commit c01e4ca
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
36 changes: 30 additions & 6 deletions plugins/Delay/DelayEffect.cpp
Expand Up @@ -82,25 +82,44 @@ bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
return( false );
}
double outSum = 0.0;
const float sr = Engine::mixer()->processingSampleRate();
const float d = dryLevel();
const float w = wetLevel();
const float length = m_delayControls.m_delayTimeModel.value() * Engine::mixer()->processingSampleRate();
const float amplitude = m_delayControls.m_lfoAmountModel.value() * Engine::mixer()->processingSampleRate();
m_lfo->setFrequency( 1.0 / m_delayControls.m_lfoTimeModel.value() );
m_delay->setFeedback( m_delayControls.m_feedbackModel.value() );
sample_t dryS[2];
float lPeak = 0.0;
float rPeak = 0.0;
float length = m_delayControls.m_delayTimeModel.value();
float amplitude = m_delayControls.m_lfoAmountModel.value() * sr;
float lfoTime = 1.0 / m_delayControls.m_lfoTimeModel.value();
float feedback = m_delayControls.m_feedbackModel.value();
ValueBuffer *lengthBuffer = m_delayControls.m_delayTimeModel.valueBuffer();
ValueBuffer *feedbackBuffer = m_delayControls.m_feedbackModel.valueBuffer();
ValueBuffer *lfoTimeBuffer = m_delayControls.m_lfoTimeModel.valueBuffer();
ValueBuffer *lfoAmountBuffer = m_delayControls.m_lfoAmountModel.valueBuffer();
int lengthInc = lengthBuffer ? 1 : 0;
int amplitudeInc = lfoAmountBuffer ? 1 : 0;
int lfoTimeInc = lfoTimeBuffer ? 1 : 0;
int feedbackInc = feedbackBuffer ? 1 : 0;
float *lengthPtr = lengthBuffer ? &( lengthBuffer->values()[ 0 ] ) : &length;
float *amplitudePtr = lfoAmountBuffer ? &( lfoAmountBuffer->values()[ 0 ] ) : &amplitude;
float *lfoTimePtr = lfoTimeBuffer ? &( lfoTimeBuffer->values()[ 0 ] ) : &lfoTime;
float *feedbackPtr = feedbackBuffer ? &( feedbackBuffer->values()[ 0 ] ) : &feedback;

if( m_delayControls.m_outGainModel.isValueChanged() )
{
m_outGain = dbvToAmp( m_delayControls.m_outGainModel.value() );
}
int sampleLength;
for( fpp_t f = 0; f < frames; ++f )
{
m_currentLength = linearInterpolate( length, m_currentLength, 0.9999 );
dryS[0] = buf[f][0];
dryS[1] = buf[f][1];
m_delay->setLength( ( float )m_currentLength + ( amplitude * ( float )m_lfo->tick() ) );

m_delay->setFeedback( *feedbackPtr );
m_lfo->setFrequency( *lfoTimePtr );
sampleLength = *lengthPtr * Engine::mixer()->processingSampleRate();
m_currentLength = linearInterpolate( sampleLength, m_currentLength, 0.9999 );
m_delay->setLength( m_currentLength + ( *amplitudePtr * ( float )m_lfo->tick() ) );
m_delay->tick( buf[f] );

buf[f][0] *= m_outGain;
Expand All @@ -112,6 +131,11 @@ bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
buf[f][0] = ( d * dryS[0] ) + ( w * buf[f][0] );
buf[f][1] = ( d * dryS[1] ) + ( w * buf[f][1] );
outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];

lengthPtr += lengthInc;
amplitudePtr += amplitudeInc;
lfoTimePtr += lfoTimeInc;
feedbackPtr += feedbackInc;
}
checkGate( outSum / frames );
m_delayControls.m_outPeakL = lPeak;
Expand Down
1 change: 1 addition & 0 deletions plugins/Delay/DelayEffect.h
Expand Up @@ -29,6 +29,7 @@
#include "DelayControls.h"
#include "Lfo.h"
#include "StereoDelay.h"
#include "ValueBuffer.h"

class DelayEffect : public Effect
{
Expand Down

0 comments on commit c01e4ca

Please sign in to comment.