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

◆ computeWindow()

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

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

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