Use of WaveViewer control with raw streams

Apr 24, 2012 at 5:17 PM

I am trying to use the WaveViewer control to visualize a raw stream with 8bit, 8k data. The issue I am having is that the WaveViewer displays a nearly all black waveform (appears like extreme clipping) that looks normal in Audacity. How do I control the appearance so that it looks as expected. I would also like to change the color of the graph if possible, but when I change the color property nothing happens.

private void ShowActivePhrase(string path)
        FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read);
        WaveFormat format = new WaveFormat(8000, 8, 1);
        WaveStream rawStream = new RawSourceWaveStream(file, format);
        waveViewer1.SamplesPerPixel = 24;
        waveViewer1.WaveStream = rawStream;

Apr 25, 2012 at 5:00 PM

I found the source code to the control and saw what my problem is. The control is expecting 16 bit data and I was feeding it 8 bit data. I used WaveFormatConversionStream plotStream = new WaveFormatConversionStream(new WaveFormat(8000, 16, 1), rawStream) to do the conversion and now it plots correctly. I also saw the control is hard coded to use a black pen so I will probably modify the control to use the forecolor.

I am very pleased with NAudio, it does everything I need, just wish there was more documentation available for newbies like myself.

Apr 26, 2012 at 4:00 PM

glad you got it working. Sorry about lack of documentation. NAudio is just a spare time hobby project for me and for the first 7 years I was the only person to use it, so there was no point writing reams of documentation. I try to regularly blog about NAudio, and the NAudioDemo project is the main place to go to see examples of the classes in real situations.


Apr 26, 2012 at 8:28 PM

I really appreciate your efforts to develop this and I think others who have a good handle on how to use the objects could help provide highly simplified code examples and class descriptions to distribute the documentation work. The YouTube videos by Giawa are a good example of this.