|
libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
|
Abstract base class for platform-specific audio output backends. More...
#include <AudioPlayer.h>
Public Member Functions | |
| AudioPlayer (AudioSettings settings) | |
| Constructs an AudioPlayer with the given configuration. | |
| ~AudioPlayer () | |
| bool | Init () |
| Calls DoInit() and sets the initialised flag on success. | |
| virtual int32_t | Buffered ()=0 |
| Returns the number of audio frames currently queued in the device buffer. | |
| 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 | |
| virtual bool | DoInit ()=0 |
| Opens and configures the platform audio device. | |
| virtual void | DoClose ()=0 |
| Closes the platform audio device and releases its resources. | |
| virtual void | DoPlay (const uint8_t *buf, size_t len)=0 |
| Writes interleaved PCM samples to the platform audio device. | |
Abstract base class for platform-specific audio output backends.
AudioPlayer owns the audio device lifecycle (DoInit / DoClose) and the optional SoundMatrixDecoder that converts stereo input to 5.1 surround. Concrete subclasses implement DoInit(), DoClose(), and DoPlay() for each supported platform (SDL2, CoreAudio, WASAPI, or a null no-op).
Obtain the active instance from Context::GetAudio() → Audio::GetAudioPlayer().
|
inline |
Constructs an AudioPlayer with the given configuration.
| settings | Sample rate, buffer size, desired buffered frames, and channel mode. |
| Ship::AudioPlayer::~AudioPlayer | ( | ) |
|
pure virtual |
Returns the number of audio frames currently queued in the device buffer.
The audio system uses this to pace audio production: if Buffered() exceeds DesiredBuffered the game can skip producing audio for that tick.
Implemented in Ship::CoreAudioAudioPlayer, Ship::NullAudioPlayer, Ship::SDLAudioPlayer, and Ship::WasapiAudioPlayer.
|
protectedpure virtual |
Closes the platform audio device and releases its resources.
Called by SetAudioChannels() before reinitialisation and by the destructor.
Implemented in Ship::CoreAudioAudioPlayer, Ship::NullAudioPlayer, Ship::SDLAudioPlayer, and Ship::WasapiAudioPlayer.
|
protectedpure virtual |
Opens and configures the platform audio device.
Called by Init() and by SetAudioChannels() when reinitialising.
Implemented in Ship::CoreAudioAudioPlayer, Ship::NullAudioPlayer, Ship::SDLAudioPlayer, and Ship::WasapiAudioPlayer.
|
protectedpure virtual |
Writes interleaved PCM samples to the platform audio device.
Receives audio already in the correct output format (stereo or 6-channel).
| buf | Sample data. |
| len | Length of buf in bytes. |
Implemented in Ship::CoreAudioAudioPlayer, Ship::NullAudioPlayer, Ship::SDLAudioPlayer, and Ship::WasapiAudioPlayer.
| AudioChannelsSetting Ship::AudioPlayer::GetAudioChannels | ( | ) | const |
Returns the current channel-output mode.
| int32_t Ship::AudioPlayer::GetDesiredBuffered | ( | ) | const |
Returns the target number of frames to keep buffered.
| int32_t Ship::AudioPlayer::GetNumOutputChannels | ( | ) | const |
Returns the number of output channels implied by the current channel setting.
| int32_t Ship::AudioPlayer::GetSampleLength | ( | ) | const |
Returns the configured number of samples per audio frame.
| int32_t Ship::AudioPlayer::GetSampleRate | ( | ) | const |
Returns the configured output sample rate in Hz.
| bool Ship::AudioPlayer::Init | ( | ) |
Calls DoInit() and sets the initialised flag on success.
| bool Ship::AudioPlayer::IsInitialized | ( | ) |
Returns true if Init() has been called and succeeded.
| void Ship::AudioPlayer::Play | ( | const uint8_t * | buf, |
| size_t | len | ||
| ) |
Submits a frame of PCM audio to the output device.
If 5.1 surround output is configured and the channel setting requires matrix decoding, the stereo buf is first decoded to 6-channel surround before being passed to DoPlay().
| buf | Interleaved samples:
|
| len | Length of buf in bytes. |
| bool Ship::AudioPlayer::SetAudioChannels | ( | AudioChannelsSetting | channels | ) |
Changes the channel mode and reinitialises the audio device.
Closes the current device, updates the channel setting, and calls DoInit() again. If reinitialisation fails the previous channel mode is restored.
| channels | New channel mode. |
| void Ship::AudioPlayer::SetDesiredBuffered | ( | int32_t | size | ) |
Sets the target number of buffered frames.
| size | New buffered-frame target. |
| void Ship::AudioPlayer::SetSampleLength | ( | int32_t | length | ) |
Sets the number of samples per audio frame.
| length | New frame size in samples. |
| void Ship::AudioPlayer::SetSampleRate | ( | int32_t | rate | ) |
Sets the output sample rate.
| rate | New sample rate in Hz. |