GREM 3.12.0
Game/Rendering Engine Modules for C++
Loading...
Searching...
No Matches
grem::audio::SoundStage Class Reference

Persistent system for playing sound in a simulated 3D arena to the default audio device. More...

#include <GREM/audio/SoundStage.hpp>

Public Member Functions

 SoundStage (const SoundStageOptions &options={})
 Construct a sound stage.
void update (const Listener &listener)
 Update the 3D parameters of the sound stage.
SoundInstanceID playSound (const Sound &sound, float volume=-1.0f, Panning panning={})
 Create a new relative sound instance and start playing it.
SoundInstanceID play3DSound (const Sound &sound, vec3 position, vec3 velocity, float volume=-1.0f)
 Create a new 3D sound instance and start playing it.
SoundInstanceID playSoundInBackground (const Sound &sound, float volume=-1.0f)
 Create a new sound instance without any panning and start playing it.
SoundInstanceID createPausedSound (const Sound &sound, float volume=-1.0f, Panning panning={})
 Create a new relative sound instance, but don't start playing it yet.
SoundInstanceID createPaused3DSound (const Sound &sound, vec3 position, vec3 velocity, float volume=-1.0f)
 Create a new 3D sound instance, but don't start playing it yet.
SoundInstanceID createPausedSoundInBackground (const Sound &sound, float volume=-1.0f)
 Create a new sound instance without any panning, but don't start playing it yet.
SoundInstanceID playSoundClocked (Duration time, const Sound &sound, float volume=-1.0f, Panning panning={})
 Create a new 3D sound instance and start playing it at a specific time relative to other sounds that were also played using playSoundClocked().
SoundInstanceID play3DSoundClocked (Duration time, const Sound &sound, vec3 position, vec3 velocity, float volume=-1.0f)
 Create a new 3D sound instance and start playing it at a specific time relative to other sounds that were also played using playSoundClocked().
bool isSoundPaused (SoundInstanceID id) const noexcept
 Check if a specific sound instance is currently paused.
bool isSoundStopped (SoundInstanceID id) const noexcept
 Check if a specific sound instance has finished playing.
bool isSoundLooping (SoundInstanceID id) const noexcept
 Check if a specific sound instance is set to repeat instead of stopping.
Optional< Duration > getSoundTime (SoundInstanceID id) const
 Get the current playback time point of a specific sound instance.
void stopSound (SoundInstanceID id) noexcept
 Stop a specific sound instance and remove it.
void pauseSound (SoundInstanceID id)
 Pause a specific sound instance.
void resumeSound (SoundInstanceID id)
 Unpause and resume a specific sound instance.
void scheduleSoundStop (SoundInstanceID id, Duration timePointInSound)
 Schedule for a specific sound instance to stop playing and remove itself when the playback reaches a specific time point.
void scheduleSoundPause (SoundInstanceID id, Duration timePointInSound)
 Schedule for a specific sound instance to pause itself when the playback reaches a specific time point.
void setSoundLooping (SoundInstanceID id, bool newLooping)
 Set whether a specific sound instance should repeat or stop when it ends.
void seekToSoundTime (SoundInstanceID id, Duration timePointInSound)
 Set the current playback time point of a specific sound instance.
void setSoundPosition (SoundInstanceID id, vec3 newPosition)
 Set the current 3D position of a specific sound instance.
void setSoundVelocity (SoundInstanceID id, vec3 newVelocity)
 Set the current 3D velocity of a specific sound instance.
void setSoundPositionAndVelocity (SoundInstanceID id, vec3 newPosition, vec3 newVelocity)
 Set both the 3D position and 3D velocity of a specific sound instance at the same time.
void setSoundPanning (SoundInstanceID id, Panning newPanning)
 Set the panning of a specific sound instance.
void setSoundVolume (SoundInstanceID id, float newVolume)
 Set the volume of a specific sound instance.
void fadeSoundVolume (SoundInstanceID id, float targetVolume, Duration fadeDuration)
 Fade the volume of a specific sound instance towards a target volume over a given duration.
void setSoundPlaybackSpeed (SoundInstanceID id, float newPlaybackSpeed)
 Set the relative playback speed of a specific sound instance.
void fadeSoundPlaybackSpeed (SoundInstanceID id, float targetPlaybackSpeed, Duration fadeDuration)
 Fade the relative playback speed of a specific sound instance towards a target relative playback speed over a given duration.
void setOutputChannelSpeakerPosition (size_t outputChannelIndex, vec3 newPosition)
 Set the listener-relative speaker position of an output audio channel.
void setOutputVolume (float newVolume)
 Set the global master volume of the sound stage.
void fadeOutputVolume (float targetVolume, Duration fadeDuration)
 Fade the global master volume of the sound stage towards a target volume over a given duration.
void setSpeedOfSound (float newSpeedOfSound)
 Set the speed of sound in the sound stage.
void setMaxSimultaneousSoundInstanceCount (size_t newMaxSimultaneousSoundInstanceCount)
 Set the maximum total number of sound instances that can play simultaneously.
void setStatisticsEnabled (bool newEnableStatistics)
 Set whether to enable statistics gathering or not.
size_t getOutputChannelCount () const noexcept
 Get the number of output audio channels.
vec3 getOutputChannelSpeakerPosition (size_t outputChannelIndex) const noexcept
 Get the listener-relative speaker position of an output audio channel.
float getOutputVolume () const noexcept
 Get the global master volume of the sound stage.
float getSpeedOfSound () const noexcept
 Get the speed of sound in the sound stage.
size_t getMaxSimultaneousSounds () const noexcept
 Get the maximum total number of sound instances that can play simultaneously.
Array< float, 256 > calculateOutputFastFourierTransformStatistics () const
 Calculate the fast Fourier transform of the audio currently playing through the sound stage.
Array< float, 256 > getOutputWaveStatistics () const
 Get the sound wave currently playing through the sound stage.
float getOutputChannelVolumeStatistics (size_t outputChannelIndex) const
 Get an approximation of the volume of the audio currently playing through a specific channel of the sound stage.
template<filter F>
void setGlobalFilter (size_t filterSlotIndex, const F &newFilter)
 Set the filter at a particular global filter slot of the sound stage.
void clearGlobalFilter (size_t filterSlotIndex) noexcept
 Remove the filter at a particular global filter slot of the sound stage.
template<auto Member>
void setSoundFilterParameter (SoundInstanceID id, size_t filterSlotIndex, meta::member_pointer_target_type_t< Member > newValue)
 Set a live parameter of an active filter at a particular filter slot of a sound instance in the sound stage.
template<auto Member>
void setGlobalFilterParameter (size_t filterSlotIndex, meta::member_pointer_target_type_t< Member > newValue)
 Set a live parameter of an active filter at a particular global filter slot of the sound stage.
template<auto Member>
void fadeSoundFilterParameter (SoundInstanceID id, size_t filterSlotIndex, meta::member_pointer_target_type_t< Member > targetValue, Duration fadeDuration)
 Fade a live parameter of an active filter at a particular filter slot of a sound instance in the sound stage towards a target value over a given duration.
template<auto Member>
void fadeGlobalFilterParameter (size_t filterSlotIndex, meta::member_pointer_target_type_t< Member > targetValue, Duration fadeDuration)
 Fade a live parameter of an active filter at a particular global filter slot of the sound stage towards a target value over a given duration.
template<auto Member>
meta::member_pointer_target_type_t< Member > getSoundFilterParameter (SoundInstanceID id, size_t filterSlotIndex) const
 Get a live parameter of an active filter at a particular filter slot of a sound instance in the sound stage.
template<auto Member>
meta::member_pointer_target_type_t< Member > getGlobalFilterParameter (size_t filterSlotIndex) const
 Get a live parameter of an active filter at a particular global filter slot of the sound stage.
void * get () noexcept
 Get an opaque handle to the internal representation of the sound stage.
const void * get () const noexcept
 Get an opaque handle to the internal representation of the sound stage.

Detailed Description

Persistent system for playing sound in a simulated 3D arena to the default audio device.

The sound stage uses a right-handed coordinate system for 3D calculations, and any coordinates are assumed to be in meters by default. Applications that use a different unit of length should adjust the SoundStageOptions::speedOfSound in the sound stage configuration as well as the SoundOptions::rolloffFactor of each Sound accordingly.

Constructor & Destructor Documentation

◆ SoundStage()

grem::audio::SoundStage::SoundStage ( const SoundStageOptions & options = {})
explicit

Construct a sound stage.

Parameters
optionsinitial configuration of the sound stage, see SoundStageOptions.
Exceptions
audio::Erroron failure to initialize the underlying audio engine.
std::bad_allocon allocation failure.
Warning
Due to having global access to the default audio device, only a single SoundManager instance may exist in the program at any given time.

Member Function Documentation

◆ update()

void grem::audio::SoundStage::update ( const Listener & listener)

Update the 3D parameters of the sound stage.

Parameters
listenercurrent parameters to use for the sound listener on this frame.
Note
This function should typically be called once every frame during the application::Application::update() callback.

◆ playSound()

SoundInstanceID grem::audio::SoundStage::playSound ( const Sound & sound,
float volume = -1.0f,
Panning panning = {} )

Create a new relative sound instance and start playing it.

Parameters
soundthe sound data to use for this instance.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
panningpanning to apply to the sound when playing.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
createPausedSound()
play3DSound()
playSoundClocked()
playSoundInBackground()
createPausedSoundInBackground()

◆ play3DSound()

SoundInstanceID grem::audio::SoundStage::play3DSound ( const Sound & sound,
vec3 position,
vec3 velocity,
float volume = -1.0f )

Create a new 3D sound instance and start playing it.

Parameters
soundthe sound data to use for this instance.
positionthe position to play the sound at, in sound stage coordinates. Used for distance attenuation/falloff according to the SoundAttenuationModel set in the sound's SoundOptions.
velocityinitial linear velocity of the sound. Relevant for simulating the doppler effect.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
playSound()
play3DSoundClocked()
playSoundInBackground()
createPausedSoundInBackground()

◆ playSoundInBackground()

SoundInstanceID grem::audio::SoundStage::playSoundInBackground ( const Sound & sound,
float volume = -1.0f )

Create a new sound instance without any panning and start playing it.

Parameters
soundthe sound data to use for this instance.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
playSound()
createPausedSoundInBackground()

◆ createPausedSound()

SoundInstanceID grem::audio::SoundStage::createPausedSound ( const Sound & sound,
float volume = -1.0f,
Panning panning = {} )

Create a new relative sound instance, but don't start playing it yet.

Parameters
soundthe sound data to use for this instance.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
panningpanning to apply to the sound when playing.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
playSound()
play3DSound()
playSoundClocked()
playSoundInBackground()
createPausedSoundInBackground()

◆ createPaused3DSound()

SoundInstanceID grem::audio::SoundStage::createPaused3DSound ( const Sound & sound,
vec3 position,
vec3 velocity,
float volume = -1.0f )

Create a new 3D sound instance, but don't start playing it yet.

Parameters
soundthe sound data to use for this instance.
positionthe position to play the sound at, in sound stage coordinates. Used for distance attenuation/falloff according to the SoundAttenuationModel set in the sound's SoundOptions.
velocityinitial linear velocity of the sound. Relevant for simulating the doppler effect.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
createPausedSound()
play3DSound()
play3DSoundClocked()
playSoundInBackground()
createPausedSoundInBackground()

◆ createPausedSoundInBackground()

SoundInstanceID grem::audio::SoundStage::createPausedSoundInBackground ( const Sound & sound,
float volume = -1.0f )

Create a new sound instance without any panning, but don't start playing it yet.

Parameters
soundthe sound data to use for this instance.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
createPausedSound()
playSoundInBackground()

◆ playSoundClocked()

SoundInstanceID grem::audio::SoundStage::playSoundClocked ( Duration time,
const Sound & sound,
float volume = -1.0f,
Panning panning = {} )

Create a new 3D sound instance and start playing it at a specific time relative to other sounds that were also played using playSoundClocked().

Parameters
timetime point to play the sound at, relative to other clocked sounds. This is typically the current frame or tick time, plus some offset.
soundthe sound data to use for this instance.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
panningpanning to apply to the sound when playing.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
playSound()
createPausedSound()
playSoundInBackground()
createPausedSoundInBackground()

◆ play3DSoundClocked()

SoundInstanceID grem::audio::SoundStage::play3DSoundClocked ( Duration time,
const Sound & sound,
vec3 position,
vec3 velocity,
float volume = -1.0f )

Create a new 3D sound instance and start playing it at a specific time relative to other sounds that were also played using playSoundClocked().

Parameters
timetime point to play the sound at, relative to other clocked sounds. This is typically the current frame or tick time, plus some offset.
soundthe sound data to use for this instance.
positionthe position to play the sound at, in sound stage coordinates. Used for distance attenuation/falloff according to the SoundAttenuationModel set in the sound's SoundOptions.
velocityinitial linear velocity of the sound. Relevant for simulating the doppler effect.
volumegain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead.
Returns
a handle to the new sound instance that can be used to refer back to it later in order to query its state or make changes to it.
See also
play3DSound()
createPaused3DSound()
playSoundClocked()
playSoundInBackground()
createPausedSoundInBackground()

◆ isSoundPaused()

bool grem::audio::SoundStage::isSoundPaused ( SoundInstanceID id) const
nodiscardnoexcept

Check if a specific sound instance is currently paused.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
Returns
true if the sound instance still exists and is currently paused, false otherwise.
See also
isSoundStopped()
pauseSound()
resumeSound()

◆ isSoundStopped()

bool grem::audio::SoundStage::isSoundStopped ( SoundInstanceID id) const
nodiscardnoexcept

Check if a specific sound instance has finished playing.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
Returns
true if the sound instance has been stopped or finished playing and no longer exists, false otherwise.
See also
isSoundPaused()
stopSound()

◆ isSoundLooping()

bool grem::audio::SoundStage::isSoundLooping ( SoundInstanceID id) const
nodiscardnoexcept

Check if a specific sound instance is set to repeat instead of stopping.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
Returns
true if the sound instance still exists and is currently set to play on repeat, false otherwise.
See also
isSoundStopped()
setSoundLooping()

◆ getSoundTime()

Optional< Duration > grem::audio::SoundStage::getSoundTime ( SoundInstanceID id) const
nodiscard

Get the current playback time point of a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
Returns
the current time point, measured from the beginning of the sound, or an empty optional if the sound has stopped or does not exist.
See also
seekToSoundTime()

◆ stopSound()

void grem::audio::SoundStage::stopSound ( SoundInstanceID id)
noexcept

Stop a specific sound instance and remove it.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
isSoundStopped()
scheduleSoundStop()

◆ pauseSound()

void grem::audio::SoundStage::pauseSound ( SoundInstanceID id)

Pause a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
Note
If the given sound instance doesn't exist, or if it is already paused, this function has no effect.
See also
isSoundPaused()
resumeSound()
scheduleSoundPause()

◆ resumeSound()

void grem::audio::SoundStage::resumeSound ( SoundInstanceID id)

Unpause and resume a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
Note
If the given sound instance doesn't exist, or if it is not paused, this function has no effect.
See also
isSoundPaused()
pauseSound()

◆ scheduleSoundStop()

void grem::audio::SoundStage::scheduleSoundStop ( SoundInstanceID id,
Duration timePointInSound )

Schedule for a specific sound instance to stop playing and remove itself when the playback reaches a specific time point.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
timePointInSoundthe time point, measured from the beginning of the sound, where the sound instance will stop itself.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
isSoundStopped()
stopSound()

◆ scheduleSoundPause()

void grem::audio::SoundStage::scheduleSoundPause ( SoundInstanceID id,
Duration timePointInSound )

Schedule for a specific sound instance to pause itself when the playback reaches a specific time point.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
timePointInSoundthe time point, measured from the beginning of the sound, where the sound instance will pause itself.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
isSoundPaused()
pauseSound()

◆ setSoundLooping()

void grem::audio::SoundStage::setSoundLooping ( SoundInstanceID id,
bool newLooping )

Set whether a specific sound instance should repeat or stop when it ends.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
newLoopingtrue to set the sound to play on repeat, false to disable looping and stop the sound when it ends.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
isSoundLooping()
stopSound()

◆ seekToSoundTime()

void grem::audio::SoundStage::seekToSoundTime ( SoundInstanceID id,
Duration timePointInSound )

Set the current playback time point of a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
timePointInSoundthe time point, measured from the beginning of the sound, to seek to.
Note
If the given sound instance exists, it will continue playing after seeking unless it was paused.
If the given sound instance doesn't exist, this function has no effect.
See also
getSoundTime()

◆ setSoundPosition()

void grem::audio::SoundStage::setSoundPosition ( SoundInstanceID id,
vec3 newPosition )

Set the current 3D position of a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
newPositionnew position of the sound instance, in sound stage coordinates.
Note
The effect of this function will only apply after the next call to update().
If the given sound instance doesn't exist, this function has no effect.
See also
setSoundVelocity()
setSoundPositionAndVelocity()

◆ setSoundVelocity()

void grem::audio::SoundStage::setSoundVelocity ( SoundInstanceID id,
vec3 newVelocity )

Set the current 3D velocity of a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
newVelocitynew linear velocity of the sound instance.
Note
The effect of this function will only apply after the next call to update().
If the given sound instance doesn't exist, this function has no effect.
See also
setSoundPosition()
setSoundPositionAndVelocity()

◆ setSoundPositionAndVelocity()

void grem::audio::SoundStage::setSoundPositionAndVelocity ( SoundInstanceID id,
vec3 newPosition,
vec3 newVelocity )

Set both the 3D position and 3D velocity of a specific sound instance at the same time.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
newPositionnew position of the sound instance, in sound stage coordinates.
newVelocitynew linear velocity of the sound instance.
Note
The effect of this function will only apply after the next call to update().
If the given sound instance doesn't exist, this function has no effect.
See also
setSoundPosition()
setSoundVelocity()

◆ setSoundPanning()

void grem::audio::SoundStage::setSoundPanning ( SoundInstanceID id,
Panning newPanning )

Set the panning of a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
newPanningnew panning value.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
setSoundVolume()

◆ setSoundVolume()

void grem::audio::SoundStage::setSoundVolume ( SoundInstanceID id,
float newVolume )

Set the volume of a specific sound instance.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
newVolumenew volume, see SoundOptions::volume.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
setOutputVolume()
fadeSoundVolume()

◆ fadeSoundVolume()

void grem::audio::SoundStage::fadeSoundVolume ( SoundInstanceID id,
float targetVolume,
Duration fadeDuration )

Fade the volume of a specific sound instance towards a target volume over a given duration.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
targetVolumenew volume to fade towards, see SoundOptions::volume.
fadeDurationduration of time to fade over.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
setSoundVolume()

◆ setSoundPlaybackSpeed()

void grem::audio::SoundStage::setSoundPlaybackSpeed ( SoundInstanceID id,
float newPlaybackSpeed )

Set the relative playback speed of a specific sound instance.

The effective sample rate of the playing sound is adjusted by this factor, meaning that a value of 1 represents no change, i.e. 100% of the original playback speed of the loaded sound file.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
newPlaybackSpeednew relative playback speed. Must be greater than 0.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
fadeSoundPlaybackSpeed()

◆ fadeSoundPlaybackSpeed()

void grem::audio::SoundStage::fadeSoundPlaybackSpeed ( SoundInstanceID id,
float targetPlaybackSpeed,
Duration fadeDuration )

Fade the relative playback speed of a specific sound instance towards a target relative playback speed over a given duration.

Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
targetPlaybackSpeednew relative playback speed to fade towards. Must be greater than 0.
fadeDurationduration of time to fade over.
Note
If the given sound instance doesn't exist, this function has no effect.
See also
setSoundPlaybackSpeed()

◆ setOutputChannelSpeakerPosition()

void grem::audio::SoundStage::setOutputChannelSpeakerPosition ( size_t outputChannelIndex,
vec3 newPosition )

Set the listener-relative speaker position of an output audio channel.

Parameters
outputChannelIndexindex of the output channel to set the speaker position of. Must be less than getOutputChannelCount().
newPositionnew speaker position to set.

◆ setOutputVolume()

void grem::audio::SoundStage::setOutputVolume ( float newVolume)

Set the global master volume of the sound stage.

Parameters
newVolumenew volume, see SoundStageOptions::volume.
See also
setSoundVolume()
fadeOutputVolume()

◆ fadeOutputVolume()

void grem::audio::SoundStage::fadeOutputVolume ( float targetVolume,
Duration fadeDuration )

Fade the global master volume of the sound stage towards a target volume over a given duration.

Parameters
targetVolumenew volume to fade towards, see SoundStageOptions::outputVolume.
fadeDurationduration of time to fade over.
See also
setOutputVolume()

◆ setSpeedOfSound()

void grem::audio::SoundStage::setSpeedOfSound ( float newSpeedOfSound)

Set the speed of sound in the sound stage.

Parameters
newSpeedOfSoundnew speed of sound, see SoundStageOptions::speedOfSound.

◆ setMaxSimultaneousSoundInstanceCount()

void grem::audio::SoundStage::setMaxSimultaneousSoundInstanceCount ( size_t newMaxSimultaneousSoundInstanceCount)

Set the maximum total number of sound instances that can play simultaneously.

Parameters
newMaxSimultaneousSoundInstanceCountnew number of sound instances, see SoundStageOptions::maxSimultaneousSoundInstanceCount.

◆ setStatisticsEnabled()

void grem::audio::SoundStage::setStatisticsEnabled ( bool newEnableStatistics)

Set whether to enable statistics gathering or not.

Statistics gathering must be enabled in order for calculateOutputFastFourierTransformStatistics(), getOutputWaveStatistics() and getOutputChannelVolumeStatistics() to work.

Parameters
newEnableStatisticsnew mode of statistics gathering to set.

◆ getOutputChannelCount()

size_t grem::audio::SoundStage::getOutputChannelCount ( ) const
nodiscardnoexcept

Get the number of output audio channels.

Returns
the number of channels.

◆ getOutputChannelSpeakerPosition()

vec3 grem::audio::SoundStage::getOutputChannelSpeakerPosition ( size_t outputChannelIndex) const
nodiscardnoexcept

Get the listener-relative speaker position of an output audio channel.

Parameters
outputChannelIndexindex of the output channel to get the speaker position of.
Returns
the speaker position of the given channel, or (0, 0, 0) if the channel index was out of range.

◆ getOutputVolume()

float grem::audio::SoundStage::getOutputVolume ( ) const
nodiscardnoexcept

Get the global master volume of the sound stage.

Returns
the current global master volume, see SoundStageOptions::outputVolume.

◆ getSpeedOfSound()

float grem::audio::SoundStage::getSpeedOfSound ( ) const
nodiscardnoexcept

Get the speed of sound in the sound stage.

Returns
the current speed of sound.

◆ getMaxSimultaneousSounds()

size_t grem::audio::SoundStage::getMaxSimultaneousSounds ( ) const
nodiscardnoexcept

Get the maximum total number of sound instances that can play simultaneously.

Returns
the maximum number of simultaneous sound instances.

◆ calculateOutputFastFourierTransformStatistics()

Array< float, 256 > grem::audio::SoundStage::calculateOutputFastFourierTransformStatistics ( ) const
nodiscard

Calculate the fast Fourier transform of the audio currently playing through the sound stage.

Returns
A sequence of 256 values representing the discrete Fourier transform of the currently playing audio, from low to high frequencies.
Note
This function requires statistics gathering to be enabled on the sound stage in order to produce meaningful results.
See also
SoundStageOptions::enableStatistics
setStatisticsEnabled()

◆ getOutputWaveStatistics()

Array< float, 256 > grem::audio::SoundStage::getOutputWaveStatistics ( ) const
nodiscard

Get the sound wave currently playing through the sound stage.

Returns
a sequence of the 256 latest audio samples played through the sound stage.
Note
This function requires statistics gathering to be enabled on the sound stage in order to produce meaningful results.
See also
SoundStageOptions::enableStatistics
setStatisticsEnabled()

◆ getOutputChannelVolumeStatistics()

float grem::audio::SoundStage::getOutputChannelVolumeStatistics ( size_t outputChannelIndex) const
nodiscard

Get an approximation of the volume of the audio currently playing through a specific channel of the sound stage.

Parameters
outputChannelIndexindex of the channel to get the volume of.
Returns
an approximation of the volume of the current audio playing through the given sound stage channel, or 0.0f if the channel index was out of range.
Note
This function requires statistics gathering to be enabled on the sound stage in order to produce meaningful results.
See also
SoundMixOptions::enableStatistics
setStatisticsEnabled()

◆ setGlobalFilter()

template<filter F>
void grem::audio::SoundStage::setGlobalFilter ( size_t filterSlotIndex,
const F & newFilter )
inline

Set the filter at a particular global filter slot of the sound stage.

This replaces any existing filter at the given slot.

Parameters
filterSlotIndexfilter slot index to set the filter of. Must be less than Sound::MAX_FILTER_COUNT.
newFilternew filter to insert.
Exceptions
audio::Erroron failure to create the filter.
std::length_errorif the maximum filter size was exceeded.
std::bad_allocon allocation failure.
Remarks
A custom filter is any trivially copyable and trivially destructible type that provides the following public member function: cpp void filter(Span<float> samples, size_t channelCount, size_t sampleCountPerChannel, float sampleRate, double time); Filters may also provide a field named parameters of an aggregate type containing a scalar field for each filter parameter that should be adjustable on-the-fly.

◆ clearGlobalFilter()

void grem::audio::SoundStage::clearGlobalFilter ( size_t filterSlotIndex)
noexcept

Remove the filter at a particular global filter slot of the sound stage.

Parameters
filterSlotIndexfilter slot index to clear the filter of. Must be less than Sound::MAX_FILTER_COUNT.

◆ setSoundFilterParameter()

template<auto Member>
void grem::audio::SoundStage::setSoundFilterParameter ( SoundInstanceID id,
size_t filterSlotIndex,
meta::member_pointer_target_type_t< Member > newValue )
inline

Set a live parameter of an active filter at a particular filter slot of a sound instance in the sound stage.

Template Parameters
Memberpointer-to-member of the parameter field in the filter's parameters struct to set the value of. If the given sound instance exists, its sound source must have a filter at the given slot whose parameters member is an aggregate type that is the same as this member pointer's object type.
Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
filterSlotIndexfilter slot index of the filter whose parameter to set. Must be less than Sound::MAX_FILTER_COUNT.
newValuenew value to set the parameter to.
Note
If the given sound instance doesn't exist, this function has no effect.
Remarks
Example usage: cpp const size_t filterSlotIndex = 3; sound.setFilter(filterSlotIndex, MyFilter{}); const SoundInstanceID id = soundStage.playSound(sound); soundStage.setSoundFilterParameter<&MyFilter::Parameters::wet>(id, filterSlotIndex, 0.5f);

◆ setGlobalFilterParameter()

template<auto Member>
void grem::audio::SoundStage::setGlobalFilterParameter ( size_t filterSlotIndex,
meta::member_pointer_target_type_t< Member > newValue )
inline

Set a live parameter of an active filter at a particular global filter slot of the sound stage.

Template Parameters
Memberpointer-to-member of the parameter field in the filter's parameters struct to set the value of. The sound stage must have a global filter at the given slot whose parameters member is an aggregate type that is the same as this member pointer's object type.
Parameters
filterSlotIndexfilter slot index of the filter whose parameter to set. Must be less than Sound::MAX_FILTER_COUNT.
newValuenew value to set the parameter to.
Remarks
Example usage: cpp const size_t filterSlotIndex = 3; soundStage.setGlobalFilter(filterSlotIndex, MyFilter{}); soundStage.setGlobalFilterParameter<&MyFilter::Parameters::wet>(filterSlotIndex, 0.5f);

◆ fadeSoundFilterParameter()

template<auto Member>
void grem::audio::SoundStage::fadeSoundFilterParameter ( SoundInstanceID id,
size_t filterSlotIndex,
meta::member_pointer_target_type_t< Member > targetValue,
Duration fadeDuration )
inline

Fade a live parameter of an active filter at a particular filter slot of a sound instance in the sound stage towards a target value over a given duration.

Template Parameters
Memberpointer-to-member of the parameter field in the filter's parameters struct to fade the value of. If the given sound instance exists, its sound source must have a filter at the given slot whose parameters member is an aggregate type that is the same as this member pointer's object type.
Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
filterSlotIndexfilter slot index of the filter whose parameter to set. Must be less than Sound::MAX_FILTER_COUNT.
targetValuenew value to fade the parameter towards.
fadeDurationduration of time to fade over.
Note
If the given sound instance doesn't exist, this function has no effect.
Remarks
Example usage: cpp const size_t filterSlotIndex = 3; sound.setFilter(filterSlotIndex, MyFilter{}); const SoundInstanceID id = soundStage.playSound(sound); soundStage.fadeSoundFilterParameter<&MyFilter::Parameters::wet>(id, filterSlotIndex, 0.5f, 2_seconds);

◆ fadeGlobalFilterParameter()

template<auto Member>
void grem::audio::SoundStage::fadeGlobalFilterParameter ( size_t filterSlotIndex,
meta::member_pointer_target_type_t< Member > targetValue,
Duration fadeDuration )
inline

Fade a live parameter of an active filter at a particular global filter slot of the sound stage towards a target value over a given duration.

Template Parameters
Memberpointer-to-member of the parameter field in the filter's parameters struct to fade the value of. The sound stage must have a global filter at the given slot whose parameters member is an aggregate type that is the same as this member pointer's object type.
Parameters
filterSlotIndexfilter slot index of the filter whose parameter to set. Must be less than Sound::MAX_FILTER_COUNT.
targetValuenew value to fade the parameter towards.
fadeDurationduration of time to fade over.
Remarks
Example usage: cpp const size_t filterSlotIndex = 3; sound.setGlobalFilter(filterSlotIndex, MyFilter{}); soundStage.fadeGlobalFilterParameter<&MyFilter::Parameters::wet>(filterSlotIndex, 0.5f, 2_seconds);

◆ getSoundFilterParameter()

template<auto Member>
meta::member_pointer_target_type_t< Member > grem::audio::SoundStage::getSoundFilterParameter ( SoundInstanceID id,
size_t filterSlotIndex ) const
inlinenodiscard

Get a live parameter of an active filter at a particular filter slot of a sound instance in the sound stage.

Template Parameters
Memberpointer-to-member of the parameter field in the filter's parameters struct to get the value of. If the given sound instance exists, its sound source must have a filter at the given slot whose parameters member is an aggregate type that is the same as this member pointer's object type.
Parameters
idhandle to the sound instance, acquired from when the sound instance was created.
filterSlotIndexfilter slot index of the filter whose parameter to get. Must be less than Sound::MAX_FILTER_COUNT.
Note
If the given sound instance doesn't exist, this function returns an unspecified value.
Remarks
Example usage: cpp const size_t filterSlotIndex = 3; sound.setFilter(filterSlotIndex, MyFilter{}); const SoundInstanceID id = soundStage.playSound(sound); const float wet = soundStage.getSoundFilterParameter<&MyFilter::Parameters::wet>(id, filterSlotIndex);

◆ getGlobalFilterParameter()

template<auto Member>
meta::member_pointer_target_type_t< Member > grem::audio::SoundStage::getGlobalFilterParameter ( size_t filterSlotIndex) const
inlinenodiscard

Get a live parameter of an active filter at a particular global filter slot of the sound stage.

Template Parameters
Memberpointer-to-member of the parameter field in the filter's parameters struct to get the value of. The sound stage must have a global filter at the given slot whose parameters member is an aggregate type that is the same as this member pointer's object type.
Parameters
filterSlotIndexfilter slot index of the filter whose parameter to get. Must be less than Sound::MAX_FILTER_COUNT.
Remarks
Example usage: cpp const size_t filterSlotIndex = 3; soundStage.setGlobalFilter(filterSlotIndex, MyFilter{}); const float wet = soundStage.getGlobalFilterParameter<&MyFilter::Parameters::wet>(filterSlotIndex);

◆ get() [1/2]

void * grem::audio::SoundStage::get ( )
inlinenodiscardnoexcept

Get an opaque handle to the internal representation of the sound stage.

Returns
an untyped non-owning pointer to the internal representation of the sound stage.
Note
This function is used internally by the implementation of the audio module and is not intended to be used outside of it. The returned handle has no meaning to application code.

◆ get() [2/2]

const void * grem::audio::SoundStage::get ( ) const
inlinenodiscardnoexcept

Get an opaque handle to the internal representation of the sound stage.

Returns
an untyped non-owning read-only pointer to the internal representation of the sound stage.
Note
This function is used internally by the implementation of the audio module and is not intended to be used outside of it. The returned handle has no meaning to application code.

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