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

Function runContinuousSweep

tests/misc/fft_sweep.hpp:56–107  ·  view source on GitHub ↗

Run a full logarithmic frequency sweep and collect per-frame diagnostics.

Source from the content-addressed store, hash-verified

54
55// Run a full logarithmic frequency sweep and collect per-frame diagnostics.
56fl::vector<SweepFrame> runContinuousSweep(int numFrames, int bands, float fmin,
57 float fmax, int sampleRate,
58 int samplesPerFrame,
59 fl::audio::fft::Mode mode) {
60 fl::audio::fft::Args args(samplesPerFrame, bands, fmin, fmax, sampleRate, mode);
61 fl::audio::fft::Impl fft(args);
62
63 fl::vector<SweepFrame> frames;
64 frames.reserve(numFrames);
65
66 float logRatio = fl::logf(fmax / fmin);
67
68 for (int f = 0; f < numFrames; ++f) {
69 float t = static_cast<float>(f) / static_cast<float>(numFrames - 1);
70 float freq = fmin * fl::expf(logRatio * t);
71
72 auto samples = makeSine(freq, samplesPerFrame, static_cast<float>(sampleRate));
73 fl::audio::fft::Bins bins(bands);
74 fft.run(samples, &bins);
75
76 SweepFrame frame;
77 frame.frequency = freq;
78 frame.peakBin = 0;
79 frame.peakEnergy = 0.0f;
80 frame.totalEnergy = 0.0f;
81 frame.activeBins = 0;
82
83 for (int i = 0; i < bands; ++i) {
84 float e = bins.raw()[i];
85 frame.totalEnergy += e;
86 if (e > frame.peakEnergy) {
87 frame.peakEnergy = e;
88 frame.peakBin = i;
89 }
90 }
91
92 float threshold = frame.peakEnergy * 0.1f;
93 for (int i = 0; i < bands; ++i) {
94 if (bins.raw()[i] > threshold) {
95 frame.activeBins++;
96 }
97 }
98
99 frame.concentration = (frame.totalEnergy > 0.0f)
100 ? frame.peakEnergy / frame.totalEnergy
101 : 0.0f;
102 frame.expectedBin = bins.freqToBin(freq);
103 frames.push_back(frame);
104 }
105
106 return frames;
107}
108
109int countNonMonotonicSteps(fl::span<const SweepFrame> frames) {
110 int count = 0;

Callers 1

fft_sweep.hppFile · 0.85

Calls 8

logfFunction · 0.85
expfFunction · 0.85
makeSineFunction · 0.85
freqToBinMethod · 0.80
reserveMethod · 0.45
runMethod · 0.45
rawMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected