Files
esp32i2s/include/AudioLevelTracker.h
Jose 7331d2fe01 refactor ♻️: Updated I2S sample rate from 8 kHz to 4 kHz, reduced DMA buffer count and length, adjusted gain for 16-bit range, increased task stack size and priority, and decreased debug interval
- Updated `AudioLevelTracker.h` to scale the maximum range limit by a factor of 16.
- Updated the I2S sample rate from 8 kHz to 4 kHz, reduced DMA buffer count and length, adjusted gain for 16-bit range, increased task stack size and priority, and decreased debug interval.
- The `initI2S` function has been modified to use a smaller buffer size and adjust the data format to 16-bit, ensuring compatibility with existing code while reducing memory usage.
2025-04-25 10:47:52 +02:00

24 lines
573 B
C++

#pragma once
#include <Arduino.h>
#include <deque>
#include "Config.h"
class AudioLevelTracker {
public:
AudioLevelTracker();
void updateMaxLevel(int32_t sample);
int32_t getMaxLevel() const;
void resetMaxLevel();
private:
struct SamplePoint {
uint32_t timestamp;
int32_t value;
};
std::deque<SamplePoint> sampleHistory;
int32_t maxLevel;
static const uint32_t HISTORY_DURATION_MS = 3000; // 3 seconds history
static const int32_t MAX_RANGE_LIMIT = Config::DEFAULT_RANGE_LIMIT << 16; // Scale up 16-bit limit
};