FastLED 3.10.9
Loading...
Searching...
No Matches

◆ computeWindow()

static void fl::audio::fft::Context::computeWindow ( fl::vector< alpha16 > & win,
int N,
Window type )
inlinestaticprivate

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

501 {
502 using FP = fl::fixed_point<16, 16>;
503 win.resize(N);
504
505 // NONE: rectangular window (all coefficients = 1.0)
506 if (type == Window::NONE) {
507 for (int n = 0; n < N; ++n) {
508 win[n] = alpha16(65535);
509 }
510 return;
511 }
512
513 const FP two_pi(6.2831853f); // 2π
514 const FP invNm1 = FP(1) / FP(N - 1);
515 const FP phase_step = two_pi * invNm1;
516
517 // Blackman-Harris coefficients
518 constexpr FP bh_a0(0.35875f);
519 constexpr FP bh_a1(0.48829f);
520 constexpr FP bh_a2(0.14128f);
521 constexpr FP bh_a3(0.01168f);
522 // Hanning coefficients
523 constexpr FP half(0.5f);
524 constexpr FP one(1.0f);
525
526 FP phase(0.0f);
527 for (int n = 0; n < N; ++n) {
528 FP w;
529 switch (type) {
531 // 4-term Blackman-Harris: -92 dB sidelobe rejection
532 FP phase2 = phase + phase;
533 FP phase3 = phase2 + phase;
534 w = bh_a0 - bh_a1 * FP::cos(phase)
535 + bh_a2 * FP::cos(phase2)
536 - bh_a3 * FP::cos(phase3);
537 break;
538 }
539 case Window::HANNING:
540 default:
541 w = half * (one - FP::cos(phase));
542 break;
543 }
544 i32 raw = w.raw();
545 if (raw < 0) raw = 0; // guard against FP rounding
546 if (raw > 65535) raw = 65535; // 1.0 in s16x16 = 65536, clamp for u16
547 win[n] = alpha16(static_cast<unsigned short>(raw));
548 phase = phase + phase_step;
549 }
550 }
constexpr i32 raw() const FL_NO_EXCEPT
Definition s16x16.h:62
void resize(fl::size n) FL_NO_EXCEPT
Definition vector.h:593

References fl::audio::fft::BLACKMAN_HARRIS, fl::FL_NO_EXCEPT, fl::audio::fft::HANNING, fl::audio::fft::NONE, and fl::s16x16::raw().

Referenced by initHybrid(), initLogRebin(), initOctaveWise(), and initWindow().

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