Background-thread audio file reader for gapless streaming playback.
More...
#include <buffering_reader.hpp>
|
| using | ReadCallback = std::function<int(float* dest, int num_frames, int num_channels)> |
| | Callback that reads audio data from a source (file, network, etc.).
|
Background-thread audio file reader for gapless streaming playback.
Maintains a ring buffer that is filled from a background thread while the audio thread reads from it. The audio thread never blocks on I/O.
return audio_file.read(dest, frames, channels);
});
int got = reader.
read(output_buffer, num_frames, num_channels);
void set_read_callback(ReadCallback cb)
Set the callback that provides audio data.
Definition buffering_reader.hpp:53
BufferingReader()=default
void start(int num_channels, int buffer_frames=44100)
Start the background reader thread.
Definition buffering_reader.hpp:58
int read(float *dest, int num_frames, int num_channels)
Read frames from the buffer (audio thread, lock-free on the hot path).
Definition buffering_reader.hpp:101
◆ ReadCallback
Callback that reads audio data from a source (file, network, etc.).
- Parameters
-
| dest | Destination interleaved buffer. |
| num_frames | Number of frames to read. |
| num_channels | Number of channels. |
- Returns
- Number of frames actually read (0 = end of source).
◆ BufferingReader() [1/2]
| pulp::audio::BufferingReader::BufferingReader |
( |
| ) |
|
|
default |
◆ ~BufferingReader()
| pulp::audio::BufferingReader::~BufferingReader |
( |
| ) |
|
|
inline |
◆ BufferingReader() [2/2]
| pulp::audio::BufferingReader::BufferingReader |
( |
const BufferingReader & | | ) |
|
|
delete |
◆ frames_available()
| int pulp::audio::BufferingReader::frames_available |
( |
| ) |
const |
|
inline |
Number of frames currently available in the buffer.
◆ is_finished()
| bool pulp::audio::BufferingReader::is_finished |
( |
| ) |
const |
|
inline |
Check if the source has been fully read.
◆ is_running()
| bool pulp::audio::BufferingReader::is_running |
( |
| ) |
const |
|
inline |
Check if the reader is running.
◆ operator=()
◆ read()
| int pulp::audio::BufferingReader::read |
( |
float * | dest, |
|
|
int | num_frames, |
|
|
int | num_channels ) |
|
inline |
Read frames from the buffer (audio thread, lock-free on the hot path).
- Parameters
-
| dest | Destination interleaved buffer. |
| num_frames | Number of frames requested. |
| num_channels | Number of channels (must match start()). |
- Returns
- Number of frames actually copied (may be less if buffer underrun).
◆ set_read_callback()
| void pulp::audio::BufferingReader::set_read_callback |
( |
ReadCallback | cb | ) |
|
|
inline |
Set the callback that provides audio data.
◆ start()
| void pulp::audio::BufferingReader::start |
( |
int | num_channels, |
|
|
int | buffer_frames = 44100 ) |
|
inline |
Start the background reader thread.
- Parameters
-
| num_channels | Number of audio channels. |
| buffer_frames | Size of the ring buffer in frames (default: 1 second at 44.1kHz). |
◆ stop()
| void pulp::audio::BufferingReader::stop |
( |
| ) |
|
|
inline |
Stop the background thread and release resources.
The documentation for this class was generated from the following file: