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:
23
include/AudioLevelTracker.h
Normal file
23
include/AudioLevelTracker.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <deque>
|
||||
|
||||
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 = 200000000; // Maximum allowed range limit
|
||||
};
|
||||
41
include/Config.h
Normal file
41
include/Config.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace Config {
|
||||
|
||||
// Serial Configuration
|
||||
constexpr int SERIAL_BAUD_RATE = 115200; // Serial communication baud rate
|
||||
|
||||
// I2S Pin Configuration
|
||||
constexpr int I2S_MIC_SERIAL_CLOCK = 8; // SCK
|
||||
constexpr int I2S_MIC_LEFT_RIGHT_CLOCK = 9; // WS/LRC
|
||||
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 CHANNELS = 1; // Mono input
|
||||
constexpr int SAMPLE_BUFFER_SIZE = 512; // Samples per buffer
|
||||
|
||||
// DMA Configuration
|
||||
constexpr int DMA_BUFFER_COUNT = 8; // Number of DMA buffers
|
||||
constexpr int DMA_BUFFER_LEN = 1024; // Length of each DMA buffer
|
||||
|
||||
// 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
|
||||
|
||||
// Timing and Debug
|
||||
constexpr uint32_t LEVEL_UPDATE_INTERVAL_MS = 100; // Level update interval
|
||||
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)
|
||||
|
||||
}
|
||||
9
include/I2SConfig.h
Normal file
9
include/I2SConfig.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <driver/i2s.h>
|
||||
#include "Config.h"
|
||||
|
||||
// I2S setup functions
|
||||
void initI2S();
|
||||
void readI2SSamples(int32_t* samples, size_t* bytesRead);
|
||||
Reference in New Issue
Block a user