Click here to Skip to main content
13,866,093 members
Click here to Skip to main content
Add your own
alternative version


32 bookmarked
Posted 22 Mar 2005

VB.NET Wav file graphical viewer control

, 22 Mar 2005
Rate this:
Please Sign up or sign in to vote.
A control to produce a graphical display of any 16bit PCM Wav file.


Firstly, I would like to acknowledge that the some of the methods for this control came from Steve McMahon's ( VB6 version, so, all the credit for the idea goes to him. The contribution I have made is to update the code for use in VB.NET 2003 and introduce a few additional elements. I should also mention that the WaveFile class used in the control is an extension of the one written by The KPD-Team.

The operation of the control is to provide a visual representation of both channels of a 16-bit PCM wav file, with variable zoom. (Future versions will hopefully support other bit sizes as well.) The full list of features is as follows:

  • Display 2-channel 16-bit wav file data.
  • Provide sample frequency data.
  • Provide bits per sample information.
  • Provide number of channels (see #).
  • Zoom control ranging from 24:1 to 1:16384.
  • Full control over the color used in the graphics.
  • Full control over the line forms used in the graphics.
  • Ability to run wav file data gathering function in a secondary thread for slow computers.
  • Events for all major operations available to host application.

# It will always have a result of 2 due to limitations of this version and will be more useful in later versions that will have support for mono wav files.

The project files provided along with this article include both the control code and a test application. It should be possible for most of you to follow how the code works, but here is a small guide:

  1. The control is set to default values when first inserted into the host application.
  2. The format for background and lines is determined by using the RenderWave sub.
  3. Main_Paint sub takes the information and displays the lines. Changes to any properties causes Renderwave to be called again and in turn Main_Paint.
  4. The file name is passed to the control from the host app using <name>.WaveFile=.
  5. This is passed to the WaveFile class where the file headers are stripped out and checked, make sure that the file is a valid wav file.
  6. The class sets up a data buffer, returns to the main control code.
  7. RenderWave is again called.
  8. If thread support has been enabled, the function WaveInfo is called via thread calls, otherwise it is called as a normal function. Either method triggers the RenderStart event.
  9. WaveInfo starts to read data from the wav file in blocks equal to the buffer length (0.1s).
  10. The number of samples plotted per block depends on the zoom factor.
  11. If you are using threading, RenderWave will finish. The callback function will cause Main_Paint to update once the data has been collected. Otherwise Renderwave will continue after the WaveInfo function has finished and in turn will call Main_Paint.
  12. Changing the zoom or moving the scroll bar will start the functions again.

The project, although useful in its own right, might also be useful for people wishing to learn more about:

  • GDI+
  • GraphicsPath
  • Marshal.Copy
  • Wave headers and Streaming
  • Control Properties and the "Visual Studio Property" descriptions and category options.
  • Unmanaged code
  • Structures

Please contact me if you have any questions or suggestions for improvement.

Updates to this article
  • Corrected spellings.
  • Inserted a new point "10" in the guide.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United Kingdom United Kingdom
Having done a four year Electronic Engineering Undergraduate course at the University of Warwick, I have now moved on to doing a PhD at the same place.

I am currently envolved in the use of signal processing in watermarking for copyright control.

I have always had a knack of picking up different programming languages quite easily but have not done much serious programming untill now.

You may also be interested in...


Comments and Discussions

Questionsend a zip code, please Pin
Member 923336224-Apr-14 3:39
memberMember 923336224-Apr-14 3:39 
QuestionCan it do 8-bit? Pin
Member 402649816-Jul-09 7:09
memberMember 402649816-Jul-09 7:09 
GeneralGenerating a tone Pin
jumpjack7-Jun-08 22:36
memberjumpjack7-Jun-08 22:36 
QuestionAnalog to digital converter? Pin
jumpjack19-May-08 8:49
memberjumpjack19-May-08 8:49 
GeneralC# usage and possible bug Pin
dnjuls9-Apr-08 23:04
memberdnjuls9-Apr-08 23:04 
GeneralRe: C# usage and possible bug Pin
Quenchmaster9-Apr-08 23:51
memberQuenchmaster9-Apr-08 23:51 
Generalmodify for only one chanel Pin
amiashu25-Jul-07 10:10
memberamiashu25-Jul-07 10:10 
QuestionFor a C++ Project? Pin
laserbeak4320-Mar-07 15:14
memberlaserbeak4320-Mar-07 15:14 
GeneralDrawing problems Pin
Enriad27-Nov-06 15:08
memberEnriad27-Nov-06 15:08 
GeneralRe: Drawing problems Pin
Quenchmaster28-Nov-06 1:42
memberQuenchmaster28-Nov-06 1:42 
Questionmono only? Pin
nicolas_gauthier8-Mar-06 6:43
membernicolas_gauthier8-Mar-06 6:43 
AnswerRe: mono only? Pin
Quenchmaster28-Nov-06 1:53
memberQuenchmaster28-Nov-06 1:53 
GeneralQuestions Pin
nicolas_gauthier17-Feb-06 5:29
membernicolas_gauthier17-Feb-06 5:29 
GeneralJust simply reading a wavefile Pin
Josh19911821-Oct-05 23:07
memberJosh19911821-Oct-05 23:07 
GeneralAn AN An ! Pin
Muhammad Masood Saleem30-Aug-05 10:32
memberMuhammad Masood Saleem30-Aug-05 10:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190214.1 | Last Updated 22 Mar 2005
Article Copyright 2005 by Quenchmaster
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid