libdonut
2.3.2
Application framework for cross-platform game development in C++20
|
Persistent system for playing sound in a simulated 3D arena to the default audio device. More...
#include <donut/audio/SoundStage.hpp>
Public Types | |
using | SoundInstanceId = unsigned |
Opaque handle to a specific instance of a sound in the sound stage. More... | |
Public Member Functions | |
SoundStage (const SoundStageOptions &options={}) | |
Construct a sound stage. More... | |
void | update (Time< float > deltaTime, const Listener &listener) |
Update the 3D parameters of the sound stage and advance the current time. More... | |
SoundInstanceId | playSound (const Sound &sound, float volume=-1.0f, vec3 position={0.0f, 0.0f, 0.0f}, vec3 velocity={0.0f, 0.0f, 0.0f}) |
Create a new 3D sound instance and start playing it. More... | |
SoundInstanceId | playSoundInBackground (const Sound &sound, float volume=-1.0f) |
Create a new sound instance without any panning and start playing it. More... | |
SoundInstanceId | createPausedSoundInBackground (const Sound &sound, float volume=-1.0f) |
Create a new sound instance without any panning, but don't start playing it yet. More... | |
bool | isSoundPaused (SoundInstanceId id) const noexcept |
Check if a specific sound instance is currently paused. More... | |
bool | isSoundStopped (SoundInstanceId id) const noexcept |
Check if a specific sound instance has finished playing. More... | |
void | stopSound (SoundInstanceId id) |
Stop a specific sound instance and remove it. More... | |
void | pauseSound (SoundInstanceId id) |
Pause a specific sound instance. More... | |
void | resumeSound (SoundInstanceId id) |
Unpause and resume a specific sound instance. More... | |
void | scheduleSoundStop (SoundInstanceId id, Time< float > timePointInSound) |
Schedule for a specific sound instance to stop playing and remove itself when the playback reaches a specific time point. More... | |
void | scheduleSoundPause (SoundInstanceId id, Time< float > timePointInSound) |
Schedule for a specific sound instance to pause itself when the playback reaches a specific time point. More... | |
void | seekToSoundTime (SoundInstanceId id, Time< float > timePointInSound) |
Set the current playback time point for a specific sound instance. More... | |
void | setSoundPosition (SoundInstanceId id, vec3 newPosition) |
Set the current 3D position of a specific sound instance. More... | |
void | setSoundVelocity (SoundInstanceId id, vec3 newVelocity) |
Set the current 3D velocity of a specific sound instance. More... | |
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. More... | |
void | setSoundVolume (SoundInstanceId id, float volume) |
Set the volume of a specific sound instance. More... | |
void | fadeSoundVolume (SoundInstanceId id, float targetVolume, float fadeDuration) |
Fade the volume of a specific sound instance towards a target volume over a given duration. More... | |
void | setSoundPlaybackSpeed (SoundInstanceId id, float playbackSpeed) |
Set the relative playback speed of a specific sound instance. More... | |
void | fadeSoundPlaybackSpeed (SoundInstanceId id, float targetPlaybackSpeed, float fadeDuration) |
Fade the relative playback speed of a specific sound instance towards a target relative playback speed over a given duration. More... | |
void | setVolume (float volume) |
Set the global master volume of the sound stage. More... | |
void | fadeVolume (float targetVolume, float fadeDuration) |
Fade the global master volume of the sound stage towards a target volume over a given duration. More... | |
void | setSpeedOfSound (float speedOfSound) |
Set the speed of sound in the sound stage. More... | |
void | setMaxSimultaneousSounds (unsigned maxSimultaneousSounds) |
Set the maximum total number of sound instances that can play simultaneously. More... | |
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.
using donut::audio::SoundStage::SoundInstanceId = unsigned |
Opaque handle to a specific instance of a sound in the sound stage.
|
explicit |
Construct a sound stage.
options | initial configuration of the sound stage, see SoundStageOptions. |
audio::Error | on failure to initialize the underlying audio engine. |
std::bad_alloc | on allocation failure. |
Update the 3D parameters of the sound stage and advance the current time.
deltaTime | time delta to advance the time by, in seconds, typically received from the current application::FrameInfo in application::Application::update(). |
listener | current parameters to use for the sound listener on this frame. |
SoundInstanceId donut::audio::SoundStage::playSound | ( | const Sound & | sound, |
float | volume = -1.0f , |
||
vec3 | position = {0.0f, 0.0f, 0.0f} , |
||
vec3 | velocity = {0.0f, 0.0f, 0.0f} |
||
) |
Create a new 3D sound instance and start playing it.
sound | the sound data to use for this instance. |
volume | gain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead. |
position | the 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. |
velocity | initial linear velocity of the sound. Relevant for simulating the doppler effect. |
SoundInstanceId donut::audio::SoundStage::playSoundInBackground | ( | const Sound & | sound, |
float | volume = -1.0f |
||
) |
Create a new sound instance without any panning and start playing it.
sound | the sound data to use for this instance. |
volume | gain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead. |
SoundInstanceId donut::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.
sound | the sound data to use for this instance. |
volume | gain to multiply the amplitude of the sound by when playing. If negative, the default volume set in the SoundOptions is used instead. |
|
noexcept |
Check if a specific sound instance is currently paused.
id | handle to the sound instance, acquired from when the sound instance was created. |
|
noexcept |
Check if a specific sound instance has finished playing.
id | handle to the sound instance, acquired from when the sound instance was created. |
void donut::audio::SoundStage::stopSound | ( | SoundInstanceId | id | ) |
Stop a specific sound instance and remove it.
id | handle to the sound instance, acquired from when the sound instance was created. |
void donut::audio::SoundStage::pauseSound | ( | SoundInstanceId | id | ) |
Pause a specific sound instance.
id | handle to the sound instance, acquired from when the sound instance was created. |
void donut::audio::SoundStage::resumeSound | ( | SoundInstanceId | id | ) |
Unpause and resume a specific sound instance.
id | handle to the sound instance, acquired from when the sound instance was created. |
void donut::audio::SoundStage::scheduleSoundStop | ( | SoundInstanceId | id, |
Time< float > | timePointInSound | ||
) |
Schedule for a specific sound instance to stop playing and remove itself when the playback reaches a specific time point.
id | handle to the sound instance, acquired from when the sound instance was created. |
timePointInSound | the time point, measured in seconds from the beginning of the sound, where the sound instance will stop itself. |
void donut::audio::SoundStage::scheduleSoundPause | ( | SoundInstanceId | id, |
Time< float > | timePointInSound | ||
) |
Schedule for a specific sound instance to pause itself when the playback reaches a specific time point.
id | handle to the sound instance, acquired from when the sound instance was created. |
timePointInSound | the time point, measured in seconds from the beginning of the sound, where the sound instance will pause itself. |
void donut::audio::SoundStage::seekToSoundTime | ( | SoundInstanceId | id, |
Time< float > | timePointInSound | ||
) |
Set the current playback time point for a specific sound instance.
id | handle to the sound instance, acquired from when the sound instance was created. |
timePointInSound | the time point, measured in seconds from the beginning of the sound, to seek to. |
void donut::audio::SoundStage::setSoundPosition | ( | SoundInstanceId | id, |
vec3 | newPosition | ||
) |
Set the current 3D position of a specific sound instance.
id | handle to the sound instance, acquired from when the sound instance was created. |
newPosition | new position of the sound instance, in sound stage coordinates. |
void donut::audio::SoundStage::setSoundVelocity | ( | SoundInstanceId | id, |
vec3 | newVelocity | ||
) |
Set the current 3D velocity of a specific sound instance.
id | handle to the sound instance, acquired from when the sound instance was created. |
newVelocity | new linear velocity of the sound instance. |
void donut::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.
id | handle to the sound instance, acquired from when the sound instance was created. |
newPosition | new position of the sound instance, in sound stage coordinates. |
newVelocity | new linear velocity of the sound instance. |
void donut::audio::SoundStage::setSoundVolume | ( | SoundInstanceId | id, |
float | volume | ||
) |
Set the volume of a specific sound instance.
id | handle to the sound instance, acquired from when the sound instance was created. |
volume | new volume, see SoundOptions::volume. |
void donut::audio::SoundStage::fadeSoundVolume | ( | SoundInstanceId | id, |
float | targetVolume, | ||
float | fadeDuration | ||
) |
Fade the volume of a specific sound instance towards a target volume over a given duration.
id | handle to the sound instance, acquired from when the sound instance was created. |
targetVolume | new volume to fade towards, see SoundOptions::volume. |
fadeDuration | duration of time, in seconds, to fade over. |
void donut::audio::SoundStage::setSoundPlaybackSpeed | ( | SoundInstanceId | id, |
float | playbackSpeed | ||
) |
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.
id | handle to the sound instance, acquired from when the sound instance was created. |
playbackSpeed | new relative playback speed. Must be greater than 0. |
void donut::audio::SoundStage::fadeSoundPlaybackSpeed | ( | SoundInstanceId | id, |
float | targetPlaybackSpeed, | ||
float | fadeDuration | ||
) |
Fade the relative playback speed of a specific sound instance towards a target relative playback speed over a given duration.
id | handle to the sound instance, acquired from when the sound instance was created. |
targetPlaybackSpeed | new relative playback speed to fade towards. Must be greater than 0. |
fadeDuration | duration of time, in seconds, to fade over. |
void donut::audio::SoundStage::setVolume | ( | float | volume | ) |
Set the global master volume of the sound stage.
volume | new volume, see SoundStageOptions::volume. |
void donut::audio::SoundStage::fadeVolume | ( | float | targetVolume, |
float | fadeDuration | ||
) |
Fade the global master volume of the sound stage towards a target volume over a given duration.
targetVolume | new volume to fade towards, see SoundStageOptions::volume. |
fadeDuration | duration of time, in seconds, to fade over. |
void donut::audio::SoundStage::setSpeedOfSound | ( | float | speedOfSound | ) |
Set the speed of sound in the sound stage.
speedOfSound | new speed of sound, see SoundStageOptions::speedOfSound. |
void donut::audio::SoundStage::setMaxSimultaneousSounds | ( | unsigned | maxSimultaneousSounds | ) |
Set the maximum total number of sound instances that can play simultaneously.
maxSimultaneousSounds | new number of sound instances, see SoundStageOptions::maxSimultaneousSounds. |