Skip to content

Commit

Permalink
Added test for Cavern's FFT
Browse files Browse the repository at this point in the history
  • Loading branch information
VoidXH committed Oct 11, 2023
1 parent c3b068f commit cd8bf64
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
48 changes: 48 additions & 0 deletions fftbench/fftbench.Common/Benchmark/TestCavern.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

namespace fftbench.Benchmark {
using Cavern.Utilities;

public class TestCavern : ITest {
public string Name => ToString();

public int Size => data.Length;

public bool Enabled { get; set; }

Complex[] data;

FFTCache cache;

public void Initialize(double[] data) {
this.data = new Complex[data.Length];
cache = new FFTCache(data.Length);
for (int i = 0; i < data.Length; i++) {
this.data[i].Real = (float)data[i];
}
}

public void FFT(bool forward) {
Complex[] workingSet = (Complex[])data.Clone();
Measurements.InPlaceFFT(workingSet, cache);
}

public double[] Spectrum(double[] input, bool scale) {
Complex[] workingSet = (Complex[])data.Clone();
Measurements.InPlaceFFT(workingSet, cache);

float[] spectrumSource = Measurements.GetSpectrum(workingSet);
double[] spectrum = new double[spectrumSource.Length];
Helper.CopyToDouble(spectrumSource, spectrum);

Measurements.InPlaceIFFT(workingSet, cache);
float[] ifftResult = Measurements.GetRealPart(workingSet);
Helper.CopyToDouble(ifftResult, input);

return spectrum;
}

public override string ToString() {
return "Cavern";
}
}
}
3 changes: 2 additions & 1 deletion fftbench/fftbench.Common/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ public static List<ITest> LoadTests()

tests.Add(new TestAccord() { Enabled = true });
tests.Add(new TestAForge() { Enabled = true });
tests.Add(new TestMathNet() { Enabled = true });
tests.Add(new TestCavern() { Enabled = true });
tests.Add(new TestExocortex() { Enabled = true });
tests.Add(new TestLomont() { Enabled = true });
tests.Add(new TestMathNet() { Enabled = true });
tests.Add(new TestNAudio() { Enabled = true });
tests.Add(new TestNWaves() { Enabled = true });
tests.Add(new TestExocortexReal() { Enabled = true });
Expand Down
3 changes: 2 additions & 1 deletion fftbench/fftbench.Common/fftbench.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<Copyright>Copyright © Christian Woltering 2016-2022</Copyright>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
Expand All @@ -14,6 +14,7 @@
<ItemGroup>
<PackageReference Include="Accord" Version="3.8.0" />
<PackageReference Include="Accord.Math" Version="3.8.0" />
<PackageReference Include="Cavern" Version="2.0.2" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="NAudio.Core" Version="2.2.1" />
<PackageReference Include="NWaves" Version="0.9.6" />
Expand Down

0 comments on commit cd8bf64

Please sign in to comment.