2021-03-21 11:50:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Cesar Torres <shortanemoia@protonmail.com>
|
2022-02-10 19:28:48 +00:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2021-03-21 11:50:58 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-03-21 11:50:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-30 04:55:42 +00:00
|
|
|
#include "VisualizationWidget.h"
|
2022-01-09 22:21:55 +00:00
|
|
|
#include <AK/Array.h>
|
2021-03-21 11:50:58 +00:00
|
|
|
#include <AK/Complex.h>
|
2022-01-09 21:46:06 +00:00
|
|
|
#include <AK/FixedArray.h>
|
2021-03-21 11:50:58 +00:00
|
|
|
#include <LibGUI/Frame.h>
|
|
|
|
|
2021-09-30 04:55:42 +00:00
|
|
|
class BarsVisualizationWidget final : public VisualizationWidget {
|
2021-03-21 11:50:58 +00:00
|
|
|
C_OBJECT(BarsVisualizationWidget)
|
|
|
|
|
|
|
|
public:
|
2022-02-10 19:28:48 +00:00
|
|
|
~BarsVisualizationWidget() override = default;
|
2021-03-21 11:50:58 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
BarsVisualizationWidget();
|
2021-03-26 00:28:56 +00:00
|
|
|
|
2022-05-06 20:14:16 +00:00
|
|
|
void render(GUI::PaintEvent&, FixedArray<float> const&) override;
|
2021-07-11 17:06:20 +00:00
|
|
|
void context_menu_event(GUI::ContextMenuEvent& event) override;
|
2021-03-21 11:50:58 +00:00
|
|
|
|
2022-03-03 21:32:45 +00:00
|
|
|
static constexpr size_t fft_size = 512;
|
2022-01-09 22:21:55 +00:00
|
|
|
static constexpr size_t bar_count = 64;
|
2022-03-03 23:25:15 +00:00
|
|
|
// Things become weird near the Nyquist limit. Just don't use that FFT data.
|
|
|
|
static constexpr size_t cutoff = fft_size - 32;
|
2022-01-09 22:21:55 +00:00
|
|
|
|
2022-05-06 20:14:16 +00:00
|
|
|
Array<Complex<float>, fft_size> m_fft_samples {};
|
|
|
|
Array<float, fft_size> m_fft_window {};
|
|
|
|
Array<float, fft_size / 2> m_previous_samples {};
|
2022-01-09 22:21:55 +00:00
|
|
|
Array<int, bar_count> m_gfx_falling_bars {};
|
2021-03-21 11:50:58 +00:00
|
|
|
bool m_is_using_last;
|
|
|
|
bool m_adjust_frequencies;
|
2022-03-03 23:25:15 +00:00
|
|
|
bool m_logarithmic_spectrum;
|
2021-03-21 11:50:58 +00:00
|
|
|
RefPtr<GUI::Menu> m_context_menu;
|
|
|
|
};
|