JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::SoundPlayer Class Reference

A simple sound player that you can add to the AudioDeviceManager to play simple sounds. More...

#include <juce_SoundPlayer.h>

Inheritance diagram for juce::SoundPlayer:
Collaboration diagram for juce::SoundPlayer:

Public Member Functions

 SoundPlayer ()
 
 ~SoundPlayer () override
 Destructor. More...
 
void audioDeviceAboutToStart (AudioIODevice *) override
 
void audioDeviceError (const String &errorMessage) override
 
void audioDeviceIOCallback (const float **, int, float **, int, int) override
 
void audioDeviceStopped () override
 
void play (AudioBuffer< float > *buffer, bool deleteWhenFinished=false, bool playOnAllOutputChannels=false)
 Plays the sound from an audio sample buffer. More...
 
void play (AudioFormatReader *buffer, bool deleteWhenFinished=false)
 Plays the sound from an audio format reader. More...
 
void play (const File &file)
 Plays a sound from a file. More...
 
void play (const void *resourceData, size_t resourceSize)
 Convenient method to play sound from a JUCE resource. More...
 
void play (PositionableAudioSource *audioSource, bool deleteWhenFinished=false, double sampleRateOfSource=0.0)
 Plays the sound from a positionable audio source. More...
 
void playTestSound ()
 Plays a beep through the current audio device. More...
 

Private Attributes

int bufferSize
 
AudioFormatManager formatManager
 
MixerAudioSource mixer
 
AudioSourcePlayer player
 
double sampleRate
 
OwnedArray< AudioSourcesources
 

Detailed Description

A simple sound player that you can add to the AudioDeviceManager to play simple sounds.

See also
AudioProcessor, AudioProcessorGraph

@tags{Audio}

Constructor & Destructor Documentation

◆ SoundPlayer()

juce::SoundPlayer::SoundPlayer ( )

◆ ~SoundPlayer()

juce::SoundPlayer::~SoundPlayer ( )
override

Destructor.

Member Function Documentation

◆ audioDeviceAboutToStart()

void juce::SoundPlayer::audioDeviceAboutToStart ( AudioIODevice )
overridevirtual

◆ audioDeviceError()

void juce::SoundPlayer::audioDeviceError ( const String errorMessage)
overridevirtual

Reimplemented from juce::AudioIODeviceCallback.

◆ audioDeviceIOCallback()

void juce::SoundPlayer::audioDeviceIOCallback ( const float **  ,
int  ,
float **  ,
int  ,
int   
)
overridevirtual

◆ audioDeviceStopped()

void juce::SoundPlayer::audioDeviceStopped ( )
overridevirtual

◆ play() [1/5]

void juce::SoundPlayer::play ( AudioBuffer< float > *  buffer,
bool  deleteWhenFinished = false,
bool  playOnAllOutputChannels = false 
)

Plays the sound from an audio sample buffer.

This will output the sound contained in an audio sample buffer. If deleteWhenFinished is true then the audio sample buffer will be automatically deleted once the sound has finished playing.

If playOnAllOutputChannels is true, then if there are more output channels than buffer channels, then the ones that are available will be re-used on multiple outputs so that something is sent to all output channels. If it is false, then the buffer will just be played on the first output channels.

◆ play() [2/5]

void juce::SoundPlayer::play ( AudioFormatReader buffer,
bool  deleteWhenFinished = false 
)

Plays the sound from an audio format reader.

If deleteWhenFinished is true then the format reader will be automatically deleted once the sound has finished playing.

◆ play() [3/5]

void juce::SoundPlayer::play ( const File file)

Plays a sound from a file.

◆ play() [4/5]

void juce::SoundPlayer::play ( const void *  resourceData,
size_t  resourceSize 
)

Convenient method to play sound from a JUCE resource.

◆ play() [5/5]

void juce::SoundPlayer::play ( PositionableAudioSource audioSource,
bool  deleteWhenFinished = false,
double  sampleRateOfSource = 0.0 
)

Plays the sound from a positionable audio source.

This will output the sound coming from a positionable audio source. This gives you slightly more control over the sound playback compared to the other playSound methods. For example, if you would like to stop the sound prematurely you can call this method with a TransportAudioSource and then call audioSource->stop. Note that, you must call audioSource->start to start the playback, if your audioSource is a TransportAudioSource.

The audio device manager will not hold any references to this audio source once the audio source has stopped playing for any reason, for example when the sound has finished playing or when you have called audioSource->stop. Therefore, calling audioSource->start() on a finished audioSource will not restart the sound again. If this is desired simply call playSound with the same audioSource again.

Parameters
audioSourcethe audio source to play
deleteWhenFinishedIf this is true then the audio source will be deleted once the device manager has finished playing.
sampleRateOfSourceThe sample rate of the source. If this is zero, JUCE will assume that the sample rate is the same as the audio output device.

◆ playTestSound()

void juce::SoundPlayer::playTestSound ( )

Plays a beep through the current audio device.

This is here to allow the audio setup UI panels to easily include a "test" button so that the user can check where the audio is coming from.

Member Data Documentation

◆ bufferSize

int juce::SoundPlayer::bufferSize
private

◆ formatManager

AudioFormatManager juce::SoundPlayer::formatManager
private

◆ mixer

MixerAudioSource juce::SoundPlayer::mixer
private

◆ player

AudioSourcePlayer juce::SoundPlayer::player
private

◆ sampleRate

double juce::SoundPlayer::sampleRate
private

◆ sources

OwnedArray<AudioSource> juce::SoundPlayer::sources
private

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