ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
MicrophoneSimple_SPW2430.cpp
Go to the documentation of this file.
2
4 this->pin = pin;
5
6 analogReadRes(12);
7 analogReadAveraging(32);
8
9 pinMode(pin, INPUT);
10
11 startMillis = millis();
12}
13
15 float read = analogRead(pin);
16 float change = read - previousReading;
17 float dT = ((float)millis() - (float)previousMillis) / 1000.0f;
18 float changeRate = change / dT;
19 float amplitude = mv.Filter(fabs(changeRate));
20 float minimum = minF.Filter(amplitude);
21 float normalized = Mathematics::Constrain(amplitude - minimum - 250, 0.0f, 4000.0f);
22 float truncate = output.Filter(normalized / 100.0f);
23
24 previousReading = read;
25 previousMillis = millis();
26
27 return Mathematics::Constrain(truncate, 0.0f, 1.0f);
28}
A simple microphone processing class for analog input.
static T Constrain(T value, T minimum, T maximum)
Constrains a value between minimum and maximum.
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.
float Filter(float value)
Filters the given value, updating the minimum value within the memory window.
float Filter(float value)
Filters the input value using the running average.