Skip to content

Commit

Permalink
FFT1D optimization for low sizes + test
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Oct 10, 2023
1 parent 5c58e2a commit 904dd56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cavern/Utilities/Measurements.FFT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
13 changes: 13 additions & 0 deletions Tests/Test.Cavern/Measurements_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public void FFT_IFFT_Sine() {
}
}

/// <summary>
/// Tests the FFT variant which optimizes the first step of the FFT to keep an absolute result.
/// </summary>
[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);
}
}

/// <summary>
/// Tests an FFT with a length of 4, which is calling a hardcoded FFT variant.
/// </summary>
Expand Down

0 comments on commit 904dd56

Please sign in to comment.