Пример #1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            double[] newAudio = listener.GetNewAudio();
            spec.Add(newAudio, process: false);

            double multiplier = tbBrightness.Value / 20.0;

            if (spec.FftsToProcess > 0)
            {
                Stopwatch sw = Stopwatch.StartNew();
                spec.Process();
                spec.SetFixedWidth(pbSpectrogram.Width);
                Bitmap bmpSpec = new Bitmap(spec.Width, spec.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
                using (var bmpSpecIndexed = spec.GetBitmap(multiplier, cbDecibels.Checked, cbRoll.Checked))
                    using (var gfx = Graphics.FromImage(bmpSpec))
                        using (var pen = new Pen(Color.White))
                        {
                            gfx.DrawImage(bmpSpecIndexed, 0, 0);
                            if (cbRoll.Checked)
                            {
                                gfx.DrawLine(pen, spec.NextColumnIndex, 0, spec.NextColumnIndex, pbSpectrogram.Height);
                            }
                        }
                sw.Stop();
                pbSpectrogram.Image?.Dispose();
                pbSpectrogram.Image = bmpSpec;
                lblStatus3.Text     = $"Render time: {sw.ElapsedMilliseconds:D2} ms";
                lblStatus4.Text     = $"Peak (Hz): {spec.GetPeak().freqHz:N0}";
            }

            lblStatus1.Text   = $"Time: {listener.TotalTimeSec:N3} sec";
            lblStatus2.Text   = $"FFTs processed: {spec.FftsProcessed:N0}";
            pbAmplitude.Value = (int)(listener.AmplitudeFrac * pbAmplitude.Maximum);
        }