ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MicrophoneFourier_MAX9814.h
Go to the documentation of this file.
1/**
2 * @file MicrophoneFourier_MAX9814.h
3 * @brief Extends the MicrophoneFourierBase class for real-time FFT microphone analysis.
4 *
5 * This file defines the MicrophoneFourier class, which builds upon MicrophoneFourierBase to include
6 * real-time sampling and processing of microphone signals using FFT. It incorporates utilities for
7 * updating and resetting the microphone processing system.
8 *
9 * For the MAX9814 microphone.
10 *
11 * @date 22/12/2024
12 * @author Coela Can't
13 */
14
15#pragma once
16
17#include <Arduino.h> // Include for Arduino compatibility.
18#include "../../../Utils/Filter/DerivativeFilter.h" // Include for derivative filtering.
19#include "../../../Utils/Filter/FFTFilter.h" // Include for FFT filtering.
20#include "../../../Utils/Time/TimeStep.h" // Include for time management.
21#include "Utils/MicrophoneFourierBase.h" // Include the base class for microphone FFT processing.
22
23/**
24 * @class MicrophoneFourier
25 * @brief Provides real-time microphone analysis using FFT.
26 *
27 * The MicrophoneFourier class extends MicrophoneFourierBase to add capabilities for
28 * real-time sampling, signal processing, and frequency bin analysis. It enables
29 * dynamic updating and resetting of the microphone system.
30 */
32private:
33 static IntervalTimer sampleTimer; ///< Timer for managing sampling intervals.
34 static TimeStep timeStep; ///< Time step utility for controlling updates.
35
36 static uint16_t samples; ///< Number of samples collected in the current cycle.
37 static uint16_t samplesStorage; ///< Total number of samples stored.
38 static float refreshRate; ///< Refresh rate for processing in Hz.
39 static bool samplesReady; ///< Flag indicating if samples are ready for processing.
40
41 static uint16_t frequencyBins[OutputBins]; ///< Array for storing frequency bin data.
42
43 /**
44 * @brief Callback function for the sampling timer.
45 *
46 * This function is triggered at each sampling interval to collect microphone data.
47 */
48 static void SamplerCallback();
49
50 /**
51 * @brief Starts the sampling process using the IntervalTimer.
52 */
53 static void StartSampler();
54
55public:
56 /**
57 * @brief Initializes the microphone and FFT system.
58 *
59 * @param pin The pin connected to the microphone.
60 * @param sampleRate The desired sampling rate in Hz.
61 * @param minDB Minimum dB level for normalization.
62 * @param maxDB Maximum dB level for normalization.
63 * @param refreshRate The desired refresh rate for processing (default is 60 Hz).
64 */
65 static void Initialize(uint8_t pin, uint16_t sampleRate, float minDB, float maxDB, float refreshRate = 60.0f);
66
67 /**
68 * @brief Resets the microphone system and clears stored data.
69 */
70 static void Reset();
71
72 /**
73 * @brief Updates the microphone system, processing new samples and performing FFT.
74 */
75 static void Update();
76};
Provides a base class for FFT-based microphone signal processing.
Base class for FFT-based microphone signal processing.
static const uint16_t OutputBins
Number of output bins from FFT 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 void Reset()
Resets the microphone system and clears stored data.
static void StartSampler()
Starts the sampling process using the IntervalTimer.
static uint16_t samples
Number of samples collected in the current cycle.
static TimeStep timeStep
Time step utility for controlling updates.
static uint16_t frequencyBins[OutputBins]
Array for storing frequency bin data.
static float refreshRate
Refresh rate for processing in Hz.
static IntervalTimer sampleTimer
Timer for managing sampling intervals.
static void Initialize(uint8_t pin, uint32_t sampleRate, float minDB, float maxDB)
Initializes the microphone and FFT system with basic parameters.
static uint16_t samplesStorage
Total number of samples stored.
static bool samplesReady
Flag indicating if samples are ready for processing.
static void SamplerCallback()
Callback function for the sampling timer.
static void Update()
Updates the microphone system, processing new samples and performing FFT.
Provides a mechanism to trigger actions at a specified frequency.
Definition TimeStep.h:18