Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::audio::BufferingReader Class Reference

Background-thread audio file reader for gapless streaming playback. More...

#include <buffering_reader.hpp>

Public Types

using ReadCallback = std::function<int(float* dest, int num_frames, int num_channels)>
 Callback that reads audio data from a source (file, network, etc.).

Public Member Functions

 BufferingReader ()=default
 ~BufferingReader ()
 BufferingReader (const BufferingReader &)=delete
BufferingReader & operator= (const BufferingReader &)=delete
void set_read_callback (ReadCallback cb)
 Set the callback that provides audio data.
void start (int num_channels, int buffer_frames=44100)
 Start the background reader thread.
void stop ()
 Stop the background thread and release resources.
int read (float *dest, int num_frames, int num_channels)
 Read frames from the buffer (audio thread, lock-free on the hot path).
bool is_finished () const
 Check if the source has been fully read.
bool is_running () const
 Check if the reader is running.
int frames_available () const
 Number of frames currently available in the buffer.

Detailed Description

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.

reader.set_read_callback([&](float* dest, int frames, int channels) {
return audio_file.read(dest, frames, channels);
});
reader.start(2, 44100); // 2 channels, 1 second buffer
// In audio callback:
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
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

Member Typedef Documentation

◆ ReadCallback

using pulp::audio::BufferingReader::ReadCallback = std::function<int(float* dest, int num_frames, int num_channels)>

Callback that reads audio data from a source (file, network, etc.).

Parameters
destDestination interleaved buffer.
num_framesNumber of frames to read.
num_channelsNumber of channels.
Returns
Number of frames actually read (0 = end of source).

Constructor & Destructor Documentation

◆ BufferingReader() [1/2]

pulp::audio::BufferingReader::BufferingReader ( )
default

◆ ~BufferingReader()

pulp::audio::BufferingReader::~BufferingReader ( )
inline

◆ BufferingReader() [2/2]

pulp::audio::BufferingReader::BufferingReader ( const BufferingReader & )
delete

Member Function Documentation

◆ 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=()

BufferingReader & pulp::audio::BufferingReader::operator= ( const BufferingReader & )
delete

◆ 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
destDestination interleaved buffer.
num_framesNumber of frames requested.
num_channelsNumber 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_channelsNumber of audio channels.
buffer_framesSize 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: