Manages an SDL3 audio output device for playback. More...
#include <sdlaudiooutput.h>


Public Member Functions | |
| SDLAudioOutput (ObjectBase *parent=nullptr) | |
| Constructs an SDLAudioOutput. | |
| bool | configure (const AudioDesc &desc) |
| Configures the audio output format. | |
| bool | open () |
| Opens the SDL audio device and starts playback. | |
| void | close () |
| Closes the audio device and frees resources. | |
| bool | isOpen () const |
| Returns true if the device is open and playing. | |
| bool | pushAudio (const PcmAudioPayload &payload) |
| Pushes uncompressed audio samples to the output stream. | |
| virtual int | queuedBytes () const |
| Returns the number of bytes currently queued. | |
| const AudioDesc & | desc () const |
| Returns the configured audio descriptor. | |
| virtual int64_t | totalBytesPushed () const |
| Returns total float32 bytes pushed since open. | |
| virtual ClockDomain | clockDomain () const |
| Returns the ClockDomain registered for the open SDL device. | |
| virtual Error | setPaused (bool paused) |
| Pauses or resumes the underlying SDL audio device. | |
| virtual bool | isPaused () const |
| Returns the current pause state. | |
| Clock * | createClock () |
| Returns a Clock whose time is driven by this output's consumed-byte counter. | |
Manages an SDL3 audio output device for playback.
SDLAudioOutput opens an SDL audio device and stream, accepting promeki Audio objects for playback. Audio data is converted to the platform's native float format if necessary and pushed to an SDL audio stream, which handles sample rate conversion and buffering automatically.
pushAudio() is thread-safe — it can be called from any thread (e.g. a MediaIO Strand worker) while the SDL audio device plays on its own thread.
Each open device registers its own ClockDomain (derived from the SDL device name) and can hand out a Clock via createClock. The returned clock is a subclass of Clock bound to this output — pausing it pauses the SDL device, and it propagates Error::ObjectGone via the underlying ObjectBasePtr when the output is destroyed.
|
inlinevirtual |
Returns the ClockDomain registered for the open SDL device.
Invalid (default-constructed) until open succeeds. Multiple Clock instances constructed from the same device share this domain. Virtual so tests can supply a controllable stand-in without opening a real SDL audio device.
| bool promeki::SDLAudioOutput::configure | ( | const AudioDesc & | desc | ) |
Configures the audio output format.
Must be called before open(). The audio stream will accept data in this format and convert to the device's native format as needed.
| desc | The audio format descriptor. |
| Clock * promeki::SDLAudioOutput::createClock | ( | ) |
Returns a Clock whose time is driven by this output's consumed-byte counter.
The clock's domain is this output's clockDomain, its pause mode is ClockPauseMode::PausesRawStops, and pausing it pauses the SDL device. Returned pointer is heap allocated — the caller adopts it into a Clock::Ptr.
|
virtual |
Returns the current pause state.
Virtual so tests can supply a controllable stand-in.
| bool promeki::SDLAudioOutput::open | ( | ) |
Opens the SDL audio device and starts playback.
Also registers the per-device ClockDomain derived from the underlying SDL device identity. The domain is accessible via clockDomain after a successful open.
| bool promeki::SDLAudioOutput::pushAudio | ( | const PcmAudioPayload & | payload | ) |
Pushes uncompressed audio samples to the output stream.
Thread-safe. The audio data is converted to float32 if necessary before being pushed to the SDL stream.
| payload | The payload's PCM bytes to play. |
|
virtual |
Returns the number of bytes currently queued.
Useful for monitoring buffer health and A/V sync.
Virtual so tests can supply a controllable stand-in without opening a real SDL audio device.
|
virtual |
Pauses or resumes the underlying SDL audio device.
The SDL-level pause freezes consumption of queued audio — queuedBytes and totalBytesPushed stop advancing relative to each other until the device is resumed. Virtual so tests can override without holding a real SDL stream.
| paused | The target state. |
|
inlinevirtual |
Returns total float32 bytes pushed since open.
Combined with queuedBytes(), this lets callers derive how many bytes the device has consumed: consumed = totalBytesPushed() - queuedBytes().
Virtual so tests can supply a controllable stand-in without opening a real SDL audio device.