arduino-audio-tools
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 ModifyingStream AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream 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 void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
AudioInfo audioInfoOut () override
 provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
 
int available () override
 
int availableForWrite () override
 
bool begin () override
 
bool begin (AudioInfo from, AudioInfo to)
 
bool begin (AudioInfo from, int toRate)
 
bool begin (AudioInfo from, sample_rate_t toRate)
 
virtual bool begin (AudioInfo info)
 
bool begin (AudioInfo info, float step)
 
bool begin (ResampleConfig cfg)
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
ResampleConfig defaultConfig ()
 Provides the default configuraiton.
 
void end () override
 
void flush ()
 When buffering is active, writes the buffered audio to the output.
 
float getByteFactor ()
 
virtual PrintgetPrint ()
 
float getStepSize ()
 Returns the actual step size.
 
float getStepSize (float sampleRateFrom, float sampleRateTo)
 
virtual StreamgetStream ()
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
size_t readBytes (uint8_t *data, size_t len) override
 
virtual size_t readSilence (uint8_t *buffer, size_t length)
 Source to generate silence: just sets the buffer to 0.
 
virtual bool removeNotifyAudioChange (AudioInfoSupport &bi)
 Removes a target in order not to be notified about audio changes.
 
void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setBuffered (bool active)
 Activates buffering to avoid small incremental writes.
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
virtual void setOutput (AudioOutput &print)
 
virtual void setOutput (Print &print) override
 Defines/Changes the output target.
 
void setStepSize (float step)
 influence the sample rate
 
virtual void setStream (AudioStream &stream)
 
virtual void setStream (Stream &stream) override
 Defines/Changes the input & output.
 
void setTargetSampleRate (int rate)
 
size_t write (const uint8_t *data, size_t len) 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)
 lookup value for indicated frame & channel: index starts with -1;
 
virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 
void setupLastSamples (AudioInfo cfg)
 Sets up the buffer for the rollover samples.
 
template<typename T >
void setupLastSamples (T *data, int frame)
 store last samples to provide values for index -1
 
void setupReader ()
 
template<typename T >
size_t write (Print *p_out, const uint8_t *buffer, size_t bytes, size_t &written)
 Writes the buffer to defined output after resampling.
 

Protected Attributes

int _timeout = 10
 
int bytes_per_frame = 0
 
float idx = 0
 
AudioInfo info
 
bool is_buffer_active = USE_RESAMPLE_BUFFER
 
bool is_first = true
 
bool is_notify_active = true
 
Vector< uint8_t > last_samples {0}
 
Vector< AudioInfoSupport * > notify_vector
 
SingleBuffer< uint8_t > out_buffer {0}
 
Printp_out = nullptr
 
Printp_print = nullptr
 
Streamp_stream = nullptr
 
TransformationReader< ReformatBaseStreamreader
 
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.

Author
Phil Schatzmann
Template Parameters
T

Constructor & Destructor Documentation

◆ ResampleStream() [1/2]

ResampleStream ( AudioOutput out)
inline

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

◆ ResampleStream() [2/2]

ResampleStream ( AudioStream io)
inline

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 
)
inline

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: