Server/Spectrum/SpectrumBase.cs
changeset 276 7cd495550d5f
parent 274 920fea7a6427
child 278 2481c46d1f93
     1.1 --- a/Server/Spectrum/SpectrumBase.cs	Thu Jan 05 14:54:43 2017 +0100
     1.2 +++ b/Server/Spectrum/SpectrumBase.cs	Fri Jan 06 18:27:19 2017 +0100
     1.3 @@ -167,6 +167,33 @@
     1.4              double actualMaxValue = maxValue;
     1.5              int spectrumPointIndex = 0;
     1.6  
     1.7 +            int b0 = _minimumFrequencyIndex;
     1.8 +            int x, y;
     1.9 +            for (x = 0; x < SpectrumResolution; x++)
    1.10 +            {
    1.11 +                float peak = 0;
    1.12 +                //SL: We should have to compute that only once for a given resolution.
    1.13 +                // Try using the existing pre-computed array we have and refactor that whole mess.
    1.14 +                int b1 = (int)Math.Pow(2, x * 10.0 / (SpectrumResolution - 1)); 
    1.15 +                //int b1 = (IsXLogScale ? _spectrumLogScaleIndexMax[x] : _spectrumIndexMax[x]);
    1.16 +                if (b1 > _maximumFrequencyIndex) b1 = _maximumFrequencyIndex;
    1.17 +                if (b1 <= b0) b1 = b0 + 1;
    1.18 +                for (; b0 < b1; b0++)
    1.19 +                {
    1.20 +                    if (peak < fftBuffer[1 + b0]) peak = fftBuffer[1 + b0];
    1.21 +                }
    1.22 +                
    1.23 +                const int KHeightScaleFactor = 5; // SL: You can play with that scale factor to tune the height of the bars
    1.24 +                y = (int)(Math.Sqrt(peak) * KHeightScaleFactor * maxValue); 
    1.25 +                if (y > maxValue) y = (int)maxValue;
    1.26 +                if (y < 0) y = 0;
    1.27 +
    1.28 +                dataPoints.Add(new SpectrumPointData { SpectrumPointIndex = x, Value = y });
    1.29 +                //_spectrumdata.Add((byte)y);
    1.30 +                //Console.Write("{0, 3} ", y);
    1.31 +            }
    1.32 +
    1.33 +            /*
    1.34              for (int i = _minimumFrequencyIndex; i <= _maximumFrequencyIndex; i++)
    1.35              {
    1.36                  switch (ScalingStrategy)
    1.37 @@ -211,6 +238,8 @@
    1.38  
    1.39                  //value = 0;
    1.40              }
    1.41 +            */
    1.42 +
    1.43  
    1.44              return dataPoints.ToArray();
    1.45          }