Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
sound.h
Go to the documentation of this file.
1
5#ifndef PHYSICAL_SOUND_H
6#define PHYSICAL_SOUND_H
7
9
10#include <cstdint>
12
13namespace lampda {
14namespace physical {
16namespace microphone {
17
19constexpr float silenceLevelDb = 30.0;
21constexpr float highLevelDb = 80.0;
22
24constexpr float desiredoutput = 0.5f;
26constexpr int16_t gainedSignalTarget = INT16_MAX * desiredoutput;
27
33{
34 /*
35 * raw data
36 */
37
39 bool isDataValid = false;
40
43
45 std::array<int16_t, SAMPLE_SIZE> data;
47 std::array<int16_t, SAMPLE_SIZE> rectifiedData;
48
50 float sound_level_Db = 0.0f;
52 float maxAmplitude = 0.0f;
55
56 /*
57 * FFT
58 */
59
61 bool isFFTValid = false;
62
64 static constexpr uint8_t numberOfFFtChanels = 24;
65
67 static constexpr float get_fft_resolution_Hz() { return utils::fft::SAMPLE_RATE / static_cast<float>(SAMPLE_SIZE); }
68
69 // FFT results
70
72 std::array<float, SAMPLE_SIZE / 2> fft_raw;
74 std::array<float, numberOfFFtChanels> fft_log;
76 std::array<float, numberOfFFtChanels> fft_log_end_frequencies;
77};
78
83bool enable();
84
88void disable();
89
94
100
101} // namespace microphone
102} // namespace physical
103} // namespace lampda
104
105#endif
Wrapper of the ArduinoFFT library.
SoundStruct & get_sound_characteristics()
Compute and process sound data.
Definition: sound.cpp:168
void disable()
Disable the microphone data analysis, if its running.
Definition: sound.cpp:64
constexpr float highLevelDb
Microphone is not good enough at after this.
Definition: sound.h:21
bool enable()
Start the microphone data analysis, if not already started.
Definition: sound.cpp:53
constexpr int16_t gainedSignalTarget
Desired output of the auto gain (0-INT16_MAX)
Definition: sound.h:26
constexpr float silenceLevelDb
Decibel level for a silent room.
Definition: sound.h:19
constexpr float desiredoutput
Desired output of the auto gain (0-1)
Definition: sound.h:24
void disable_after_non_use()
disable microphone if last used a target time ago
Definition: sound.cpp:75
Program scope.
Definition: control_fixed_modes.hpp:12
Interface for the platform specific microphone.
Handle the analysis of a sound sample. This structure handled the FastFourrier analysis of a sound sa...
Definition: sound.h:33
std::array< float, SAMPLE_SIZE/2 > fft_raw
Results of the FFT process, in raw Hertz bins.
Definition: sound.h:72
std::array< int16_t, SAMPLE_SIZE > data
raw audio data
Definition: sound.h:45
bool isFFTValid
validity flag for the FFT results
Definition: sound.h:61
std::array< float, numberOfFFtChanels > fft_log_end_frequencies
Results of the FFT process, in maximum frequency for every bin.
Definition: sound.h:76
static constexpr float get_fft_resolution_Hz()
Return the FFT resolution of a single FFT bin in Hertz.
Definition: sound.h:67
float maxAmplitudeFrequency
Maximum detected amplitude frequency of this sample, in Hertz.
Definition: sound.h:54
static constexpr auto SAMPLE_SIZE
Size fo the audio sample.
Definition: sound.h:42
float maxAmplitude
Maximum detected amplitude of this sample.
Definition: sound.h:52
bool isDataValid
flag that indicate sound data validity
Definition: sound.h:39
std::array< int16_t, SAMPLE_SIZE > rectifiedData
audio data with auto gain enabled
Definition: sound.h:47
static constexpr uint8_t numberOfFFtChanels
Define the number of FFt bins to use. You should set this number close to the lamp max X coordinates.
Definition: sound.h:64
std::array< float, numberOfFFtChanels > fft_log
Results of the FFT process, in scaled logarithmic bins. This is closer to the sound sensitivity of th...
Definition: sound.h:74
float sound_level_Db
Sound level of this sample, in Decibels A.
Definition: sound.h:50
static constexpr uint16_t SAMPLE_SIZE
Size of the sound sample.
Definition: pdm_handle.h:26