- New HTML file added to the `data` directory for a piano spectrum analyzer. - Updated `Config.h` with WiFi settings and web configuration portal details. - Update the Arduino sketch with WiFi and WebSocket support, enabling real-time spectrum data transmission over the web.
90 lines
4.5 KiB
C++
90 lines
4.5 KiB
C++
#pragma once
|
|
#include <cstdint>
|
|
|
|
namespace Config {
|
|
|
|
// Serial Configuration
|
|
constexpr int SERIAL_BAUD_RATE = 115200; // Serial communication baud rate
|
|
|
|
// WiFi Configuration
|
|
constexpr const char* WIFI_AP_NAME = "ESP32Piano"; // AP name when in configuration mode
|
|
constexpr const char* WIFI_AP_PASSWORD = "12345678"; // AP password when in configuration mode
|
|
constexpr uint32_t WIFI_CONFIG_TIMEOUT = 180; // Seconds to wait for WiFi configuration
|
|
constexpr uint32_t WIFI_CONFIG_PORT = 80; // Web configuration portal port
|
|
|
|
// 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 - 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 = 1024; // Match FFT_SIZE for efficiency
|
|
|
|
// DMA Configuration
|
|
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 = 4.0f; // Increased gain for better note detection
|
|
constexpr int16_t NOISE_THRESHOLD = 100; // Lower threshold for 16-bit samples
|
|
constexpr int16_t DEFAULT_RANGE_LIMIT = 32767; // Max value for 16-bit
|
|
constexpr float DECAY_FACTOR = 0.7f; // Faster decay for quicker note changes
|
|
|
|
// FFT Configuration
|
|
constexpr int FFT_SIZE = 1024; // Must be power of 2, gives ~7.8 Hz resolution at 8kHz
|
|
constexpr float FREQUENCY_RESOLUTION = static_cast<float>(SAMPLE_RATE) / FFT_SIZE;
|
|
|
|
// Piano Note Frequencies (Hz)
|
|
constexpr float NOTE_FREQ_C2 = 65.41f; // Lowest note we'll detect
|
|
constexpr float NOTE_FREQ_C3 = 130.81f;
|
|
constexpr float NOTE_FREQ_C4 = 261.63f; // Middle C
|
|
constexpr float NOTE_FREQ_C5 = 523.25f;
|
|
constexpr float NOTE_FREQ_C6 = 1046.50f; // Highest note we'll detect
|
|
|
|
// Note Detection Parameters
|
|
constexpr float FREQUENCY_TOLERANCE = 3.0f; // Hz tolerance, increased for better detection
|
|
constexpr float MIN_MAGNITUDE_THRESHOLD = 500.0f; // Adjusted for 16-bit samples
|
|
constexpr int MAX_SIMULTANEOUS_NOTES = 7; // Maximum number of notes to detect simultaneously
|
|
constexpr float PEAK_RATIO_THRESHOLD = 0.1f; // Peaks must be at least this ratio of the strongest peak
|
|
|
|
// Timing and Debug
|
|
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 = 2; // Increased priority for more consistent timing
|
|
constexpr uint8_t TASK_CORE = 1; // Run on second core to avoid interference
|
|
|
|
// Calibration Parameters
|
|
constexpr bool CALIBRATION_MODE = false; // Set to true to enable calibration output
|
|
constexpr int CALIBRATION_DURATION_MS = 5000; // Duration to collect calibration data
|
|
constexpr float CALIBRATION_PEAK_PERCENTILE = 0.95f; // Use 95th percentile for thresholds
|
|
|
|
// Note Detection Timing
|
|
constexpr int NOTE_PRINT_INTERVAL_MS = 100; // How often to print detected notes
|
|
constexpr int MIN_NOTE_DURATION_MS = 50; // Minimum duration to consider a note valid
|
|
constexpr int NOTE_RELEASE_TIME_MS = 100; // Time before considering a note released
|
|
|
|
// Serial Commands
|
|
constexpr char CMD_HELP = 'h'; // Show help
|
|
constexpr char CMD_CALIBRATE = 'c'; // Start calibration
|
|
constexpr char CMD_THRESHOLD_UP = '+'; // Increase sensitivity
|
|
constexpr char CMD_THRESHOLD_DOWN = '-'; // Decrease sensitivity
|
|
constexpr char CMD_TOGGLE_SPECTRUM = 's'; // Toggle spectrum display
|
|
constexpr float THRESHOLD_STEP = 0.1f; // Threshold adjustment step
|
|
|
|
// Command Response Messages
|
|
constexpr const char* MSG_HELP =
|
|
"Commands:\n"
|
|
"h - Show this help\n"
|
|
"c - Start calibration\n"
|
|
"+ - Increase sensitivity\n"
|
|
"- - Decrease sensitivity\n"
|
|
"s - Toggle spectrum display\n";
|
|
} |