Player12
An open source football management simulator
Loading...
Searching...
No Matches
Audio::Mixer Class Reference

#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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Mixer()

Audio::Mixer::Mixer ( )
default

Member Function Documentation

◆ activeVoices()

int Audio::Mixer::activeVoices ( ) const
inline

Voices playing after the last render() (any thread).

◆ render()

void Audio::Mixer::render ( float *  out,
int  frames 
)

Mixes frames stereo frames into out (overwrites it).

◆ setCrowd()

void Audio::Mixer::setCrowd ( float  intensity,
float  level 
)

Crowd bed intensity (0..1) and level (0..1, lowered while paused).

◆ setLevels()

void Audio::Mixer::setLevels ( const BusLevels &  levels)

◆ startVoice()

void Audio::Mixer::startVoice ( const SoundCommand &  command)
private

◆ trigger()

bool Audio::Mixer::trigger ( const SoundCommand &  command)

Queues a sound; false when the command ring is full.

◆ triggeredCount()

std::uint64_t Audio::Mixer::triggeredCount ( Sound  sound) const
inline

Sounds accepted by trigger() so far, per kind (producer thread).

Member Data Documentation

◆ activeVoiceCount

std::atomic<int> Audio::Mixer::activeVoiceCount {0}
private

◆ appliedCrowd

float Audio::Mixer::appliedCrowd = 0.0f
private

◆ appliedEffects

float Audio::Mixer::appliedEffects = 0.0f
private

◆ appliedMaster

float Audio::Mixer::appliedMaster = 0.0f
private

◆ bed

CrowdBed Audio::Mixer::bed
private

◆ COMMAND_CAPACITY

constexpr std::size_t Audio::Mixer::COMMAND_CAPACITY = 64
staticconstexpr

◆ commandHead

std::atomic<std::uint32_t> Audio::Mixer::commandHead {0}
private

◆ commands

std::array<SoundCommand, COMMAND_CAPACITY> Audio::Mixer::commands {}
private

◆ commandTail

std::atomic<std::uint32_t> Audio::Mixer::commandTail {0}
private

◆ crowdGain

std::atomic<float> Audio::Mixer::crowdGain {0.8f}
private

◆ crowdIntensity

std::atomic<float> Audio::Mixer::crowdIntensity {0.3f}
private

◆ crowdLevel

std::atomic<float> Audio::Mixer::crowdLevel {1.0f}
private

◆ effectsGain

std::atomic<float> Audio::Mixer::effectsGain {0.8f}
private

◆ masterGain

std::atomic<float> Audio::Mixer::masterGain {0.8f}
private

◆ MAX_VOICES

constexpr int Audio::Mixer::MAX_VOICES = 24
staticconstexpr

◆ muted

std::atomic<bool> Audio::Mixer::muted {false}
private

◆ scratch

std::array<float, 2 * 256> Audio::Mixer::scratch {}
private

◆ triggered

std::array<std::uint64_t, SOUND_COUNT> Audio::Mixer::triggered {}
private

◆ voices

std::array<Voice, MAX_VOICES> Audio::Mixer::voices {}
private

◆ voiceSeed

std::uint32_t Audio::Mixer::voiceSeed = 0x5EED1234U
private

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