예제 #1
0
        private void RenderFFTScan(short[] samples)
        {
            Dispatcher.BeginInvoke(() =>
            {
                var height = (int)outputImage.Height;
                // var width = (int)outputImage.Width;
                byte[] frequencyPeaks = PeakMeter.CalculateFrequencies(samples, AudioFormat.Default.SamplesPerSecond);

                if (_fftScanIsCleared)
                {
                    ClearOutputBitmap();
                    _xRunningScanCounter = marginLeft;
                    _fftScanIsCleared    = false;
                }

                int bandTotal          = frequencyPeaks.Length;
                bool isAlternateColour = false;

                // Clear previous scan line
                _outputWriteableBitmap.DrawLine(_xRunningScanCounter, 0, _xRunningScanCounter, height, _clearColour);

                for (int x = 0; x < bandTotal; x++)
                {
                    int maximumPeak  = (frequencyPeaks[x] >> 1);
                    int baseOffsetY  = ((bandTotal - x) * 39);
                    _maximumPeaks[x] = ((_maximumPeaks[x] + maximumPeak) >> 1);
                    int offsetY      = (baseOffsetY - _maximumPeaks[x]);

                    int drawingColour = isAlternateColour ? _alternatePrimaryColour : _primaryColour;
                    isAlternateColour = !(isAlternateColour);

                    if (offsetY == baseOffsetY)
                    {
                        _outputWriteableBitmap.SetPixel(_xRunningScanCounter, baseOffsetY, drawingColour);
                    }
                    else
                    {
                        _outputWriteableBitmap.DrawLine(_xRunningScanCounter, offsetY, _xRunningScanCounter, baseOffsetY, drawingColour);
                    }
                }

                // Current Scanline
                _outputWriteableBitmap.DrawLine((_xRunningScanCounter + 1), 0, (_xRunningScanCounter + 1), height, _secondaryColour);

                _xRunningScanCounter++;
                if (_xRunningScanCounter >= _widthWithoutMarginRight)
                {
                    _outputWriteableBitmap.DrawLine(_xRunningScanCounter, 0, _xRunningScanCounter, height, _clearColour);
                    _xRunningScanCounter = marginLeft;
                }

                FlushOutputBitmap();
            });
        }
예제 #2
0
        private void RenderPeakMeter(short[] samples)
        {
            Dispatcher.BeginInvoke(() =>
            {
                int barSpacing        = 25;
                int barWidth          = (barSpacing - 8);
                int lineWidth         = (barWidth + 1);
                int leftOffset        = 60;
                byte[] frequencyPeaks = PeakMeter.CalculateFrequencies(samples, AudioFormat.Default.SamplesPerSecond);

                if (!(_clearEffectIsEnabled))
                {
                    ClearOutputBitmap();
                }

                const int baseY = 255;
                for (int x = 0; x < frequencyPeaks.Length; x++)
                {
                    int offsetX = (x * barSpacing) + leftOffset;
                    int offsetY = Convert.ToInt32(Math.Max(baseY - (frequencyPeaks[x] * VolumeFactor), 0));
                    // offsetY = baseY - frequencyPeaks[x];

                    _lastPeaks[x]    = CalculatePeakDelay(_lastPeaks[x], offsetY, 4, baseY);
                    _maximumPeaks[x] = CalculatePeakDelay(_maximumPeaks[x], offsetY, 2, baseY);

                    _outputWriteableBitmap.DrawFilledRectangle(offsetX, _lastPeaks[x], (offsetX + barWidth), baseY, _primaryColour);
                    // Only draw the maximum peak if it is above the empty bar level (cutoff)
                    if (_lastPeaks[x] < baseY)
                    {
                        _outputWriteableBitmap.DrawLine(offsetX, _maximumPeaks[x], (offsetX + lineWidth), _maximumPeaks[x], _secondaryColour);
                    }
                }

                if (_clearEffectIsEnabled)
                {
                    RunClearEffect();
                }

                FlushOutputBitmap();
            });
        }