@@ -14,6 +14,7 @@ public class Renderer
1414 public bool UseFFTPositions { get ; set ; }
1515 public bool UseImaginaryFFTValues { get ; set ; }
1616 public bool UseImaginaryAndRealAverage { get ; set ; }
17+ public bool UsePleaseHelpMe { get ; set ; } = false ;
1718
1819 public delegate double _fftWindow ( int n , int frameSize ) ;
1920 public _fftWindow FFTWindow { get ; set ; }
@@ -27,6 +28,8 @@ public Renderer(int fftResolution = 512)
2728 UseImaginaryAndRealAverage = false ;
2829 FFTWindow = FastFourierTransform . HannWindow ;
2930 _fftResolution = fftResolution ;
31+ var could = Bass . Init ( ) ;
32+ Console . WriteLine ( "Bass.Init returned " + could ) ;
3033 }
3134
3235 public Renderer ( ref _fftWindow fftWindow , bool useFFTPositions = true , bool useImaginaryFFTValues = true , bool useImaginaryAndRealAverage = false , int fftResolution = 512 )
@@ -36,6 +39,8 @@ public Renderer(ref _fftWindow fftWindow, bool useFFTPositions = true, bool useI
3639 UseImaginaryAndRealAverage = useImaginaryAndRealAverage ;
3740 FFTWindow = fftWindow ;
3841 _fftResolution = fftResolution ;
42+ var could = Bass . Init ( ) ;
43+ Console . WriteLine ( "Bass.Init returned " + could ) ;
3944 }
4045
4146 public string Md5HashFile ( string fileName )
@@ -123,8 +128,6 @@ public List<float> DecodeSongSums(string path)
123128 {
124129 var fft = new float [ _fftResolution ] ;
125130
126- var could = Bass . Init ( ) ;
127- Console . WriteLine ( "Bass.Init returned " + could ) ;
128131 var chan = Bass . CreateStream ( path , Flags : BassFlags . Decode | BassFlags . Float | BassFlags . Prescan ) ;
129132
130133 Console . WriteLine ( "Prescan2 complete" ) ;
@@ -178,6 +181,34 @@ private float FastDecodeStepAsync(int chan, float[] ffts)
178181
179182 FastFourierTransform . FFT ( false , ( int ) Math . Log ( _fftResolution , 2.0 ) , ref complexFFTs ) ;
180183
184+
185+ if ( UsePleaseHelpMe )
186+ {
187+ //get avg of real and imaginary parts
188+ //var avg = (ulong)complexFFTs[i];
189+ var the3CThing = new Complex ( ) ;
190+ complexFFTs [ 0 ] = new Complex ( 0 , 0 ) ;
191+ complexFFTs [ 1 ] = new Complex ( 0 , 0 ) ;
192+ for ( var i = 0 ; i < complexFFTs . Length ; i ++ )
193+ {
194+ var current = complexFFTs [ i ] ;
195+ var next = new Complex ( ) ;
196+ if ( i + 1 < complexFFTs . Length )
197+ {
198+ next = complexFFTs [ i + 1 ] ;
199+ }
200+
201+ var sqrt = Complex . Sqrt ( current * current + next * next ) * 0.0009765625f ;
202+ complexFFTs [ i ] = sqrt ;
203+
204+ if ( sqrt . Real <= the3CThing . Real )
205+ {
206+ sqrt = the3CThing ;
207+ }
208+ the3CThing = sqrt ;
209+ }
210+ }
211+
181212 int fFT512KISS = data ;
182213 if ( fFT512KISS < 1 )
183214 {
@@ -192,7 +223,7 @@ private float FastDecodeStepAsync(int chan, float[] ffts)
192223 var avg = ( complexFFTs [ i ] . Real + complexFFTs [ i ] . Imaginary ) / 2 ;
193224 num += ( float ) Math . Sqrt ( Math . Max ( 0f , avg ) ) ;
194225 }
195- else if ( UseImaginaryFFTValues )
226+ else if ( UseImaginaryFFTValues && ! UsePleaseHelpMe )
196227 {
197228 num += ( float ) Math . Sqrt ( Math . Max ( 0f , complexFFTs [ i ] . Imaginary ) ) ;
198229 }
0 commit comments