RADLib
RADical C++ application framework
RADMedia::AudioPlayer Class Reference

Convenience WAV/audio playback object with sync and async APIs. More...

#include <RADMedia.h>

+ Inheritance diagram for RADMedia::AudioPlayer:
+ Collaboration diagram for RADMedia::AudioPlayer:

Public Member Functions

bool play (const WavFile &wav, const std::string &deviceId="default", std::string *error=nullptr)
 Plays an already-loaded WAV file synchronously. More...
 
bool playBuffer (const AudioBuffer &buffer, const std::string &deviceId="default", std::string *error=nullptr)
 Plays an interleaved Float32 buffer synchronously using default low-latency settings. More...
 
bool playBufferLowLatency (const AudioBuffer &buffer, const std::string &deviceId="default", size_t framesPerChunk=256, unsigned int targetLatencyUsec=5000, std::string *error=nullptr)
 Plays an interleaved Float32 buffer synchronously with explicit low-level buffer settings. More...
 
bool playFile (const std::string &path, const std::string &deviceId="default", std::string *error=nullptr)
 Loads and plays a WAV file synchronously. More...
 
void stop ()
 Requests that current playback stop. More...
 
void playAsync (RADCore::EventLoop &loop, WavFile wav, const std::string &deviceId="default")
 Plays an already-loaded WAV file on a background task and emits events on loop. More...
 
void playFileAsync (RADCore::EventLoop &loop, const std::string &path, const std::string &deviceId="default")
 Loads and plays a WAV file on a background task and emits events on loop. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Public Attributes

RADCore::Event< void() > started
 Raised when playback starts. More...
 
RADCore::Event< void() > finished
 Raised when playback reaches the end. More...
 
RADCore::Event< void() > stopped
 Raised when playback is explicitly stopped. More...
 
RADCore::Event< void(std::string) > errorOccurred
 Raised when loading, format negotiation, or playback fails. More...
 

Detailed Description

Convenience WAV/audio playback object with sync and async APIs.

Member Function Documentation

◆ play()

bool RADMedia::AudioPlayer::play ( const WavFile wav,
const std::string &  deviceId = "default",
std::string *  error = nullptr 
)

Plays an already-loaded WAV file synchronously.

◆ playAsync()

void RADMedia::AudioPlayer::playAsync ( RADCore::EventLoop loop,
WavFile  wav,
const std::string &  deviceId = "default" 
)

Plays an already-loaded WAV file on a background task and emits events on loop.

◆ playBuffer()

bool RADMedia::AudioPlayer::playBuffer ( const AudioBuffer buffer,
const std::string &  deviceId = "default",
std::string *  error = nullptr 
)

Plays an interleaved Float32 buffer synchronously using default low-latency settings.

◆ playBufferLowLatency()

bool RADMedia::AudioPlayer::playBufferLowLatency ( const AudioBuffer buffer,
const std::string &  deviceId = "default",
size_t  framesPerChunk = 256,
unsigned int  targetLatencyUsec = 5000,
std::string *  error = nullptr 
)

Plays an interleaved Float32 buffer synchronously with explicit low-level buffer settings.

◆ playFile()

bool RADMedia::AudioPlayer::playFile ( const std::string &  path,
const std::string &  deviceId = "default",
std::string *  error = nullptr 
)

Loads and plays a WAV file synchronously.

◆ playFileAsync()

void RADMedia::AudioPlayer::playFileAsync ( RADCore::EventLoop loop,
const std::string &  path,
const std::string &  deviceId = "default" 
)

Loads and plays a WAV file on a background task and emits events on loop.

◆ stop()

void RADMedia::AudioPlayer::stop ( )

Requests that current playback stop.

Member Data Documentation

◆ errorOccurred

RADCore::Event<void (std::string) > RADMedia::AudioPlayer::errorOccurred

Raised when loading, format negotiation, or playback fails.

◆ finished

RADCore::Event<void () > RADMedia::AudioPlayer::finished

Raised when playback reaches the end.

◆ started

RADCore::Event<void () > RADMedia::AudioPlayer::started

Raised when playback starts.

◆ stopped

RADCore::Event<void () > RADMedia::AudioPlayer::stopped

Raised when playback is explicitly stopped.


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