summaryrefslogtreecommitdiff
path: root/src/tests/test_dct.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/test_dct.cc')
-rw-r--r--src/tests/test_dct.cc57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/tests/test_dct.cc b/src/tests/test_dct.cc
index b40f392..89b7964 100644
--- a/src/tests/test_dct.cc
+++ b/src/tests/test_dct.cc
@@ -2,42 +2,43 @@
// It tests the DCT implementation for correctness and coverage.
#include "audio/dct.h"
-#include <vector>
-#include <cmath>
#include <cassert>
-#include <iostream>
+#include <cmath>
#include <cstdlib>
+#include <iostream>
+#include <vector>
void test_fdct_idct() {
- float input[DCT_SIZE];
- float freq[DCT_SIZE];
- float output[DCT_SIZE];
+ float input[DCT_SIZE];
+ float freq[DCT_SIZE];
+ float output[DCT_SIZE];
+
+ // Initialize with random data
+ srand(12345); // Fixed seed for reproducibility
+ for (int i = 0; i < DCT_SIZE; ++i) {
+ input[i] = (float)rand() / RAND_MAX * 2.0f - 1.0f;
+ }
- // Initialize with random data
- srand(12345); // Fixed seed for reproducibility
- for (int i = 0; i < DCT_SIZE; ++i) {
- input[i] = (float)rand() / RAND_MAX * 2.0f - 1.0f;
- }
+ fdct_512(input, freq);
+ idct_512(freq, output);
- fdct_512(input, freq);
- idct_512(freq, output);
+ // Verify reconstruction
+ float max_error = 0.0f;
+ for (int i = 0; i < DCT_SIZE; ++i) {
+ float err = std::abs(input[i] - output[i]);
+ if (err > max_error)
+ max_error = err;
+ }
+ std::cout << "Max reconstruction error: " << max_error << std::endl;
- // Verify reconstruction
- float max_error = 0.0f;
- for (int i = 0; i < DCT_SIZE; ++i) {
- float err = std::abs(input[i] - output[i]);
- if (err > max_error) max_error = err;
- }
- std::cout << "Max reconstruction error: " << max_error << std::endl;
-
- // Allow some error due to float precision and iterative sum
- // 512 sums can accumulate error.
- assert(max_error < 1e-4f);
+ // Allow some error due to float precision and iterative sum
+ // 512 sums can accumulate error.
+ assert(max_error < 1e-4f);
}
int main() {
- std::cout << "Running DCT tests..." << std::endl;
- test_fdct_idct();
- std::cout << "DCT tests PASSED" << std::endl;
- return 0;
+ std::cout << "Running DCT tests..." << std::endl;
+ test_fdct_idct();
+ std::cout << "DCT tests PASSED" << std::endl;
+ return 0;
}