1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

AudioTransportSource: Fix thread sanitizer warnings

The AudioPlaybackDemo was previously triggering thread sanitizer
warnings when starting playback.
This commit is contained in:
reuk 2021-10-04 13:28:46 +01:00
parent a62d4c6a5a
commit eb3c3ed27c
No known key found for this signature in database
GPG key ID: 9ADCD339CFC98A11
2 changed files with 15 additions and 15 deletions

View file

@ -45,9 +45,6 @@ void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
setSource (nullptr, 0, nullptr); // deselect and reselect to avoid releasing resources wrongly
}
readAheadBufferSize = readAheadSize;
sourceSampleRate = sourceSampleRateToCorrectFor;
ResamplingAudioSource* newResamplerSource = nullptr;
BufferingAudioSource* newBufferingSource = nullptr;
PositionableAudioSource* newPositionableSource = nullptr;
@ -82,8 +79,8 @@ void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
if (isPrepared)
{
if (newResamplerSource != nullptr && sourceSampleRate > 0 && sampleRate > 0)
newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
if (newResamplerSource != nullptr && sourceSampleRateToCorrectFor > 0 && sampleRate > 0)
newResamplerSource->setResamplingRatio (sourceSampleRateToCorrectFor / sampleRate);
newMasterSource->prepareToPlay (blockSize, sampleRate);
}
@ -97,8 +94,9 @@ void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
bufferingSource = newBufferingSource;
masterSource = newMasterSource;
positionableSource = newPositionableSource;
readAheadBufferSize = readAheadSize;
sourceSampleRate = sourceSampleRateToCorrectFor;
inputStreamEOF = false;
playing = false;
}
@ -114,7 +112,6 @@ void AudioTransportSource::start()
const ScopedLock sl (callbackLock);
playing = true;
stopped = false;
inputStreamEOF = false;
}
sendChangeMessage();
@ -157,6 +154,12 @@ double AudioTransportSource::getLengthInSeconds() const
return 0.0;
}
bool AudioTransportSource::hasStreamFinished() const noexcept
{
return positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
&& ! positionableSource->isLooping();
}
void AudioTransportSource::setNextReadPosition (int64 newPosition)
{
if (positionableSource != nullptr)
@ -168,13 +171,13 @@ void AudioTransportSource::setNextReadPosition (int64 newPosition)
if (resamplerSource != nullptr)
resamplerSource->flushBuffers();
inputStreamEOF = false;
}
}
int64 AudioTransportSource::getNextReadPosition() const
{
const ScopedLock sl (callbackLock);
if (positionableSource != nullptr)
{
const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
@ -221,7 +224,6 @@ void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected, double ne
if (resamplerSource != nullptr && sourceSampleRate > 0)
resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
inputStreamEOF = false;
isPrepared = true;
}
@ -258,11 +260,9 @@ void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info
info.buffer->clear (info.startSample + 256, info.numSamples - 256);
}
if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
&& ! positionableSource->isLooping())
if (hasStreamFinished())
{
playing = false;
inputStreamEOF = true;
sendChangeMessage();
}

View file

@ -102,7 +102,7 @@ public:
double getLengthInSeconds() const;
/** Returns true if the player has stopped because its input stream ran out of data. */
bool hasStreamFinished() const noexcept { return inputStreamEOF; }
bool hasStreamFinished() const noexcept;
//==============================================================================
/** Starts playing (if a source has been selected).
@ -170,7 +170,7 @@ private:
std::atomic<bool> playing { false }, stopped { true };
double sampleRate = 44100.0, sourceSampleRate = 0;
int blockSize = 128, readAheadBufferSize = 0;
bool isPrepared = false, inputStreamEOF = false;
bool isPrepared = false;
void releaseMasterResources();