JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Member Functions | List of all members
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:
juce::AudioIODeviceCallback

Public Member Functions

 ~SoundPlayer () override
 Destructor.
 
void play (const File &file)
 Plays a sound from a file.
 
void play (const void *resourceData, size_t resourceSize)
 Convenient method to play sound from a JUCE resource.
 
void play (AudioFormatReader *buffer, bool deleteWhenFinished=false)
 Plays the sound from an audio format reader.
 
void play (PositionableAudioSource *audioSource, bool deleteWhenFinished=false, double sampleRateOfSource=0.0)
 Plays the sound from a positionable audio source.
 
void play (AudioBuffer< float > *buffer, bool deleteWhenFinished=false, bool playOnAllOutputChannels=false)
 Plays the sound from an audio sample buffer.
 
void playTestSound ()
 Plays a beep through the current audio device.
 
void audioDeviceIOCallbackWithContext (const float *const *, int, float *const *, int, int, const AudioIODeviceCallbackContext &) override
 Processes a block of incoming and outgoing audio data.
 
void audioDeviceAboutToStart (AudioIODevice *) override
 Called to indicate that the device is about to start calling back.
 
void audioDeviceStopped () override
 Called to indicate that the device has stopped.
 
void audioDeviceError (const String &errorMessage) override
 This can be overridden to be told if the device generates an error while operating.
 
- Public Member Functions inherited from juce::AudioIODeviceCallback
virtual ~AudioIODeviceCallback ()=default
 Destructor.
 

Detailed Description

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

See also
AudioProcessor, AudioProcessorGraph

@tags{Audio}

Definition at line 38 of file juce_SoundPlayer.h.

Constructor & Destructor Documentation

◆ SoundPlayer()

juce::SoundPlayer::SoundPlayer ( )

Definition at line 153 of file juce_SoundPlayer.cpp.

◆ ~SoundPlayer()

juce::SoundPlayer::~SoundPlayer ( )
override

Destructor.

Definition at line 160 of file juce_SoundPlayer.cpp.

Member Function Documentation

◆ audioDeviceAboutToStart()

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

Called to indicate that the device is about to start calling back.

This will be called just before the audio callbacks begin, either when this callback has just been added to an audio device, or after the device has been restarted because of a sample-rate or block-size change.

You can use this opportunity to find out the sample rate and block size that the device is going to use by calling the AudioIODevice::getCurrentSampleRate() and AudioIODevice::getCurrentBufferSizeSamples() on the supplied pointer.

Parameters
devicethe audio IO device that will be used to drive the callback. Note that if you're going to store this this pointer, it is only valid until the next time that audioDeviceStopped is called.

Implements juce::AudioIODeviceCallback.

Definition at line 257 of file juce_SoundPlayer.cpp.

◆ audioDeviceError()

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

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 from juce::AudioIODeviceCallback.

Definition at line 273 of file juce_SoundPlayer.cpp.

◆ audioDeviceIOCallbackWithContext()

void juce::SoundPlayer::audioDeviceIOCallbackWithContext ( const float *const inputChannelData,
int  numInputChannels,
float *const outputChannelData,
int  numOutputChannels,
int  numSamples,
const AudioIODeviceCallbackContext context 
)
overridevirtual

Processes a block of incoming and outgoing audio data.

The subclass's implementation should use the incoming audio for whatever purposes it needs to, and must fill all the output channels with the next block of output data before returning.

The channel data is arranged with the same array indices as the channel name array returned by AudioIODevice::getOutputChannelNames(), but those channels that aren't specified in AudioIODevice::open() will have a null pointer for their associated channel, so remember to check for this.

Parameters
inputChannelDataa set of arrays containing the audio data for each incoming channel - this data is valid until the function returns. There will be one channel of data for each input channel that was enabled when the audio device was opened (see AudioIODevice::open())
numInputChannelsthe number of pointers to channel data in the inputChannelData array.
outputChannelDataa set of arrays which need to be filled with the data that should be sent to each outgoing channel of the device. There will be one channel of data for each output channel that was enabled when the audio device was opened (see AudioIODevice::open()) The initial contents of the array is undefined, so the callback function must fill all the channels with zeros if its output is silence. Failing to do this could cause quite an unpleasant noise!
numOutputChannelsthe number of pointers to channel data in the outputChannelData array.
numSamplesthe number of samples in each channel of the input and output arrays. The number of samples will depend on the audio device's buffer size and will usually remain constant, although this isn't guaranteed. For example, on Android, on devices which support it, Android will chop up your audio processing into several smaller callbacks to ensure higher audio performance. So make sure your code can cope with reasonable changes in the buffer size from one callback to the next.
contextAdditional information that may be passed to the AudioIODeviceCallback.

Reimplemented from juce::AudioIODeviceCallback.

Definition at line 245 of file juce_SoundPlayer.cpp.

◆ audioDeviceStopped()

void juce::SoundPlayer::audioDeviceStopped ( )
overridevirtual

Called to indicate that the device has stopped.

Implements juce::AudioIODeviceCallback.

Definition at line 268 of file juce_SoundPlayer.cpp.

◆ 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.

Definition at line 187 of file juce_SoundPlayer.cpp.

◆ 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.

Definition at line 181 of file juce_SoundPlayer.cpp.

◆ play() [3/5]

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

Plays a sound from a file.

Definition at line 166 of file juce_SoundPlayer.cpp.

◆ play() [4/5]

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

Convenient method to play sound from a JUCE resource.

Definition at line 172 of file juce_SoundPlayer.cpp.

◆ 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.

Definition at line 193 of file juce_SoundPlayer.cpp.

◆ 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.

Definition at line 225 of file juce_SoundPlayer.cpp.


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