33 releaseMasterResources();
38 double sourceSampleRateToCorrectFor,
int maxNumChannels)
40 if (source == newSource)
42 if (source ==
nullptr)
48 readAheadBufferSize = readAheadSize;
49 sourceSampleRate = sourceSampleRateToCorrectFor;
56 std::unique_ptr<ResamplingAudioSource> oldResamplerSource (resamplerSource);
57 std::unique_ptr<BufferingAudioSource> oldBufferingSource (bufferingSource);
60 if (newSource !=
nullptr)
62 newPositionableSource = newSource;
64 if (readAheadSize > 0)
68 jassert (readAheadThread !=
nullptr);
70 newPositionableSource = newBufferingSource
72 false, readAheadSize, maxNumChannels);
77 if (sourceSampleRateToCorrectFor > 0)
78 newMasterSource = newResamplerSource
81 newMasterSource = newPositionableSource;
85 if (newResamplerSource !=
nullptr && sourceSampleRate > 0 && sampleRate > 0)
96 resamplerSource = newResamplerSource;
97 bufferingSource = newBufferingSource;
98 masterSource = newMasterSource;
99 positionableSource = newPositionableSource;
101 inputStreamEOF =
false;
105 if (oldMasterSource !=
nullptr)
111 if ((! playing) && masterSource !=
nullptr)
117 inputStreamEOF =
false;
131 while (--n >= 0 && ! stopped)
140 if (sampleRate > 0.0)
146 if (sampleRate > 0.0)
154 if (sampleRate > 0.0)
162 if (positionableSource !=
nullptr)
164 if (sampleRate > 0 && sourceSampleRate > 0)
165 newPosition = (int64) ((
double) newPosition * sourceSampleRate / sampleRate);
169 if (resamplerSource !=
nullptr)
172 inputStreamEOF =
false;
178 if (positionableSource !=
nullptr)
180 const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
191 if (positionableSource !=
nullptr)
193 const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
194 return (int64) ((double) positionableSource->
getTotalLength() * ratio);
203 return positionableSource !=
nullptr && positionableSource->
isLooping();
215 sampleRate = newSampleRate;
216 blockSize = samplesPerBlockExpected;
218 if (masterSource !=
nullptr)
219 masterSource->
prepareToPlay (samplesPerBlockExpected, sampleRate);
221 if (resamplerSource !=
nullptr && sourceSampleRate > 0)
224 inputStreamEOF =
false;
228void AudioTransportSource::releaseMasterResources()
232 if (masterSource !=
nullptr)
240 releaseMasterResources();
247 if (masterSource !=
nullptr && ! stopped)
265 inputStreamEOF =
true;
int getNumChannels() const noexcept
Returns the number of channels of audio data that this buffer contains.
void clear() noexcept
Clears all the samples in all channels.
void applyGainRamp(int channel, int startSample, int numSamples, Type startGain, Type endGain) noexcept
Applies a range of gains to a region of a channel.
Base class for objects that can produce a continuous stream of audio.
virtual void releaseResources()=0
Allows the source to release anything it no longer needs after playback has stopped.
virtual void prepareToPlay(int samplesPerBlockExpected, double sampleRate)=0
Tells the source to prepare for playing.
virtual void getNextAudioBlock(const AudioSourceChannelInfo &bufferToFill)=0
Called repeatedly to fetch subsequent blocks of audio data.
void stop()
Stops playing.
void prepareToPlay(int samplesPerBlockExpected, double sampleRate) override
Implementation of the AudioSource method.
int64 getNextReadPosition() const override
Implements the PositionableAudioSource method.
double getCurrentPosition() const
Returns the position that the next data block will be read from This is a time in seconds.
void releaseResources() override
Implementation of the AudioSource method.
void getNextAudioBlock(const AudioSourceChannelInfo &) override
Implementation of the AudioSource method.
int64 getTotalLength() const override
Implements the PositionableAudioSource method.
~AudioTransportSource() override
Destructor.
void setPosition(double newPosition)
Changes the current playback position in the source stream.
double getLengthInSeconds() const
Returns the stream's length in seconds.
void setGain(float newGain) noexcept
Changes the gain to apply to the output.
void setSource(PositionableAudioSource *newSource, int readAheadBufferSize=0, TimeSliceThread *readAheadThread=nullptr, double sourceSampleRateToCorrectFor=0.0, int maxNumChannels=2)
Sets the reader that is being used as the input source.
bool isLooping() const override
Implements the PositionableAudioSource method.
AudioTransportSource()
Creates an AudioTransportSource.
void start()
Starts playing (if a source has been selected).
void setNextReadPosition(int64 newPosition) override
Implements the PositionableAudioSource method.
An AudioSource which takes another source as input, and buffers it using a thread.
void sendChangeMessage()
Causes an asynchronous change message to be sent to all the registered listeners.
Automatically locks and unlocks a mutex object.
A type of AudioSource which can be repositioned.
virtual bool isLooping() const =0
Returns true if this source is actually playing in a loop.
virtual int64 getNextReadPosition() const =0
Returns the position from which the next block will be returned.
virtual int64 getTotalLength() const =0
Returns the total length of the stream (in samples).
virtual void setNextReadPosition(int64 newPosition)=0
Tells the stream to move to a new position.
A type of AudioSource that takes an input source and changes its sample rate.
void flushBuffers()
Clears any buffers and filters that the resampler is using.
void setResamplingRatio(double samplesInPerOutputSample)
Changes the resampling ratio.
static void JUCE_CALLTYPE sleep(int milliseconds)
Suspends the execution of the current thread until the specified timeout period has elapsed (note tha...
A thread that keeps a list of clients, and calls each one in turn, giving them all a chance to run so...
Used by AudioSource::getNextAudioBlock().
int numSamples
The number of samples in the buffer which the callback is expected to fill with data.
void clearActiveBufferRegion() const
Convenient method to clear the buffer if the source is not producing any data.
AudioBuffer< float > * buffer
The destination buffer to fill with audio data.
int startSample
The first sample in the buffer from which the callback is expected to write data.