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

◆ smoothResults()

void fl::AudioReactive::smoothResults ( )
private

Definition at line 276 of file audio_reactive.cpp.

276 {
277 // Attack/decay smoothing - different rates for rising vs falling values
278 // Convert attack/decay times to smoothing factors
279 // Shorter times = less smoothing (faster response)
280 float attackFactor = 1.0f - (mConfig.attack / 255.0f * 0.9f); // Range: 0.1 to 1.0
281 float decayFactor = 1.0f - (mConfig.decay / 255.0f * 0.95f); // Range: 0.05 to 1.0
282
283 // Apply attack/decay smoothing to volume
284 if (mCurrentData.volume > mSmoothedData.volume) {
285 // Rising - use attack time (faster response)
286 mSmoothedData.volume = mSmoothedData.volume * (1.0f - attackFactor) +
287 mCurrentData.volume * attackFactor;
288 } else {
289 // Falling - use decay time (slower response)
290 mSmoothedData.volume = mSmoothedData.volume * (1.0f - decayFactor) +
291 mCurrentData.volume * decayFactor;
292 }
293
294 // Apply attack/decay smoothing to volumeRaw
295 if (mCurrentData.volumeRaw > mSmoothedData.volumeRaw) {
296 mSmoothedData.volumeRaw = mSmoothedData.volumeRaw * (1.0f - attackFactor) +
297 mCurrentData.volumeRaw * attackFactor;
298 } else {
299 mSmoothedData.volumeRaw = mSmoothedData.volumeRaw * (1.0f - decayFactor) +
300 mCurrentData.volumeRaw * decayFactor;
301 }
302
303 // Apply attack/decay smoothing to peak
304 if (mCurrentData.peak > mSmoothedData.peak) {
305 mSmoothedData.peak = mSmoothedData.peak * (1.0f - attackFactor) +
306 mCurrentData.peak * attackFactor;
307 } else {
308 mSmoothedData.peak = mSmoothedData.peak * (1.0f - decayFactor) +
309 mCurrentData.peak * decayFactor;
310 }
311
312 // Apply attack/decay smoothing to frequency bins
313 for (int i = 0; i < 16; ++i) {
314 if (mCurrentData.frequencyBins[i] > mSmoothedData.frequencyBins[i]) {
315 // Rising - use attack time
316 mSmoothedData.frequencyBins[i] = mSmoothedData.frequencyBins[i] * (1.0f - attackFactor) +
317 mCurrentData.frequencyBins[i] * attackFactor;
318 } else {
319 // Falling - use decay time
320 mSmoothedData.frequencyBins[i] = mSmoothedData.frequencyBins[i] * (1.0f - decayFactor) +
321 mCurrentData.frequencyBins[i] * decayFactor;
322 }
323 }
324
325 // Copy non-smoothed values
326 mSmoothedData.beatDetected = mCurrentData.beatDetected;
327 mSmoothedData.dominantFrequency = mCurrentData.dominantFrequency;
328 mSmoothedData.magnitude = mCurrentData.magnitude;
329 mSmoothedData.timestamp = mCurrentData.timestamp;
330}
AudioData mSmoothedData
AudioConfig mConfig

References mConfig, mCurrentData, and mSmoothedData.

Referenced by processSample(), and update().

+ Here is the caller graph for this function: