OpenShot Library | OpenShotAudio 0.2.2
juce::BufferingAudioSource Class Reference

An AudioSource which takes another source as input, and buffers it using a thread. More...

#include <juce_BufferingAudioSource.h>

+ Inheritance diagram for juce::BufferingAudioSource:

Public Member Functions

 BufferingAudioSource (PositionableAudioSource *source, TimeSliceThread &backgroundThread, bool deleteSourceWhenDeleted, int numberOfSamplesToBuffer, int numberOfChannels=2, bool prefillBufferOnPrepareToPlay=true)
 Creates a BufferingAudioSource. More...
 
 ~BufferingAudioSource () override
 Destructor. More...
 
void prepareToPlay (int samplesPerBlockExpected, double sampleRate) override
 Implementation of the AudioSource method. More...
 
void releaseResources () override
 Implementation of the AudioSource method. More...
 
void getNextAudioBlock (const AudioSourceChannelInfo &) override
 Implementation of the AudioSource method. More...
 
void setNextReadPosition (int64 newPosition) override
 Implements the PositionableAudioSource method. More...
 
int64 getNextReadPosition () const override
 Implements the PositionableAudioSource method. More...
 
int64 getTotalLength () const override
 Implements the PositionableAudioSource method. More...
 
bool isLooping () const override
 Implements the PositionableAudioSource method. More...
 
bool waitForNextAudioBlockReady (const AudioSourceChannelInfo &info, const uint32 timeout)
 A useful function to block until the next the buffer info can be filled. More...
 
- Public Member Functions inherited from juce::PositionableAudioSource
 ~PositionableAudioSource () override=default
 Destructor.
 
virtual void setNextReadPosition (int64 newPosition)=0
 Tells the stream to move to a new position. More...
 
virtual int64 getNextReadPosition () const =0
 Returns the position from which the next block will be returned. More...
 
virtual int64 getTotalLength () const =0
 Returns the total length of the stream (in samples). More...
 
virtual bool isLooping () const =0
 Returns true if this source is actually playing in a loop. More...
 
virtual void setLooping (bool shouldLoop)
 Tells the source whether you'd like it to play in a loop. More...
 
- Public Member Functions inherited from juce::AudioSource
virtual ~AudioSource ()=default
 Destructor.
 
virtual void prepareToPlay (int samplesPerBlockExpected, double sampleRate)=0
 Tells the source to prepare for playing. More...
 
virtual void releaseResources ()=0
 Allows the source to release anything it no longer needs after playback has stopped. More...
 
virtual void getNextAudioBlock (const AudioSourceChannelInfo &bufferToFill)=0
 Called repeatedly to fetch subsequent blocks of audio data. More...
 

Additional Inherited Members

- Protected Member Functions inherited from juce::PositionableAudioSource
 PositionableAudioSource ()=default
 Creates the PositionableAudioSource.
 
- Protected Member Functions inherited from juce::AudioSource
 AudioSource ()=default
 Creates an AudioSource.
 

Detailed Description

An AudioSource which takes another source as input, and buffers it using a thread.

Create this as a wrapper around another thread, and it will read-ahead with a background thread to smooth out playback. You can either create one of these directly, or use it indirectly using an AudioTransportSource.

See also
PositionableAudioSource, AudioTransportSource

Definition at line 42 of file juce_BufferingAudioSource.h.

Constructor & Destructor Documentation

◆ BufferingAudioSource()

juce::BufferingAudioSource::BufferingAudioSource ( PositionableAudioSource source,
TimeSliceThread backgroundThread,
bool  deleteSourceWhenDeleted,
int  numberOfSamplesToBuffer,
int  numberOfChannels = 2,
bool  prefillBufferOnPrepareToPlay = true 
)

Creates a BufferingAudioSource.

Parameters
sourcethe input source to read from
backgroundThreada background thread that will be used for the background read-ahead. This object must not be deleted until after any BufferingAudioSources that are using it have been deleted!
deleteSourceWhenDeletedif true, then the input source object will be deleted when this object is deleted
numberOfSamplesToBufferthe size of buffer to use for reading ahead
numberOfChannelsthe number of channels that will be played
prefillBufferOnPrepareToPlayif true, then calling prepareToPlay on this object will block until the buffer has been filled

Definition at line 26 of file juce_BufferingAudioSource.cpp.

◆ ~BufferingAudioSource()

juce::BufferingAudioSource::~BufferingAudioSource ( )
override

Destructor.

The input source may be deleted depending on whether the deleteSourceWhenDeleted flag was set in the constructor.

Definition at line 44 of file juce_BufferingAudioSource.cpp.

References releaseResources().

Member Function Documentation

◆ prepareToPlay()

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

◆ releaseResources()

void juce::BufferingAudioSource::releaseResources ( )
overridevirtual

Implementation of the AudioSource method.

Implements juce::AudioSource.

Definition at line 83 of file juce_BufferingAudioSource.cpp.

References juce::TimeSliceThread::removeTimeSliceClient(), and juce::AudioBuffer< Type >::setSize().

Referenced by ~BufferingAudioSource().

◆ getNextAudioBlock()

◆ setNextReadPosition()

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

◆ getNextReadPosition()

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

Implements the PositionableAudioSource method.

Implements juce::PositionableAudioSource.

Definition at line 202 of file juce_BufferingAudioSource.cpp.

◆ getTotalLength()

int64 juce::BufferingAudioSource::getTotalLength ( ) const
inlineoverridevirtual

◆ isLooping()

bool juce::BufferingAudioSource::isLooping ( ) const
inlineoverridevirtual

◆ waitForNextAudioBlockReady()

bool juce::BufferingAudioSource::waitForNextAudioBlockReady ( const AudioSourceChannelInfo info,
const uint32  timeout 
)

A useful function to block until the next the buffer info can be filled.

This is useful for offline rendering.

Definition at line 158 of file juce_BufferingAudioSource.cpp.

References juce::Time::getMillisecondCounter(), getTotalLength(), isLooping(), juce::AudioSourceChannelInfo::numSamples, and juce::WaitableEvent::wait().


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