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

Plays back a MemoryMappedAudioReader as a PositionableAudioSource. More...

#include <format_reader_source.hpp>

Public Member Functions

 AudioFormatReaderSource ()=default
 AudioFormatReaderSource (std::shared_ptr< MemoryMappedAudioReader > reader)
void set_reader (std::shared_ptr< MemoryMappedAudioReader > reader)
MemoryMappedAudioReader * reader () const
 Non-owning accessor — useful when the caller already owns the reader and wants to query info / metadata.
void prepare_to_play (int, double) override
 Called before playback begins.
void release_resources () override
 Called when playback is finished.
void get_next_audio_block (BufferView< float > out, int start_sample, int num_samples) override
 Fill num_samples of out, starting at start_sample within out.
void set_next_read_position (uint64_t new_position) override
 Move the read head to new_position (frames from the start of the source).
uint64_t get_next_read_position () const override
 Current frame position the next get_next_audio_block call will read from.
uint64_t get_total_length () const override
 Total length in frames. 0 means "unknown" or "infinite".
bool is_looping () const override
 True if the source should wrap back to 0 when it reaches the end.
void set_looping (bool should_loop) override
 Enable / disable looping.

Detailed Description

Plays back a MemoryMappedAudioReader as a PositionableAudioSource.

Read position is tracked in frames from the start of the file. Loops back to 0 when set_looping(true) is set and the read head reaches the end. Past-end reads on non-looping sources fill the remainder of the requested block with silence.

Constructor & Destructor Documentation

◆ AudioFormatReaderSource() [1/2]

pulp::audio::AudioFormatReaderSource::AudioFormatReaderSource ( )
default

◆ AudioFormatReaderSource() [2/2]

pulp::audio::AudioFormatReaderSource::AudioFormatReaderSource ( std::shared_ptr< MemoryMappedAudioReader > reader)
inlineexplicit

Member Function Documentation

◆ get_next_audio_block()

void pulp::audio::AudioFormatReaderSource::get_next_audio_block ( BufferView< float > out,
int start_sample,
int num_samples )
inlineoverridevirtual

Fill num_samples of out, starting at start_sample within out.

The source writes (not adds) into the range so callers don't need to pre-zero.

Implements pulp::audio::AudioSource.

◆ get_next_read_position()

uint64_t pulp::audio::AudioFormatReaderSource::get_next_read_position ( ) const
inlineoverridevirtual

Current frame position the next get_next_audio_block call will read from.

Implements pulp::audio::PositionableAudioSource.

◆ get_total_length()

uint64_t pulp::audio::AudioFormatReaderSource::get_total_length ( ) const
inlineoverridevirtual

Total length in frames. 0 means "unknown" or "infinite".

Implements pulp::audio::PositionableAudioSource.

◆ is_looping()

bool pulp::audio::AudioFormatReaderSource::is_looping ( ) const
inlineoverridevirtual

True if the source should wrap back to 0 when it reaches the end.

Looping infinite sources are no-op.

Implements pulp::audio::PositionableAudioSource.

◆ prepare_to_play()

void pulp::audio::AudioFormatReaderSource::prepare_to_play ( int samples_per_block_expected,
double sample_rate )
inlineoverridevirtual

Called before playback begins.

samples_per_block_expected is the maximum block length the host will ever ask for; implementations may allocate scratch buffers of that size here.

Implements pulp::audio::AudioSource.

◆ reader()

MemoryMappedAudioReader * pulp::audio::AudioFormatReaderSource::reader ( ) const
inline

Non-owning accessor — useful when the caller already owns the reader and wants to query info / metadata.

◆ release_resources()

void pulp::audio::AudioFormatReaderSource::release_resources ( )
inlineoverridevirtual

Called when playback is finished.

Implementations should free any buffers allocated in prepare_to_play.

Implements pulp::audio::AudioSource.

◆ set_looping()

void pulp::audio::AudioFormatReaderSource::set_looping ( bool )
inlineoverridevirtual

Enable / disable looping.

Default no-op for sources that don't support it; concrete sources override.

Reimplemented from pulp::audio::PositionableAudioSource.

◆ set_next_read_position()

void pulp::audio::AudioFormatReaderSource::set_next_read_position ( uint64_t new_position)
inlineoverridevirtual

Move the read head to new_position (frames from the start of the source).

For finite sources, positions past get_total_length() are caller-defined behavior — most implementations clamp to total length or wrap on the next read.

Implements pulp::audio::PositionableAudioSource.

◆ set_reader()

void pulp::audio::AudioFormatReaderSource::set_reader ( std::shared_ptr< MemoryMappedAudioReader > reader)
inline

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