Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Introduce an enum to describe the VCA mode
Replace the integer encoding of the VCA mode with an enumeration.
  • Loading branch information
michaelgregorius committed Sep 30, 2017
commit 7d50a24cbc52177467318c3b9946ccae4cb3b808
20 changes: 10 additions & 10 deletions plugins/lb302/lb302.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ lb302Synth::lb302Synth( InstrumentTrack * _instrumentTrack ) :
vca_decay(0.99897516),
vca_a0(0.5),
vca_a(0.),
vca_mode(3)
vca_mode(never_played)
{

connect( Engine::mixer(), SIGNAL( sampleRateChanged( ) ),
Expand Down Expand Up @@ -472,7 +472,7 @@ int lb302Synth::process(sampleFrame *outbuf, const int size)

if( release_frame == 0 || ! m_playingNote )
{
vca_mode = 1;
vca_mode = decay;
}

if( new_freq )
Expand All @@ -496,7 +496,7 @@ int lb302Synth::process(sampleFrame *outbuf, const int size)
// start decay if we're past release
if( i >= release_frame )
{
vca_mode = 1;
vca_mode = decay;
}

// update vcf
Expand Down Expand Up @@ -636,18 +636,18 @@ int lb302Synth::process(sampleFrame *outbuf, const int size)
}

// Handle Envelope
if(vca_mode==0) {
if(vca_mode==attack) {
vca_a+=(vca_a0-vca_a)*vca_attack;
if(sample_cnt>=0.5*Engine::mixer()->processingSampleRate())
vca_mode = 2;
vca_mode = idle;
}
else if(vca_mode == 1) {
else if(vca_mode == decay) {
vca_a *= vca_decay;

// the following line actually speeds up processing
if(vca_a < (1/65536.0)) {
vca_a = 0;
vca_mode = 3;
vca_mode = never_played;
}
}

Expand All @@ -669,15 +669,15 @@ void lb302Synth::initNote( lb302Note *n)

// Always reset vca on non-dead notes, and
// Only reset vca on decaying(decayed) and never-played
if(n->dead == 0 || (vca_mode==1 || vca_mode==3)) {
if(n->dead == 0 || (vca_mode == decay || vca_mode == never_played)) {
//printf(" good\n");
sample_cnt = 0;
vca_mode = 0;
vca_mode = attack;
// LB303:
//vca_a = 0;
}
else {
vca_mode = 2;
vca_mode = idle;
}

initSlide();
Expand Down
9 changes: 8 additions & 1 deletion plugins/lb302/lb302.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,14 @@ public slots:
vca_a; // Amplifier coefficient.

// Envelope State
int vca_mode; // 0: attack, 1: decay, 2: idle, 3: never played
enum VCA_Mode
{
attack = 0,
decay = 1,
idle = 2,
never_played = 3
};
VCA_Mode vca_mode;

// My hacks
int sample_cnt;
Expand Down