Skip to content

Commit

Permalink
Added "PleaseHelp" option that does some stuff to the values that the…
Browse files Browse the repository at this point in the history
… OG library does too
  • Loading branch information
Sekoree committed Jul 15, 2022
1 parent 4557e6a commit c50b53d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
13 changes: 12 additions & 1 deletion RendererUI/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ public bool UseImaginaryAndRealAverage
this.RaisePropertyChanged();
}
}

public bool UsePleaseHelpMe
{
get => _renderer.UsePleaseHelpMe;
set
{
_renderer.UsePleaseHelpMe = value;
this.RaisePropertyChanged();
}
}

[Reactive] public ObservableCollection<string> FFTWindows { get; set; } = new();
[Reactive] public string SelectedFFTWindow { get; set; }
Expand Down Expand Up @@ -123,9 +133,10 @@ public async Task BrowseForOutputPathAsync()
}
}

public void RenderSongAsync()
public async Task RenderSongAsync()
{
ShowDoneText = false;
await Task.Delay(1000);
if (!File.Exists(FileToRender) || !Directory.Exists(OutputPath))
{
OutputText = "Invalid file or output path";
Expand Down
4 changes: 3 additions & 1 deletion RendererUI/Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
SelectedItem="{Binding SelectedFFTWindow}"/>
<CheckBox IsChecked="{Binding UseImaginaryAndRealAverage}"
Content="Use Real + Imaginary FFT Average"/>
<CheckBox IsChecked="{Binding UsePleaseHelpMe}"
Content="PleaseGodI'mHavingABreakdown"/>
</StackPanel>

<StackPanel Grid.Column="0"
Expand All @@ -71,7 +73,7 @@
<CheckBox IsChecked="{Binding UseFFTPositions}"
Content="Use FFT Positions"/>

<TextBlock IsVisible="{Binding ShowDoneText}"
<TextBlock IsVisible="{Binding ShowDoneText, Mode=TwoWay}"
VerticalAlignment="Center"
FontWeight="ExtraBold"
FontSize="20"
Expand Down
37 changes: 34 additions & 3 deletions SekoRenderer/Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Renderer
public bool UseFFTPositions { get; set; }
public bool UseImaginaryFFTValues { get; set; }
public bool UseImaginaryAndRealAverage { get; set; }
public bool UsePleaseHelpMe { get; set; } = false;

public delegate double _fftWindow(int n, int frameSize);
public _fftWindow FFTWindow { get; set; }
Expand All @@ -27,6 +28,8 @@ public Renderer(int fftResolution = 512)
UseImaginaryAndRealAverage = false;
FFTWindow = FastFourierTransform.HannWindow;
_fftResolution = fftResolution;
var could = Bass.Init();
Console.WriteLine("Bass.Init returned " + could);
}

public Renderer(ref _fftWindow fftWindow, bool useFFTPositions = true, bool useImaginaryFFTValues = true, bool useImaginaryAndRealAverage = false, int fftResolution = 512)
Expand All @@ -36,6 +39,8 @@ public Renderer(ref _fftWindow fftWindow, bool useFFTPositions = true, bool useI
UseImaginaryAndRealAverage = useImaginaryAndRealAverage;
FFTWindow = fftWindow;
_fftResolution = fftResolution;
var could = Bass.Init();
Console.WriteLine("Bass.Init returned " + could);
}

public string Md5HashFile(string fileName)
Expand Down Expand Up @@ -123,8 +128,6 @@ public List<float> DecodeSongSums(string path)
{
var fft = new float[_fftResolution];

var could = Bass.Init();
Console.WriteLine("Bass.Init returned " + could);
var chan = Bass.CreateStream(path, Flags: BassFlags.Decode | BassFlags.Float | BassFlags.Prescan);

Console.WriteLine("Prescan2 complete");
Expand Down Expand Up @@ -178,6 +181,34 @@ private float FastDecodeStepAsync(int chan, float[] ffts)

FastFourierTransform.FFT(false, (int)Math.Log(_fftResolution, 2.0), ref complexFFTs);


if (UsePleaseHelpMe)
{
//get avg of real and imaginary parts
//var avg = (ulong)complexFFTs[i];
var the3CThing = new Complex();
complexFFTs[0] = new Complex(0, 0);
complexFFTs[1] = new Complex(0, 0);
for (var i = 0; i < complexFFTs.Length; i++)
{
var current = complexFFTs[i];
var next = new Complex();
if (i + 1 < complexFFTs.Length)
{
next = complexFFTs[i + 1];
}

var sqrt = Complex.Sqrt(current * current + next * next) * 0.0009765625f;
complexFFTs[i] = sqrt;

if (sqrt.Real <= the3CThing.Real)
{
sqrt = the3CThing;
}
the3CThing = sqrt;
}
}

int fFT512KISS = data;
if (fFT512KISS < 1)
{
Expand All @@ -192,7 +223,7 @@ private float FastDecodeStepAsync(int chan, float[] ffts)
var avg = (complexFFTs[i].Real + complexFFTs[i].Imaginary) / 2;
num += (float)Math.Sqrt(Math.Max(0f, avg));
}
else if (UseImaginaryFFTValues)
else if (UseImaginaryFFTValues && !UsePleaseHelpMe)
{
num += (float)Math.Sqrt(Math.Max(0f, complexFFTs[i].Imaginary));
}
Expand Down

0 comments on commit c50b53d

Please sign in to comment.