mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-30 02:50:05 +00:00
More use of atomics to avoid asan warnings
This commit is contained in:
parent
dab49b3f58
commit
f9a5bf1729
2 changed files with 14 additions and 20 deletions
|
|
@ -32,9 +32,7 @@ BufferingAudioReader::BufferingAudioReader (AudioFormatReader* sourceReader,
|
|||
int samplesToBuffer)
|
||||
: AudioFormatReader (nullptr, sourceReader->getFormatName()),
|
||||
source (sourceReader), thread (timeSliceThread),
|
||||
nextReadPosition (0),
|
||||
numBlocks (1 + (samplesToBuffer / samplesPerBlock)),
|
||||
timeoutMs (0)
|
||||
numBlocks (1 + (samplesToBuffer / samplesPerBlock))
|
||||
{
|
||||
sampleRate = source->sampleRate;
|
||||
lengthInSamples = source->lengthInSamples;
|
||||
|
|
@ -62,7 +60,7 @@ void BufferingAudioReader::setReadTimeout (int timeoutMilliseconds) noexcept
|
|||
bool BufferingAudioReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
|
||||
int64 startSampleInFile, int numSamples)
|
||||
{
|
||||
const uint32 startTime = Time::getMillisecondCounter();
|
||||
auto startTime = Time::getMillisecondCounter();
|
||||
clearSamplesBeyondAvailableLength (destSamples, numDestChannels, startOffsetInDestBuffer,
|
||||
startSampleInFile, numSamples, lengthInSamples);
|
||||
|
||||
|
|
@ -71,14 +69,14 @@ bool BufferingAudioReader::readSamples (int** destSamples, int numDestChannels,
|
|||
|
||||
while (numSamples > 0)
|
||||
{
|
||||
if (const BufferedBlock* const block = getBlockContaining (startSampleInFile))
|
||||
if (auto block = getBlockContaining (startSampleInFile))
|
||||
{
|
||||
const int offset = (int) (startSampleInFile - block->range.getStart());
|
||||
const int numToDo = jmin (numSamples, (int) (block->range.getEnd() - startSampleInFile));
|
||||
auto offset = (int) (startSampleInFile - block->range.getStart());
|
||||
auto numToDo = jmin (numSamples, (int) (block->range.getEnd() - startSampleInFile));
|
||||
|
||||
for (int j = 0; j < numDestChannels; ++j)
|
||||
{
|
||||
if (float* dest = (float*) destSamples[j])
|
||||
if (auto dest = (float*) destSamples[j])
|
||||
{
|
||||
dest += startOffsetInDestBuffer;
|
||||
|
||||
|
|
@ -98,7 +96,7 @@ bool BufferingAudioReader::readSamples (int** destSamples, int numDestChannels,
|
|||
if (timeoutMs >= 0 && Time::getMillisecondCounter() >= startTime + (uint32) timeoutMs)
|
||||
{
|
||||
for (int j = 0; j < numDestChannels; ++j)
|
||||
if (float* dest = (float*) destSamples[j])
|
||||
if (auto dest = (float*) destSamples[j])
|
||||
FloatVectorOperations::clear (dest + startOffsetInDestBuffer, numSamples);
|
||||
|
||||
break;
|
||||
|
|
@ -123,13 +121,9 @@ BufferingAudioReader::BufferedBlock::BufferedBlock (AudioFormatReader& reader, i
|
|||
|
||||
BufferingAudioReader::BufferedBlock* BufferingAudioReader::getBlockContaining (int64 pos) const noexcept
|
||||
{
|
||||
for (int i = blocks.size(); --i >= 0;)
|
||||
{
|
||||
BufferedBlock* const b = blocks.getUnchecked(i);
|
||||
|
||||
for (auto* b : blocks)
|
||||
if (b->range.contains (pos))
|
||||
return b;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -141,9 +135,9 @@ int BufferingAudioReader::useTimeSlice()
|
|||
|
||||
bool BufferingAudioReader::readNextBufferChunk()
|
||||
{
|
||||
const int64 pos = nextReadPosition;
|
||||
const int64 startPos = ((pos - 1024) / samplesPerBlock) * samplesPerBlock;
|
||||
const int64 endPos = startPos + numBlocks * samplesPerBlock;
|
||||
auto pos = nextReadPosition.get();
|
||||
auto startPos = ((pos - 1024) / samplesPerBlock) * samplesPerBlock;
|
||||
auto endPos = startPos + numBlocks * samplesPerBlock;
|
||||
|
||||
OwnedArray<BufferedBlock> newBlocks;
|
||||
|
||||
|
|
@ -157,7 +151,7 @@ bool BufferingAudioReader::readNextBufferChunk()
|
|||
return false;
|
||||
}
|
||||
|
||||
for (int64 p = startPos; p < endPos; p += samplesPerBlock)
|
||||
for (auto p = startPos; p < endPos; p += samplesPerBlock)
|
||||
{
|
||||
if (getBlockContaining (p) == nullptr)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -69,9 +69,9 @@ public:
|
|||
private:
|
||||
std::unique_ptr<AudioFormatReader> source;
|
||||
TimeSliceThread& thread;
|
||||
int64 nextReadPosition;
|
||||
std::atomic<int64> nextReadPosition { 0 };
|
||||
const int numBlocks;
|
||||
int timeoutMs;
|
||||
int timeoutMs = 0;
|
||||
|
||||
enum { samplesPerBlock = 32768 };
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue