Browse Source

AudioTransportSource: Fix thread sanitizer warnings

The AudioPlaybackDemo was previously triggering thread sanitizer
warnings when starting playback.
v6.1.6
reuk 4 years ago
parent
commit
eb3c3ed27c
No known key found for this signature in database GPG Key ID: 9ADCD339CFC98A11
2 changed files with 15 additions and 15 deletions
  1. +13
    -13
      modules/juce_audio_devices/sources/juce_AudioTransportSource.cpp
  2. +2
    -2
      modules/juce_audio_devices/sources/juce_AudioTransportSource.h

+ 13
- 13
modules/juce_audio_devices/sources/juce_AudioTransportSource.cpp 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();
}


+ 2
- 2
modules/juce_audio_devices/sources/juce_AudioTransportSource.h 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();


Loading…
Cancel
Save