arduino-audio-tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
DynamicResamplingQueueStream Class Reference

An Audio Stream backed by a buffer (queue) which tries to correct jitter and automatically adjusts for the slightly different clock rates between an audio source and audio target. Use separate tasks to write and read the data. Also make sure that you protect the access with a mutex or provide a thread save buffer! More...

#include <DynamicResamplingQueueStream.h>

Inheritance diagram for DynamicResamplingQueueStream:
AudioStream BaseStream AudioInfoSupport AudioInfoSource Stream Print

Public Member Functions

 DynamicResamplingQueueStream (BaseBuffer< uint8_t > &buffer, float stepRangePercent=0.05)
 
virtual void addNotifyAudioChange (AudioInfoSupport &bi)
 Adds target to be notified about audio changes.
 
virtual AudioInfo audioInfo () override
 provides the actual input AudioInfo
 
virtual AudioInfo audioInfoOut ()
 
virtual int available () override
 
virtual int availableForWrite () override
 
bool begin ()
 
virtual void clearNotifyAudioChange ()
 Deletes all change notify subscriptions.
 
void end ()
 
virtual void flush () override
 
bool isNotifyActive ()
 Checks if the automatic AudioInfo update is active.
 
virtual operator bool ()
 
size_t readBytes (uint8_t *data, size_t len) override
 Read resampled data from the buffer.
 
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.
 
virtual void setAudioInfo (AudioInfo newInfo) override
 Defines the input AudioInfo.
 
void setMovingAvgCount (int size)
 
void setNotifyActive (bool flag)
 Deactivate/Reactivate automatic AudioInfo updates: (default is active)
 
void setPIDParameters (float p_value, float i_value, float d_value)
 Define the PID parameters.
 
void setStepRangePercent (float rangePercent)
 
size_t write (const uint8_t *data, size_t len) override
 Fill the buffer.
 
virtual size_t write (uint8_t ch) override
 
virtual void writeSilence (size_t len)
 Writes len bytes of silence (=0).
 

Protected Member Functions

virtual int not_supported (int out, const char *msg="")
 
void notifyAudioChange (AudioInfo info)
 
void refillReadBuffer ()
 

Protected Attributes

int _timeout = 10
 
float d = 0.0001
 
float i = 0.00005
 
AudioInfo info
 
bool is_notify_active = true
 
MovingAverage< float > moving_average_level_percent {50}
 
Vector< AudioInfoSupport * > notify_vector
 
float p = 0.005
 
BaseBuffer< uint8_t > * p_buffer = nullptr
 
PIDController pid
 
QueueStream< uint8_t > queue_stream
 
uint32_t read_count = 0
 
float resample_range = 0
 
ResampleStream resample_stream
 
float step_size = 1.0
 
RingBuffer< uint8_t > tmp_in {0}
 
RingBuffer< uint8_t > tmp_out {0}
 

Detailed Description

An Audio Stream backed by a buffer (queue) which tries to correct jitter and automatically adjusts for the slightly different clock rates between an audio source and audio target. Use separate tasks to write and read the data. Also make sure that you protect the access with a mutex or provide a thread save buffer!

The resamping step size is calculated with the help of a PID controller.

Author
Phil Schatzmann

Member Function Documentation

◆ addNotifyAudioChange()

virtual void addNotifyAudioChange ( AudioInfoSupport bi)
inlinevirtualinherited

◆ audioInfo()

virtual AudioInfo audioInfo ( )
inlineoverridevirtualinherited

◆ audioInfoOut()

virtual AudioInfo audioInfoOut ( )
inlinevirtualinherited

◆ available()

virtual int available ( )
inlineoverridevirtualinherited

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

◆ begin()

bool begin ( )
inlinevirtual

Reimplemented from BaseStream.

◆ end()

void end ( )
inlinevirtual

Reimplemented from BaseStream.

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

Reimplemented from Print.

Reimplemented in ResampleStream, BufferedTaskStream, and BufferedStream.

◆ operator bool()

virtual operator bool ( )
inlinevirtualinherited

Reimplemented in A2DPStream, I2SStream, MemoryStream, and Pipeline.

◆ readBytes()

size_t readBytes ( uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Read resampled data from the buffer.

Reimplemented from AudioStream.

◆ setAudioInfo()

virtual void setAudioInfo ( AudioInfo  info)
inlineoverridevirtualinherited

◆ setMovingAvgCount()

void setMovingAvgCount ( int  size)
inline

Defines the number of historic fill levels that will be used to calculate the moving avg

◆ setStepRangePercent()

void setStepRangePercent ( float  rangePercent)
inline

e.g. a value of 0.0005 means that we allow to resample for 44100 by +- 22.05 from 44077.95 to 44122.05

◆ write() [1/2]

size_t write ( const uint8_t *  data,
size_t  len 
)
inlineoverridevirtual

Fill the buffer.

Reimplemented from AudioStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

Reimplemented in BufferedTaskStream, and BufferedStream.


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