|
Player12
An open source football management simulator
|
#include <audio_mixer.h>
Public Member Functions | |
| Mixer () | |
| bool | trigger (const SoundCommand &command) |
| void | setLevels (const BusLevels &levels) |
| void | setCrowd (float intensity, float level) |
| void | render (float *out, int frames) |
| int | activeVoices () const |
| std::uint64_t | triggeredCount (Sound sound) const |
Static Public Attributes | |
| static constexpr int | MAX_VOICES = 24 |
| static constexpr std::size_t | COMMAND_CAPACITY = 64 |
Private Member Functions | |
| void | startVoice (const SoundCommand &command) |
Private Attributes | |
| std::array< SoundCommand, COMMAND_CAPACITY > | commands {} |
| std::atomic< std::uint32_t > | commandHead {0} |
| std::atomic< std::uint32_t > | commandTail {0} |
| std::atomic< float > | masterGain {0.8f} |
| std::atomic< float > | crowdGain {0.8f} |
| std::atomic< float > | effectsGain {0.8f} |
| std::atomic< bool > | muted {false} |
| std::atomic< float > | crowdIntensity {0.3f} |
| std::atomic< float > | crowdLevel {1.0f} |
| std::atomic< int > | activeVoiceCount {0} |
| std::array< std::uint64_t, SOUND_COUNT > | triggered {} |
| std::array< Voice, MAX_VOICES > | voices {} |
| CrowdBed | bed |
| std::array< float, 2 *256 > | scratch {} |
| std::uint32_t | voiceSeed = 0x5EED1234U |
| float | appliedMaster = 0.0f |
| float | appliedCrowd = 0.0f |
| float | appliedEffects = 0.0f |
Real-time stereo mixer (48 kHz, interleaved float): the crowd bed plus a fixed pool of one-shot voices, routed through crowd and effects buses into the master bus and a soft limiter, so output never leaves [-1, 1].
Threading: the control methods (trigger, setLevels, setCrowd) are called from one producer thread (the UI thread) and render() from the audio thread. They only exchange plain data through atomics and a single- producer/single-consumer command ring; render() never allocates or locks.
|
default |
|
inline |
Voices playing after the last render() (any thread).
| void Audio::Mixer::render | ( | float * | out, |
| int | frames | ||
| ) |
Mixes frames stereo frames into out (overwrites it).
| void Audio::Mixer::setCrowd | ( | float | intensity, |
| float | level | ||
| ) |
Crowd bed intensity (0..1) and level (0..1, lowered while paused).
| void Audio::Mixer::setLevels | ( | const BusLevels & | levels | ) |
|
private |
| bool Audio::Mixer::trigger | ( | const SoundCommand & | command | ) |
Queues a sound; false when the command ring is full.
|
inline |
Sounds accepted by trigger() so far, per kind (producer thread).
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexpr |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticconstexpr |
|
private |
|
private |
|
private |
|
private |
|
private |