Browse Source

Fixed a data race in an example

tags/2021-05-28
Tom Poole 6 years ago
parent
commit
d8e07dca91
1 changed files with 5 additions and 3 deletions
  1. +5
    -3
      modules/juce_audio_utils/gui/juce_AudioVisualiserComponent.cpp

+ 5
- 3
modules/juce_audio_utils/gui/juce_AudioVisualiserComponent.cpp View File

@@ -55,8 +55,10 @@ struct AudioVisualiserComponent::ChannelInfo
{
if (--subSample <= 0)
{
nextSample %= levels.size();
levels.getReference (nextSample++) = value;
if (++nextSample == levels.size())
nextSample = 0;
levels.getReference (nextSample) = value;
subSample = owner.getSamplesPerBlock();
value = Range<float> (newSample, newSample);
}
@@ -78,7 +80,7 @@ struct AudioVisualiserComponent::ChannelInfo
AudioVisualiserComponent& owner;
Array<Range<float>> levels;
Range<float> value;
int nextSample = 0, subSample = 0;
std::atomic<int> nextSample { 0 }, subSample { 0 };
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ChannelInfo)
};


Loading…
Cancel
Save