Example #1
0
        protected void OnVisualizationUpdated(VisualizationUpdatedEventArgs e)
        {
            var handler = VisualizationUpdated;

            if (handler != null)
            {
                VisualizationUpdated(this, e);
            }
        }
Example #2
0
        void model_VisualizationUpdated(object sender, VisualizationUpdatedEventArgs e)
        {
            //Dispatcher.Invoke(() =>
            //{

            var dc = dv.RenderOpen();


            if (dpiX == 0 || dpiY == 0)
            {
                PresentationSource src = PresentationSource.FromVisual(this);
                dpiX = 96 * src.CompositionTarget.TransformToDevice.M11;
                dpiY = 96 * src.CompositionTarget.TransformToDevice.M22;
            }

            var width  = vis.ActualWidth;
            var height = vis.ActualHeight;

            int numPoints = 64;
            int skip      = e.SampleBuffer.Length / numPoints;

            double lineSpacing = (width / (numPoints)); //256 points
            double startX      = 0;
            double startY      = (height / 2);

            //dc.Draw

            //for now, we will only work with waveform
            for (var x = 0; x < numPoints; x++)
            {
                float scale = (1 / ((float)(height / 64)));
                float data1 = e.SampleBuffer[x * skip] / scale;
                float data2 = e.SampleBuffer[(x * skip) + 1] / scale;

                var data = (data1 + data2) / 2;//

                double endX = startX + lineSpacing;
                double endY = startY + data;

                dc.DrawLine(
                    pen,
                    new System.Windows.Point(startX, startY),
                    new System.Windows.Point(endX, endY)
                    );

                //next start is last end
                startX = endX;
                startY = endY;
            }


            //get ready to display
            dc.Close();
            //if (bmp == null || bmp.Width != (int)width || bmp.Height != (int)height)
            {
                bmp = new RenderTargetBitmap((int)width, (int)height, dpiX, dpiY, PixelFormats.Pbgra32);
            }

            bmp.Render(dv);
            vimg.Source = bmp;

            //}, System.Windows.Threading.DispatcherPriority.Render);
        }