arduino-audio-tools
Loading...
Searching...
No Matches
AdaptiveResamplingStream.h
Go to the documentation of this file.
1#pragma once
2
5
6namespace audio_tools {
7
26 public:
39 float stepRangePercent = 5.0f)
40 : resampling_buffer(buffer, stepRangePercent) {
42 }
43
51 }
52
62
70 size_t write(const uint8_t* data, size_t len) override {
71 return resampling_buffer.writeArray(data, len);
72 }
73
78
86 size_t readBytes(uint8_t* data, size_t len) override {
87 return resampling_buffer.readArray(data, len);
88 }
89
96
102 void setStepRangePercent(float rangePercent) {
104 }
105
114 void setStartFillPercent(float percent) {
116 }
117
121
128
135
142 void setKalmanParameters(float process_noise, float measurement_noise) {
143 resampling_buffer.setKalmanParameters(process_noise, measurement_noise);
144 }
145
153 void setPIDParameters(float p_value, float i_value, float d_value) {
154 resampling_buffer.setPIDParameters(p_value, i_value, d_value);
155 }
156
157 protected:
159};
160
161} // namespace audio_tools
A BaseBuffer<uint8_t> that wraps a raw (unresampled) backing buffer and transparently resamples on re...
Definition AdaptiveResamplingBuffer.h:52
void setStepRangePercent(float rangePercent)
Set the allowed resampling range as a percent.
Definition AdaptiveResamplingBuffer.h:346
void setStartFillPercent(float percent)
Defines the fill level (in percent of the backing buffer's capacity) that must be reached once,...
Definition AdaptiveResamplingBuffer.h:83
void setBuffer(BaseBuffer< uint8_t > &buffer)
Set the raw (unresampled) backing buffer.
Definition AdaptiveResamplingBuffer.h:98
void setPIDParameters(float p_value, float i_value, float d_value)
Set the PID controller parameters.
Definition AdaptiveResamplingBuffer.h:383
int readArray(uint8_t data[], int len) override
Definition AdaptiveResamplingBuffer.h:170
bool isPrimed()
Definition AdaptiveResamplingBuffer.h:364
bool begin()
Initialize the buffer and internal components.
Definition AdaptiveResamplingBuffer.h:117
float levelPercent() override
Current actual fill level of the backing buffer in percent (0-100).
Definition AdaptiveResamplingBuffer.h:244
void end()
End the buffer and release resources.
Definition AdaptiveResamplingBuffer.h:143
void setKalmanParameters(float process_noise, float measurement_noise)
Set the Kalman filter parameters.
Definition AdaptiveResamplingBuffer.h:372
float levelPercentSmoothed()
Get the Kalman-smoothed fill level from the last recalculate() call, in percent.
Definition AdaptiveResamplingBuffer.h:356
void setAudioInfo(AudioInfo info) override
Defines the audio format: needed to correctly interpret and resample the sample frames stored in the ...
Definition AdaptiveResamplingBuffer.h:104
float recalculate()
Recalculate the resampling step size based on buffer fill level. Called automatically by writeArray()...
Definition AdaptiveResamplingBuffer.h:255
int writeArray(const uint8_t data[], int len) override
Definition AdaptiveResamplingBuffer.h:157
An Audio Stream backed by a buffer (queue) which tries to correct jitter and automatically adjusts fo...
Definition AdaptiveResamplingStream.h:25
void setStepRangePercent(float rangePercent)
Set the allowed resampling range as a percent.
Definition AdaptiveResamplingStream.h:102
void setStartFillPercent(float percent)
Defines the fill level (percent) that must be reached once, right after begin(), before any data is r...
Definition AdaptiveResamplingStream.h:114
void setBuffer(BaseBuffer< uint8_t > &buffer)
Set the buffer used for audio data.
Definition AdaptiveResamplingStream.h:49
void setPIDParameters(float p_value, float i_value, float d_value)
Set the PID controller parameters.
Definition AdaptiveResamplingStream.h:153
AdaptiveResamplingStream()
Construct a new AdaptiveResamplingStream object You need to call setBuffer() and setStepRangePercent(...
Definition AdaptiveResamplingStream.h:31
bool isPrimed()
Definition AdaptiveResamplingStream.h:120
size_t readBytes(uint8_t *data, size_t len) override
Read resampled audio data from the buffer.
Definition AdaptiveResamplingStream.h:86
bool begin()
Initialize the stream and internal components.
Definition AdaptiveResamplingStream.h:58
AdaptiveResamplingStream(BaseBuffer< uint8_t > &buffer, float stepRangePercent=5.0f)
Construct a new AdaptiveResamplingStream object.
Definition AdaptiveResamplingStream.h:38
size_t write(const uint8_t *data, size_t len) override
Write audio data to the buffer.
Definition AdaptiveResamplingStream.h:70
float levelPercent()
Get the fill level at the last calculation in percent.
Definition AdaptiveResamplingStream.h:134
void end()
End the stream and release resources.
Definition AdaptiveResamplingStream.h:77
void setKalmanParameters(float process_noise, float measurement_noise)
Set the Kalman filter parameters.
Definition AdaptiveResamplingStream.h:142
AdaptiveResamplingBuffer resampling_buffer
Definition AdaptiveResamplingStream.h:158
float levelPercentActual()
Get the current actual buffer fill level in percent.
Definition AdaptiveResamplingStream.h:127
float recalculate()
Recalculate the resampling step size based on buffer fill level.
Definition AdaptiveResamplingStream.h:95
virtual void addNotifyAudioChange(AudioInfoSupport &bi)
Adds target to be notified about audio changes.
Definition AudioTypes.h:149
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition BaseStream.h:120
virtual AudioInfo audioInfo() override
provides the actual input AudioInfo
Definition BaseStream.h:151
Shared functionality of all buffers.
Definition Buffers.h:23
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6