mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Made sure that AudioTransportSource::hasStreamFinished() returns the correct value.
This commit is contained in:
parent
48cdb90341
commit
1872ed68c2
2 changed files with 19 additions and 31 deletions
|
|
@ -44,15 +44,12 @@ AudioTransportSource::AudioTransportSource()
|
|||
AudioTransportSource::~AudioTransportSource()
|
||||
{
|
||||
setSource (nullptr);
|
||||
|
||||
releaseMasterResources();
|
||||
}
|
||||
|
||||
void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
|
||||
int readAheadBufferSize_,
|
||||
TimeSliceThread* readAheadThread,
|
||||
double sourceSampleRateToCorrectFor,
|
||||
int maxNumChannels)
|
||||
int readAheadSize, TimeSliceThread* readAheadThread,
|
||||
double sourceSampleRateToCorrectFor, int maxNumChannels)
|
||||
{
|
||||
if (source == newSource)
|
||||
{
|
||||
|
|
@ -62,7 +59,7 @@ void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
|
|||
setSource (nullptr, 0, nullptr); // deselect and reselect to avoid releasing resources wrongly
|
||||
}
|
||||
|
||||
readAheadBufferSize = readAheadBufferSize_;
|
||||
readAheadBufferSize = readAheadSize;
|
||||
sourceSampleRate = sourceSampleRateToCorrectFor;
|
||||
|
||||
ResamplingAudioSource* newResamplerSource = nullptr;
|
||||
|
|
@ -78,7 +75,7 @@ void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
|
|||
{
|
||||
newPositionableSource = newSource;
|
||||
|
||||
if (readAheadBufferSize_ > 0)
|
||||
if (readAheadSize > 0)
|
||||
{
|
||||
// If you want to use a read-ahead buffer, you must also provide a TimeSliceThread
|
||||
// for it to use!
|
||||
|
|
@ -86,7 +83,7 @@ void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
|
|||
|
||||
newPositionableSource = newBufferingSource
|
||||
= new BufferingAudioSource (newPositionableSource, *readAheadThread,
|
||||
false, readAheadBufferSize_, maxNumChannels);
|
||||
false, readAheadSize, maxNumChannels);
|
||||
}
|
||||
|
||||
newPositionableSource->setNextReadPosition (0);
|
||||
|
|
@ -115,6 +112,7 @@ void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
|
|||
masterSource = newMasterSource;
|
||||
positionableSource = newPositionableSource;
|
||||
|
||||
inputStreamEOF = false;
|
||||
playing = false;
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +168,10 @@ double AudioTransportSource::getCurrentPosition() const
|
|||
|
||||
double AudioTransportSource::getLengthInSeconds() const
|
||||
{
|
||||
if (sampleRate > 0.0)
|
||||
return getTotalLength() / sampleRate;
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void AudioTransportSource::setNextReadPosition (int64 newPosition)
|
||||
|
|
@ -181,6 +182,7 @@ void AudioTransportSource::setNextReadPosition (int64 newPosition)
|
|||
newPosition = (int64) (newPosition * sourceSampleRate / sampleRate);
|
||||
|
||||
positionableSource->setNextReadPosition (newPosition);
|
||||
inputStreamEOF = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +191,6 @@ int64 AudioTransportSource::getNextReadPosition() const
|
|||
if (positionableSource != nullptr)
|
||||
{
|
||||
const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
|
||||
|
||||
return (int64) (positionableSource->getNextReadPosition() * ratio);
|
||||
}
|
||||
|
||||
|
|
@ -203,7 +204,6 @@ int64 AudioTransportSource::getTotalLength() const
|
|||
if (positionableSource != nullptr)
|
||||
{
|
||||
const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
|
||||
|
||||
return (int64) (positionableSource->getTotalLength() * ratio);
|
||||
}
|
||||
|
||||
|
|
@ -213,9 +213,7 @@ int64 AudioTransportSource::getTotalLength() const
|
|||
bool AudioTransportSource::isLooping() const
|
||||
{
|
||||
const ScopedLock sl (callbackLock);
|
||||
|
||||
return positionableSource != nullptr
|
||||
&& positionableSource->isLooping();
|
||||
return positionableSource != nullptr && positionableSource->isLooping();
|
||||
}
|
||||
|
||||
void AudioTransportSource::setGain (const float newGain) noexcept
|
||||
|
|
@ -236,6 +234,7 @@ void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected, double ne
|
|||
if (resamplerSource != nullptr && sourceSampleRate > 0)
|
||||
resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
|
||||
|
||||
inputStreamEOF = false;
|
||||
isPrepared = true;
|
||||
}
|
||||
|
||||
|
|
@ -258,8 +257,6 @@ void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info
|
|||
{
|
||||
const ScopedLock sl (callbackLock);
|
||||
|
||||
inputStreamEOF = false;
|
||||
|
||||
if (masterSource != nullptr && ! stopped)
|
||||
{
|
||||
masterSource->getNextAudioBlock (info);
|
||||
|
|
@ -285,10 +282,7 @@ void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info
|
|||
stopped = ! playing;
|
||||
|
||||
for (int i = info.buffer->getNumChannels(); --i >= 0;)
|
||||
{
|
||||
info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
|
||||
lastGain, gain);
|
||||
}
|
||||
info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ class JUCE_API AudioTransportSource : public PositionableAudioSource,
|
|||
public:
|
||||
//==============================================================================
|
||||
/** Creates an AudioTransportSource.
|
||||
|
||||
After creating one of these, use the setSource() method to select an input source.
|
||||
*/
|
||||
AudioTransportSource();
|
||||
|
|
@ -94,7 +93,6 @@ public:
|
|||
void setPosition (double newPosition);
|
||||
|
||||
/** Returns the position that the next data block will be read from
|
||||
|
||||
This is a time in seconds.
|
||||
*/
|
||||
double getCurrentPosition() const;
|
||||
|
|
@ -102,8 +100,7 @@ public:
|
|||
/** Returns the stream's length in seconds. */
|
||||
double getLengthInSeconds() const;
|
||||
|
||||
/** Returns true if the player has stopped because its input stream ran out of data.
|
||||
*/
|
||||
/** Returns true if the player has stopped because its input stream ran out of data. */
|
||||
bool hasStreamFinished() const noexcept { return inputStreamEOF; }
|
||||
|
||||
//==============================================================================
|
||||
|
|
@ -126,19 +123,16 @@ public:
|
|||
|
||||
//==============================================================================
|
||||
/** Changes the gain to apply to the output.
|
||||
|
||||
@param newGain a factor by which to multiply the outgoing samples,
|
||||
so 1.0 = 0dB, 0.5 = -6dB, 2.0 = 6dB, etc.
|
||||
*/
|
||||
void setGain (float newGain) noexcept;
|
||||
|
||||
/** Returns the current gain setting.
|
||||
|
||||
@see setGain
|
||||
*/
|
||||
float getGain() const noexcept { return gain; }
|
||||
|
||||
|
||||
//==============================================================================
|
||||
/** Implementation of the AudioSource method. */
|
||||
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override;
|
||||
|
|
@ -175,7 +169,7 @@ private:
|
|||
bool volatile playing, stopped;
|
||||
double sampleRate, sourceSampleRate;
|
||||
int blockSize, readAheadBufferSize;
|
||||
bool isPrepared, inputStreamEOF;
|
||||
bool volatile isPrepared, inputStreamEOF;
|
||||
|
||||
void releaseMasterResources();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue