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 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
|