libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
Ship::SDLAudioPlayer Class Referencefinal

AudioPlayer implementation backed by SDL2's audio subsystem. More...

#include <SDLAudioPlayer.h>

Inheritance diagram for Ship::SDLAudioPlayer:
[legend]
Collaboration diagram for Ship::SDLAudioPlayer:
[legend]

Public Member Functions

 SDLAudioPlayer (AudioSettings settings)
 Constructs an SDLAudioPlayer with the given audio settings.
 
 ~SDLAudioPlayer ()
 
int Buffered () override
 Returns the number of audio frames currently queued in the SDL audio device.
 
- Public Member Functions inherited from Ship::AudioPlayer
 AudioPlayer (AudioSettings settings)
 Constructs an AudioPlayer with the given configuration.
 
 ~AudioPlayer ()
 
bool Init ()
 Calls DoInit() and sets the initialised flag on success.
 
void Play (const uint8_t *buf, size_t len)
 Submits a frame of PCM audio to the output device.
 
bool IsInitialized ()
 Returns true if Init() has been called and succeeded.
 
int32_t GetSampleRate () const
 Returns the configured output sample rate in Hz.
 
int32_t GetSampleLength () const
 Returns the configured number of samples per audio frame.
 
int32_t GetDesiredBuffered () const
 Returns the target number of frames to keep buffered.
 
AudioChannelsSetting GetAudioChannels () const
 Returns the current channel-output mode.
 
void SetSampleRate (int32_t rate)
 Sets the output sample rate.
 
void SetSampleLength (int32_t length)
 Sets the number of samples per audio frame.
 
void SetDesiredBuffered (int32_t size)
 Sets the target number of buffered frames.
 
bool SetAudioChannels (AudioChannelsSetting channels)
 Changes the channel mode and reinitialises the audio device.
 
int32_t GetNumOutputChannels () const
 Returns the number of output channels implied by the current channel setting.
 

Protected Member Functions

bool DoInit () override
 Opens the SDL audio device with the configured settings.
 
void DoClose () override
 Closes the SDL audio device and releases its resources.
 
void DoPlay (const uint8_t *buf, size_t len) override
 Queues interleaved PCM samples to the SDL audio device.
 

Detailed Description

AudioPlayer implementation backed by SDL2's audio subsystem.

SDLAudioPlayer uses SDL_OpenAudioDevice to open a platform audio output, then pushes interleaved PCM samples in DoPlay(). It supports both stereo and 6-channel (5.1) output depending on the AudioChannelsSetting configured in AudioPlayer.

This backend is available on all platforms that Ship supports.

Constructor & Destructor Documentation

◆ SDLAudioPlayer()

Ship::SDLAudioPlayer::SDLAudioPlayer ( AudioSettings  settings)
inline

Constructs an SDLAudioPlayer with the given audio settings.

Parameters
settingsSample rate, buffer size, desired buffered frames, and channel mode.

◆ ~SDLAudioPlayer()

Ship::SDLAudioPlayer::~SDLAudioPlayer ( )

Member Function Documentation

◆ Buffered()

int Ship::SDLAudioPlayer::Buffered ( )
overridevirtual

Returns the number of audio frames currently queued in the SDL audio device.

Used by the audio subsystem to decide how many frames to produce per game tick.

Implements Ship::AudioPlayer.

◆ DoClose()

void Ship::SDLAudioPlayer::DoClose ( )
overrideprotectedvirtual

Closes the SDL audio device and releases its resources.

Implements Ship::AudioPlayer.

◆ DoInit()

bool Ship::SDLAudioPlayer::DoInit ( )
overrideprotectedvirtual

Opens the SDL audio device with the configured settings.

Returns
true if the device was opened successfully.

Implements Ship::AudioPlayer.

◆ DoPlay()

void Ship::SDLAudioPlayer::DoPlay ( const uint8_t *  buf,
size_t  len 
)
overrideprotectedvirtual

Queues interleaved PCM samples to the SDL audio device.

Parameters
bufInterleaved sample data (stereo: L,R,… or surround: FL,FR,C,LFE,SL,SR,…).
lenLength of buf in bytes.

Implements Ship::AudioPlayer.


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