Skip to content

Commit 60368e7

Browse files
committed
AdaptiveResamplingStream
1 parent 63ea836 commit 60368e7

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/AudioTools/CoreAudio/AdaptiveResamplingStream.h renamed to src/AudioTools/Communication/AdaptiveResamplingStream.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class AdaptiveResamplingStream : public AudioStream {
2929
* @param stepRangePercent Allowed resampling range in percent (default: 0.05)
3030
*/
3131
AdaptiveResamplingStream(BaseBuffer<uint8_t>& buffer,
32-
float stepRangePercent = 0.05) {
32+
float stepRangePercent = 5.0f) {
3333
p_buffer = &buffer;
3434
setStepRangePercent(stepRangePercent);
3535
addNotifyAudioChange(resample_stream);
@@ -60,7 +60,7 @@ class AdaptiveResamplingStream : public AudioStream {
6060
* @return size_t Number of bytes actually written
6161
*/
6262
size_t write(const uint8_t* data, size_t len) override {
63-
if (p_buffer == 0) return 0;
63+
if (p_buffer == nullptr) return 0;
6464
size_t result = p_buffer->writeArray(data, len);
6565
recalculate();
6666
return result;
@@ -72,6 +72,7 @@ class AdaptiveResamplingStream : public AudioStream {
7272
void end() {
7373
queue_stream.end();
7474
resample_stream.end();
75+
read_count = 0;
7576
}
7677

7778
/**
@@ -82,7 +83,7 @@ class AdaptiveResamplingStream : public AudioStream {
8283
* @return size_t Number of bytes actually read
8384
*/
8485
size_t readBytes(uint8_t* data, size_t len) override {
85-
if (p_buffer->available() == 0) return 0;
86+
if (p_buffer == nullptr) return 0;
8687

8788
return resample_stream.readBytes(data, len);
8889
}
@@ -100,8 +101,8 @@ class AdaptiveResamplingStream : public AudioStream {
100101
kalman_filter.addMeasurement(level_percent);
101102
step_size = pid.calculate(50.0, kalman_filter.calculate());
102103

103-
// log step size every 10th read
104-
if (read_count++ % 10 == 0) {
104+
// log step size every 100th read
105+
if (read_count++ % 100 == 0) {
105106
LOGI("step_size: %f", step_size);
106107
}
107108

@@ -113,7 +114,7 @@ class AdaptiveResamplingStream : public AudioStream {
113114
/**
114115
* @brief Set the allowed resampling range as a percent.
115116
*
116-
* @param rangePercent Allowed range in percent (e.g., 0.05 for ±0.05%)
117+
* @param rangePercent Allowed range in percent (e.g., 5.0 for ± 5%)
117118
*/
118119
void setStepRangePercent(float rangePercent) {
119120
resample_range = rangePercent / 100.0;

0 commit comments

Comments
 (0)