如何只绘制一个频道。我的例子适用于单声道,但声音是立体声。我想在这里只显示左侧或右侧通道。
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循环中改变这个,我得到了不同的图形,但不正确。我该如何解决这个问题?
答案 0 :(得分:0)
使用WaveWiever Painter。实时工作和两个渠道。