ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MicrophoneSimple_SPW2430.h
Go to the documentation of this file.
1/**
2 * @file MicrophoneSimple_SPW2430.h
3 * @brief A simple microphone processing class for analog input.
4 *
5 * This file defines the MicrophoneSimple class, which provides basic functionality
6 * for reading and processing microphone signals, including filtering for noise reduction.
7 *
8 * For the SPW2430 microphone
9 *
10 * @date 22/12/2024
11 * @author Coela Can't
12 */
13
14#pragma once
15
16#include <Arduino.h> // Include for Arduino compatibility.
17#include "../../../Utils/Math/Mathematics.h" // Include for mathematical utilities.
18#include "../../../Utils/Filter/RunningAverageFilter.h" // Include for running average filtering.
19#include "../../../Utils/Filter/MinFilter.h" // Include for minimum filtering.
20
21/**
22 * @class MicrophoneSimple
23 * @brief A simple class for processing microphone signals.
24 *
25 * The MicrophoneSimple class handles analog input from a microphone,
26 * applies smoothing filters, and provides processed signal values.
27 */
28class MicrophoneSimple {
29private:
30 uint8_t pin; ///< Pin number for the microphone input.
31 RunningAverageFilter<40> mv = RunningAverageFilter<40>(0.075f); ///< Moving average filter for smoothing input.
32 MinFilter<100> minF = MinFilter<100>(); ///< Minimum filter for peak detection.
33 RunningAverageFilter<10> output = RunningAverageFilter<10>(0.1f); ///< Filter for smoothing the output.
34 float previousReading = 0.0f; ///< Previous reading from the microphone.
35 long previousMillis = 0; ///< Time of the previous reading.
36 long startMillis = 0; ///< Start time for processing.
37
38public:
39 /**
40 * @brief Constructs a MicrophoneSimple instance with a specified pin.
41 *
42 * @param pin The pin number for the microphone input.
43 */
44 MicrophoneSimple(uint8_t pin);
45
46 /**
47 * @brief Updates the microphone reading and processes the signal.
48 *
49 * @return The processed microphone value.
50 */
51 float Update();
52};
A simple class for processing microphone signals.
float previousReading
Previous reading from the microphone.
long previousMillis
Time of the previous reading.
long startMillis
Start time for processing.
RunningAverageFilter< 5 > mv
Moving average filter for smoothing input.
MinFilter< 100 > minF
Minimum filter for peak detection.
float Update()
Updates the microphone reading and processes the signal.
uint8_t pin
Pin number for the microphone input.
RunningAverageFilter< 5 > output
Filter for smoothing the output.
MicrophoneSimple()
Constructs a default MicrophoneSimple instance.
Implements a minimum filter over a sliding window.
Definition MinFilter.h:28
Smooths data values using a weighted running average.