From 8ad46aabacf94bebf142f8bc684aac91351f2f29 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sat, 30 Sep 2017 22:50:09 +0200 Subject: [PATCH 1/3] Fix #3842: Opening a project with LB302 produces a noise burst Fix the noise burst described in #3842 by removing the second initialization of vca_a to 9 in the constructor of lb302Synth. --- plugins/lb302/lb302.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index dedd9822c95..34059e95a59 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -339,7 +339,6 @@ lb302Synth::lb302Synth( InstrumentTrack * _instrumentTrack ) : // Experimenting with a0 between original (0.5) and 1.0 vca_a0 = 0.5; - vca_a = 9; vca_mode = 3; vcfs[0] = new lb302FilterIIR2(&fs); From 08e840b8bd79d3942339f1fe08f0875b808cf35c Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sat, 30 Sep 2017 22:55:04 +0200 Subject: [PATCH 2/3] LB302: Move init of VCA members into constructor initializer list Move the initialization of the members belonging to the VCA into lb302Synth's constructor initializer list. This also removes a duplication initialization of vca_mode from the code. --- plugins/lb302/lb302.cpp | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index 34059e95a59..a5be95ad61f 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -284,8 +284,12 @@ lb302Synth::lb302Synth( InstrumentTrack * _instrumentTrack ) : slideToggle( false, this, tr( "Slide" ) ), accentToggle( false, this, tr( "Accent" ) ), deadToggle( false, this, tr( "Dead" ) ), - db24Toggle( false, this, tr( "24dB/oct Filter" ) ) - + db24Toggle( false, this, tr( "24dB/oct Filter" ) ), + vca_attack(1.0 - 0.96406088), + vca_decay(0.99897516), + vca_a0(0.5), + vca_a(0.), + vca_mode(3) { connect( Engine::mixer(), SIGNAL( sampleRateChanged( ) ), @@ -327,20 +331,8 @@ lb302Synth::lb302Synth( InstrumentTrack * _instrumentTrack ) : vcf_envpos = ENVINC; - // Start VCA on an attack. - vca_mode = 3; - vca_a = 0; - - //vca_attack = 1.0 - 0.94406088; - vca_attack = 1.0 - 0.96406088; - vca_decay = 0.99897516; - vco_shape = BL_SAWTOOTH; - // Experimenting with a0 between original (0.5) and 1.0 - vca_a0 = 0.5; - vca_mode = 3; - vcfs[0] = new lb302FilterIIR2(&fs); vcfs[1] = new lb302Filter3Pole(&fs); db24Toggled(); From 7d50a24cbc52177467318c3b9946ccae4cb3b808 Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sat, 30 Sep 2017 23:01:35 +0200 Subject: [PATCH 3/3] Introduce an enum to describe the VCA mode Replace the integer encoding of the VCA mode with an enumeration. --- plugins/lb302/lb302.cpp | 20 ++++++++++---------- plugins/lb302/lb302.h | 9 ++++++++- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index a5be95ad61f..1a32f7f92d0 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -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( ) ), @@ -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 ) @@ -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 @@ -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; } } @@ -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(); diff --git a/plugins/lb302/lb302.h b/plugins/lb302/lb302.h index 4b58a314f43..3ca22c78bb7 100644 --- a/plugins/lb302/lb302.h +++ b/plugins/lb302/lb302.h @@ -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;