feat ✨: Added new header files AudioLevelTracker.h, Config.h, I2SConfig.h, and updated Arduino code for improved I2S communication and dynamic range limiting.
- Added a new header file `AudioLevelTracker.h` to track audio levels with a history of up to 3 seconds and a maximum range limit. - `Config.h` has been added with new serial and I2S configurations. The aim is to configure these peripherals for audio processing. - Added new header file `I2SConfig.h` with setup functions for initializing and reading from I2S interface. - The `AudioLevelTracker.cpp` file has been updated to include functionality for tracking the maximum audio level over a specified duration. - Initial setup for I2S communication with a microphone. - Updated `Arduino` code with improved I2S configuration and dynamic range limiting.
This commit is contained in:
34
src/I2SConfig.cpp
Normal file
34
src/I2SConfig.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "I2SConfig.h"
|
||||
|
||||
void initI2S() {
|
||||
// I2S configuration
|
||||
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,
|
||||
.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,
|
||||
.use_apll = false,
|
||||
.tx_desc_auto_clear = false,
|
||||
.fixed_mclk = 0
|
||||
};
|
||||
|
||||
// I2S pin configuration
|
||||
i2s_pin_config_t i2s_mic_pins = {
|
||||
.bck_io_num = Config::I2S_MIC_SERIAL_CLOCK,
|
||||
.ws_io_num = Config::I2S_MIC_LEFT_RIGHT_CLOCK,
|
||||
.data_out_num = I2S_PIN_NO_CHANGE,
|
||||
.data_in_num = Config::I2S_MIC_SERIAL_DATA
|
||||
};
|
||||
|
||||
// Install and configure I2S driver
|
||||
i2s_driver_install(I2S_NUM_0, &i2s_config, 0, NULL);
|
||||
i2s_set_pin(I2S_NUM_0, &i2s_mic_pins);
|
||||
}
|
||||
|
||||
void readI2SSamples(int32_t* samples, size_t* bytesRead) {
|
||||
i2s_read(I2S_NUM_0, samples, Config::SAMPLE_BUFFER_SIZE * sizeof(int32_t), bytesRead, portMAX_DELAY);
|
||||
}
|
||||
Reference in New Issue
Block a user