ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MicrophoneFourier_DMA.h
Go to the documentation of this file.
1/**
2 * @file MicrophoneFourier_DMA.h
3 * @brief Declares the MicrophoneFourier class for performing FFT on microphone input.
4 *
5 * This file defines the MicrophoneFourier class, which extends MicrophoneFourierBase to provide
6 * functionality for real-time Fast Fourier Transform (FFT) analysis of microphone signals using DMA.
7 *
8 * @date 22/12/2024
9 * @author Bitstream
10 */
11
12#pragma once
13
14#include <Arduino.h> // Include for Arduino compatibility.
15#include <ADC.h> // Include for analog-to-digital conversion support.
16#include <DMAChannel.h> // Include for DMA channel handling.
17#include <AnalogBufferDMA.h> // Include for DMA-based analog buffer management.
18#include "Utils/MicrophoneFourierBase.h" // Base class for microphone FFT operations.
19
20/**
21 * @class MicrophoneFourier
22 * @brief Provides real-time FFT analysis of microphone signals.
23 *
24 * The MicrophoneFourier class leverages DMA and FFT techniques to analyze microphone input signals
25 * in real time. It supports configurable sampling rates, gain control, and signal processing.
26 */
28private:
29 static const int16_t Hanning256[]; ///< Hanning window coefficients for FFT.
30
31 static bool microphoneGain_50db; ///< Flag to enable or disable 50dB microphone gain.
32 static uint8_t gain_pin; ///< Pin number for gain control (if applicable).
33
34 /**
35 * @brief Applies a Hanning window to raw FFT data.
36 *
37 * @param buffer Pointer to the raw FFT data buffer.
38 * @param window Pointer to the windowing coefficients.
39 */
40 static void window_raw_fft_data(void* buffer, const void* window);
41
42 /**
43 * @brief Callback function for DMA sampling.
44 *
45 * @param dma_buffer_instance Instance of the DMA buffer used for sampling.
46 * @param adc_num ADC number associated with the sample.
47 */
48 static void SamplerCallback(AnalogBufferDMA* dma_buffer_instance, int8_t adc_num);
49
50public:
51 /**
52 * @brief Initializes the microphone and FFT system with basic parameters.
53 *
54 * @param pin Pin number connected to the microphone output.
55 * @param sampleRate Sampling rate in Hz.
56 * @param minDB Minimum dB level for normalization.
57 * @param maxDB Maximum dB level for normalization.
58 */
59 static void Initialize(uint8_t pin, uint32_t sampleRate, float minDB, float maxDB);
60
61 /**
62 * @brief Initializes the microphone and FFT system with advanced parameters.
63 *
64 * @param pin Pin number connected to the microphone output.
65 * @param gain_pin Pin number for gain control.
66 * @param sampleRate Sampling rate in Hz.
67 * @param minDB Minimum dB level for normalization.
68 * @param maxDB Maximum dB level for normalization.
69 * @param microphoneGain_50db Flag to enable or disable 50dB microphone gain.
70 */
71 static void Initialize(uint8_t pin, uint8_t gain_pin, uint32_t sampleRate, float minDB, float maxDB, bool microphoneGain_50db);
72
73 /**
74 * @brief Sets the sampling rate for the microphone.
75 *
76 * @param sampleRate Sampling rate in Hz.
77 */
78 static void setSamplingRate(uint32_t sampleRate);
79
80 /**
81 * @brief Sets the microphone gain.
82 *
83 * @param is50db True to enable 50dB gain, false to disable.
84 */
85 static void setMicGain(bool is50db);
86
87 /**
88 * @brief Updates the DMA system to process new samples.
89 */
90 static void UpdateDMA();
91};
Provides a base class for FFT-based microphone signal processing.
Base class for FFT-based microphone signal processing.
static float maxDB
Maximum decibel value for normalization.
static uint8_t pin
Pin number for microphone input.
static uint16_t sampleRate
Sampling rate in Hz.
static float minDB
Minimum decibel value for normalization.
Provides real-time FFT analysis of microphone signals.
static uint8_t gain_pin
Pin number for gain control (if applicable).
static void setMicGain(bool is50db)
Sets the microphone gain.
static void setSamplingRate(uint32_t sampleRate)
Sets the sampling rate for the microphone.
static void UpdateDMA()
Updates the DMA system to process new samples.
static const int16_t Hanning256[]
Hanning window coefficients for FFT.
static void Initialize(uint8_t pin, uint32_t sampleRate, float minDB, float maxDB)
Initializes the microphone and FFT system with basic parameters.
static void SamplerCallback()
Callback function for the sampling timer.
static void window_raw_fft_data(void *buffer, const void *window)
Applies a Hanning window to raw FFT data.
static bool microphoneGain_50db
Flag to enable or disable 50dB microphone gain.