Google Answers Logo
View Question
 
Q: Displaying a waveform ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Displaying a waveform
Category: Computers > Algorithms
Asked by: waterjock2000-ga
List Price: $20.00
Posted: 17 Sep 2002 08:50 PDT
Expires: 17 Oct 2002 08:50 PDT
Question ID: 66003
I need to display an audio waveform (.wav file) graphically.   I don't
need the actual graphics routines, but need to understand the math for
generating the graph points.

An example of a waveform graph:
http://www-classes.usc.edu/engr/ee-ep/519/homework/WaveForm.JPG

A link to a solid example in C++ or explaination of the math would be
sufficient.
Answer  
Subject: Re: Displaying a waveform
Answered By: eiffel-ga on 17 Sep 2002 09:33 PDT
Rated:5 out of 5 stars
 
Hi waterjock2000,

To display an audio waveform you must extract the individual audio
samples from the .wav file, then plot them graphically.

The .wav file is in RIFF format, and comprises a number of nested
"chunks". The outer chunk identifies the file as RIFF format. Within
that chunk is a WAVE chunk, which includes a format header chunk and
an audio data chunk. Other chunks, such as text comments and copyright
data, may also be present.

The format header chunk specifies the number of channels, the sampling
rate, and number of bits per sample, and some other housekeeping
information. In the basic .wav format, the audio data is Pulse Code
Modulated (PCM). However, other codings are also possible and can lead
to more compact .wav files.

The .wav file format is described informally but clearly by Don Cross:

"Reading and Writing WAV files"
http://www.intersrv.com/~dcross/wavio.html

Don Cross also offers source code in Turbo Pascal and C++ which can be
used to read or write PCM-encoded .wav files. There's a sample
application which takes a text file of numbers and creates a .wav file
based on it. Your application is pretty much the reverse of this -
taking a .wav file and extracting a bunch of numbers from it (which
you will then plot). The source code and example can be downloaded
from the above link.

More detailed descriptions of the file format are available from:

Wotsit's Format:
http://www.wotsit.org/
(type WAV into the search box then scroll down to the three WAV
documents)

Another source of C++ code to read the audio data from .wav files is
here:

Shoecake.com (Yung-hsiang Lee)
http://www.shoecake.com/files/docs/wav.html

Happy waveform plotting!


Additional Links:

The Audio File Format FAQ
(includes u-law and A-law formulae)
http://home.sprynet.com/~cbagwell/audio.html


Google search strategy:

"wav file" format
://www.google.com/search?q=%22wav%20file%22%20format

"reading wav files"
://www.google.com/search?q=%22reading+wav+files%22

"reading wav files" "sample OR source code"
://www.google.com/search?q=%22reading%20wav%20files%22%20%22sample%20OR%20source%20code%22


Regards,
eiffel-ga

Clarification of Answer by eiffel-ga on 17 Sep 2002 09:40 PDT
I might add that the Wotsit's Format site also has details of audio
(de)compression routines including ADPCM.

Request for Answer Clarification by waterjock2000-ga on 17 Sep 2002 10:03 PDT
Thank you very much for your answer...  Unfortunately it doesn't
actually answer the question of how to display the information.  I am
already reading in the wav data (I understand the RIFF format - I
admit that I wasn't very clear about this).  The problem is that when
I plot the raw data, it looks very odd.

There is some sort of interpretation that you have to do in order to
display the data as a meaningful graph.

Any further information would be greatly appreciated - thank you!

Clarification of Answer by eiffel-ga on 17 Sep 2002 12:31 PDT
Hi waterjock2000,

Thanks for your feedback. I'm sure that we can work out what further
processing you need to do, in order to get the kind of graph you want.
For now, I'll assume that you want your plot to look like the sample
plot that you posted a URL for.

Your sample plot has a resolution on the X-axis (the time axis) of
about 200 pixels per second, or one pixel per five milliseconds. To
replicate this appearance, you would calculate the minimum and maximum
audio sample during each 5ms of audio data, then plot these
minima/maxima with the line between each minimum/maximum filled in.
That way, for low frequency data (say 20Hz) you will see a
representation of the waveform, but for high frequency data you just
see the amplitude envelope.

Perhaps this is the additional information that you need? If not,
please post a more detailed explanation of the way in which your plot
"looks very odd" and I'll research it further. If you could post the
URL of an image file for your plot that would be even better!

Regards,
eiffel-ga
waterjock2000-ga rated this answer:5 out of 5 stars
I wasn't very clear in my question, but the response was very
thorough, prompt, and readable.  I will use this service again. 
Thanks!

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy