- This code snippet is a C++ program that utilizes the Arduino framework to implement audio processing for a microphone. The program includes several classes and functions to handle various aspects of audio analysis, such as note detection, frequency analysis, and spectrum visualization.
The key components of this program include:
1. **AudioLevelTracker**: This class provides real-time audio level monitoring by tracking the maximum amplitude of an input signal. It uses a simple peak detection algorithm to determine when the input signal reaches a certain threshold.
2. **NoteDetector**: This class performs frequency analysis on the input audio signal and identifies specific notes based on their frequencies. The note detector utilizes a pre-defined list of known frequencies and compares them against the detected frequencies to identify matches.
3. **SpectrumVisualizer**: This class provides real-time spectrum visualization by displaying the magnitude of the input audio signal in the form of an ASCII graph. The magnitude scaling is done dynamically based on the signal power to ensure that all frequencies are visible.
4. **Main Loop**: The main loop handles all the other components and processes them sequentially. It initializes the audio level tracker, note detector, and spectrum visualizer, and then enters a loop where it continuously processes the input audio signal.
The program also includes error handling mechanisms, such as automatic I2S reset on communication errors and dynamic threshold adjustment to ensure that the audio processing remains stable and accurate. The project is structured with clear class definitions and proper documentation for each component.
- The updateMaxLevel and getMaxLevel methods in AudioLevelTracker have been modified to accept and return int16_t values instead of int32_t, which improves range handling.
- The `Config.h` file has been updated to enhance audio processing by increasing gain, adjusting noise threshold for 16-bit samples, and changing the FFT size from a power of 2. The main goal is to optimize performance while maintaining good noise detection and note detection capabilities for better accuracy in music analysis tasks.
- The `git diff` output shows a change to the I2SConfig.h file. Specifically, it adds a line to define an additional parameter for reading I2S samples: int16_t*.
- This commit introduces a new header file `NoteDetector.h` for detecting musical notes in an Arduino project, enhancing the detection process with FFT analysis and dynamic threshold adjustments.
- The `SpectrumVisualizer.h` file has been added to the project with new definitions and functions to visualize audio spectrum and detected notes.
- The main goal of these changes is to update the `lib_deps` in the `platformio.ini` file to include a specific library named `kosme/arduinoFFT` which is version 1.6.
- The changes improve the audio level tracking by rounding the integer samples to 16 bits before storing them, ensuring that the range remains within a feasible limit for processing.
- The main goal of the changes is to optimize the `readI2SSamples` function by removing unnecessary conversion from 16-bit to 32-bit samples, which was previously done in an existing code section that could be reused for other purposes. This change improves performance and reduces complexity while maintaining compatibility with existing code.
- A new `NoteDetector` class has been created in the `src/NoteDetector.cpp` file, implementing various calibration and note detection functionalities.
- The user has added new functions `magnitudeToDb`, `mapToDisplay`, `printBarGraph`, `drawFFTMagnitudes`, `visualizeSpectrum`, and `visualizeNotes` to the `SpectrumVisualizer.cpp` file. The changes are related to visualizing spectrum data and note detection results in a serial monitor format for debugging.
- The main goal is to enhance the piano note detection system by adding support for a NoteDetector and updating SpectrumVisualizer when notes are detected, as well as handling serial commands for calibration, threshold adjustments, and toggling spectrum display.
- 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.
- 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.