Skip to content

Commit 43bbeed

Browse files
committed
CAR: implemented race-condition free behaviour for gain parameter.
1 parent 7b9078e commit 43bbeed

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

Source/Plugins/CAR/CAR.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,16 @@ AudioProcessorEditor* CAR::createEditor()
4646
}
4747

4848

49+
float CAR::getGainLevel()
50+
{
51+
m_gainLevel.updateTarget();
52+
return m_gainLevel.getNextValue();
53+
}
54+
55+
4956
void CAR::setGainLevel (float newGain)
5057
{
51-
m_gainLevel = newGain;
58+
m_gainLevel.setValue (newGain);
5259
}
5360

5461

@@ -80,7 +87,8 @@ void CAR::process (AudioSampleBuffer& buffer, MidiBuffer& events)
8087

8188
m_avgBuffer.applyGain (1.0f / float (numReferenceChannels));
8289

83-
const float gain = -1.0f * m_gainLevel / 100.f;
90+
m_gainLevel.updateTarget();
91+
const float gain = -1.0f * m_gainLevel.getNextValue() / 100.f;
8492

8593
for (int i = 0; i < numAffectedChannels; ++i)
8694
{

Source/Plugins/CAR/CAR.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class CAR : public GenericProcessor
7373
void process (AudioSampleBuffer& buffer, MidiBuffer& events) override;
7474

7575
/** Returns the current gain level that is set in the processor */
76-
float getGainLevel() const { return m_gainLevel; }
76+
float getGainLevel();
7777

7878
/** Sets the new gain level that will be used in the processor */
7979
void setGainLevel (float newGain);
@@ -92,7 +92,7 @@ class CAR : public GenericProcessor
9292

9393

9494
private:
95-
float m_gainLevel;
95+
LinearSmoothedValueAtomic<float> m_gainLevel;
9696

9797
AudioSampleBuffer m_avgBuffer;
9898

0 commit comments

Comments
 (0)