|
Game Audio Module
A C++ audio system using miniaudio with Python bindings
|
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< SoundHandle > | sounds_ |
| Loaded sound handles. | |
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.
| audio::RandomSoundContainer::RandomSoundContainer | ( | const std::string & | name, |
| const RandomSoundContainerConfig & | config = {} |
||
| ) |
Construct a random sound container.
| name | Name identifier for this container |
| config | Configuration settings |
| audio::RandomSoundContainer::~RandomSoundContainer | ( | ) |
Destructor.
| void audio::RandomSoundContainer::AddSound | ( | const std::string & | filepath | ) |
Add a sound to the container.
| filepath | Path to the audio file |
|
inline |
Get the name of this container.
| 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.
|
inline |
Get the number of sounds in this container.
| void audio::RandomSoundContainer::LoadFromFolder | ( | const std::string & | folderPath | ) |
Load all .wav files from a folder.
| folderPath | Path to the folder containing sound files |
| void audio::RandomSoundContainer::Play | ( | ) |
Play a random sound from the container.
Applies pitch variation and avoids repeating the last played sound if configured.
| void audio::RandomSoundContainer::PlayWithVolume | ( | float | volume | ) |
Play a random sound with specific volume.
| volume | Volume level (0.0 to 1.0) |
|
private |
Select a random sound, avoiding the last played if configured.
| void audio::RandomSoundContainer::SetAvoidRepeat | ( | bool | avoid | ) |
Enable or disable repeat avoidance.
| avoid | If true, the same sound won't play twice in a row |
| void audio::RandomSoundContainer::SetPitchRange | ( | float | minPitch, |
| float | maxPitch | ||
| ) |
Set the pitch range for randomization.
| minPitch | Minimum pitch multiplier (e.g., 0.9 for 10% lower) |
| maxPitch | Maximum pitch multiplier (e.g., 1.1 for 10% higher) |
| void audio::RandomSoundContainer::StopAll | ( | ) |
Stop all currently playing sounds from this container.
|
private |
Configuration settings.
|
private |
Handle of the last played sound.
|
private |
Container name.
|
private |
Random number generator.
|
private |
Loaded sound handles.