summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibDSP/FFT.h
diff options
context:
space:
mode:
authorkleines Filmröllchen <filmroellchen@serenityos.org>2022-05-06 22:14:16 +0200
committerLinus Groh <mail@linusgroh.de>2022-05-07 20:20:16 +0200
commit19a4b820c470d3124afe00471d4fe091d92a00dd (patch)
treed79efedaef7acefd8fa520d2ba991262ac8cd3f6 /Userland/Libraries/LibDSP/FFT.h
parent39c0f310090c6db997ea7c7c4948083cdbd6b4cf (diff)
downloadserenity-19a4b820c470d3124afe00471d4fe091d92a00dd.zip
LibAudio+LibDSP: Switch samples to 32-bit float instead of 64-bit float
This has been overkill from the start, and it has been bugging me for a long time. With this change, we're probably a bit slower on most platforms but save huge amounts of space with all in-memory sample datastructures.
Diffstat (limited to 'Userland/Libraries/LibDSP/FFT.h')
-rw-r--r--Userland/Libraries/LibDSP/FFT.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/Userland/Libraries/LibDSP/FFT.h b/Userland/Libraries/LibDSP/FFT.h
index faf0af84c0..22e6041b93 100644
--- a/Userland/Libraries/LibDSP/FFT.h
+++ b/Userland/Libraries/LibDSP/FFT.h
@@ -12,7 +12,7 @@
namespace LibDSP {
-constexpr void fft(Span<Complex<double>> sample_data, bool invert = false)
+constexpr void fft(Span<Complex<float>> sample_data, bool invert = false)
{
int n = sample_data.size();
@@ -27,13 +27,13 @@ constexpr void fft(Span<Complex<double>> sample_data, bool invert = false)
}
for (int len = 2; len <= n; len <<= 1) {
- double ang = 2 * AK::Pi<double> / len * (invert ? -1 : 1);
- Complex<double> wlen = Complex<double>::from_polar(1., ang);
+ float ang = 2 * AK::Pi<float> / static_cast<float>(len * (invert ? -1 : 1));
+ Complex<float> wlen = Complex<float>::from_polar(1.f, ang);
for (int i = 0; i < n; i += len) {
- Complex<double> w = { 1., 0. };
+ Complex<float> w = { 1., 0. };
for (int j = 0; j < len / 2; j++) {
- Complex<double> u = sample_data[i + j];
- Complex<double> v = sample_data[i + j + len / 2] * w;
+ Complex<float> u = sample_data[i + j];
+ Complex<float> v = sample_data[i + j + len / 2] * w;
sample_data[i + j] = u + v;
sample_data[i + j + len / 2] = u - v;
w *= wlen;