コード例 #1
0
        public unsafe void Render(float *powerSpectrum, int length)
        {
            if (_scaledPowerSpectrum == null || _scaledPowerSpectrum.Length != length)
            {
                _scaledPowerSpectrum = new byte[length];
            }

            fixed(byte *scaledPowerSpectrumPtr = _scaledPowerSpectrum)
            {
                var displayOffset = _displayOffset / 10 * 10;
                var displayRange  = _displayRange / 10 * 10;

                Fourier.ScaleFFT(powerSpectrum, scaledPowerSpectrumPtr, length, displayOffset - displayRange, displayOffset);
            }

            var scaledLength = (int)(length / _scale);
            var offset       = (int)((length - scaledLength) / 2.0 + length * (double)(_displayCenterFrequency - _centerFrequency) / _spectrumWidth);

            if (_useSmoothing)
            {
                Fourier.SmoothCopy(_scaledPowerSpectrum, _temp, length, _scale, offset);
                for (var i = 0; i < _powerSpectrum.Length; i++)
                {
                    var ratio = _powerSpectrum[i] < _temp[i] ? Attack : Decay;
                    _powerSpectrum[i] = (byte)Math.Round(_powerSpectrum[i] * (1 - ratio) + _temp[i] * ratio);
                }
            }
            else
            {
                Fourier.SmoothCopy(_scaledPowerSpectrum, _powerSpectrum, length, _scale, offset);
            }

            Draw();
            InvalidateVisual();
        }
コード例 #2
0
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);

            Rectangle ClientRectangle = new Rectangle(0, 0, (int)RenderSize.Width, (int)RenderSize.Height);

            if (ClientRectangle.Width == 0 || ClientRectangle.Height == 0)
            {
                return;
            }

            if (_initialized)
            {
                _buffer.Dispose();
                _graphics.Dispose();
                _bkgBuffer.Dispose();
                _gradientBrush.Dispose();
            }
            else
            {
                ApplyZoom();
            }

            _buffer = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppPArgb);

            _graphics = Graphics.FromImage(_buffer);
            ConfigureGraphics(_graphics);

            _bkgBuffer = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppPArgb);
            var length      = ClientRectangle.Width - 2 * AxisMargin;
            var oldSpectrum = _spectrum;

            _maxSpectrum = new byte[length];
            _spectrum    = new byte[length];
            _peaks       = new bool[length];
            if (oldSpectrum != null)
            {
                Fourier.SmoothCopy(oldSpectrum, _spectrum, oldSpectrum.Length, 1, 0);
            }
            else
            {
                for (var i = 0; i < _spectrum.Length; i++)
                {
                    _spectrum[i] = 0;
                }
            }
            _temp   = new byte[length];
            _points = new System.Drawing.Point[length + 2];
            if (_spectrumWidth > 0)
            {
                _xIncrement = _scale * (ClientRectangle.Width - 2 * AxisMargin) / _spectrumWidth;
            }

            _gradientBrush = new LinearGradientBrush(new Rectangle(AxisMargin, AxisMargin, ClientRectangle.Width - AxisMargin, ClientRectangle.Height - AxisMargin), Color.White, Color.Black, LinearGradientMode.Vertical);
            _gradientBrush.InterpolationColors = _gradientColorBlend;
            _writeableBitmap = new WriteableBitmap(ClientRectangle.Width, ClientRectangle.Height, _buffer.HorizontalResolution, _buffer.VerticalResolution, System.Windows.Media.PixelFormats.Bgr32, null);
            _initialized     = true;

            _drawBackgroundNeeded = true;
            Perform();
        }
コード例 #3
0
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);

            Rectangle ClientRectangle = new Rectangle(0, 0, (int)RenderSize.Width, (int)RenderSize.Height);

            if (ClientRectangle.Width <= AxisMargin || ClientRectangle.Height <= AxisMargin)
            {
                return;
            }

            if (!_initialized)
            {
                _powerSpectrum = new byte[ClientRectangle.Width - 2 * AxisMargin];
                _temp          = new byte[_powerSpectrum.Length];
                _buffer        = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppPArgb);
                _buffer2       = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppPArgb);
                _graphics      = Graphics.FromImage(_buffer);
                _graphics2     = Graphics.FromImage(_buffer2);
                _gradientBrush = new LinearGradientBrush(new Rectangle(AxisMargin / 2, AxisMargin / 2, ClientRectangle.Width - AxisMargin / 2, ClientRectangle.Height - AxisMargin / 2), Color.White, Color.Black, LinearGradientMode.Vertical);
                _gradientBrush.InterpolationColors = _gradientColorBlend;
                _writeableBitmap = new WriteableBitmap(ClientRectangle.Width, ClientRectangle.Height, _buffer.HorizontalResolution, _buffer.VerticalResolution, System.Windows.Media.PixelFormats.Bgr32, null);
                _initialized     = true;

                ApplyZoom();
            }
            else
            {
                var temp = new byte[ClientRectangle.Width - 2 * AxisMargin];
                Fourier.SmoothCopy(_powerSpectrum, temp, _powerSpectrum.Length, (_temp.Length + temp.Length) / (float)_temp.Length, 0);
                _powerSpectrum = temp;
                _temp          = new byte[_powerSpectrum.Length];

                var oldBuffer = _buffer;
                _buffer = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppPArgb);
                var oldBuffer2 = _buffer2;
                _buffer2 = new Bitmap(ClientRectangle.Width, ClientRectangle.Height, PixelFormat.Format32bppPArgb);

                _writeableBitmap = new WriteableBitmap(ClientRectangle.Width, ClientRectangle.Height, _buffer.HorizontalResolution, _buffer.VerticalResolution, System.Windows.Media.PixelFormats.Bgr32, null);

                _graphics.Dispose();
                _graphics = Graphics.FromImage(_buffer);
                ConfigureGraphics(_graphics);

                _graphics2.Dispose();
                _graphics2 = Graphics.FromImage(_buffer2);
                ConfigureGraphics(_graphics2);

                _graphics.Clear(Color.Black);
                var rect = new Rectangle(AxisMargin, 0, _buffer.Width - 2 * AxisMargin, _buffer.Height);
                _graphics.DrawImage(oldBuffer, rect, AxisMargin, 0, oldBuffer.Width - 2 * AxisMargin, oldBuffer.Height, GraphicsUnit.Pixel);
                oldBuffer.Dispose();
                oldBuffer2.Dispose();
                if (_spectrumWidth > 0)
                {
                    _xIncrement = _scale * (ClientRectangle.Width - 2 * AxisMargin) / _spectrumWidth;
                }
                _gradientBrush.Dispose();
                _gradientBrush  = new LinearGradientBrush(new Rectangle(AxisMargin / 2, AxisMargin / 2, ClientRectangle.Width - AxisMargin / 2, ClientRectangle.Height - AxisMargin / 2), Color.White, Color.Black, LinearGradientMode.Vertical);
                _gradientPixels = null;
                _gradientBrush.InterpolationColors = _gradientColorBlend;
            }

            GC.Collect();

            DrawGradient();
            BuildGradientVector();
            _performNeeded = true;
            var oldMouseIn = _mouseIn;

            _mouseIn = true;
            Perform();
            _mouseIn = oldMouseIn;
        }