FastLED 3.9.15
Loading...
Searching...
No Matches

◆ loop()

void loop ( )

Definition at line 70 of file AudioInput.ino.

70 {
71 EVERY_N_MILLIS(1000) {
72 Serial.println("Loop active...");
73 }
74
75 // Check if audio source is valid
76 if (!audioSource) {
77 Serial.println("Audio source is null!");
78 delay(1000);
79 return;
80 }
81
82 // Check for audio errors
83 fl::string errorMsg;
84 if (audioSource->error(&errorMsg)) {
85 Serial.print("Audio error: ");
86 Serial.println(errorMsg.c_str());
87 delay(100);
88 return;
89 }
90
91 // Read audio data
93
94 if (sample.isValid()) {
95 EVERY_N_MILLIS(100) {
96 const auto& audioBuffer = sample.pcm();
97 const i16* max_sample = fl::max_element(audioBuffer.begin(), audioBuffer.end());
98 const i16* min_sample = fl::min_element(audioBuffer.begin(), audioBuffer.end());
99
100 fl::sstream ss;
101 ss << "\n--- Audio Sample ---\n";
102 ss << "Samples: " << audioBuffer.size() << "\n";
103 ss << "Timestamp: " << sample.timestamp() << " ms\n";
104 ss << "Max: " << *max_sample << "\n";
105 ss << "Min: " << *min_sample << "\n";
106 ss << "RMS: " << sample.rms() << "\n";
107 ss << "Zero Crossing Frequency: " << sample.zcf() << " Hz\n";
108 FL_WARN(ss.str());
109 }
110 }
111}
fl::shared_ptr< fl::audio::IInput > audioSource
const char * c_str() const FL_NOEXCEPT
string str() const FL_NOEXCEPT
Definition strstream.h:43
#define EVERY_N_MILLIS(N)
Checks whether to execute a block of code every N milliseconds.
Definition lib8tion.h:1001
#define FL_WARN(X)
Definition log.h:276
void delay(u32 ms, bool run_async=true) FL_NOEXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
Definition delay.h:98
Iterator min_element(Iterator first, Iterator last) FL_NOEXCEPT
Definition algorithm.h:56
CRGB sample(const CRGB *grid, const XYMap &xyMap, float x, float y, SampleMode mode)
Sample a pixel from a 2D CRGB grid at floating-point coordinates.
Definition sample.cpp.hpp:9
Iterator max_element(Iterator first, Iterator last) FL_NOEXCEPT
Definition algorithm.h:18
#define Serial
Definition serial.h:304

References audioSource, fl::basic_string::c_str(), EVERY_N_MILLIS, FL_WARN, fl::max_element(), fl::min_element(), Serial, and fl::sstream::str().

+ Here is the call graph for this function: