From b19522c55aa49edecc1e800f1235121bd6682416 Mon Sep 17 00:00:00 2001 From: Paul Giblock Date: Wed, 19 Feb 2014 20:53:50 -0500 Subject: [PATCH] Hopefully fix race-condition in lb302 db24 switch So, we were swapping out some pointer mid-process at times. Instead, use an atomic pointer, and just have the process function grab the current value and use it through the entire processing period. Still has a sound glitch when switching, but this switch was never intended to be used "live". Closes #353 --- plugins/lb302/lb302.cpp | 20 ++++++++++---------- plugins/lb302/lb302.h | 8 ++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/plugins/lb302/lb302.cpp b/plugins/lb302/lb302.cpp index d2dccb93e..7e546cf34 100644 --- a/plugins/lb302/lb302.cpp +++ b/plugins/lb302/lb302.cpp @@ -338,7 +338,9 @@ lb302Synth::lb302Synth( InstrumentTrack * _instrumentTrack ) : vca_a = 9; vca_mode = 3; - vcf = new lb302FilterIIR2(&fs); + vcfs[0] = new lb302Filter3Pole(&fs); + vcfs[1] = new lb302FilterIIR2(&fs); + vcf = vcfs[1]; sample_cnt = 0; release_frame = 1<<24; @@ -422,13 +424,8 @@ void lb302Synth::filterChanged() void lb302Synth::db24Toggled() { - delete vcf; - if(db24Toggle.value()) { - vcf = new lb302Filter3Pole(&fs); - } - else { - vcf = new lb302FilterIIR2(&fs); - } + vcf = vcfs[db24Toggle.value()]; + // These recalcFilter calls might suck recalcFilter(); } @@ -471,6 +468,9 @@ int lb302Synth::process(sampleFrame *outbuf, const int size) float w; float samp; + // Hold on to the current VCF, and use it throughout this period + lb302Filter *filter = vcf; + if( delete_freq == current_freq ) { // Normal release delete_freq = -1; @@ -503,7 +503,7 @@ int lb302Synth::process(sampleFrame *outbuf, const int size) // update vcf if(vcf_envpos >= ENVINC) { - vcf->envRecalc(); + filter->envRecalc(); vcf_envpos = 0; @@ -599,7 +599,7 @@ int lb302Synth::process(sampleFrame *outbuf, const int size) #ifdef LB_FILTERED //samp = vcf->process(vco_k)*2.0*vca_a; //samp = vcf->process(vco_k)*2.0; - samp = vcf->process(vco_k) * vca_a; + samp = filter->process(vco_k) * vca_a; //printf("%f %d\n", vco_c, sample_cnt); diff --git a/plugins/lb302/lb302.h b/plugins/lb302/lb302.h index 7c6475562..9ce92cfb7 100644 --- a/plugins/lb302/lb302.h +++ b/plugins/lb302/lb302.h @@ -39,6 +39,8 @@ #include "knob.h" #include "Mixer.h" +static const int NUM_FILTERS = 2; + class lb302SynthView; class NotePlayHandle; @@ -198,13 +200,15 @@ private: enum vco_shape_t { SAWTOOTH, SQUARE, TRIANGLE, MOOG, ROUND_SQUARE, SINE, EXPONENTIAL, WHITE_NOISE }; vco_shape_t vco_shape; + // Filters (just keep both loaded and switch) + lb302Filter* vcfs[NUM_FILTERS]; + // User settings lb302FilterKnobState fs; - lb302Filter *vcf; + QAtomicPointer vcf; int release_frame; - // More States int vcf_envpos; // Update counter. Updates when >= ENVINC