From a099a77e821724afcd36840f457727ba21e27a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Sat, 20 Nov 2021 17:44:12 +0100 Subject: [PATCH] SoundPlayer+LibDSP: Move the FFT implementation to LibDSP LibDSP can greatly benefit from this nice FFT implementation, so let's move it into the fitting library :^) Note that this now requires linking SoundPlayer against LibDSP. That's not an issue (LibDSP is rather small currently anyways), as we can probably make great use of it in the future anyways. --- .../Applications/SoundPlayer/BarsVisualizationWidget.cpp | 4 ++-- Userland/Applications/SoundPlayer/CMakeLists.txt | 3 +-- Userland/Libraries/LibDSP/CMakeLists.txt | 1 + .../AudioAlgorithms.cpp => Libraries/LibDSP/FFT.cpp} | 6 +++++- .../AudioAlgorithms.h => Libraries/LibDSP/FFT.h} | 6 +++++- 5 files changed, 14 insertions(+), 6 deletions(-) rename Userland/{Applications/SoundPlayer/AudioAlgorithms.cpp => Libraries/LibDSP/FFT.cpp} (97%) rename Userland/{Applications/SoundPlayer/AudioAlgorithms.h => Libraries/LibDSP/FFT.h} (66%) diff --git a/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp b/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp index 4c0a584768..adf2dbdb73 100644 --- a/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp +++ b/Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp @@ -5,8 +5,8 @@ */ #include "BarsVisualizationWidget.h" -#include "AudioAlgorithms.h" #include +#include #include #include #include @@ -25,7 +25,7 @@ void BarsVisualizationWidget::paint_event(GUI::PaintEvent& event) if (m_sample_buffer.is_empty()) return; - fft(m_sample_buffer, false); + LibDSP::fft(m_sample_buffer, false); double max = AK::sqrt(m_sample_count * 2.); double freq_bin = m_samplerate / (double)m_sample_count; diff --git a/Userland/Applications/SoundPlayer/CMakeLists.txt b/Userland/Applications/SoundPlayer/CMakeLists.txt index 578078938e..26f5e31c1f 100644 --- a/Userland/Applications/SoundPlayer/CMakeLists.txt +++ b/Userland/Applications/SoundPlayer/CMakeLists.txt @@ -13,11 +13,10 @@ set(SOURCES SampleWidget.cpp SoundPlayerWidgetAdvancedView.cpp BarsVisualizationWidget.cpp - AudioAlgorithms.cpp NoVisualizationWidget.cpp M3UParser.cpp PlaylistWidget.cpp ) serenity_app(SoundPlayer ICON app-sound-player) -target_link_libraries(SoundPlayer LibAudio LibGUI) +target_link_libraries(SoundPlayer LibAudio LibDSP LibGUI) diff --git a/Userland/Libraries/LibDSP/CMakeLists.txt b/Userland/Libraries/LibDSP/CMakeLists.txt index a5de6f120e..f7dc72fcd1 100644 --- a/Userland/Libraries/LibDSP/CMakeLists.txt +++ b/Userland/Libraries/LibDSP/CMakeLists.txt @@ -3,6 +3,7 @@ set(SOURCES Track.cpp Effects.cpp Synthesizers.cpp + FFT.cpp ) serenity_lib(LibDSP dsp) diff --git a/Userland/Applications/SoundPlayer/AudioAlgorithms.cpp b/Userland/Libraries/LibDSP/FFT.cpp similarity index 97% rename from Userland/Applications/SoundPlayer/AudioAlgorithms.cpp rename to Userland/Libraries/LibDSP/FFT.cpp index b25de59797..8083333f96 100644 --- a/Userland/Applications/SoundPlayer/AudioAlgorithms.cpp +++ b/Userland/Libraries/LibDSP/FFT.cpp @@ -4,10 +4,12 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include "AudioAlgorithms.h" +#include "FFT.h" #include #include +namespace LibDSP { + // This function uses the input vector as output too. therefore, if you wish to // leave it intact, pass a copy to this function // @@ -56,3 +58,5 @@ void fft(Vector>& sample_data, bool invert) data[i] /= n; } } + +} diff --git a/Userland/Applications/SoundPlayer/AudioAlgorithms.h b/Userland/Libraries/LibDSP/FFT.h similarity index 66% rename from Userland/Applications/SoundPlayer/AudioAlgorithms.h rename to Userland/Libraries/LibDSP/FFT.h index 904c9acefe..d13d358af2 100644 --- a/Userland/Applications/SoundPlayer/AudioAlgorithms.h +++ b/Userland/Libraries/LibDSP/FFT.h @@ -9,4 +9,8 @@ #include #include -void fft(Vector>& sample_data, bool invert); +namespace LibDSP { + +void fft(Vector>& sample_data, bool invert = false); + +}