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

Container for a mix of sound waves that can be played in a SoundStage. More...

#include <GREM/audio/SoundMix.hpp>

Inheritance diagram for grem::audio::SoundMix:

Public Member Functions

 SoundMix ()
 Construct a stereo sound mix with the default options.
 SoundMix (const SoundMixOptions &options, const SoundOptions &soundOptions={})
 Construct a sound mix.
SoundInstanceID playSound (const Sound &sound, float volume=-1.0f)
 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 createPausedSound (const Sound &sound, float volume=-1.0f)
 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 playSoundClocked (Duration time, const Sound &sound, 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().
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().
void setVolume (float volume)
 Set the volume of the sound mix.
void setStatisticsEnabled (bool newEnableStatistics)
 Set whether to enable statistics gathering or not.
Array< float, 256 > calculateOutputFastFourierTransformStatistics () const
 Calculate the fast Fourier transform of the audio currently playing through the sound mix.
Array< float, 256 > getOutputWaveStatistics () const
 Get the sound wave currently playing through the sound mix.
float getOutputChannelVolumeStatistics (uint32_t channelIndex) const
 Get an approximation of the volume of the audio currently playing through a specific channel of the sound mix.
Public Member Functions inherited from grem::audio::Sound
 Sound () noexcept=default
 Construct an invalid sound that must be reassigned before use.
 Sound (const Filesystem &filesystem, CStringView filepath, const SoundOptions &options={})
 Load a sound from a virtual file.
 Sound (Span< const byte > fileContents, const SoundOptions &options={})
 Load a sound from an in-memory file.
 Sound (Span< const uint8_t > samples, float sampleRate, size_t channelCount=1, const SoundOptions &options={})
 Construct a sound wave from a raw array of samples.
 Sound (Span< const int16_t > samples, float sampleRate, size_t channelCount=1, const SoundOptions &options={})
 Construct a sound wave from a raw array of samples.
 Sound (Span< const float32_t > samples, float sampleRate, size_t channelCount=1, const SoundOptions &options={})
 Construct a sound wave from a raw array of samples.
 operator bool () const noexcept
 Check if the sound has a value.
template<filter F>
void setFilter (size_t filterSlotIndex, const F &newFilter)
 Set the filter at a particular filter slot of the sound.
void removeFilter (size_t filterSlotIndex) noexcept
 Remove the filter at a particular filter slot of the sound.
Duration getDuration () const noexcept
 Get the duration of the sound.
void * get () noexcept
 Get an opaque handle to the internal representation of the sound.
const void * get () const noexcept
 Get an opaque handle to the internal representation of the sound.

Additional Inherited Members

Static Public Attributes inherited from grem::audio::Sound
static constexpr size_t MAX_FILTER_COUNT = 8
 Maximum number of filters that can be applied simultaneously to a sound.
Protected Member Functions inherited from grem::audio::Sound
 Sound (void *handle, const SoundOptions &options)

Detailed Description

Container for a mix of sound waves that can be played in a SoundStage.

Note
Only one instance of a sound mix can be played at a time.

Constructor & Destructor Documentation

◆ SoundMix() [1/2]

grem::audio::SoundMix::SoundMix ( )
inline

Construct a stereo sound mix with the default options.

Exceptions
audio::Erroron failure to create the sound mix.
std::bad_allocon allocation failure.

◆ SoundMix() [2/2]

grem::audio::SoundMix::SoundMix ( const SoundMixOptions & options,
const SoundOptions & soundOptions = {} )
explicit

Construct a sound mix.

Parameters
optionssound mix options, see SoundMixOptions.
soundOptionssound options, see SoundOptions.
Exceptions
audio::Erroron failure to create the sound mix.
std::bad_allocon allocation failure.

Member Function Documentation

◆ playSound()

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

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::SoundMix::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()

◆ createPausedSound()

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

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::SoundMix::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()

◆ playSoundClocked()

SoundInstanceID grem::audio::SoundMix::playSoundClocked ( Duration time,
const Sound & sound,
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.
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::SoundMix::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()

◆ setVolume()

void grem::audio::SoundMix::setVolume ( float volume)

Set the volume of the sound mix.

Parameters
volumenew volume, see SoundMixOptions::volume.

◆ setStatisticsEnabled()

void grem::audio::SoundMix::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.

◆ calculateOutputFastFourierTransformStatistics()

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

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

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 mix in order to produce meaningful results.
See also
SoundMixOptions::enableStatistics
setStatisticsEnabled()

◆ getOutputWaveStatistics()

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

Get the sound wave currently playing through the sound mix.

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

◆ getOutputChannelVolumeStatistics()

float grem::audio::SoundMix::getOutputChannelVolumeStatistics ( uint32_t channelIndex) const
nodiscard

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

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

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