Published v1.4.3
authorStephaneLenclud
Fri, 06 Jan 2017 18:27:19 +0100
changeset 2767cd495550d5f
parent 275 a4a341accc89
child 277 71ba0dd622a5
Published v1.4.3
Major hack into our spectrum math to make it prettier.
Server/FormMain.cs
Server/SharpDisplayManager.csproj
Server/Spectrum/LineSpectrum.cs
Server/Spectrum/SpectrumBase.cs
     1.1 --- a/Server/FormMain.cs	Thu Jan 05 14:54:43 2017 +0100
     1.2 +++ b/Server/FormMain.cs	Fri Jan 06 18:27:19 2017 +0100
     1.3 @@ -666,7 +666,7 @@
     1.4              SoundInSource soundInSource = new SoundInSource(iSoundIn);
     1.5              ISampleSource source = soundInSource.ToSampleSource();
     1.6  
     1.7 -            const FftSize fftSize = FftSize.Fft4096;
     1.8 +            const FftSize fftSize = FftSize.Fft2048;
     1.9              //create a spectrum provider which provides fft data based on some input
    1.10              BasicSpectrumProvider spectrumProvider = new BasicSpectrumProvider(source.WaveFormat.Channels, source.WaveFormat.SampleRate, fftSize);
    1.11  
     2.1 --- a/Server/SharpDisplayManager.csproj	Thu Jan 05 14:54:43 2017 +0100
     2.2 +++ b/Server/SharpDisplayManager.csproj	Fri Jan 06 18:27:19 2017 +0100
     2.3 @@ -34,7 +34,7 @@
     2.4      <WebPage>index.htm</WebPage>
     2.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     2.6      <ApplicationRevision>0</ApplicationRevision>
     2.7 -    <ApplicationVersion>1.4.2.0</ApplicationVersion>
     2.8 +    <ApplicationVersion>1.4.3.0</ApplicationVersion>
     2.9      <UseApplicationTrust>false</UseApplicationTrust>
    2.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    2.11      <PublishWizardCompleted>true</PublishWizardCompleted>
     3.1 --- a/Server/Spectrum/LineSpectrum.cs	Thu Jan 05 14:54:43 2017 +0100
     3.2 +++ b/Server/Spectrum/LineSpectrum.cs	Fri Jan 06 18:27:19 2017 +0100
     3.3 @@ -137,7 +137,7 @@
     3.4                  double xCoord = BarSpacing * (barIndex + 1) + (_barWidth * barIndex) + _barWidth / 2;
     3.5  
     3.6                  var p1 = new PointF((float)xCoord, height);
     3.7 -                var p2 = new PointF((float)xCoord, height - (float)p.Value - 1);
     3.8 +                var p2 = new PointF((float)xCoord, height - (float)p.Value);
     3.9  
    3.10                  graphics.DrawLine(pen, p1, p2);
    3.11              }
     4.1 --- a/Server/Spectrum/SpectrumBase.cs	Thu Jan 05 14:54:43 2017 +0100
     4.2 +++ b/Server/Spectrum/SpectrumBase.cs	Fri Jan 06 18:27:19 2017 +0100
     4.3 @@ -167,6 +167,33 @@
     4.4              double actualMaxValue = maxValue;
     4.5              int spectrumPointIndex = 0;
     4.6  
     4.7 +            int b0 = _minimumFrequencyIndex;
     4.8 +            int x, y;
     4.9 +            for (x = 0; x < SpectrumResolution; x++)
    4.10 +            {
    4.11 +                float peak = 0;
    4.12 +                //SL: We should have to compute that only once for a given resolution.
    4.13 +                // Try using the existing pre-computed array we have and refactor that whole mess.
    4.14 +                int b1 = (int)Math.Pow(2, x * 10.0 / (SpectrumResolution - 1)); 
    4.15 +                //int b1 = (IsXLogScale ? _spectrumLogScaleIndexMax[x] : _spectrumIndexMax[x]);
    4.16 +                if (b1 > _maximumFrequencyIndex) b1 = _maximumFrequencyIndex;
    4.17 +                if (b1 <= b0) b1 = b0 + 1;
    4.18 +                for (; b0 < b1; b0++)
    4.19 +                {
    4.20 +                    if (peak < fftBuffer[1 + b0]) peak = fftBuffer[1 + b0];
    4.21 +                }
    4.22 +                
    4.23 +                const int KHeightScaleFactor = 5; // SL: You can play with that scale factor to tune the height of the bars
    4.24 +                y = (int)(Math.Sqrt(peak) * KHeightScaleFactor * maxValue); 
    4.25 +                if (y > maxValue) y = (int)maxValue;
    4.26 +                if (y < 0) y = 0;
    4.27 +
    4.28 +                dataPoints.Add(new SpectrumPointData { SpectrumPointIndex = x, Value = y });
    4.29 +                //_spectrumdata.Add((byte)y);
    4.30 +                //Console.Write("{0, 3} ", y);
    4.31 +            }
    4.32 +
    4.33 +            /*
    4.34              for (int i = _minimumFrequencyIndex; i <= _maximumFrequencyIndex; i++)
    4.35              {
    4.36                  switch (ScalingStrategy)
    4.37 @@ -211,6 +238,8 @@
    4.38  
    4.39                  //value = 0;
    4.40              }
    4.41 +            */
    4.42 +
    4.43  
    4.44              return dataPoints.ToArray();
    4.45          }