mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:42:44 +00:00 
			
		
		
		
	 19a4b820c4
			
		
	
	
		19a4b820c4
		
	
	
	
	
		
			
			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.
		
			
				
	
	
		
			43 lines
		
	
	
	
		
			959 B
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
	
		
			959 B
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * 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<float>(AK::Pi<float> / (2 * N) * (2 * static_cast<float>(n) + 1 + N / 2.0f) * static_cast<float>(2 * k + 1));
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     void transform(Span<float const> data, Span<float> 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<float, N / 2>, N> m_phi;
 | |
| };
 | |
| 
 | |
| }
 |