summaryrefslogtreecommitdiff
path: root/Userland/Applications/SoundPlayer/BarsVisualizationWidget.h
blob: 363a51e4d648cb05b129376c2205a3f638857d32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright (c) 2021, Cesar Torres <shortanemoia@protonmail.com>
 * Copyright (c) 2022, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "VisualizationWidget.h"
#include <AK/Array.h>
#include <AK/Complex.h>
#include <AK/FixedArray.h>
#include <LibGUI/Frame.h>

class BarsVisualizationWidget final : public VisualizationWidget {
    C_OBJECT(BarsVisualizationWidget)

public:
    ~BarsVisualizationWidget() override = default;

private:
    BarsVisualizationWidget();

    void render(GUI::PaintEvent&, FixedArray<float> const&) override;
    void context_menu_event(GUI::ContextMenuEvent& event) override;

    static constexpr size_t fft_size = 512;
    static constexpr size_t bar_count = 64;
    // Things become weird near the Nyquist limit. Just don't use that FFT data.
    static constexpr size_t cutoff = fft_size - 32;

    Array<Complex<float>, fft_size> m_fft_samples {};
    Array<float, fft_size> m_fft_window {};
    Array<float, fft_size / 2> m_previous_samples {};
    Array<int, bar_count> m_gfx_falling_bars {};
    bool m_is_using_last;
    bool m_adjust_frequencies;
    bool m_logarithmic_spectrum;
    RefPtr<GUI::Menu> m_context_menu;
};