在 WaveViever - Naudio 中显示每个通道

Show each channel in WaveViever - Naudio

如何只绘制一个通道。我的示例适用于单声道,但声音是立体声。我想在这里只显示左声道或只显示右声道。

protected override void OnPaint(PaintEventArgs e)
    {
        if (waveStream != null)
        {
            waveStream.Position = 0;
            int bytesRead;
            byte[] waveData = new byte[samplesPerPixel * bytesPerSample];
            waveStream.Position = startPosition + (e.ClipRectangle.Left * bytesPerSample * samplesPerPixel);

            using (Pen linePen = new Pen(PenColor, PenWidth))
            {
                for (float x = e.ClipRectangle.X; x < e.ClipRectangle.Right; x += 1)
                {
                    short low = 0;
                    short high = 0;

                    bytesRead = waveStream.Read(waveData, 0, samplesPerPixel * bytesPerSample);
                    if (bytesRead == 0)
                        break;
                    for (int n = 0; n < bytesRead; n+=2)
                    {
                        short sample = BitConverter.ToInt16(waveData, n);
                        if (sample < low) low = sample;
                        if (sample > high) high = sample;
                    }
                    float lowPercent = ((((float)low) - short.MinValue) / ushort.MaxValue);
                    float highPercent = ((((float)high) - short.MinValue) / ushort.MaxValue);
                    e.Graphics.DrawLine(linePen, x, this.Height * lowPercent, x, this.Height * highPercent);
                }
            }
        }

        base.OnPaint(e);
    }

我读了,第一个频道是 1-3-5...,第二个频道是 2-4-6...。但是如果在 for 循环中改变这个,我会得到不同的图表,但不正确。我该如何解决?

使用 WaveWiever Painter。实时和两个通道工作。