ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MicrophoneSimple_MAX9814.h
Go to the documentation of this file.
1/**
2 * @file MicrophoneSimple_MAX9814.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 gain adjustment,
7 * clipping, and filtering.
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/Math/Mathematics.h" // Include for mathematical utilities.
19#include "../../../Utils/Filter/RunningAverageFilter.h" // Include for running average filtering.
20#include "../../../Utils/Filter/MinFilter.h" // Include for minimum filtering.
21
22/**
23 * @class MicrophoneSimple
24 * @brief A simple class for processing microphone signals.
25 *
26 * The MicrophoneSimple class handles analog input from a microphone,
27 * applies gain and clipping, and uses filters to smooth the output.
28 */
30private:
31 uint8_t pin; ///< Pin number for the microphone input.
32 RunningAverageFilter<5> mv = RunningAverageFilter<5>(0.2f); ///< Moving average filter for smoothing input.
33 MinFilter<100> minF = MinFilter<100>(); ///< Minimum filter for peak detection.
34 RunningAverageFilter<5> output = RunningAverageFilter<5>(0.2f); ///< Filter for smoothing the output.
35 float previousReading = 0.0f; ///< Previous reading from the microphone.
36 float gain = 1.0f; ///< Gain applied to the microphone signal.
37 float clipping = 1.0f; ///< Clipping level for the microphone signal.
38 long previousMillis = 0; ///< Time of the previous reading.
39 long startMillis = 0; ///< Start time for processing.
40 float currentValue = 0.0f; ///< Current processed microphone value.
41
42public:
43 /**
44 * @brief Constructs a default MicrophoneSimple instance.
45 */
47
48 /**
49 * @brief Constructs a MicrophoneSimple instance with specified parameters.
50 *
51 * @param pin The pin number for the microphone input.
52 * @param gain The gain to apply to the microphone signal (default is 1.0).
53 * @param clipping The clipping level for the microphone signal (default is 1.0).
54 */
55 MicrophoneSimple(uint8_t pin, float gain = 1.0f, float clipping = 1.0f);
56
57 /**
58 * @brief Retrieves the current processed microphone value.
59 *
60 * @return The current value of the microphone signal.
61 */
62 float GetCurrentValue();
63
64 /**
65 * @brief Updates the microphone reading and processes the signal.
66 *
67 * @return The processed microphone value.
68 */
69 float Update();
70
71 /**
72 * @brief Updates the microphone reading with an externally provided value.
73 *
74 * @param read The external reading to process.
75 * @return The processed microphone value.
76 */
77 float Update(float read);
78};
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.
float clipping
Clipping level for the microphone signal.
RunningAverageFilter< 5 > mv
Moving average filter for smoothing input.
MinFilter< 100 > minF
Minimum filter for peak detection.
float GetCurrentValue()
Retrieves the current processed microphone value.
float currentValue
Current processed microphone value.
float Update()
Updates the microphone reading and processes the signal.
uint8_t pin
Pin number for the microphone input.
float gain
Gain applied to the microphone signal.
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.