Class thl::audio_io::AudioFileLoader#
-
class AudioFileLoader#
Loads and decodes audio files using miniaudio.
Supports WAV, MP3, and FLAC from both file paths and in-memory buffers. Automatically resamples to a target sample rate and converts to a target channel count when requested. Output is a planar BufferF.
This class has no mutable state, so multiple instances may be used concurrently on different threads.
Public Functions
-
AudioFileLoader() = default#
-
~AudioFileLoader() = default#
-
core::BufferF load_from_file(const std::string &file_path, double target_sample_rate = 0.0, uint32_t target_channels = 0)#
Decode an audio file from a file path.
- Parameters:
file_path – Path to the audio file.
target_sample_rate – Desired output sample rate (0 = keep native).
target_channels – Desired output channel count (0 = keep native).
- Returns:
Planar BufferF, or an empty buffer on failure.
-
core::BufferF load_from_memory(const void *data, size_t size, double target_sample_rate = 0.0, uint32_t target_channels = 0)#
Decode audio from an in-memory buffer (e.g.
embedded binary data).
- Parameters:
data – Pointer to the binary audio data.
size – Size of the data in bytes.
target_sample_rate – Desired output sample rate (0 = keep native).
target_channels – Desired output channel count (0 = keep native).
- Returns:
Planar BufferF, or an empty buffer on failure.
-
DataSource load_data_source_from_file(const std::string &file_path, double target_sample_rate = 0.0, uint32_t target_channels = 0)#
Open an audio file and return a streaming DataSource.
Unlike load_from_file(), this does not decode the entire file into memory. The caller reads PCM data incrementally via the returned DataSource.
- Parameters:
file_path – Path to the audio file.
target_sample_rate – Desired output sample rate (0 = keep native).
target_channels – Desired output channel count (0 = keep native).
- Returns:
A DataSource wrapping the file, or an invalid DataSource on failure (check DataSource::is_valid()).
-
DataSource load_data_source_from_memory(const void *data, size_t size, double target_sample_rate = 0.0, uint32_t target_channels = 0)#
Open an in-memory audio buffer and return a streaming DataSource.
Unlike load_from_memory(), this does not decode the entire buffer upfront. The caller reads PCM data incrementally via the returned DataSource.
Note
The caller must keep the memory pointed to by
dataalive for the lifetime of the returned DataSource.- Parameters:
data – Pointer to the binary audio data.
size – Size of the data in bytes.
target_sample_rate – Desired output sample rate (0 = keep native).
target_channels – Desired output channel count (0 = keep native).
- Returns:
A DataSource wrapping the memory, or an invalid DataSource on failure (check DataSource::is_valid()).
-
AudioFileLoader() = default#