Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ResampleStream Class Reference

Dynamic Resampling. We can use a variable factor to speed up or slow down the playback. More...

#include <ResampleStream.h>

Inheritance diagram for ResampleStream:
ReformatBaseStream AudioStream Stream AudioInfoSupport AudioInfoSource Print

Public Member Functions

 ResampleStream (AudioOutput &out)
 ResampleStream (AudioStream &io)
 ResampleStream (Print &out)
 Support for resampling via write.
 ResampleStream (Stream &io)
 Support for resampling via write and read.
virtual AudioInfo audioInfo () override
int available () override
int availableForWrite () override
virtual bool begin ()
bool begin (AudioInfo from, int toRate)
bool begin (AudioInfo info, float step)
bool begin (ResampleConfig cfg)
ResampleConfig defaultConfig ()
 Provides the default configuraiton.
virtual void end ()
void flush () override
 When buffering is active, writes the buffered audio to the output.
virtual PrintgetPrint ()
float getStepSize ()
 Returns the actual step size.
float getStepSize (float sampleRateFrom, float sampleRateTo)
virtual StreamgetStream ()
 operator bool ()
size_t readBytes (uint8_t *data, size_t size) override
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
void setAudioInfo (AudioInfo info) override
void setBuffered (bool active)
 Activates buffering to avoid small incremental writes.
virtual void setNotifyAudioChange (AudioInfoSupport &bi) override
void setStepSize (float step)
 influence the sample rate
virtual void setStream (Print &print)
virtual void setStream (Stream &stream)
void setupReader ()
virtual bool validate (AudioInfo &info)
size_t write (const uint8_t *buffer, size_t bytes) override
virtual size_t write (uint8_t ch) override
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).

Protected Member Functions

template<typename T >
getValue (T *data, float frame_idx, int channel)
 get the interpolated value for indicated (float) index value
template<typename T >
lookup (T *data, int frame, int channel)
virtual int not_supported (int out, const char *msg="")
void refillReadBuffer ()
void setupLastSamples (AudioInfo cfg)
 Sets up the buffer for the rollover samples.
template<typename T >
void setupLastSamples (T *data, int frame)
template<typename T >
size_t write (Print *p_out, const uint8_t *buffer, size_t bytes, size_t &written)
 Writes the buffer to p_print after resampling.

Protected Attributes

int bytes_per_frame = 0
float factor
float idx = 0
AudioInfo info
bool is_buffer_active = false
bool is_first = true
Vector< uint8_t > last_samples {0}
SingleBuffer< uint8_t > out_buffer {0}
AudioInfoSupportp_notify =nullptr
Printp_out =nullptr
Printp_print = nullptr
Streamp_stream = nullptr
TransformationReader< ResampleStreamreader
float step_size = 1.0
RingBuffer< uint8_t > tmp_in {0}
RingBuffer< uint8_t > tmp_out {0}
int to_sample_rate = 0

Detailed Description

Dynamic Resampling. We can use a variable factor to speed up or slow down the playback.

Phil Schatzmann
Template Parameters

Constructor & Destructor Documentation

◆ ResampleStream() [1/2]

ResampleStream ( AudioOutput out)

Support for resampling via write. The audio information is copied from the io

◆ ResampleStream() [2/2]

ResampleStream ( AudioStream io)

Support for resampling via write and read. The audio information is copied from the io

Member Function Documentation

◆ getStepSize()

float getStepSize ( float  sampleRateFrom,
float  sampleRateTo 

calculate the step size the sample rate: e.g. from 44200 to 22100 gives a step size of 2 in order to provide fewer samples

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