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.
This commit is contained in:
2025-04-25 10:47:52 +02:00
parent 178bfc630a
commit 7331d2fe01
3 changed files with 25 additions and 17 deletions

View File

@@ -2,6 +2,7 @@
#include <Arduino.h>
#include <deque>
#include "Config.h"
class AudioLevelTracker {
public:
@@ -19,5 +20,5 @@ private:
int32_t maxLevel;
static const uint32_t HISTORY_DURATION_MS = 3000; // 3 seconds history
static const int32_t MAX_RANGE_LIMIT = 200000000; // Maximum allowed range limit
static const int32_t MAX_RANGE_LIMIT = Config::DEFAULT_RANGE_LIMIT << 16; // Scale up 16-bit limit
};

View File

@@ -12,30 +12,30 @@ namespace Config {
constexpr int I2S_MIC_SERIAL_DATA = 10; // SD
// I2S Configuration
constexpr int SAMPLE_RATE = 8000; // Hz
constexpr int BITS_PER_SAMPLE = 32; // Bits
constexpr int SAMPLE_RATE = 8000; // Hz - good for frequencies up to 4kHz
constexpr int BITS_PER_SAMPLE = 16; // Changed to 16-bit
constexpr int CHANNELS = 1; // Mono input
constexpr int SAMPLE_BUFFER_SIZE = 512; // Samples per buffer
constexpr int SAMPLE_BUFFER_SIZE = 1024; // 128ms window at 8kHz - good for low frequency resolution
// DMA Configuration
constexpr int DMA_BUFFER_COUNT = 8; // Number of DMA buffers
constexpr int DMA_BUFFER_LEN = 1024; // Length of each DMA buffer
constexpr int DMA_BUFFER_COUNT = 4; // Reduced for lower latency
constexpr int DMA_BUFFER_LEN = 512; // Smaller chunks for faster processing
// Audio Processing
constexpr float DC_OFFSET = 0.0f; // DC offset correction
constexpr float GAIN = 1.0f; // Audio gain multiplier
constexpr int32_t NOISE_THRESHOLD = 1000; // Ignore audio below this level
constexpr int32_t DEFAULT_RANGE_LIMIT = 200000000; // Default range limit for plotting
constexpr float DECAY_FACTOR = 0.95f; // Level decay rate
constexpr float GAIN = 1.5f; // Adjusted gain for 16-bit range
constexpr int16_t NOISE_THRESHOLD = 1000; // Adjusted for 16-bit range
constexpr int16_t DEFAULT_RANGE_LIMIT = 32767; // Max value for 16-bit
constexpr float DECAY_FACTOR = 0.80f; // Faster decay for quicker note changes
// Timing and Debug
constexpr uint32_t LEVEL_UPDATE_INTERVAL_MS = 100; // Level update interval
constexpr uint32_t LEVEL_UPDATE_INTERVAL_MS = 50; // Faster updates for better responsiveness
constexpr bool ENABLE_DEBUG = true; // Enable debug output
constexpr int DEBUG_INTERVAL_MS = 1000; // Debug print interval
// System Configuration
constexpr uint32_t TASK_STACK_SIZE = 4096; // Audio task stack size
constexpr uint8_t TASK_PRIORITY = 1; // Audio task priority (0-24)
constexpr uint8_t TASK_CORE = 0; // Core to run audio task (0 or 1)
constexpr uint8_t TASK_PRIORITY = 2; // Increased priority for more consistent timing
constexpr uint8_t TASK_CORE = 1; // Run on second core to avoid interference
}