This project has moved. For the latest updates, please go here.

Using NAudio.GUI.WaveViewer

Dec 8, 2011 at 2:16 PM

Hi, can someone tell me how to use WaveViewer? I don't think I'm using it properly.

I want to record voice and show its waveform while recording. Now I am using waveFormPainter, but this control "erases" waveform while scrolling.
So I want to use waveViewer which I think shows all the wave and scrollbar if needed(?).

So far I'm doing something like VoiceRecorder. While recording, I'm showing the waveform using WaveFormPainter. When recording is finished I want to show all the wave in WaveViewer. Unfortunately VoiceRecorder is WPF application(and my is windows form) and it doesn't use WaveViewer.

So now I'm adding every read buffer to memory stream:

private void input_DataAvailable(object sender, WaveInEventArgs e)
    //some code here

    memStream.Write(e.Buffer, 0, e.BytesRecorded);


and then after the recording is stopped I do something like that:

rawSource = new RawSourceWaveStream(memStream, input.WaveFormat);
waveViewer.WaveStream = rawSource;


The wave is showed, but... I noticed some things. This waveform was completely different than this one in waveFormPainter. I noticed that this is connected with SamplesPerPixel property of WaveViewer. So I tried some values and it occured that 2048 gives me rather the same waveform(why?). BUT. When this wave form is longer than control width it is being scaled I thing, so it looks completely different again ;)
I expected WaveViever to give me the same waveform as waveFormPainter and scrollbar if needed. So am I doing something wrong, or just this control works like that?


Dec 12, 2011 at 10:37 AM

they do both use slightly different ways of drawing the waveform. There is no reason why you couldn't make a WPF one that uses the same tehcnique as waveFormPainter (which just draws vertical lines representing the loudest sample out of the samples for that pixel).