diff options
author | Arne Elster <arne@elster.li> | 2021-12-09 22:19:17 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-02-26 16:01:26 +0100 |
commit | 6a64aabce86fb9d24ef468ff764a4a340afad3de (patch) | |
tree | 3c9461d9c51872dac133aa3908dceba2c54ce376 /Userland/Libraries | |
parent | 82afbd659346c01419b8f60a2496c7a58bc737b7 (diff) | |
download | serenity-6a64aabce86fb9d24ef468ff764a4a340afad3de.zip |
LibDSP: Add IMDCT
This implements a generic IMDCT to be used by the MP3 decoder.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibDSP/MDCT.h | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/Userland/Libraries/LibDSP/MDCT.h b/Userland/Libraries/LibDSP/MDCT.h new file mode 100644 index 0000000000..940013498b --- /dev/null +++ b/Userland/Libraries/LibDSP/MDCT.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2021, Arne Elster <arne@elster.li> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Array.h> +#include <AK/Math.h> +#include <AK/Span.h> + +namespace LibDSP { + +template<size_t N> +requires(N % 2 == 0) class MDCT { +public: + constexpr MDCT() + { + 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)); + } + } + } + + void transform(Span<double const> data, Span<double> output) + { + assert(N == 2 * data.size()); + assert(N == output.size()); + for (size_t n = 0; n < N; n++) { + output[n] = 0; + for (size_t k = 0; k < N / 2; k++) { + output[n] += data[k] * m_phi[n][k]; + } + } + } + +private: + Array<Array<double, N / 2>, N> m_phi; +}; + +} |