NanoLux (Device) 3.0
Codebase for the open-source AudioLux device.
Loading...
Searching...
No Matches
audio_analysis.h
Go to the documentation of this file.
1
7
8#ifndef AUDIO_ANALYSIS_H
9#define AUDIO_ANALYSIS_H
10
11#define INIT_PRISM(M) \
12 M.setWindowSize(SAMPLES); \
13 M.setSampleRate(SAMPLING_FREQUENCY); \
14 M.setSpectrogram(&fftHistory);
15
16#include <math.h>
17#include <Arduino.h>
18#include <Fast4ier.h>
19#include <complex>
20#include "AudioPrism.h"
21#include "nanolux_types.h"
22#include "nanolux_util.h"
23
24
39public:
45
46 /* ============== Public Interface ============== */
47
53 void processAudioFrame(int);
54
59 float* getVReal();
60
66 float* getVReal(float);
67
72 float getPeak();
73
78 float getVolume();
79
84 int getMaxDelta();
85
90 float* getDeltas();
91
96 int* getSalientFreqs();
97
102 float getCentroid();
103
109
114 float getNoisiness();
115
121 float* getFiveBandSplit(int len);
122
126 void resetCache();
127
128private:
129 /* ============== Result Cache ============== */
130 float volume = 0; // Volume level
131 float peak = 0; // Peak frequency in Hz
132 int maxDelt = 0; // Maximum delta between FFT bins
133 int salFreqs[3] = {0,0,0}; // Salient frequencies
134 float centroid = 0; // Centroid frequency
135 bool percussionPresent = false; // Percussion presence flag
136 float noisiness = 0; // Noisiness level
137 float fbs[5] = {0,0,0,0,0}; // Five-band split values
138
139 /* ============== Internal Buffers ============== */
140 complex fftBuffer[SAMPLES]; // Buffer for FFT samples
141 float vReal[SAMPLES]; // Raw real FFT values
142 float smoothVReal[SAMPLES]; // Smoothed FFT values
143 float delt[SAMPLES]; // Delta FFT values
144
145 /* ============== AudioPrism Modules ============== */
146 Spectrogram fftHistory; // Spectrogram history
147 MeanAmplitude volumeModule; // Volume analysis module
148 MajorPeaks peaksModule; // Peaks detection module
149 DeltaAmplitudes deltaModule; // Delta amplitudes detection module
150 SalientFreqs salientModule; // Salient frequencies detection module
151 Centroid centroidModule; // Centroid frequency detection module
152 PercussionDetection percussionModule; // Percussion detection module
153 Noisiness noisinessModule; // Noisiness detection module
154
155 /* ============== Flags ============== */
156 bool vRealSmoothed = false; // Flag for vReal smoothing
157 bool peakUpdated = false; // Flag for peak value update
158 bool volumeUpdated = false; // Flag for volume update
159 bool maxDeltaUpdated = false; // Flag for max delta update
160 bool deltasUpdated = false; // Flag for delta values update
161 bool salientsUpdated = false; // Flag for salient frequencies update
162 bool centroidUpdated = false; // Flag for centroid frequency update
163 bool percussionUpdated = false; // Flag for percussion detection update
164 bool noisinessUpdated = false; // Flag for noisiness level update
165 bool fbsUpdated = false; // Flag for five-band split update
166
167 /* ============== Helper Functions ============== */
168
172 void sample_audio();
173
177 void compute_FFT();
178
183 void noise_gate(int);
184
189 void vReal_smoothing(float);
190
194 void update_peak();
195
199 void update_volume();
200
204 void update_max_delta();
205
209 void update_deltas();
210
214 void update_salient_freqs();
215
219 void update_centroid();
220
224 void update_percussion_detection();
225
229 void update_noisiness();
230
235 void update_five_band_split(int);
236};
237
242
243#endif
AudioAnalysis audioAnalysis
External reference to the AudioAnalysis instance.
Definition globals.h:45
Handles audio signal processing and feature extraction.
Definition audio_analysis.h:38
void processAudioFrame(int)
Processes an audio frame, including sampling, FFT computation, and noise gating.
Definition audio_analysis.cpp:48
float getCentroid()
Gets the centroid frequency of the audio spectrum.
Definition audio_analysis.cpp:91
float * getFiveBandSplit(int len)
Calculates and returns a five-band split of the audio spectrum.
Definition audio_analysis.cpp:106
int getMaxDelta()
Gets the maximum delta value between FFT bins.
Definition audio_analysis.cpp:76
float * getVReal()
Gets the raw real part of the FFT result.
Definition audio_analysis.cpp:57
float getPeak()
Gets the peak frequency detected in the audio.
Definition audio_analysis.cpp:66
float * getDeltas()
Gets the delta values between FFT bins.
Definition audio_analysis.cpp:81
void resetCache()
Clears all flags that indicate updated data for getters.
Definition audio_analysis.cpp:35
int * getSalientFreqs()
Gets the salient frequencies detected in the audio.
Definition audio_analysis.cpp:86
AudioAnalysis()
Constructor for the AudioAnalysis class. Initializes AudioPrism modules and other variables.
Definition audio_analysis.cpp:13
float getVolume()
Gets the volume level of the audio.
Definition audio_analysis.cpp:71
float getNoisiness()
Gets the noisiness level of the audio.
Definition audio_analysis.cpp:101
bool getPercussionPresence()
Checks for the presence of percussion in the audio.
Definition audio_analysis.cpp:96