# HG changeset patch
# User StephaneLenclud
# Date 1483723639 -3600
# Node ID 7cd495550d5f559d9a20a75bb4507ad6e8c2955f
# Parent a4a341accc89c6cf1a264e227b887bfa8e5913b1
Published v1.4.3
Major hack into our spectrum math to make it prettier.
diff -r a4a341accc89 -r 7cd495550d5f Server/FormMain.cs
--- a/Server/FormMain.cs Thu Jan 05 14:54:43 2017 +0100
+++ b/Server/FormMain.cs Fri Jan 06 18:27:19 2017 +0100
@@ -666,7 +666,7 @@
SoundInSource soundInSource = new SoundInSource(iSoundIn);
ISampleSource source = soundInSource.ToSampleSource();
- const FftSize fftSize = FftSize.Fft4096;
+ const FftSize fftSize = FftSize.Fft2048;
//create a spectrum provider which provides fft data based on some input
BasicSpectrumProvider spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize);
diff -r a4a341accc89 -r 7cd495550d5f Server/SharpDisplayManager.csproj
--- a/Server/SharpDisplayManager.csproj Thu Jan 05 14:54:43 2017 +0100
+++ b/Server/SharpDisplayManager.csproj Fri Jan 06 18:27:19 2017 +0100
@@ -34,7 +34,7 @@
index.htm
false
0
- 1.4.2.0
+ 1.4.3.0
false
true
true
diff -r a4a341accc89 -r 7cd495550d5f Server/Spectrum/LineSpectrum.cs
--- a/Server/Spectrum/LineSpectrum.cs Thu Jan 05 14:54:43 2017 +0100
+++ b/Server/Spectrum/LineSpectrum.cs Fri Jan 06 18:27:19 2017 +0100
@@ -137,7 +137,7 @@
double xCoord = BarSpacing * (barIndex + 1) + (_barWidth * barIndex) + _barWidth / 2;
var p1 = new PointF((float)xCoord, height);
- var p2 = new PointF((float)xCoord, height - (float)p.Value - 1);
+ var p2 = new PointF((float)xCoord, height - (float)p.Value);
graphics.DrawLine(pen, p1, p2);
}
diff -r a4a341accc89 -r 7cd495550d5f Server/Spectrum/SpectrumBase.cs
--- a/Server/Spectrum/SpectrumBase.cs Thu Jan 05 14:54:43 2017 +0100
+++ b/Server/Spectrum/SpectrumBase.cs Fri Jan 06 18:27:19 2017 +0100
@@ -167,6 +167,33 @@
double actualMaxValue = maxValue;
int spectrumPointIndex = 0;
+ int b0 = _minimumFrequencyIndex;
+ int x, y;
+ for (x = 0; x < SpectrumResolution; x++)
+ {
+ float peak = 0;
+ //SL: We should have to compute that only once for a given resolution.
+ // Try using the existing pre-computed array we have and refactor that whole mess.
+ int b1 = (int)Math.Pow(2, x * 10.0 / (SpectrumResolution - 1));
+ //int b1 = (IsXLogScale ? _spectrumLogScaleIndexMax[x] : _spectrumIndexMax[x]);
+ if (b1 > _maximumFrequencyIndex) b1 = _maximumFrequencyIndex;
+ if (b1 <= b0) b1 = b0 + 1;
+ for (; b0 < b1; b0++)
+ {
+ if (peak < fftBuffer[1 + b0]) peak = fftBuffer[1 + b0];
+ }
+
+ const int KHeightScaleFactor = 5; // SL: You can play with that scale factor to tune the height of the bars
+ y = (int)(Math.Sqrt(peak) * KHeightScaleFactor * maxValue);
+ if (y > maxValue) y = (int)maxValue;
+ if (y < 0) y = 0;
+
+ dataPoints.Add(new SpectrumPointData { SpectrumPointIndex = x, Value = y });
+ //_spectrumdata.Add((byte)y);
+ //Console.Write("{0, 3} ", y);
+ }
+
+ /*
for (int i = _minimumFrequencyIndex; i <= _maximumFrequencyIndex; i++)
{
switch (ScalingStrategy)
@@ -211,6 +238,8 @@
//value = 0;
}
+ */
+
return dataPoints.ToArray();
}