1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 19:07:34 +00:00

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.
This commit is contained in:
kleines Filmröllchen 2022-05-06 22:14:16 +02:00 committed by Linus Groh
parent 39c0f31009
commit 19a4b820c4
16 changed files with 329 additions and 329 deletions

View file

@ -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;

View file

@ -19,12 +19,12 @@ public:
{
for (size_t n = 0; n < N; n++) {
for (size_t k = 0; k < N / 2; k++) {
m_phi[n][k] = AK::cos(AK::Pi<double> / (2 * N) * (2 * n + 1 + N / 2.0) * (2 * k + 1));
m_phi[n][k] = AK::cos<float>(AK::Pi<float> / (2 * N) * (2 * static_cast<float>(n) + 1 + N / 2.0f) * static_cast<float>(2 * k + 1));
}
}
}
void transform(Span<double const> data, Span<double> output)
void transform(Span<float const> data, Span<float> output)
{
assert(N == 2 * data.size());
assert(N == output.size());
@ -37,7 +37,7 @@ public:
}
private:
Array<Array<double, N / 2>, N> m_phi;
Array<Array<float, N / 2>, N> m_phi;
};
}

View file

@ -27,17 +27,17 @@ public:
constexpr static FixedArray<T> blackman_harris(size_t size) { return make_window(size, calculate_blackman_harris); }
private:
constexpr static double calculate_hann(size_t index, size_t size)
constexpr static float calculate_hann(size_t index, size_t size)
{
return 0.5 * (1 - AK::cos((2 * AK::Pi<T> * index) / (size - 1)));
return 0.5f * (1 - AK::cos<float>((2 * AK::Pi<T> * index) / (size - 1)));
}
constexpr static double calculate_hamming(size_t index, size_t size)
constexpr static float calculate_hamming(size_t index, size_t size)
{
return 0.54 - 0.46 * AK::cos((2 * AK::Pi<T> * index) / (size - 1));
return 0.54f - 0.46f * AK::cos<float>((2 * AK::Pi<T> * index) / (size - 1));
}
constexpr static double calculate_blackman_harris(size_t index, size_t size)
constexpr static float calculate_blackman_harris(size_t index, size_t size)
{
T const a0 = 0.35875;
T const a1 = 0.48829;