![]() |
Multimedia »
Audio and Video »
Audio
Intermediate
WaveControlBy pj4533A user control for displaying .WAV files using C# |
C#.NET 1.1, Win2K, WinXPVS.NET2003, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

WaveControl is based on the WaveFile class that I wrote in another article. This user control uses that class for parsing of the wave file, and the control itself handles all the drawing/zooming of the waveform.
Using the control in your own applications is very simple.
WaveControl should be available for addition to your forms from the 'My User Controls' toolbox. I am in the process of learning VS.NET & C#, so this might not have been the easiest way to create a reusable control, but it does work. I look forward to other suggestions readers might have.
When I wrote the WaveFile article and first tried to display a waveform, I was getting very poor performance when drawing larger wave files. It was pointed out that this was because I was using PageScale to scale the drawing to something usable. However, this caused much more drawing than was actually necessary. So, in this version I find the max/min peaks for each X value that is being drawn, and draw a line between them, as shown here:
for ( int x = 0; x < m_SamplesPerPixel; x++ ) { maxVal = Math.Max( maxVal, m_Wavefile.Data[ x + index ] ); minVal = Math.Min( minVal, m_Wavefile.Data[ x + index ] ); } int scaledMinVal = (int) (( (minVal + 32768) * visBounds.Height ) / 65536 ); int scaledMaxVal = (int) (( (maxVal + 32768) * visBounds.Height ) / 65536 );
Things that need fixing/changing:
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 22 Aug 2003 Editor: Smitha Vijayan |
Copyright 2003 by pj4533 Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |