From 904dd561d0154844e673dd79297c9bc5e4ff4e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Sg=C3=A1netz?= Date: Wed, 11 Oct 2023 01:05:20 +0200 Subject: [PATCH] FFT1D optimization for low sizes + test --- Cavern/Utilities/Measurements.FFT.cs | 5 ++++- Tests/Test.Cavern/Measurements_Tests.cs | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Cavern/Utilities/Measurements.FFT.cs b/Cavern/Utilities/Measurements.FFT.cs index 8cab362a..b68d4ce8 100644 --- a/Cavern/Utilities/Measurements.FFT.cs +++ b/Cavern/Utilities/Measurements.FFT.cs @@ -219,9 +219,12 @@ static void ProcessFFT(float[] samples, FFTCache cache) { if (CavernAmp.IsMono()) { ProcessFFT_Mono(even, cache, --depth); ProcessFFT_Mono(odd, cache, depth); - } else { + } else if (even.Length != 4) { ProcessFFT(even, cache, --depth); ProcessFFT(odd, cache, depth); + } else { + ProcessFFT4(even); + ProcessFFT4(odd); } float[] cosCache = FFTCache.cos[depth + 1], diff --git a/Tests/Test.Cavern/Measurements_Tests.cs b/Tests/Test.Cavern/Measurements_Tests.cs index b5f7ebc9..2a6c884f 100644 --- a/Tests/Test.Cavern/Measurements_Tests.cs +++ b/Tests/Test.Cavern/Measurements_Tests.cs @@ -54,6 +54,19 @@ public void FFT_IFFT_Sine() { } } + /// + /// Tests the FFT variant which optimizes the first step of the FFT to keep an absolute result. + /// + [TestMethod, Timeout(1000)] + public void FFT1D() { + float[] signal = new float[16]; + signal[0] = 1; + float[] fft = signal.FFT1D(); + for (int i = 0; i < fft.Length; i++) { + Assert.IsTrue(fft[i] == 1); + } + } + /// /// Tests an FFT with a length of 4, which is calling a hardcoded FFT variant. ///