kicker: envelope slope
This commit is contained in:
@@ -29,16 +29,19 @@
|
||||
#include "DspEffectLibrary.h"
|
||||
#include "Oscillator.h"
|
||||
|
||||
#include "fastpow.h"
|
||||
|
||||
|
||||
template<class FX = DspEffectLibrary::StereoBypass>
|
||||
class KickerOsc
|
||||
{
|
||||
public:
|
||||
KickerOsc( const FX & fx, const float start, const float end, const float offset, const float slope, const float length ) :
|
||||
KickerOsc( const FX & fx, const float start, const float end, const float offset, const float slope, const float env, const float length ) :
|
||||
m_phase( offset ),
|
||||
m_startFreq( start ),
|
||||
m_endFreq( end ),
|
||||
m_slope( slope ),
|
||||
m_env( env ),
|
||||
m_length( length ),
|
||||
m_FX( fx ),
|
||||
m_counter( 0 ),
|
||||
@@ -54,19 +57,15 @@ public:
|
||||
{
|
||||
for( fpp_t frame = 0; frame < frames; ++frame )
|
||||
{
|
||||
//~ if( m_counter > m_length )
|
||||
//~ {
|
||||
//~ buf[frame][0] = 0.0f;
|
||||
//~ buf[frame][1] = 0.0f;
|
||||
//~ continue;
|
||||
//~ }
|
||||
const double gain = ( 1 - fastPow( ( m_counter < m_length ) ? m_counter / m_length : 1, m_env ) );
|
||||
//~ qDebug( "%f", gain );
|
||||
const sample_t s = Oscillator::sinSample( m_phase );
|
||||
buf[frame][0] = s;
|
||||
buf[frame][1] = s;
|
||||
buf[frame][0] = s * gain;
|
||||
buf[frame][1] = s * gain;
|
||||
m_FX.nextSample( buf[frame][0], buf[frame][1] );
|
||||
m_phase += m_freq / sampleRate;
|
||||
|
||||
const double change = ( m_counter < m_length ) ? ( ( m_startFreq - m_endFreq ) * ( 1 - powf( m_counter / m_length, m_slope ) ) ) : 0;
|
||||
const double change = ( m_counter < m_length ) ? ( ( m_startFreq - m_endFreq ) * ( 1 - fastPow( m_counter / m_length, m_slope ) ) ) : 0;
|
||||
//~ qDebug( "%f (%f) [%lu, %f]", change, powf( m_counter / m_length, m_slope ), m_counter, m_length );
|
||||
m_freq = m_endFreq + change;
|
||||
++m_counter;
|
||||
@@ -79,6 +78,7 @@ private:
|
||||
const float m_startFreq;
|
||||
const float m_endFreq;
|
||||
const float m_slope;
|
||||
const float m_env;
|
||||
const float m_length;
|
||||
FX m_FX;
|
||||
|
||||
|
||||
20
plugins/kicker/fastpow.h
Normal file
20
plugins/kicker/fastpow.h
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
#ifndef FASTPOW_H
|
||||
#define FASTPOW_H
|
||||
|
||||
/*
|
||||
* source:
|
||||
* http://martin.ankerl.com/2007/10/04/optimized-pow-approximation-for-java-and-c-c/
|
||||
*/
|
||||
|
||||
double fastPow(double a, double b) {
|
||||
union {
|
||||
double d;
|
||||
int x[2];
|
||||
} u = { a };
|
||||
u.x[1] = (int)(b * (u.x[1] - 1072632447) + 1072632447);
|
||||
u.x[0] = 0;
|
||||
return u.d;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -60,11 +60,12 @@ kickerInstrument::kickerInstrument( InstrumentTrack * _instrument_track ) :
|
||||
Instrument( _instrument_track, &kicker_plugin_descriptor ),
|
||||
m_startFreqModel( 150.0f, 5.0f, 1000.0f, 1.0f, this, tr( "Start frequency" ) ),
|
||||
m_endFreqModel( 40.0f, 5.0f, 1000.0f, 1.0f, this, tr( "End frequency" ) ),
|
||||
m_decayModel( 120.0f, 5.0f, 1000.0f, 1.0f, this, tr( "Decay" ) ),
|
||||
m_decayModel( 440.0f, 5.0f, 2000.0f, 1.0f, this, tr( "Decay" ) ),
|
||||
m_distModel( 0.8f, 0.0f, 100.0f, 0.1f, this, tr( "Distortion" ) ),
|
||||
m_gainModel( 1.0f, 0.1f, 5.0f, 0.05f, this, tr( "Gain" ) ),
|
||||
m_clickModel( 1.0f, 0.0f, 1.0f, 0.1f, this, tr( "Click" ) ),
|
||||
m_slopeModel( 0.5f, 0.001f, 1.0f, 0.001f, this, tr( "Slope" ) )
|
||||
m_envModel( 0.163f, 0.01f, 1.0f, 0.001f, this, tr( "Env" ) ),
|
||||
m_clickModel( 0.4f, 0.0f, 1.0f, 0.05f, this, tr( "Click" ) ),
|
||||
m_slopeModel( 0.06f, 0.001f, 1.0f, 0.001f, this, tr( "Slope" ) )
|
||||
{
|
||||
}
|
||||
|
||||
@@ -86,6 +87,7 @@ void kickerInstrument::saveSettings( QDomDocument & _doc,
|
||||
m_decayModel.saveSettings( _doc, _this, "decay" );
|
||||
m_distModel.saveSettings( _doc, _this, "dist" );
|
||||
m_gainModel.saveSettings( _doc, _this, "gain" );
|
||||
m_envModel.saveSettings( _doc, _this, "env" );
|
||||
m_clickModel.saveSettings( _doc, _this, "click" );
|
||||
m_slopeModel.saveSettings( _doc, _this, "slope" );
|
||||
}
|
||||
@@ -100,7 +102,8 @@ void kickerInstrument::loadSettings( const QDomElement & _this )
|
||||
m_decayModel.loadSettings( _this, "decay" );
|
||||
m_distModel.loadSettings( _this, "dist" );
|
||||
m_gainModel.loadSettings( _this, "gain" );
|
||||
m_clickModel.loadSettings( _this, "gain" );
|
||||
m_envModel.loadSettings( _this, "env" );
|
||||
m_clickModel.loadSettings( _this, "click" );
|
||||
m_slopeModel.loadSettings( _this, "slope" );
|
||||
}
|
||||
|
||||
@@ -135,6 +138,7 @@ void kickerInstrument::playNote( NotePlayHandle * _n,
|
||||
m_endFreqModel.value(),
|
||||
m_clickModel.value() * 0.25f,
|
||||
m_slopeModel.value(),
|
||||
m_envModel.value(),
|
||||
decfr );
|
||||
}
|
||||
else if( tfp > decfr && !_n->isReleased() )
|
||||
@@ -233,13 +237,17 @@ kickerInstrumentView::kickerInstrumentView( Instrument * _instrument,
|
||||
m_gainKnob->setHintText( tr( "Gain:" ) + " ", "" );
|
||||
m_gainKnob->move( 203, 124 );
|
||||
|
||||
m_envKnob = new kickerKnob( this );
|
||||
m_envKnob->setHintText( tr( "Env:" ) + " ", "" );
|
||||
m_envKnob->move( 203, 204 );
|
||||
|
||||
m_clickKnob = new kickerKnob( this );
|
||||
m_clickKnob->setHintText( tr( "Click:" ) + " ", "" );
|
||||
m_clickKnob->move( 203, 164 );
|
||||
m_clickKnob->move( 12, 204 );
|
||||
|
||||
m_slopeKnob = new kickerKnob( this );
|
||||
m_slopeKnob->setHintText( tr( "Slope:" ) + " ", "" );
|
||||
m_slopeKnob->move( 203, 204 );
|
||||
m_slopeKnob->move( 59, 204 );
|
||||
|
||||
setAutoFillBackground( true );
|
||||
QPalette pal;
|
||||
@@ -266,6 +274,7 @@ void kickerInstrumentView::modelChanged()
|
||||
m_decayKnob->setModel( &k->m_decayModel );
|
||||
m_distKnob->setModel( &k->m_distModel );
|
||||
m_gainKnob->setModel( &k->m_gainModel );
|
||||
m_envKnob->setModel( &k->m_envModel );
|
||||
m_clickKnob->setModel( &k->m_clickModel );
|
||||
m_slopeKnob->setModel( &k->m_slopeModel );
|
||||
}
|
||||
|
||||
@@ -66,6 +66,7 @@ private:
|
||||
FloatModel m_decayModel;
|
||||
FloatModel m_distModel;
|
||||
FloatModel m_gainModel;
|
||||
FloatModel m_envModel;
|
||||
FloatModel m_clickModel;
|
||||
FloatModel m_slopeModel;
|
||||
|
||||
@@ -90,6 +91,7 @@ private:
|
||||
knob * m_decayKnob;
|
||||
knob * m_distKnob;
|
||||
knob * m_gainKnob;
|
||||
knob * m_envKnob;
|
||||
knob * m_clickKnob;
|
||||
knob * m_slopeKnob;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user