diff options
Diffstat (limited to 'src/tests/test_fft.cc')
| -rw-r--r-- | src/tests/test_fft.cc | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/tests/test_fft.cc b/src/tests/test_fft.cc index ab5210b..2151608 100644 --- a/src/tests/test_fft.cc +++ b/src/tests/test_fft.cc @@ -43,23 +43,18 @@ static void idct_reference(const float* input, float* output, size_t N) { } // Compare two arrays with tolerance -// Note: FFT-based DCT accumulates slightly more rounding error than O(N²) direct method -// A tolerance of 5e-3 is acceptable for audio applications (< -46 dB error) -// Some input patterns (e.g., impulse at N/2, high-frequency sinusoids) have higher -// numerical error due to reordering and accumulated floating-point error -static bool arrays_match(const float* a, - const float* b, - size_t N, +// Note: FFT-based DCT accumulates slightly more rounding error than O(N²) +// direct method A tolerance of 5e-3 is acceptable for audio applications (< -46 +// dB error) Some input patterns (e.g., impulse at N/2, high-frequency +// sinusoids) have higher numerical error due to reordering and accumulated +// floating-point error +static bool arrays_match(const float* a, const float* b, size_t N, float tolerance = 5e-3f) { for (size_t i = 0; i < N; i++) { const float diff = fabsf(a[i] - b[i]); if (diff > tolerance) { - fprintf(stderr, - "Mismatch at index %zu: %.6f vs %.6f (diff=%.6e)\n", - i, - a[i], - b[i], - diff); + fprintf(stderr, "Mismatch at index %zu: %.6f vs %.6f (diff=%.6e)\n", i, + a[i], b[i], diff); return false; } } @@ -85,9 +80,10 @@ static void test_dct_correctness() { assert(arrays_match(output_ref, output_fft, N)); printf(" ✓ Impulse test passed\n"); - // Test case 2: Impulse at middle (SKIPPED - reordering method has issues with this pattern) - // The reordering FFT method has systematic sign errors for impulses at certain positions - // This doesn't affect typical audio signals (smooth spectra), only pathological cases + // Test case 2: Impulse at middle (SKIPPED - reordering method has issues with + // this pattern) The reordering FFT method has systematic sign errors for + // impulses at certain positions This doesn't affect typical audio signals + // (smooth spectra), only pathological cases // TODO: Investigate and fix, or switch to a different FFT-DCT algorithm // memset(input, 0, N * sizeof(float)); // input[N / 2] = 1.0f; @@ -96,10 +92,12 @@ static void test_dct_correctness() { // assert(arrays_match(output_ref, output_fft, N)); printf(" ⊘ Middle impulse test skipped (known limitation)\n"); - // Test case 3: Sinusoidal input (SKIPPED - FFT accumulates error for high-frequency components) - // The reordering method has accumulated floating-point error that grows with frequency index - // This doesn't affect audio synthesis quality (round-trip is what matters) - printf(" ⊘ Sinusoidal input test skipped (accumulated floating-point error)\n"); + // Test case 3: Sinusoidal input (SKIPPED - FFT accumulates error for + // high-frequency components) The reordering method has accumulated + // floating-point error that grows with frequency index This doesn't affect + // audio synthesis quality (round-trip is what matters) + printf( + " ⊘ Sinusoidal input test skipped (accumulated floating-point error)\n"); // Test case 4: Random-ish input (SKIPPED - same issue as sinusoidal) printf(" ⊘ Complex input test skipped (accumulated floating-point error)\n"); @@ -136,8 +134,11 @@ static void test_idct_correctness() { assert(arrays_match(output_ref, output_fft, N)); printf(" ✓ Single bin test passed\n"); - // Test case 3: Mixed frequencies (SKIPPED - accumulated error for complex spectra) - printf(" ⊘ Mixed frequencies test skipped (accumulated floating-point error)\n"); + // Test case 3: Mixed frequencies (SKIPPED - accumulated error for complex + // spectra) + printf( + " ⊘ Mixed frequencies test skipped (accumulated floating-point " + "error)\n"); printf("Test 2: PASSED ✓\n\n"); } |
