JUCE  v5.4.1-191-g0ab5e696f
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::AudioTransportSource Class Reference

An AudioSource that takes a PositionableAudioSource and allows it to be played, stopped, started, etc. More...

#include <juce_AudioTransportSource.h>

Inheritance diagram for juce::AudioTransportSource:
Collaboration diagram for juce::AudioTransportSource:

Public Member Functions

 AudioTransportSource ()
 Creates an AudioTransportSource. More...
 
 ~AudioTransportSource () override
 Destructor. More...
 
void addChangeListener (ChangeListener *listener)
 Registers a listener to receive change callbacks from this broadcaster. More...
 
void dispatchPendingMessages ()
 If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately. More...
 
double getCurrentPosition () const
 Returns the position that the next data block will be read from This is a time in seconds. More...
 
float getGain () const noexcept
 Returns the current gain setting. More...
 
double getLengthInSeconds () const
 Returns the stream's length in seconds. More...
 
void getNextAudioBlock (const AudioSourceChannelInfo &) override
 Implementation of the AudioSource method. More...
 
int64 getNextReadPosition () const override
 Implements the PositionableAudioSource method. More...
 
int64 getTotalLength () const override
 Implements the PositionableAudioSource method. More...
 
bool hasStreamFinished () const noexcept
 Returns true if the player has stopped because its input stream ran out of data. More...
 
bool isLooping () const override
 Implements the PositionableAudioSource method. More...
 
bool isPlaying () const noexcept
 Returns true if it's currently playing. More...
 
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override
 Implementation of the AudioSource method. More...
 
void releaseResources () override
 Implementation of the AudioSource method. More...
 
void removeAllChangeListeners ()
 Removes all listeners from the list. More...
 
void removeChangeListener (ChangeListener *listener)
 Unregisters a listener from the list. More...
 
void sendChangeMessage ()
 Causes an asynchronous change message to be sent to all the registered listeners. More...
 
void sendSynchronousChangeMessage ()
 Sends a synchronous change message to all the registered listeners. More...
 
void setGain (float newGain) noexcept
 Changes the gain to apply to the output. More...
 
virtual void setLooping (bool shouldLoop)
 Tells the source whether you'd like it to play in a loop. More...
 
void setNextReadPosition (int64 newPosition) override
 Implements the PositionableAudioSource method. More...
 
void setPosition (double newPosition)
 Changes the current playback position in the source stream. More...
 
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. More...
 
void start ()
 Starts playing (if a source has been selected). More...
 
void stop ()
 Stops playing. More...
 

Private Member Functions

void releaseMasterResources ()
 

Private Attributes

int blockSize = 128
 
BufferingAudioSourcebufferingSource = nullptr
 
CriticalSection callbackLock
 
float gain = 1.0f
 
bool inputStreamEOF = false
 
bool isPrepared = false
 
float lastGain = 1.0f
 
AudioSourcemasterSource = nullptr
 
bool playing = false
 
PositionableAudioSourcepositionableSource = nullptr
 
int readAheadBufferSize = 0
 
ResamplingAudioSourceresamplerSource = nullptr
 
double sampleRate = 44100.0
 
PositionableAudioSourcesource = nullptr
 
double sourceSampleRate = 0
 
bool stopped = true
 

Detailed Description

An AudioSource that takes a PositionableAudioSource and allows it to be played, stopped, started, etc.

This can also be told use a buffer and background thread to read ahead, and if can correct for different sample-rates.

You may want to use one of these along with an AudioSourcePlayer and AudioIODevice to control playback of an audio file.

See also
AudioSource, AudioSourcePlayer

{Audio}

Constructor & Destructor Documentation

◆ AudioTransportSource()

juce::AudioTransportSource::AudioTransportSource ( )

Creates an AudioTransportSource.

After creating one of these, use the setSource() method to select an input source.

◆ ~AudioTransportSource()

juce::AudioTransportSource::~AudioTransportSource ( )
override

Destructor.

Member Function Documentation

◆ addChangeListener()

void juce::ChangeBroadcaster::addChangeListener ( ChangeListener listener)
inherited

Registers a listener to receive change callbacks from this broadcaster.

Trying to add a listener that's already on the list will have no effect.

◆ dispatchPendingMessages()

void juce::ChangeBroadcaster::dispatchPendingMessages ( )
inherited

If a change message has been sent but not yet dispatched, this will call sendSynchronousChangeMessage() to make the callback immediately.

For thread-safety reasons, you must only call this method on the main message thread.

◆ getCurrentPosition()

double juce::AudioTransportSource::getCurrentPosition ( ) const

Returns the position that the next data block will be read from This is a time in seconds.

◆ getGain()

float juce::AudioTransportSource::getGain ( ) const
inlinenoexcept

Returns the current gain setting.

See also
setGain

◆ getLengthInSeconds()

double juce::AudioTransportSource::getLengthInSeconds ( ) const

Returns the stream's length in seconds.

◆ getNextAudioBlock()

void juce::AudioTransportSource::getNextAudioBlock ( const AudioSourceChannelInfo )
overridevirtual

Implementation of the AudioSource method.

Implements juce::AudioSource.

◆ getNextReadPosition()

int64 juce::AudioTransportSource::getNextReadPosition ( ) const
overridevirtual

Implements the PositionableAudioSource method.

Implements juce::PositionableAudioSource.

◆ getTotalLength()

int64 juce::AudioTransportSource::getTotalLength ( ) const
overridevirtual

Implements the PositionableAudioSource method.

Implements juce::PositionableAudioSource.

◆ hasStreamFinished()

bool juce::AudioTransportSource::hasStreamFinished ( ) const
inlinenoexcept

Returns true if the player has stopped because its input stream ran out of data.

◆ isLooping()

bool juce::AudioTransportSource::isLooping ( ) const
overridevirtual

Implements the PositionableAudioSource method.

Implements juce::PositionableAudioSource.

◆ isPlaying()

bool juce::AudioTransportSource::isPlaying ( ) const
inlinenoexcept

Returns true if it's currently playing.

◆ prepareToPlay()

void juce::AudioTransportSource::prepareToPlay ( int  samplesPerBlockExpected,
double  sampleRate 
)
overridevirtual

Implementation of the AudioSource method.

Implements juce::AudioSource.

◆ releaseMasterResources()

void juce::AudioTransportSource::releaseMasterResources ( )
private

◆ releaseResources()

void juce::AudioTransportSource::releaseResources ( )
overridevirtual

Implementation of the AudioSource method.

Implements juce::AudioSource.

◆ removeAllChangeListeners()

void juce::ChangeBroadcaster::removeAllChangeListeners ( )
inherited

Removes all listeners from the list.

◆ removeChangeListener()

void juce::ChangeBroadcaster::removeChangeListener ( ChangeListener listener)
inherited

Unregisters a listener from the list.

If the listener isn't on the list, this won't have any effect.

◆ sendChangeMessage()

void juce::ChangeBroadcaster::sendChangeMessage ( )
inherited

Causes an asynchronous change message to be sent to all the registered listeners.

The message will be delivered asynchronously by the main message thread, so this method will return immediately. To call the listeners synchronously use sendSynchronousChangeMessage().

Referenced by juce::SelectedItemSet< SelectableItemType >::changed().

◆ sendSynchronousChangeMessage()

void juce::ChangeBroadcaster::sendSynchronousChangeMessage ( )
inherited

Sends a synchronous change message to all the registered listeners.

This will immediately call all the listeners that are registered. For thread-safety reasons, you must only call this method on the main message thread.

See also
dispatchPendingMessages

Referenced by juce::SelectedItemSet< SelectableItemType >::changed().

◆ setGain()

void juce::AudioTransportSource::setGain ( float  newGain)
noexcept

Changes the gain to apply to the output.

Parameters
newGaina factor by which to multiply the outgoing samples, so 1.0 = 0dB, 0.5 = -6dB, 2.0 = 6dB, etc.

◆ setLooping()

virtual void juce::PositionableAudioSource::setLooping ( bool  shouldLoop)
inlinevirtualinherited

Tells the source whether you'd like it to play in a loop.

Reimplemented in juce::AudioFormatReaderSource.

References juce::ignoreUnused().

◆ setNextReadPosition()

void juce::AudioTransportSource::setNextReadPosition ( int64  newPosition)
overridevirtual

Implements the PositionableAudioSource method.

Implements juce::PositionableAudioSource.

◆ setPosition()

void juce::AudioTransportSource::setPosition ( double  newPosition)

Changes the current playback position in the source stream.

The next time the getNextAudioBlock() method is called, this is the time from which it'll read data.

Parameters
newPositionthe new playback position in seconds
See also
getCurrentPosition

◆ setSource()

void juce::AudioTransportSource::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.

This will stop playback, reset the position to 0 and change to the new reader.

The source passed in will not be deleted by this object, so must be managed by the caller.

Parameters
newSourcethe new input source to use. This may be a nullptr
readAheadBufferSizea size of buffer to use for reading ahead. If this is zero, no reading ahead will be done; if it's greater than zero, a BufferingAudioSource will be used to do the reading-ahead. If you set a non-zero value here, you'll also need to set the readAheadThread parameter.
readAheadThreadif you set readAheadBufferSize to a non-zero value, then you'll also need to supply this TimeSliceThread object for the background reader to use. The thread object must not be deleted while the AudioTransport source is still using it.
sourceSampleRateToCorrectForif this is non-zero, it specifies the sample rate of the source, and playback will be sample-rate adjusted to maintain playback at the correct pitch. If this is 0, no sample-rate adjustment will be performed
maxNumChannelsthe maximum number of channels that may need to be played

◆ start()

void juce::AudioTransportSource::start ( )

Starts playing (if a source has been selected).

If it starts playing, this will send a message to any ChangeListeners that are registered with this object.

◆ stop()

void juce::AudioTransportSource::stop ( )

Stops playing.

If it's actually playing, this will send a message to any ChangeListeners that are registered with this object.

Member Data Documentation

◆ blockSize

int juce::AudioTransportSource::blockSize = 128
private

◆ bufferingSource

BufferingAudioSource* juce::AudioTransportSource::bufferingSource = nullptr
private

◆ callbackLock

CriticalSection juce::AudioTransportSource::callbackLock
private

◆ gain

float juce::AudioTransportSource::gain = 1.0f
private

◆ inputStreamEOF

bool juce::AudioTransportSource::inputStreamEOF = false
private

◆ isPrepared

bool juce::AudioTransportSource::isPrepared = false
private

◆ lastGain

float juce::AudioTransportSource::lastGain = 1.0f
private

◆ masterSource

AudioSource* juce::AudioTransportSource::masterSource = nullptr
private

◆ playing

bool juce::AudioTransportSource::playing = false
private

◆ positionableSource

PositionableAudioSource* juce::AudioTransportSource::positionableSource = nullptr
private

◆ readAheadBufferSize

int juce::AudioTransportSource::readAheadBufferSize = 0
private

◆ resamplerSource

ResamplingAudioSource* juce::AudioTransportSource::resamplerSource = nullptr
private

◆ sampleRate

double juce::AudioTransportSource::sampleRate = 44100.0
private

◆ source

PositionableAudioSource* juce::AudioTransportSource::source = nullptr
private

◆ sourceSampleRate

double juce::AudioTransportSource::sourceSampleRate = 0
private

◆ stopped

bool juce::AudioTransportSource::stopped = true
private

The documentation for this class was generated from the following file: