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

#include <audio_device.h>

Public Member Functions

 AudioDevice (Mixer &mixer)
 
 ~AudioDevice ()
 
 AudioDevice (const AudioDevice &)=delete
 
AudioDevice & operator= (const AudioDevice &)=delete
 
bool isOpen ()
 

Private Member Functions

void open ()
 

Static Private Member Functions

static void SDLCALL feed (void *userdata, SDL_AudioStream *stream, int additionalAmount, int totalAmount)
 

Private Attributes

Mixer & mixer
 
std::atomic< SDL_AudioStream * > stream {nullptr}
 
bool subsystemStarted = false
 
std::jthread opener
 
std::array< float, 2 *CHUNK_FRAMES > chunk {}
 

Static Private Attributes

static constexpr int CHUNK_FRAMES = 512
 

Detailed Description

Plays a Mixer on the default output through an SDL audio stream (48 kHz stereo float). SDL pulls audio from its own thread through the stream callback, which renders straight from the mixer. Without an audio device (or with SDL_AUDIODRIVER=dummy) everything still works; nothing is heard. The mixer must outlive the device.

The audio subsystem starts on the constructing (main) thread, as SDL asks; the stream itself opens on a short-lived helper thread because connecting to the sound server can take tens of milliseconds.

Constructor & Destructor Documentation

◆ AudioDevice() [1/2]

Audio::AudioDevice::AudioDevice ( Mixer &  mixer)
explicit

◆ ~AudioDevice()

Audio::AudioDevice::~AudioDevice ( )

◆ AudioDevice() [2/2]

Audio::AudioDevice::AudioDevice ( const AudioDevice &  )
delete

Member Function Documentation

◆ feed()

void SDLCALL Audio::AudioDevice::feed ( void *  userdata,
SDL_AudioStream *  stream,
int  additionalAmount,
int  totalAmount 
)
staticprivate

◆ isOpen()

bool Audio::AudioDevice::isOpen ( )

Waits for the device to finish opening; true when it plays.

◆ open()

void Audio::AudioDevice::open ( )
private

◆ operator=()

AudioDevice & Audio::AudioDevice::operator= ( const AudioDevice &  )
delete

Member Data Documentation

◆ chunk

std::array<float, 2 * CHUNK_FRAMES> Audio::AudioDevice::chunk {}
private

Callback scratch (audio thread only).

◆ CHUNK_FRAMES

constexpr int Audio::AudioDevice::CHUNK_FRAMES = 512
staticconstexprprivate

◆ mixer

Mixer& Audio::AudioDevice::mixer
private

◆ opener

std::jthread Audio::AudioDevice::opener
private

◆ stream

std::atomic<SDL_AudioStream*> Audio::AudioDevice::stream {nullptr}
private

◆ subsystemStarted

bool Audio::AudioDevice::subsystemStarted = false
private

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