JUCE  v5.1.1-3-g1a0b28c73
JUCE API
AudioSourcePlayer Class Reference

Wrapper class to continuously stream audio from an audio source to an AudioIODevice. More...

#include <juce_AudioSourcePlayer.h>

Inheritance diagram for AudioSourcePlayer:
Collaboration diagram for AudioSourcePlayer:

Public Member Functions

 AudioSourcePlayer ()
 Creates an empty AudioSourcePlayer. More...
 
virtual ~AudioSourcePlayer ()
 Destructor. More...
 
void audioDeviceAboutToStart (AudioIODevice *device) override
 Implementation of the AudioIODeviceCallback method. More...
 
virtual void audioDeviceError (const String &errorMessage)
 This can be overridden to be told if the device generates an error while operating. More...
 
void audioDeviceIOCallback (const float **inputChannelData, int totalNumInputChannels, float **outputChannelData, int totalNumOutputChannels, int numSamples) override
 Implementation of the AudioIODeviceCallback method. More...
 
void audioDeviceStopped () override
 Implementation of the AudioIODeviceCallback method. More...
 
AudioSourcegetCurrentSource () const noexcept
 Returns the source that's playing. More...
 
float getGain () const noexcept
 Returns the current gain. More...
 
void prepareToPlay (double sampleRate, int blockSize)
 An alternative method for initialising the source without an AudioIODevice. More...
 
void setGain (float newGain) noexcept
 Sets a gain to apply to the audio data. More...
 
void setSource (AudioSource *newSource)
 Changes the current audio source to play from. More...
 

Private Attributes

int bufferSize
 
float * channels [128]
 
float gain
 
const float * inputChans [128]
 
float lastGain
 
float * outputChans [128]
 
CriticalSection readLock
 
double sampleRate
 
AudioSourcesource
 
AudioSampleBuffer tempBuffer
 

Detailed Description

Wrapper class to continuously stream audio from an audio source to an AudioIODevice.

This object acts as an AudioIODeviceCallback, so can be attached to an output device, and will stream audio from an AudioSource.

Constructor & Destructor Documentation

◆ AudioSourcePlayer()

AudioSourcePlayer::AudioSourcePlayer ( )

Creates an empty AudioSourcePlayer.

◆ ~AudioSourcePlayer()

virtual AudioSourcePlayer::~AudioSourcePlayer ( )
virtual

Destructor.

Make sure this object isn't still being used by an AudioIODevice before deleting it!

Member Function Documentation

◆ audioDeviceAboutToStart()

void AudioSourcePlayer::audioDeviceAboutToStart ( AudioIODevice device)
overridevirtual

Implementation of the AudioIODeviceCallback method.

Implements AudioIODeviceCallback.

◆ audioDeviceError()

virtual void AudioIODeviceCallback::audioDeviceError ( const String errorMessage)
virtualinherited

This can be overridden to be told if the device generates an error while operating.

Be aware that this could be called by any thread! And not all devices perform this callback.

Reimplemented in SoundPlayer.

◆ audioDeviceIOCallback()

void AudioSourcePlayer::audioDeviceIOCallback ( const float **  inputChannelData,
int  totalNumInputChannels,
float **  outputChannelData,
int  totalNumOutputChannels,
int  numSamples 
)
overridevirtual

Implementation of the AudioIODeviceCallback method.

Implements AudioIODeviceCallback.

◆ audioDeviceStopped()

void AudioSourcePlayer::audioDeviceStopped ( )
overridevirtual

Implementation of the AudioIODeviceCallback method.

Implements AudioIODeviceCallback.

◆ getCurrentSource()

AudioSource* AudioSourcePlayer::getCurrentSource ( ) const
inlinenoexcept

Returns the source that's playing.

May return nullptr if there's no source.

◆ getGain()

float AudioSourcePlayer::getGain ( ) const
inlinenoexcept

◆ prepareToPlay()

void AudioSourcePlayer::prepareToPlay ( double  sampleRate,
int  blockSize 
)

An alternative method for initialising the source without an AudioIODevice.

◆ setGain()

void AudioSourcePlayer::setGain ( float  newGain)
noexcept

Sets a gain to apply to the audio data.

See also
getGain

◆ setSource()

void AudioSourcePlayer::setSource ( AudioSource newSource)

Changes the current audio source to play from.

If the source passed in is already being used, this method will do nothing. If the source is not null, its prepareToPlay() method will be called before it starts being used for playback.

If there's another source currently playing, its releaseResources() method will be called after it has been swapped for the new one.

Parameters
newSourcethe new source to use - this will NOT be deleted by this object when no longer needed, so it's the caller's responsibility to manage it.

Member Data Documentation

◆ bufferSize

int AudioSourcePlayer::bufferSize
private

◆ channels

float* AudioSourcePlayer::channels[128]
private

◆ gain

float AudioSourcePlayer::gain
private

◆ inputChans

const float* AudioSourcePlayer::inputChans[128]
private

◆ lastGain

float AudioSourcePlayer::lastGain
private

◆ outputChans

float* AudioSourcePlayer::outputChans[128]
private

◆ readLock

CriticalSection AudioSourcePlayer::readLock
private

◆ sampleRate

double AudioSourcePlayer::sampleRate
private

◆ source

AudioSource* AudioSourcePlayer::source
private

◆ tempBuffer

AudioSampleBuffer AudioSourcePlayer::tempBuffer
private

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