summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorkleines Filmröllchen <malu.bertsch@gmail.com>2021-11-20 17:44:12 +0100
committerLinus Groh <mail@linusgroh.de>2021-11-24 23:45:08 +0000
commita099a77e821724afcd36840f457727ba21e27a45 (patch)
treef882d627bd5b24643070f7d4ff4ee4efabcb0d19 /Userland
parent4cbf7f24be804f899c797f99c125a39cd31b9c4b (diff)
downloadserenity-a099a77e821724afcd36840f457727ba21e27a45.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/SoundPlayer/BarsVisualizationWidget.cpp4
-rw-r--r--Userland/Applications/SoundPlayer/CMakeLists.txt3
-rw-r--r--Userland/Libraries/LibDSP/CMakeLists.txt1
-rw-r--r--Userland/Libraries/LibDSP/FFT.cpp (renamed from Userland/Applications/SoundPlayer/AudioAlgorithms.cpp)6
-rw-r--r--Userland/Libraries/LibDSP/FFT.h (renamed from Userland/Applications/SoundPlayer/AudioAlgorithms.h)6
5 files changed, 14 insertions, 6 deletions
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 <AK/Math.h>
+#include <LibDSP/FFT.h>
#include <LibGUI/Event.h>
#include <LibGUI/Menu.h>
#include <LibGUI/Painter.h>
@@ -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
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 <AK/Complex.h>
#include <AK/Math.h>
+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<Complex<double>>& sample_data, bool invert)
data[i] /= n;
}
}
+
+}
diff --git a/Userland/Applications/SoundPlayer/AudioAlgorithms.h b/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 <AK/Complex.h>
#include <AK/Vector.h>
-void fft(Vector<Complex<double>>& sample_data, bool invert);
+namespace LibDSP {
+
+void fft(Vector<Complex<double>>& sample_data, bool invert = false);
+
+}