MCPcopy Create free account
hub / github.com/FastLED/FastLED / loop

Function loop

examples/Audio/simple/simple.h:188–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188void loop() {
189 if (triggered) {
190 FL_WARN("Triggered");
191 }
192
193 // x = pointX.as_int();
194 y = HEIGHT / 2;
195
196 bool do_frame = doFrame();
197
198 while (fl::audio::Sample sample = audio.next()) {
199 if (!do_frame) {
200 continue;
201 }
202
203 // Process pitch detection if enabled
204 if (enablePitchDetect && pitchEngine) {
205 // Convert int16_t samples to float for pitch detection
206 static float floatBuffer[512];
207 size_t numSamples = fl::min(sample.pcm().size(), (size_t)512);
208 for (size_t i = 0; i < numSamples; i++) {
209 floatBuffer[i] = sample.pcm()[i] / 32768.0f;
210 }
211 pitchEngine->processFrame(floatBuffer, numSamples);
212 }
213
214 float fade = audioFadeTracker(sample.pcm().data(), sample.pcm().size());
215 shiftUp();
216 // FL_WARN("Audio sample size: " << sample.pcm().size());
217 soundLevelMeter.processBlock(sample.pcm());
218 // FL_WARN("")
219 auto dbfs = soundLevelMeter.getDBFS();
220 FASTLED_UNUSED(dbfs);
221 // FL_WARN("getDBFS: " << dbfs);
222 int32_t max = 0;
223 for (size_t i = 0; i < sample.pcm().size(); ++i) {
224 int32_t x = ABS(sample.pcm()[i]);
225 if (x > max) {
226 max = x;
227 }
228 }
229 float anim =
230 fl::map_range<float, float>(max, 0.0f, 32768.0f, 0.0f, 1.0f);
231 anim = fl::clamp(anim, 0.0f, 1.0f);
232
233 x = fl::map_range<float, float>(anim, 0.0f, 1.0f, 0.0f, WIDTH - 1);
234 // FL_WARN("x: " << x);
235
236 // fft.run(sample.pcm(), &fftOut);
237 sample.fft(&fftOut);
238
239 if (enableFFT) {
240 auto max_x = fftOut.raw().size() - 1;
241 FASTLED_UNUSED(max_x);
242 for (size_t i = 0; i < fftOut.raw().size(); ++i) {
243 auto x = i;
244 auto v = fftOut.db()[i];
245 // Map audio intensity to a position in the heat palette (0-255)

Callers

nothing calls this directly

Calls 15

doFrameFunction · 0.85
shiftUpFunction · 0.85
clampFunction · 0.85
ColorFromPaletteFunction · 0.85
downscaleFunction · 0.85
processFrameMethod · 0.80
getDBFSMethod · 0.80
fftMethod · 0.80
dbMethod · 0.80
CRGBClass · 0.50
nextMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected