private double ConfigureBrightness(AnalysisResult result)
        {
            int offsetIndex = result.GetIndex(BrightnessRange.From);
            int endIndex    = result.GetIndex(BrightnessRange.To);
            var dbfs        = result.GetDBFS(offsetIndex, endIndex);

            var averageDbfs = 0.0;

            foreach (var value in dbfs)
            {
                averageDbfs += value;
            }

            averageDbfs /= dbfs.Length;

            double minimum = -90;
            double maximum = -70;
            var    linear  = (averageDbfs - minimum) / (maximum - minimum);

            if (!double.IsNormal(linear))
            {
                linear = 0;
            }

            linear = Math.Max(0, Math.Min(linear, 1));
            var brightness = Limit(Math.Log2(1 + linear));

            brightness = 1;
            return(brightness);
        }
        private void ConfigureColors(AnalysisResult result, LedColor[] colors, ColorRange range)
        {
            double[] dbfs;
            double   averageDbfs;
            double   linear;
            int      offsetIndex = result.GetIndex(range.Frequency.From);
            int      endIndex    = result.GetIndex(range.Frequency.To);

            dbfs = result.GetDBFS(offsetIndex, endIndex);

            averageDbfs = 0.0;
            foreach (var value in dbfs)
            {
                averageDbfs += value;
            }

            averageDbfs /= dbfs.Length;
            averageDbfs += Gain;

            linear = (averageDbfs - range.Minimum) / (range.Maximum - range.Minimum);
            if (!double.IsNormal(linear))
            {
                linear = 0;
            }

            linear = Math.Max(0, Math.Min(linear, 1));

            var maxFreq   = range.Frequency.To;
            int ledOffset = (int)(Math.Round(range.LedFrom * _controller.LEDCount));
            int ledCount  = (int)(Math.Round((range.LedTo - range.LedFrom) * _controller.LEDCount));

            if (ledOffset + ledCount >= colors.Length)
            {
                ledCount = colors.Length - ledOffset;
            }

            int ledEndIndex = ledOffset + ledCount - 1;

            var overlay     = range.Overlay ?? new LedColor(1, 1, 1);
            var peakOverlay = range.PeakOverlay ?? new LedColor(1, 1, 1);

            for (int i = ledOffset; i <= ledEndIndex; i++)
            {
                colors[i] += Color * overlay * linear;
            }

            if (UsePeakDetection)
            {
                var    peaks = result.GetPeaks(offsetIndex, endIndex);
                double peakDbfs;
                foreach (var peak in peaks)
                {
                    peakDbfs = dbfs[peak.Key] + Gain;

                    linear = (peakDbfs - range.Minimum) / (range.Maximum - range.Minimum);
                    if (!double.IsNormal(linear))
                    {
                        linear = 0;
                    }

                    linear = Math.Max(0, Math.Min(linear, 1));

                    var index = GetLedIndex(maxFreq, range.Frequency.From, peak.Value, ledOffset, ledCount);
                    colors[index] += PeakColor * peakOverlay * linear * PeakBrightness;
                }
            }
        }