arduino-audio-tools
|
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-safe buffer! More...
#include <AdaptiveResamplingStream.h>
Public Member Functions | |
AdaptiveResamplingStream (BaseBuffer< uint8_t > &buffer, float stepRangePercent=5.0f) | |
Construct a new AdaptiveResamplingStream object. | |
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 () |
Initialize the stream and internal components. | |
virtual void | clearNotifyAudioChange () |
Deletes all change notify subscriptions. | |
void | end () |
End the stream and release resources. | |
virtual void | flush () override |
bool | isNotifyActive () |
Checks if the automatic AudioInfo update is active. | |
float | levelPercent () |
Get the fill level at the last calculation in percent. | |
float | levelPercentActual () |
Get the current actual buffer fill level in percent. | |
virtual | operator bool () |
size_t | readBytes (uint8_t *data, size_t len) override |
Read resampled audio data from the buffer. | |
virtual size_t | readSilence (uint8_t *buffer, size_t length) |
Source to generate silence: just sets the buffer to 0. | |
float | recalculate () |
Recalculate the resampling step size based on buffer fill level. | |
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 | setKalmanParameters (float process_noise, float measurement_noise) |
Set the Kalman filter parameters. | |
void | setNotifyActive (bool flag) |
Deactivate/Reactivate automatic AudioInfo updates: (default is active) | |
void | setPIDParameters (float p_value, float i_value, float d_value) |
Set the PID controller parameters. | |
void | setStepRangePercent (float rangePercent) |
Set the allowed resampling range as a percent. | |
void | setWriteBufferSize (int size) |
size_t | write (const uint8_t *data, size_t len) override |
Write audio data to 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 |
KalmanFilter | kalman_filter {0.01f, 0.1f} |
float | level_percent = 0.0 |
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} |
int | write_buffer_size = MAX_SINGLE_CHARS |
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-safe buffer!
The resamping step size is calculated with the help of a PID controller. The fill level is smoothed using a Kalman filter.
|
inline |
Construct a new AdaptiveResamplingStream object.
buffer | Reference to the buffer used for audio data |
stepRangePercent | Allowed resampling range in percent (default: 0.05) |
|
inlinevirtualinherited |
Adds target to be notified about audio changes.
Reimplemented in CodecNOP, EncodedAudioOutput, EncodedAudioStream, AACDecoderFDK, DecoderBasic, CodecChain, MP3DecoderHelix, MP3DecoderMAD, OggContainerDecoder, RTSPClient< TcpClient, UdpSocket >, Pipeline, and Pipeline::ModifyingStreamAdapter.
|
inlineoverridevirtualinherited |
provides the actual input AudioInfo
Implements AudioInfoSupport.
Reimplemented in JupyterAudioT< T >, MozziStream, TimerCallbackAudioStream, EncodedAudioStream, PureDataStream, AdapterAudioOutputToAudioStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, and InputMerge< T >.
|
inlinevirtualinherited |
provides the actual output AudioInfo: this is usually the same as audioInfo() unless we use a transforming stream
Reimplemented in PureDataStream, PWMAudioOutput, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, FormatConverterStream, Pipeline, ResampleStream, and ResampleStreamT< TInterpolator >.
|
inlineoverridevirtualinherited |
Reimplemented from Stream.
Reimplemented in AudioKitStream, AudioFFTBase, I2SCodecStream, TfLiteAudioStream, A2DPStream, HLSStreamT< URLStream >, ICYStreamT< T >, BufferedTaskStream, UDPStream, Equalizer3Bands, Equalizer3BandsPerChannel, I2SStream, TimedStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, BufferedStream, ConverterStream< T >, InputMerge< T >, FrequencyDetectorAutoCorrelation, FrequencyDetectorZeroCrossing, Pipeline::ModifyingStreamAdapter, and VolumeStream.
|
inlineoverridevirtualinherited |
Reimplemented from Print.
Reimplemented in UDPStream, AudioFFTBase, I2SCodecStream, A2DPStream, AbstractURLStream, URLStreamESP32, Equalizer3Bands, Equalizer3BandsPerChannel, I2SStream, MeasuringStream, ProgressStream, FrequencyDetectorAutoCorrelation, FrequencyDetectorZeroCrossing, and VolumeStream.
|
inlinevirtual |
Initialize the stream and internal components.
Reimplemented from BaseStream.
|
inlinevirtualinherited |
Deletes all change notify subscriptions.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlinevirtual |
End the stream and release resources.
Reimplemented from BaseStream.
|
inlineoverridevirtualinherited |
Reimplemented from Print.
Reimplemented in ResampleStream, BufferedTaskStream, and BufferedStream.
|
inline |
Get the fill level at the last calculation in percent.
|
inline |
Get the current actual buffer fill level in percent.
|
inlinevirtualinherited |
Reimplemented in A2DPStream, ICYStreamT< T >, I2SStream, MemoryStream, and Pipeline.
|
inlineoverridevirtual |
Read resampled audio data from the buffer.
data | Pointer to the buffer to fill |
len | Number of bytes to read |
Reimplemented from AudioStream.
|
inline |
Recalculate the resampling step size based on buffer fill level.
|
inlinevirtualinherited |
Removes a target in order not to be notified about audio changes.
Reimplemented in RTSPClient< TcpClient, UdpSocket >.
|
inlineoverridevirtualinherited |
Defines the input AudioInfo.
Implements AudioInfoSupport.
Reimplemented in VS1053Stream, WM8960Stream, ChannelFormatConverterStreamT< T >, ChannelFormatConverterStream, VolumeStream, MiniAudioStream, PortAudioStream, I2SCodecStream, MozziStream, SPDIFOutput, AudioLoRa, AnalogAudioStream, I2SStream, TimerCallbackAudioStream, AudioBLEStream, LoRaStream, AudioFFTBase, AudioKitStream, VBANStream, AnalogAudioArduino, Equalizer3Bands, Equalizer3BandsPerChannel, AdapterAudioOutputToAudioStream, TimedStream, MeasuringStream, ProgressStream, CallbackStream, VolumeMeter, AudioInputMonitor, FormatConverterStream, FadeStream, GoertzelStream, Pipeline::ModifyingStreamAdapter, EncodedAudioStream, PureDataStream, GeneratedSoundStream< T >, GeneratedSoundStream< int16_t >, NumberFormatConverterStreamT< TFrom, TTo >, NumberFormatConverterStream, Pipeline, ResampleStream, and ResampleStreamT< TInterpolator >.
|
inline |
Set the Kalman filter parameters.
process_noise | Process noise covariance (Q) |
measurement_noise | Measurement noise covariance (R) |
|
inline |
Set the PID controller parameters.
p_value | Proportional gain |
i_value | Integral gain |
d_value | Derivative gain |
|
inline |
Set the allowed resampling range as a percent.
rangePercent | Allowed range in percent (e.g., 5.0 for ± 5%) |
|
inlineoverridevirtual |
Write audio data to the buffer.
data | Pointer to the data to write |
len | Number of bytes to write |
Reimplemented from AudioStream.
|
inlineoverridevirtualinherited |
Reimplemented in BufferedTaskStream, and BufferedStream.