I'm using WaveViewer to show wave file while playback and WavePainter to show waveFile while recording. And in some my post on this forum I have described everything.
Use dataAvailable event:
private void input_DataAvailable(object sender, NAudio.Wave.WaveInEventArgs e) { if (OnVolumePeak != null) { float max = 0; float min = 0; for (int index = 0; index < e.BytesRecorded; index += 2) { short sample = (short)((e.Buffer[index+1]<<8) | (e.Buffer[index]) ); float sample32 = sample / 32768f; max = Math.Max(sample32, max); min = Math.Min(sample32, min); } OnVolumePeak(this, max, min); } if (_state == State.RECORDING) { if (waveWriter != null) { waveWriter.WriteData(e.Buffer, 0, e.BytesRecorded); waveWriter.Flush(); } memStream.Write(e.Buffer, 0, e.BytesRecorded); } }
OnVolumePeak is my event. You can treat is as an ordinary method.
It looks like that:
public void am_OnVolumePeak(object Sender, float max, float min) { max = Math.Max(max, Math.Abs(min)); wavePainter.AddMax(max); }
When you want to show waveform of existing wave file, WaveViewer has a property called WaveStream.