Lamp-Da 0.1
A compact lantern project
Loading...
Searching...
No Matches
sound.h
Go to the documentation of this file.
1
5#ifndef COMPONENT_SOUND_H
6#define COMPONENT_SOUND_H
7
8#include <cstdint>
9
11
13
14namespace lampda {
15namespace component {
17namespace microphone {
18
20constexpr float silenceLevelDb = 30.0;
22constexpr float highLevelDb = 80.0;
23
25constexpr float desiredoutput = 0.5f;
27constexpr int16_t gainedSignalTarget = INT16_MAX * desiredoutput;
28
34{
35 /*
36 * raw data
37 */
38
40 bool isDataValid = false;
41
44
46 std::array<int16_t, SAMPLE_SIZE> data;
48 std::array<int16_t, SAMPLE_SIZE> rectifiedData;
49
51 float sound_level_Db = 0.0f;
53 float maxAmplitude = 0.0f;
56
57 /*
58 * FFT
59 */
60
62 bool isFFTValid = false;
63
65 static constexpr uint8_t numberOfFFtChanels = 24;
66
68 static constexpr float get_fft_resolution_Hz() { return common::fft::SAMPLE_RATE / static_cast<float>(SAMPLE_SIZE); }
69
70 // FFT results
71
73 std::array<float, SAMPLE_SIZE / 2> fft_raw;
75 std::array<float, numberOfFFtChanels> fft_log;
77 std::array<float, numberOfFFtChanels> fft_log_end_frequencies;
78};
79
84bool enable();
85
89void disable();
90
95
101
102} // namespace microphone
103} // namespace component
104} // namespace lampda
105
106#endif
Wrapper of the ArduinoFFT library.
constexpr float desiredoutput
Desired output of the auto gain (0-1)
Definition: sound.h:25
constexpr int16_t gainedSignalTarget
Desired output of the auto gain (0-INT16_MAX)
Definition: sound.h:27
bool enable()
Start the microphone data analysis, if not already started.
Definition: sound.cpp:54
void disable()
Disable the microphone data analysis, if its running.
Definition: sound.cpp:65
constexpr float silenceLevelDb
Decibel level for a silent room.
Definition: sound.h:20
void disable_after_non_use()
disable microphone if last used a target time ago
Definition: sound.cpp:76
SoundStruct & get_sound_characteristics()
Compute and process sound data.
Definition: sound.cpp:169
constexpr float highLevelDb
Microphone is not good enough at after this.
Definition: sound.h:22
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:34
bool isFFTValid
validity flag for the FFT results
Definition: sound.h:62
std::array< int16_t, SAMPLE_SIZE > rectifiedData
audio data with auto gain enabled
Definition: sound.h:48
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:75
float sound_level_Db
Sound level of this sample, in Decibels A.
Definition: sound.h:51
std::array< float, numberOfFFtChanels > fft_log_end_frequencies
Results of the FFT process, in maximum frequency for every bin.
Definition: sound.h:77
std::array< int16_t, SAMPLE_SIZE > data
raw audio data
Definition: sound.h:46
float maxAmplitude
Maximum detected amplitude of this sample.
Definition: sound.h:53
std::array< float, SAMPLE_SIZE/2 > fft_raw
Results of the FFT process, in raw Hertz bins.
Definition: sound.h:73
bool isDataValid
flag that indicate sound data validity
Definition: sound.h:40
static constexpr float get_fft_resolution_Hz()
Return the FFT resolution of a single FFT bin in Hertz.
Definition: sound.h:68
float maxAmplitudeFrequency
Maximum detected amplitude frequency of this sample, in Hertz.
Definition: sound.h:55
static constexpr auto SAMPLE_SIZE
Size fo the audio sample.
Definition: sound.h:43
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:65
static constexpr uint16_t SAMPLE_SIZE
Size of the sound sample.
Definition: pdm_handle.h:26