Game Audio Module
A C++ audio system using miniaudio with Python bindings
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
audio::RandomSoundContainer Class Reference

Container for playing randomized sounds with pitch variation. More...

#include <random_sound_container.h>

Public Member Functions

 RandomSoundContainer (const std::string &name, const RandomSoundContainerConfig &config={})
 Construct a random sound container.
 
 ~RandomSoundContainer ()
 Destructor.
 
void AddSound (const std::string &filepath)
 Add a sound to the container.
 
const std::string & GetName () const
 Get the name of this container.
 
SoundHandle GetRandomSound () const
 Get a random sound handle without playing it.
 
size_t GetSoundCount () const
 Get the number of sounds in this container.
 
void LoadFromFolder (const std::string &folderPath)
 Load all .wav files from a folder.
 
void Play ()
 Play a random sound from the container.
 
void PlayWithVolume (float volume)
 Play a random sound with specific volume.
 
void SetAvoidRepeat (bool avoid)
 Enable or disable repeat avoidance.
 
void SetPitchRange (float minPitch, float maxPitch)
 Set the pitch range for randomization.
 
void StopAll ()
 Stop all currently playing sounds from this container.
 

Private Member Functions

SoundHandle SelectRandomSound ()
 Select a random sound, avoiding the last played if configured.
 

Private Attributes

RandomSoundContainerConfig config_
 Configuration settings.
 
SoundHandle last_played_
 Handle of the last played sound.
 
std::string name_
 Container name.
 
std::mt19937 rng_
 Random number generator.
 
std::vector< SoundHandlesounds_
 Loaded sound handles.
 

Detailed Description

Container for playing randomized sounds with pitch variation.

Similar to Wwise random containers, this class manages a collection of sounds and plays them randomly with optional pitch variation and repeat avoidance.

Constructor & Destructor Documentation

◆ RandomSoundContainer()

audio::RandomSoundContainer::RandomSoundContainer ( const std::string &  name,
const RandomSoundContainerConfig config = {} 
)

Construct a random sound container.

Parameters
nameName identifier for this container
configConfiguration settings

◆ ~RandomSoundContainer()

audio::RandomSoundContainer::~RandomSoundContainer ( )

Destructor.

Member Function Documentation

◆ AddSound()

void audio::RandomSoundContainer::AddSound ( const std::string &  filepath)

Add a sound to the container.

Parameters
filepathPath to the audio file

◆ GetName()

const std::string & audio::RandomSoundContainer::GetName ( ) const
inline

Get the name of this container.

Returns
const std::string& Container name

◆ GetRandomSound()

SoundHandle audio::RandomSoundContainer::GetRandomSound ( ) const

Get a random sound handle without playing it.

Useful for playing sounds at specific positions while still using the container's random selection logic.

Returns
SoundHandle Handle to a randomly selected sound

◆ GetSoundCount()

size_t audio::RandomSoundContainer::GetSoundCount ( ) const
inline

Get the number of sounds in this container.

Returns
size_t Number of loaded sounds

◆ LoadFromFolder()

void audio::RandomSoundContainer::LoadFromFolder ( const std::string &  folderPath)

Load all .wav files from a folder.

Parameters
folderPathPath to the folder containing sound files

◆ Play()

void audio::RandomSoundContainer::Play ( )

Play a random sound from the container.

Applies pitch variation and avoids repeating the last played sound if configured.

◆ PlayWithVolume()

void audio::RandomSoundContainer::PlayWithVolume ( float  volume)

Play a random sound with specific volume.

Parameters
volumeVolume level (0.0 to 1.0)

◆ SelectRandomSound()

SoundHandle audio::RandomSoundContainer::SelectRandomSound ( )
private

Select a random sound, avoiding the last played if configured.

Returns
SoundHandle Handle to the selected sound

◆ SetAvoidRepeat()

void audio::RandomSoundContainer::SetAvoidRepeat ( bool  avoid)

Enable or disable repeat avoidance.

Parameters
avoidIf true, the same sound won't play twice in a row

◆ SetPitchRange()

void audio::RandomSoundContainer::SetPitchRange ( float  minPitch,
float  maxPitch 
)

Set the pitch range for randomization.

Parameters
minPitchMinimum pitch multiplier (e.g., 0.9 for 10% lower)
maxPitchMaximum pitch multiplier (e.g., 1.1 for 10% higher)

◆ StopAll()

void audio::RandomSoundContainer::StopAll ( )

Stop all currently playing sounds from this container.

Member Data Documentation

◆ config_

RandomSoundContainerConfig audio::RandomSoundContainer::config_
private

Configuration settings.

◆ last_played_

SoundHandle audio::RandomSoundContainer::last_played_
private

Handle of the last played sound.

◆ name_

std::string audio::RandomSoundContainer::name_
private

Container name.

◆ rng_

std::mt19937 audio::RandomSoundContainer::rng_
private

Random number generator.

◆ sounds_

std::vector<SoundHandle> audio::RandomSoundContainer::sounds_
private

Loaded sound handles.


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