FastLED 3.10.8
Loading...
Searching...
No Matches

◆ initLogRebin()

void fl::audio::fft::Context::initLogRebin ( )
inlineprivate

Definition at line 188 of file fft_impl.cpp.hpp.

188 {
189 // Pre-compute bin edges aligned with CQ center frequencies.
190 // CQ center[i] = fmin * exp(logRatio * i / (bands-1)), so
191 // binToFreq(i) returns these centers for both modes.
192 //
193 // Edges are placed at the geometric mean of adjacent centers:
194 // edge[i] = sqrt(center[i-1] * center[i])
195 // = fmin * exp(logRatio * (2*i - 1) / (2*(bands-1)))
196 //
197 // edge[0] and edge[bands] extend half a bin beyond fmin/fmax.
198 const int bands = mTotalBands;
199 mLogBinEdges.resize(bands + 1);
200 float logRatio = logf(mFmax / mFmin);
201 if (bands <= 1) {
202 mLogBinEdges[0] = mFmin;
203 mLogBinEdges[1] = mFmax;
204 } else {
205 float denom = 2.0f * static_cast<float>(bands - 1);
206 // Edge below first center (half-bin below fmin)
207 mLogBinEdges[0] =
208 mFmin * expf(-logRatio / denom);
209 // Intermediate edges: geometric mean of adjacent CQ centers
210 for (int i = 1; i < bands; i++) {
211 mLogBinEdges[i] =
212 mFmin *
213 expf(logRatio * (2.0f * static_cast<float>(i) - 1.0f) /
214 denom);
215 }
216 // Edge above last center (half-bin above fmax)
217 mLogBinEdges[bands] =
218 mFmax * expf(logRatio / denom);
219 }
220
221 // Clamp top bin edge to Nyquist — prevents incomplete bin coverage
222 // and bad normalization when fmax is close to Nyquist.
223 float nyquist = static_cast<float>(mSampleRate) / 2.0f;
224 if (mLogBinEdges[bands] > nyquist) {
225 mLogBinEdges[bands] = nyquist;
226 }
227
229
230 // Pre-compute bin mapping LUTs
232 static_cast<float>(mSampleRate), 0, mTotalBands);
234
235 // Pre-compute window as Q15 integer coefficients
237
238 // Pre-compute bin-width normalization factors for LOG_REBIN.
239 // Without normalization, wider high-frequency bins accumulate more
240 // sidelobe energy than narrow low-frequency bins, creating visible
241 // "aliasing" artifacts during a tone sweep.
243 mInputSamples, static_cast<float>(mSampleRate),
244 0, mTotalBands);
245 }
void buildLinearBinLut(fl::vector< u8 > &lut, int fftN) FL_NO_EXCEPT
void buildLogBinLut(fl::vector< u8 > &lut, int fftN, float fs, int binStart, int binEnd) FL_NO_EXCEPT
fl::vector< alpha16 > mWindowBuf
fl::vector< u8 > mLinearBinLut
fl::vector< float > mLogBinEdges
fl::vector< u8 > mLogBinLut
static void computeWindow(fl::vector< alpha16 > &win, int N, Window type) FL_NO_EXCEPT
void computeBinEdgesQ16() FL_NO_EXCEPT
fl::vector< float > mLogBinNormFactors
void computeLogRebinNormFactors(fl::vector< float > &normFactors, const fl::vector< u8 > &lut, int fftN, float fs, int binStart, int binEnd) FL_NO_EXCEPT
float logf(float value) FL_NO_EXCEPT
Definition math.h:426
float expf(float value) FL_NO_EXCEPT
Definition math.h:406

References buildLinearBinLut(), buildLogBinLut(), computeBinEdgesQ16(), computeLogRebinNormFactors(), computeWindow(), fl::expf(), fl::FL_NO_EXCEPT, fl::logf(), mFmax, mFmin, mInputSamples, mLinearBinLut, mLogBinEdges, mLogBinLut, mLogBinNormFactors, mSampleRate, mTotalBands, mWindow, and mWindowBuf.

Referenced by Context(), and initOctaveWise().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: