Exemplo n.º 1
0
        public WaveformDisplay()
        {
            UseLines   = true;
            MaxSamples = 10000;
            ZoomFactor = 1.0f;
            colorFG    = Color.Cyan;
            colorBG    = Color.Black;
            LinePen    = new Pen(colorFG);

            InitializeComponent();
            Image            = new Bitmap(Width, Height);
            ImageGraph       = Graphics.FromImage(Image);
            ImageBuffer      = new Bitmap(Width, Height);
            ImageBufferGraph = Graphics.FromImage(ImageBuffer);

            DisplayTimerState     = new DisplayFuncState();
            DisplayTimer          = new Timer();
            DisplayTimer.Elapsed += DisplayFunc;
            DisplayTimer.Interval = 20;
            DisplayTimer.Start();
        }
Exemplo n.º 2
0
        private void DisplayFunc(object state, ElapsedEventArgs e)
        {
            DisplayFuncState s = DisplayTimerState;

            lock (SampleValues)
            {
                ImageBufferGraph.Clear(colorBG);

                if (SampleValues.Count > 0)
                {
                    int startPos = StartSample;
                    int samples  = Width;

                    if (startPos + samples > SampleValues.Count)
                    {
                        startPos = SampleValues.Count - samples;
                    }

                    if (startPos < 0)
                    {
                        startPos = 0;
                        samples  = SampleValues.Count;
                    }

                    int lastX = 0;
                    int lastY = 0;

                    for (int pos = 0; pos < samples; pos++)
                    {
                        double sampleValue = (double)SampleValues[startPos + pos];
                        int    posX        = pos;
                        int    posY        = (int)(Height - (sampleValue * ZoomFactor * Height)) / 2;
                        posY = Math.Min(posY, Height - 1);
                        posY = Math.Max(posY, 0);


                        if (UseLines && pos > 0)
                        {
                            ImageBufferGraph.DrawLine(LinePen, lastX, lastY, posX, posY);
                        }
                        else
                        {
                            ImageBuffer.SetPixel(posX, posY, colorFG);
                        }

                        lastX = posX;
                        lastY = posY;
                    }

                    if (SampleValues.Count > MaxSamples)
                    {
                        int removeCount = SampleValues.Count - MaxSamples;
                        SampleValues.RemoveRange(0, removeCount);
                    }

                    if (ShowFPS)
                    {
                        if (s.FrameNumber++ > 500 && s.FrameNumber % 20 == 0)
                        {
                            s.FPS = s.FrameNumber / DateTime.Now.Subtract(s.StartTime).TotalSeconds;
                        }
                        ImageBufferGraph.DrawString("FPS: " + (int)s.FPS, s.TextFont, Brushes.Cyan, 10, 10);
                    }
                    if (!string.IsNullOrEmpty(DisplayName))
                    {
                        ImageBufferGraph.DrawString(DisplayName, s.TextFont, Brushes.Cyan, 10, 10);
                    }

                    double totalPhaseDiff = totalPhase - lastTotalPhase;
                    lastTotalPhase = totalPhase;

                    ImageBufferGraph.DrawString("\u03C6: " + String.Format("{0:0.00}", totalPhase), s.TextFont, Brushes.Cyan, 10, 30);
                    ImageBufferGraph.DrawString("\u0394\u03C6: " + String.Format("{0:0.00}", totalPhaseDiff), s.TextFont, Brushes.Cyan, 10, 50);

                    ImageGraph.DrawImageUnscaled(ImageBuffer, 0, 0);
                    Invalidate();
                }
            }
        }
Exemplo n.º 3
0
        private void DisplayFunc(object state, ElapsedEventArgs e)
        {
            DisplayFuncState s = DisplayState;

            lock (SampleValues)
            {
                if (SampleValues.Count > 0)
                {
                    ImageBufferGraph.Clear(colorBG);

                    double[] samples = (double[])SampleValues[0];
                    double   ratioX  = (double)Width / samples.Length;

                    if (ratioX >= 1.0f)
                    {
                        for (int pos = 0; pos < samples.Length; pos++)
                        {
                            double sampleValue = sampleToDBScale(samples[pos]);
                            int    posX        = (int)(pos * ratioX);
                            int    posY        = (int)(Height - sampleValue * Height) / 2;

                            posX = Math.Min(posX, Width - 1);
                            posX = Math.Max(posX, 0);
                            posY = Math.Min(posY, Height - 1);
                            posY = Math.Max(posY, 0);

                            LinePoints[pos].X = posX;
                            LinePoints[pos].Y = posY;

                            /*
                             * if (UseLines && pos > 0)
                             *  ImageBufferGraph.DrawLine(LinePen, lastX, lastY, posX, posY);
                             * else
                             *  ImageBuffer.SetPixel(posX, posY, colorFG);
                             *
                             * lastX = posX;
                             * lastY = posY;*/
                        }
                    }
                    else
                    {
                        for (int posX = 0; posX < Width; posX++)
                        {
                            int pos = (int)(posX / ratioX);
                            pos = Math.Min(pos, samples.Length - 1);
                            pos = Math.Max(pos, 0);

                            double sampleValue = sampleToDBScale(samples[pos]);
                            int    posY        = (int)(Height - sampleValue * Height) / 2;

                            posY = Math.Min(posY, Height - 1);
                            posY = Math.Max(posY, 0);

                            LinePoints[posX].X = posX;
                            LinePoints[posX].Y = posY;

                            /*
                             * if (UseLines && pos > 0)
                             *  ImageBufferGraph.DrawLine(LinePen, lastX, lastY, posX, posY);
                             * else
                             *  ImageBuffer.SetPixel(posX, posY, colorFG);
                             *
                             * lastX = posX;
                             * lastY = posY;
                             * */
                        }
                    }

                    ImageBufferGraph.DrawLines(LinePen, LinePoints);



                    SampleValues.Clear();

                    if (ShowFPS)
                    {
                        if (s.FrameNumber++ > 100 && s.FrameNumber % 20 == 0)
                        {
                            s.FPS = s.FrameNumber / DateTime.Now.Subtract(s.StartTime).TotalSeconds;
                        }
                        ImageBufferGraph.DrawString("FPS: " + (int)s.FPS, s.TextFont, Brushes.Cyan, 10, 10);
                    }

                    ImageGraph.DrawImageUnscaled(ImageBuffer, 0, 0);

                    Invalidate();
                }
            }
        }
Exemplo n.º 4
0
        private void DisplayFunc(object state, ElapsedEventArgs e)
        {
            DisplayFuncState s = DisplayState;

            lock (SampleValues)
            {
//                ImageBufferGraph.Clear(Color.Black);

                if (SampleValues.Count > 0)
                {
                    double[] samples = (double[])SampleValues[0];
                    double   ratioX  = (double)Width / samples.Length;
                    int      lastX   = 0;
                    int      lastY   = 0;

                    if (ratioX >= 1.0f)
                    {
                        for (int pos = 0; pos < samples.Length; pos++)
                        {
                            int posX = (int)(pos * ratioX);
                            int posY = WaterfallLine;

                            double sampleValue = sampleToDBScale(samples[pos]);
                            sampleValue *= 256;
                            sampleValue  = Math.Min(sampleValue, 255);
                            sampleValue  = Math.Max(sampleValue, 0);
                            Color color = ColorTable[(int)sampleValue];
                            Pen   pen   = PenTable[(int)sampleValue];

                            posX = Math.Min(posX, Width - 1);
                            posX = Math.Max(posX, 0);

                            if (pos > 0)
                            {
                                ImageBufferGraph.DrawLine(pen, lastX, lastY, posX, posY);
                            }
                            else
                            {
                                ImageBuffer.SetPixel(posX, posY, color);
                            }

                            lastX = posX;
                            lastY = posY;
                        }
                    }
                    else
                    {
                        for (int posX = 0; posX < Width; posX++)
                        {
                            int posY = WaterfallLine;

                            int pos = (int)(posX / ratioX);
                            pos = Math.Min(pos, samples.Length - 1);
                            pos = Math.Max(pos, 0);

                            double sampleValue = sampleToDBScale(samples[pos]);
                            sampleValue *= 256;
                            sampleValue  = Math.Min(sampleValue, 255);
                            sampleValue  = Math.Max(sampleValue, 0);
                            Color color = ColorTable[(int)sampleValue];
                            Pen   pen   = PenTable[(int)sampleValue];

                            if (pos > 0)
                            {
                                ImageBufferGraph.DrawLine(pen, lastX, lastY, posX, posY);
                            }
                            else
                            {
                                ImageBuffer.SetPixel(posX, posY, color);
                            }

                            lastX = posX;
                            lastY = posY;
                        }
                    }

                    SampleValues.Clear();

                    if (ShowFPS)
                    {
                        if (s.FrameNumber++ > 100 && s.FrameNumber % 20 == 0)
                        {
                            s.FPS = s.FrameNumber / DateTime.Now.Subtract(s.StartTime).TotalSeconds;
                        }
                        ImageBufferGraph.DrawString("FPS: " + (int)s.FPS, s.TextFont, Brushes.Cyan, 10, 10);
                    }

                    ImageGraph.DrawImage(ImageBuffer, 0, 0);
                    Invalidate();

                    /* scroll up for the next waterfall line */
                    if (++WaterfallLine > Height - 1)
                    {
                        WaterfallLine = Height - 1;

                        ImageBufferTmpGraph.DrawImage(ImageBuffer, ImageScrollRect, 0, 1, Width, Height - 1, GraphicsUnit.Pixel);
                        ImageBufferGraph.Clear(Color.Black);
                        ImageBufferGraph.DrawImage(ImageBufferTmp, 0, 0);
                    }
                }
            }
        }