/* * Copyright (c) 2021, Arne Elster * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include namespace DSP { template 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 / (2 * N) * (2 * static_cast(n) + 1 + N / 2.0f) * static_cast(2 * k + 1)); } } } void transform(ReadonlySpan data, Span 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, N> m_phi; }; }