bool bassBoosterEffect::processAudioBuffer( sampleFrame * _buf,
							const fpp_t _frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return( false );
	}

	double out_sum = 0.0;
	const float d = dryLevel();
	const float w = wetLevel();
	for( fpp_t f = 0; f < _frames; ++f )
	{
		sample_t s[2] = { _buf[f][0], _buf[f][1] };
		m_bbFX.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];

		out_sum += _buf[f][0]*_buf[f][0] + _buf[f][1]*_buf[f][1];
	}

	checkGate( out_sum / _frames );

	return( isRunning() );
}
bool BassBoosterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return( false );
	}
	// check out changed controls
	if( m_frequencyChangeNeeded || m_bbControls.m_freqModel.isValueChanged() )
	{
		changeFrequency();
		m_frequencyChangeNeeded = false;
	}
	if( m_bbControls.m_gainModel.isValueChanged() ) { changeGain(); }
	if( m_bbControls.m_ratioModel.isValueChanged() ) { changeRatio(); }

	float gain = m_bbControls.m_gainModel.value();
	ValueBuffer *gainBuffer = m_bbControls.m_gainModel.valueBuffer();
	int gainInc = gainBuffer ? 1 : 0;
	float *gainPtr = gainBuffer ? &( gainBuffer->values()[ 0 ] ) : &gain;

	double outSum = 0.0;
	const float d = dryLevel();
	const float w = wetLevel();
	if( gainBuffer )
	{
		//process period using sample exact data
		for( fpp_t f = 0; f < frames; ++f )
		{
			m_bbFX.leftFX().setGain( *gainPtr );
			m_bbFX.rightFX().setGain( *gainPtr );
			outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];

			sample_t s[2] = { buf[f][0], buf[f][1] };
			m_bbFX.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];
			gainPtr += gainInc;
		}
	} else
	{
		//process period without sample exact data
		m_bbFX.leftFX().setGain( *gainPtr );
		m_bbFX.rightFX().setGain( *gainPtr );
		for( fpp_t f = 0; f < frames; ++f )
		{
			outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];

			sample_t s[2] = { buf[f][0], buf[f][1] };
			m_bbFX.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];
		}
	}

	checkGate( outSum / frames );

	return isRunning();
}
Exemple #3
0
bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
    if( !isEnabled() || !isRunning () )
    {
        return( false );
    }
    double outSum = 0.0;
    const float d = dryLevel();
    const float w = wetLevel();
    const float length = m_delayControls.m_delayTimeModel.value() * engine::mixer()->processingSampleRate();
    m_lfo->setAmplitude( m_delayControls.m_lfoAmountModel.value() );
    m_lfo->setFrequency( 1.0 / m_delayControls.m_lfoTimeModel.value() );
    m_delay->setFeedback( m_delayControls.m_feedbackModel.value() );
    sample_t dryS[2];
    for( fpp_t f = 0; f < frames; ++f )
    {
        dryS[0] = buf[f][0];
        dryS[1] = buf[f][1];
        m_delay->setLength( ( float )length * ( float )m_lfo->tick() );
        m_delay->tick( buf[f] );

        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];
    }
    checkGate( outSum / frames );
    return isRunning();
}
Exemple #4
0
bool FlangerEffect::processAudioBuffer( sampleFrame *buf, const fpp_t frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return( false );
	}
	double outSum = 0.0;
	const float d = dryLevel();
	const float w = wetLevel();
	const float length = m_flangerControls.m_delayTimeModel.value() * Engine::mixer()->processingSampleRate();
	const float noise = m_flangerControls.m_whiteNoiseAmountModel.value();
	float amplitude = m_flangerControls.m_lfoAmountModel.value() * Engine::mixer()->processingSampleRate();
	bool invertFeedback = m_flangerControls.m_invertFeedbackModel.value();
	m_lfo->setFrequency(  1.0/m_flangerControls.m_lfoFrequencyModel.value() );
	m_lDelay->setFeedback( m_flangerControls.m_feedbackModel.value() );
	m_rDelay->setFeedback( m_flangerControls.m_feedbackModel.value() );
	sample_t dryS[2];
	float leftLfo;
	float rightLfo;
	for( fpp_t f = 0; f < frames; ++f )
	{
		buf[f][0] += m_noise->tick() * noise;
		buf[f][1] += m_noise->tick() * noise;
		dryS[0] = buf[f][0];
		dryS[1] = buf[f][1];
		m_lfo->tick(&leftLfo, &rightLfo);
		m_lDelay->setLength( ( float )length + amplitude * (leftLfo+1.0)  );
		m_rDelay->setLength( ( float )length + amplitude * (rightLfo+1.0)  );
		if(invertFeedback)
		{
			m_lDelay->tick( &buf[f][1] );
			m_rDelay->tick(&buf[f][0] );
		} else
		{
			m_lDelay->tick( &buf[f][0] );
			m_rDelay->tick( &buf[f][1] );
		}

		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];
	}
	checkGate( outSum / frames );
	return isRunning();
}
Exemple #5
0
bool VstEffect::processAudioBuffer( sampleFrame * _buf, const fpp_t _frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return false;
	}

	if( m_plugin )
	{
		const float d = dryLevel();
#ifdef __GNUC__
		sampleFrame buf[_frames];
#else
		sampleFrame * buf = new sampleFrame[_frames];
#endif
		memcpy( buf, _buf, sizeof( sampleFrame ) * _frames );
		m_pluginMutex.lock();
		m_plugin->process( buf, buf );
		m_pluginMutex.unlock();

		double out_sum = 0.0;
		const float w = wetLevel();
		for( fpp_t f = 0; f < _frames; ++f )
		{
			_buf[f][0] = w*buf[f][0] + d*_buf[f][0];
			_buf[f][1] = w*buf[f][1] + d*_buf[f][1];
		}
		for( fpp_t f = 0; f < _frames; ++f )
		{
			out_sum += _buf[f][0]*_buf[f][0] + _buf[f][1]*_buf[f][1];
		}
#ifndef __GNUC__
		delete[] buf;
#endif

		checkGate( out_sum / _frames );
	}
	return isRunning();
}
Exemple #6
0
bool DelayEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return( false );
	}
	double outSum = 0.0;
	const float sr = Engine::mixer()->processingSampleRate();
	const float d = dryLevel();
	const float w = wetLevel();
	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 = dbfsToAmp( m_delayControls.m_outGainModel.value() );
	}
	int sampleLength;
	for( fpp_t f = 0; f < frames; ++f )
	{
		dryS[0] = buf[f][0];
		dryS[1] = buf[f][1];

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

		buf[f][0] *= m_outGain;
		buf[f][1] *= m_outGain;

		lPeak = buf[f][0] > lPeak ? buf[f][0] : lPeak;
		rPeak = buf[f][1] > rPeak ? buf[f][1] : rPeak;

		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;
	m_delayControls.m_outPeakR = rPeak;

	return isRunning();
}
Exemple #7
0
bool CrossoverEQEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return( false );
	}
	
	// filters update
	if( m_needsUpdate || m_controls.m_xover12.isValueChanged() )
	{
		m_lp1.setLowpass( m_controls.m_xover12.value() );
		m_lp1.clearHistory();
		m_hp2.setHighpass( m_controls.m_xover12.value() );
		m_hp2.clearHistory();
	}
	if( m_needsUpdate || m_controls.m_xover23.isValueChanged() )
	{
		m_lp2.setLowpass( m_controls.m_xover23.value() );
		m_lp2.clearHistory();
		m_hp3.setHighpass( m_controls.m_xover23.value() );
		m_hp3.clearHistory();
	}
	if( m_needsUpdate || m_controls.m_xover34.isValueChanged() )
	{
		m_lp3.setLowpass( m_controls.m_xover34.value() );
		m_lp3.clearHistory();
		m_hp4.setHighpass( m_controls.m_xover34.value() );
		m_hp4.clearHistory();
	}
	
	// gain values update
	if( m_needsUpdate || m_controls.m_gain1.isValueChanged() )
	{
		m_gain1 = dbfsToAmp( m_controls.m_gain1.value() );
	}
	if( m_needsUpdate || m_controls.m_gain2.isValueChanged() )
	{
		m_gain2 = dbfsToAmp( m_controls.m_gain2.value() );
	}
	if( m_needsUpdate || m_controls.m_gain3.isValueChanged() )
	{
		m_gain3 = dbfsToAmp( m_controls.m_gain3.value() );
	}
	if( m_needsUpdate || m_controls.m_gain4.isValueChanged() )
	{
		m_gain4 = dbfsToAmp( m_controls.m_gain4.value() );
	}
	
	// mute values update
	const bool mute1 = m_controls.m_mute1.value();
	const bool mute2 = m_controls.m_mute2.value();
	const bool mute3 = m_controls.m_mute3.value();
	const bool mute4 = m_controls.m_mute4.value();
	
	m_needsUpdate = false;
	
	memset( m_work, 0, sizeof( sampleFrame ) * frames );
	
	// run temp bands
	for( int f = 0; f < frames; ++f )
	{
		m_tmp1[f][0] = m_lp2.update( buf[f][0], 0 );
		m_tmp1[f][1] = m_lp2.update( buf[f][1], 1 );
		m_tmp2[f][0] = m_hp3.update( buf[f][0], 0 );
		m_tmp2[f][1] = m_hp3.update( buf[f][1], 1 );
	}

	// run band 1
	if( mute1 )
	{
		for( int f = 0; f < frames; ++f )
		{
			m_work[f][0] += m_lp1.update( m_tmp1[f][0], 0 ) * m_gain1;
			m_work[f][1] += m_lp1.update( m_tmp1[f][1], 1 ) * m_gain1;
		}
	}
	
	// run band 2
	if( mute2 )
	{
		for( int f = 0; f < frames; ++f )
		{
			m_work[f][0] += m_hp2.update( m_tmp1[f][0], 0 ) * m_gain2;
			m_work[f][1] += m_hp2.update( m_tmp1[f][1], 1 ) * m_gain2;
		}
	}
	
	// run band 3
	if( mute3 )
	{
		for( int f = 0; f < frames; ++f )
		{
			m_work[f][0] += m_lp3.update( m_tmp2[f][0], 0 ) * m_gain3;
			m_work[f][1] += m_lp3.update( m_tmp2[f][1], 1 ) * m_gain3;
		}
	}
	
	// run band 4
	if( mute4 )
	{
		for( int f = 0; f < frames; ++f )
		{
			m_work[f][0] += m_hp4.update( m_tmp2[f][0], 0 ) * m_gain4;
			m_work[f][1] += m_hp4.update( m_tmp2[f][1], 1 ) * m_gain4;
		}
	}
	
	const float d = dryLevel();
	const float w = wetLevel();
	double outSum = 0.0;
	for( int f = 0; f < frames; ++f )
	{
		outSum = buf[f][0] * buf[f][0] + buf[f][1] * buf[f][1];
		buf[f][0] = d * buf[f][0] + w * m_work[f][0];
		buf[f][1] = d * buf[f][1] + w * m_work[f][1];
	}
	
	checkGate( outSum );
	
	return isRunning();
}
bool LadspaEffect::processAudioBuffer( sampleFrame * _buf, 
							const fpp_t _frames )
{
	m_pluginMutex.lock();
	if( !isOkay() || dontRun() || !isRunning() || !isEnabled() )
	{
		m_pluginMutex.unlock();
		return( false );
	}

	int frames = _frames;
	sampleFrame * o_buf = NULL;
	sampleFrame sBuf [_frames];

	if( m_maxSampleRate < engine::mixer()->processingSampleRate() )
	{
		o_buf = _buf;
		_buf = &sBuf[0];
		sampleDown( o_buf, _buf, m_maxSampleRate );
		frames = _frames * m_maxSampleRate /
				engine::mixer()->processingSampleRate();
	}

	// Copy the LMMS audio buffer to the LADSPA input buffer and initialize
	// the control ports.  Need to change this to handle non-in-place-broken
	// plugins--would speed things up to use the same buffer for both
	// LMMS and LADSPA.
	ch_cnt_t channel = 0;
	for( ch_cnt_t proc = 0; proc < processorCount(); ++proc )
	{
		for( int port = 0; port < m_portCount; ++port )
		{
			port_desc_t * pp = m_ports.at( proc ).at( port );
			switch( pp->rate )
			{
				case CHANNEL_IN:
					for( fpp_t frame = 0; 
						frame < frames; ++frame )
					{
						pp->buffer[frame] = 
							_buf[frame][channel];
					}
					++channel;
					break;
				case AUDIO_RATE_INPUT:
					pp->value = static_cast<LADSPA_Data>( 
										pp->control->value() / pp->scale );
					// This only supports control rate ports, so the audio rates are
					// treated as though they were control rate by setting the
					// port buffer to all the same value.
					for( fpp_t frame = 0; 
						frame < frames; ++frame )
					{
						pp->buffer[frame] = 
							pp->value;
					}
					break;
				case CONTROL_RATE_INPUT:
					if( pp->control == NULL )
					{
						break;
					}
					pp->value = static_cast<LADSPA_Data>( 
										pp->control->value() / pp->scale );
					pp->buffer[0] = 
						pp->value;
					break;
				case CHANNEL_OUT:
				case AUDIO_RATE_OUTPUT:
				case CONTROL_RATE_OUTPUT:
					break;
				default:
					break;
			}
		}
	}

	// Process the buffers.
	for( ch_cnt_t proc = 0; proc < processorCount(); ++proc )
	{
		(m_descriptor->run)( m_handles[proc], frames );
	}

	// Copy the LADSPA output buffers to the LMMS buffer.
	double out_sum = 0.0;
	channel = 0;
	const float d = dryLevel();
	const float w = wetLevel();
	for( ch_cnt_t proc = 0; proc < processorCount(); ++proc )
	{
		for( int port = 0; port < m_portCount; ++port )
		{
			port_desc_t * pp = m_ports.at( proc ).at( port );
			switch( pp->rate )
			{
				case CHANNEL_IN:
				case AUDIO_RATE_INPUT:
				case CONTROL_RATE_INPUT:
					break;
				case CHANNEL_OUT:
					for( fpp_t frame = 0; 
						frame < frames; ++frame )
					{
						_buf[frame][channel] = d * _buf[frame][channel] + w * pp->buffer[frame];
						out_sum += _buf[frame][channel] * _buf[frame][channel];
					}
					++channel;
					break;
				case AUDIO_RATE_OUTPUT:
				case CONTROL_RATE_OUTPUT:
					break;
				default:
					break;
			}
		}
	}

	if( o_buf != NULL )
	{
		sampleBack( _buf, o_buf, m_maxSampleRate );
	}

	checkGate( out_sum / frames );


	bool is_running = isRunning();
	m_pluginMutex.unlock();
	return( is_running );
}
Exemple #9
0
bool AmplifierEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return( false );
	}

	double outSum = 0.0;
	const float d = dryLevel();
	const float w = wetLevel();
	
	ValueBuffer * volBuf = m_ampControls.m_volumeModel.valueBuffer();
	ValueBuffer * panBuf = m_ampControls.m_panModel.valueBuffer();
	ValueBuffer * leftBuf = m_ampControls.m_leftModel.valueBuffer();
	ValueBuffer * rightBuf = m_ampControls.m_rightModel.valueBuffer();

	for( fpp_t f = 0; f < frames; ++f )
	{
//		qDebug( "offset %d, value %f", f, m_ampControls.m_volumeModel.value( f ) );
		
		sample_t s[2] = { buf[f][0], buf[f][1] };

		// vol knob
		if( volBuf )
		{
			s[0] *= volBuf->values()[ f ] * 0.01f;
			s[1] *= volBuf->values()[ f ] * 0.01f;
		}
		else
		{
			s[0] *= m_ampControls.m_volumeModel.value() * 0.01f;
			s[1] *= m_ampControls.m_volumeModel.value() * 0.01f;
		}

		// convert pan values to left/right values
		const float pan = panBuf 
			? panBuf->values()[ f ] 
			: m_ampControls.m_panModel.value();
		const float left1 = pan <= 0
			? 1.0
			: 1.0 - pan * 0.01f;
		const float right1 = pan >= 0
			? 1.0
			: 1.0 + pan * 0.01f;

		// second stage amplification
		const float left2 = leftBuf
			? leftBuf->values()[ f ] 
			: m_ampControls.m_leftModel.value();
		const float right2 = rightBuf
			? rightBuf->values()[ f ] 
			: m_ampControls.m_rightModel.value();
			
		s[0] *= left1 * left2 * 0.01;
		s[1] *= right1 * right2 * 0.01;

		buf[f][0] = d * buf[f][0] + w * s[0];
		buf[f][1] = d * buf[f][1] + w * s[1];
		outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];
	}

	checkGate( outSum / frames );

	return isRunning();
}
Exemple #10
0
bool dynProcEffect::processAudioBuffer( sampleFrame * _buf,
							const fpp_t _frames )
{
	if( !isEnabled() || !isRunning () )
	{
//apparently we can't keep running after the decay value runs out so we'll just set the peaks to zero
		m_currentPeak[0] = m_currentPeak[1] = DYN_NOISE_FLOOR;
		return( false );
	}
	//qDebug( "%f %f", m_currentPeak[0], m_currentPeak[1] );

// variables for effect
	int i = 0;

	float sm_peak[2] = { 0.0f, 0.0f };
	float gain;

	double out_sum = 0.0;
	const float d = dryLevel();
	const float w = wetLevel();
	
	const int stereoMode = m_dpControls.m_stereomodeModel.value();
	const float inputGain = m_dpControls.m_inputModel.value();
	const float outputGain = m_dpControls.m_outputModel.value();
	
	const float * samples = m_dpControls.m_wavegraphModel.samples();

// debug code
//	qDebug( "peaks %f %f", m_currentPeak[0], m_currentPeak[1] );

	if( m_needsUpdate )
	{
		m_rms[0]->setSize( 64 * Engine::mixer()->processingSampleRate() / 44100 );
		m_rms[1]->setSize( 64 * Engine::mixer()->processingSampleRate() / 44100 );
		calcAttack();
		calcRelease();
		m_needsUpdate = false;
	}
	else
	{
		if( m_dpControls.m_attackModel.isValueChanged() )
		{
			calcAttack();
		}
		if( m_dpControls.m_releaseModel.isValueChanged() )
		{
			calcRelease();
		}
	}

	for( fpp_t f = 0; f < _frames; ++f )
	{
		double s[2] = { _buf[f][0], _buf[f][1] };

// apply input gain
		s[0] *= inputGain;
		s[1] *= inputGain;

// update peak values
		for ( i=0; i <= 1; i++ )
		{
			const double t = m_rms[i]->update( s[i] );
			if( t > m_currentPeak[i] )
			{
				m_currentPeak[i] = qMin( m_currentPeak[i] * m_attCoeff, t );
			}
			else
			if( t < m_currentPeak[i] )
			{
				m_currentPeak[i] = qMax( m_currentPeak[i] * m_relCoeff, t );
			}

			m_currentPeak[i] = qBound( DYN_NOISE_FLOOR, m_currentPeak[i], 10.0f );
		}

// account for stereo mode
		switch( stereoMode )
		{
			case dynProcControls::SM_Maximum:
			{
				sm_peak[0] = sm_peak[1] = qMax( m_currentPeak[0], m_currentPeak[1] );
				break;
			}
			case dynProcControls::SM_Average:
			{
				sm_peak[0] = sm_peak[1] = ( m_currentPeak[0] + m_currentPeak[1] ) * 0.5;
				break;
			}
			case dynProcControls::SM_Unlinked:
			{
				sm_peak[0] = m_currentPeak[0];
				sm_peak[1] = m_currentPeak[1];
				break;
			}
		}

// start effect

		for ( i=0; i <= 1; i++ )
		{
			const int lookup = static_cast<int>( sm_peak[i] * 200.0f );
			const float frac = fraction( sm_peak[i] * 200.0f );

			if( sm_peak[i] > DYN_NOISE_FLOOR )
			{
				if ( lookup < 1 )
				{
					gain = frac * samples[0];
				}
				else
				if ( lookup < 200 )
				{
					gain = linearInterpolate( samples[ lookup - 1 ],
							samples[ lookup ], frac );
				}
				else
				{
					gain = samples[199];
				};

				s[i] *= gain; 
				s[i] /= sm_peak[i];
			}
		}

// apply output gain
		s[0] *= outputGain;
		s[1] *= outputGain;

		out_sum += _buf[f][0]*_buf[f][0] + _buf[f][1]*_buf[f][1];
// mix wet/dry signals
		_buf[f][0] = d * _buf[f][0] + w * s[0];
		_buf[f][1] = d * _buf[f][1] + w * s[1];
	}

	checkGate( out_sum / _frames );

	return( isRunning() );
}
Exemple #11
0
bool DualFilterEffect::processAudioBuffer( sampleFrame* buf, const fpp_t frames )
{
	if( !isEnabled() || !isRunning () )
	{
		return( false );
	}

	double outSum = 0.0;
	const float d = dryLevel();
	const float w = wetLevel();

    if( m_dfControls.m_filter1Model.isValueChanged() || m_filter1changed )
	{
		m_filter1->setFilterType( m_dfControls.m_filter1Model.value() );
		m_filter1changed = true;
	}
    if( m_dfControls.m_filter2Model.isValueChanged() || m_filter2changed )
	{
		m_filter2->setFilterType( m_dfControls.m_filter2Model.value() );
		m_filter2changed = true;
	}

	float cut1 = m_dfControls.m_cut1Model.value();
	float res1 = m_dfControls.m_res1Model.value();
	float gain1 = m_dfControls.m_gain1Model.value();
	float cut2 = m_dfControls.m_cut2Model.value();
	float res2 = m_dfControls.m_res2Model.value();
	float gain2 = m_dfControls.m_gain2Model.value();
	float mix = m_dfControls.m_mixModel.value();

	ValueBuffer *cut1Buffer = m_dfControls.m_cut1Model.valueBuffer();
	ValueBuffer *res1Buffer = m_dfControls.m_res1Model.valueBuffer();
	ValueBuffer *gain1Buffer = m_dfControls.m_gain1Model.valueBuffer();
	ValueBuffer *cut2Buffer = m_dfControls.m_cut2Model.valueBuffer();
	ValueBuffer *res2Buffer = m_dfControls.m_res2Model.valueBuffer();
	ValueBuffer *gain2Buffer = m_dfControls.m_gain2Model.valueBuffer();
	ValueBuffer *mixBuffer = m_dfControls.m_mixModel.valueBuffer();

	int cut1Inc = cut1Buffer ? 1 : 0;
	int res1Inc = res1Buffer ? 1 : 0;
	int gain1Inc = gain1Buffer ? 1 : 0;
	int cut2Inc = cut2Buffer ? 1 : 0;
	int res2Inc = res2Buffer ? 1 : 0;
	int gain2Inc = gain2Buffer ? 1 : 0;
	int mixInc = mixBuffer ? 1 : 0;

	float *cut1Ptr = cut1Buffer ? &( cut1Buffer->values()[ 0 ] ) : &cut1;
	float *res1Ptr = res1Buffer ? &( res1Buffer->values()[ 0 ] ) : &res1;
	float *gain1Ptr = gain1Buffer ? &( gain1Buffer->values()[ 0 ] ) : &gain1;
	float *cut2Ptr = cut2Buffer ? &( cut2Buffer->values()[ 0 ] ) : &cut2;
	float *res2Ptr = res2Buffer ? &( res2Buffer->values()[ 0 ] ) : &res2;
	float *gain2Ptr = gain2Buffer ? &( gain2Buffer->values()[ 0 ] ) : &gain2;
	float *mixPtr = mixBuffer ? &( mixBuffer->values()[ 0 ] ) : &mix;

	const bool enabled1 = m_dfControls.m_enabled1Model.value();
	const bool enabled2 = m_dfControls.m_enabled2Model.value();

	
	

	// buffer processing loop
	for( fpp_t f = 0; f < frames; ++f )
	{
		// get mix amounts for wet signals of both filters
		const float mix2 = ( ( *mixPtr + 1.0f ) * 0.5f );
		const float mix1 = 1.0f - mix2;
		const float gain1 = *gain1Ptr * 0.01f;
		const float gain2 = *gain2Ptr * 0.01f;
		sample_t s[2] = { 0.0f, 0.0f };	// mix
		sample_t s1[2] = { buf[f][0], buf[f][1] };	// filter 1
		sample_t s2[2] = { buf[f][0], buf[f][1] };	// filter 2

		// update filter 1
		if( enabled1 )
		{
			//update filter 1 params here
			// recalculate only when necessary: either cut/res is changed, or the changed-flag is set (filter type or samplerate changed)
			if( ( ( *cut1Ptr != m_currentCut1 ||
				*res1Ptr != m_currentRes1 ) ) || m_filter1changed )
			{
				m_filter1->calcFilterCoeffs( *cut1Ptr, *res1Ptr );
				m_filter1changed = false;
				m_currentCut1 = *cut1Ptr;
				m_currentRes1 = *res1Ptr;
			}
			s1[0] = m_filter1->update( s1[0], 0 );
			s1[1] = m_filter1->update( s1[1], 1 );

			// apply gain
			s1[0] *= gain1;
			s1[1] *= gain1;

			// apply mix
			s[0] += ( s1[0] * mix1 );
			s[1] += ( s1[1] * mix1 );
		}

		// update filter 2
		if( enabled2 )
		{
			//update filter 2 params here
			if( ( ( *cut2Ptr != m_currentCut2 ||
								*res2Ptr != m_currentRes2 ) ) || m_filter2changed )
			{
				m_filter2->calcFilterCoeffs( *cut2Ptr, *res2Ptr );
				m_filter2changed = false;
				m_currentCut2 = *cut2Ptr;
				m_currentRes2 = *res2Ptr;
			}
			s2[0] = m_filter2->update( s2[0], 0 );
			s2[1] = m_filter2->update( s2[1], 1 );

			//apply gain
			s2[0] *= gain2;
			s2[1] *= gain2;

			// apply mix
			s[0] += ( s2[0] * mix2 );
			s[1] += ( s2[1] * mix2 );
		}
		outSum += buf[f][0]*buf[f][0] + buf[f][1]*buf[f][1];

		// do another mix with dry signal
		buf[f][0] = d * buf[f][0] + w * s[0];
		buf[f][1] = d * buf[f][1] + w * s[1];

		//increment pointers
		cut1Ptr += cut1Inc;
		res1Ptr += res1Inc;
		gain1Ptr += gain1Inc;
		cut2Ptr += cut2Inc;
		res2Ptr += res2Inc;
		gain2Ptr += gain2Inc;
		mixPtr += mixInc;
	}

	checkGate( outSum / frames );

	return isRunning();
}
Exemple #12
0
bool stereoEnhancerEffect::processAudioBuffer( sampleFrame * _buf,
							const fpp_t _frames )
{
	
	// This appears to be used for determining whether or not to continue processing
	// audio with this effect	
	double out_sum = 0.0;
	
	float width;
	int frameIndex = 0;
	
	
	if( !isEnabled() || !isRunning() )
	{
		return( false );
	}

	const float d = dryLevel();
	const float w = wetLevel();

	for( fpp_t f = 0; f < _frames; ++f )
	{
		
		// copy samples into the delay buffer
		m_delayBuffer[m_currFrame][0] = _buf[f][0];
		m_delayBuffer[m_currFrame][1] = _buf[f][1];

		// Get the width knob value from the Stereo Enhancer effect
		width = m_seFX.wideCoeff();

		// Calculate the correct sample frame for processing
		frameIndex = m_currFrame - width;

		if( frameIndex < 0 )
		{
			// e.g. difference = -10, frameIndex = DBS - 10
			frameIndex += DEFAULT_BUFFER_SIZE;
		}

		//sample_t s[2] = { _buf[f][0], _buf[f][1] };	//Vanilla
		sample_t s[2] = { _buf[f][0], m_delayBuffer[frameIndex][1] };	//Chocolate

		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];
		out_sum += _buf[f][0]*_buf[f][0] + _buf[f][1]*_buf[f][1];

		// Update currFrame
		m_currFrame += 1;
		m_currFrame %= DEFAULT_BUFFER_SIZE;
	}

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

	return( isRunning() );
}