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

@@ -5,12 +5,12 @@ void initI2S() {
i2s_config_t i2s_config = {
.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),
.sample_rate = Config::SAMPLE_RATE,
.bits_per_sample = I2S_BITS_PER_SAMPLE_32BIT,
.bits_per_sample = I2S_BITS_PER_SAMPLE_16BIT,
.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,
.communication_format = I2S_COMM_FORMAT_STAND_I2S,
.intr_alloc_flags = ESP_INTR_FLAG_LEVEL1,
.dma_buf_count = 4,
.dma_buf_len = 1024,
.dma_buf_count = Config::DMA_BUFFER_COUNT,
.dma_buf_len = Config::DMA_BUFFER_LEN,
.use_apll = false,
.tx_desc_auto_clear = false,
.fixed_mclk = 0
@@ -30,5 +30,12 @@ void initI2S() {
}
void readI2SSamples(int32_t* samples, size_t* bytesRead) {
i2s_read(I2S_NUM_0, samples, Config::SAMPLE_BUFFER_SIZE * sizeof(int32_t), bytesRead, portMAX_DELAY);
// Read data as 16-bit samples
int16_t temp_buffer[Config::SAMPLE_BUFFER_SIZE];
i2s_read(I2S_NUM_0, temp_buffer, Config::SAMPLE_BUFFER_SIZE * sizeof(int16_t), bytesRead, portMAX_DELAY);
// Convert 16-bit samples to 32-bit for compatibility with existing code
for (int i = 0; i < Config::SAMPLE_BUFFER_SIZE; i++) {
samples[i] = temp_buffer[i] << 16; // Scale up to match previous 32-bit range
}
}