Player12
An open source football management simulator
Loading...
Searching...
No Matches
MatchAudio Class Reference

#include <match_audio.h>

Classes

struct  PendingShot
 

Public Member Functions

 MatchAudio (bool openDevice=true)
 
 ~MatchAudio ()
 
 MatchAudio (const MatchAudio &)=delete
 
MatchAudio & operator= (const MatchAudio &)=delete
 
void setLevels (const Audio::BusLevels &levels)
 
void update (float wallSeconds, const MatchAudioFrame &frame, std::span< const MatchEvent > events)
 
Audio::Mixer & mixer ()
 
bool deviceOpen ()
 

Static Public Member Functions

static Audio::BusLevels levelsFrom (const Settings &settings)
 

Private Types

enum class  Priority : std::uint8_t { MINOR , MAJOR , KEY }
 

Private Member Functions

void react (const MatchEvent &event)
 
void reactToGoal (const MatchEvent &event)
 
void reactToMiss (float x)
 
void detectKicks (const MatchAudioFrame &frame, bool replaying)
 
void updateCrowd (float wallSeconds, const MatchAudioFrame &frame)
 
bool allowed (Priority priority) const
 
void play (Priority priority, Audio::SoundCommand command)
 
void whistle (Priority priority, Audio::WhistlePattern pattern, float x)
 

Private Attributes

std::unique_ptr< Audio::Mixer > mixerInstance
 
std::unique_ptr< Audio::AudioDevice > device
 
MatchEventCursor cursor
 
std::vector< const MatchEvent * > freshEvents
 
float playbackSpeed = 1.0f
 
float previousBallSpeed = 0.0f
 
bool previousShot = false
 
bool previousLoose = false
 
PlayerID previousKicker = 0
 
bool haveBallHistory = false
 
float kickCooldown = 0.0f
 
float sinceReaction = 10.0f
 
Priority lastReaction = Priority::MINOR
 
float tension = 0.0f
 
PendingShot pendingShot
 
int latestPeriod = 0
 
float latestMinute = -1.0f
 

Detailed Description

Match audio: turns the live match into sound. Each frame the scene passes a MatchAudioFrame and the engine's event log; new events become crowd reactions, whistles and ball sounds (from the home crowd's point of view), ball launches become kicks panned by the ball's position, and the crowd bed follows the danger on the pitch. Above 4x playback the minor sounds are thinned out; a pause fades the crowd down. Purely presentational: it only reads copies and never feeds anything back into the simulation.

Member Enumeration Documentation

◆ Priority

enum class MatchAudio::Priority : std::uint8_t
strongprivate

Which sounds survive fast playback.

Enumerator
MINOR 
MAJOR 
KEY 

Constructor & Destructor Documentation

◆ MatchAudio() [1/2]

MatchAudio::MatchAudio ( bool  openDevice = true)
explicit

openDevice false keeps the mixer silent-to-the-world (tests).

◆ ~MatchAudio()

MatchAudio::~MatchAudio ( )

◆ MatchAudio() [2/2]

MatchAudio::MatchAudio ( const MatchAudio &  )
delete

Member Function Documentation

◆ allowed()

bool MatchAudio::allowed ( Priority  priority) const
private

◆ detectKicks()

void MatchAudio::detectKicks ( const MatchAudioFrame &  frame,
bool  replaying 
)
private

replaying: a moment already heard (seek back); history only.

◆ deviceOpen()

bool MatchAudio::deviceOpen ( )

Waits for the output device to open; true when it plays.

◆ levelsFrom()

Audio::BusLevels MatchAudio::levelsFrom ( const Settings &  settings)
static

Master/crowd/effects volumes and mute from the settings.

◆ mixer()

Audio::Mixer & MatchAudio::mixer ( )
inline

◆ operator=()

MatchAudio & MatchAudio::operator= ( const MatchAudio &  )
delete

◆ play()

void MatchAudio::play ( Priority  priority,
Audio::SoundCommand  command 
)
private

◆ react()

void MatchAudio::react ( const MatchEvent &  event)
private

◆ reactToGoal()

void MatchAudio::reactToGoal ( const MatchEvent &  event)
private

◆ reactToMiss()

void MatchAudio::reactToMiss ( float  x)
private

◆ setLevels()

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

◆ update()

void MatchAudio::update ( float  wallSeconds,
const MatchAudioFrame &  frame,
std::span< const MatchEvent >  events 
)

◆ updateCrowd()

void MatchAudio::updateCrowd ( float  wallSeconds,
const MatchAudioFrame &  frame 
)
private

◆ whistle()

void MatchAudio::whistle ( Priority  priority,
Audio::WhistlePattern  pattern,
float  x 
)
private

Member Data Documentation

◆ cursor

MatchEventCursor MatchAudio::cursor
private

◆ device

std::unique_ptr<Audio::AudioDevice> MatchAudio::device
private

Declared after the mixer so it stops pulling audio first.

◆ freshEvents

std::vector<const MatchEvent*> MatchAudio::freshEvents
private

◆ haveBallHistory

bool MatchAudio::haveBallHistory = false
private

◆ kickCooldown

float MatchAudio::kickCooldown = 0.0f
private

◆ lastReaction

Priority MatchAudio::lastReaction = Priority::MINOR
private

◆ latestMinute

float MatchAudio::latestMinute = -1.0f
private

◆ latestPeriod

int MatchAudio::latestPeriod = 0
private

Latest match moment heard, so a replay of it stays quiet.

◆ mixerInstance

std::unique_ptr<Audio::Mixer> MatchAudio::mixerInstance
private
Initial value:
=
std::make_unique<Audio::Mixer>()

◆ pendingShot

PendingShot MatchAudio::pendingShot
private

◆ playbackSpeed

float MatchAudio::playbackSpeed = 1.0f
private

◆ previousBallSpeed

float MatchAudio::previousBallSpeed = 0.0f
private

◆ previousKicker

PlayerID MatchAudio::previousKicker = 0
private

◆ previousLoose

bool MatchAudio::previousLoose = false
private

◆ previousShot

bool MatchAudio::previousShot = false
private

◆ sinceReaction

float MatchAudio::sinceReaction = 10.0f
private

Seconds since the last crowd reaction and its priority.

◆ tension

float MatchAudio::tension = 0.0f
private

Short-lived excitement on top of the crowd bed (can dip below 0).


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