Digital Sound & Music: Concepts, Applications, & Science, Chapter 5, last updated 6/25/2013
43
In WAV and AIFF, data are grouped in chunks. Let's look at the WAV format as an
example. The format chunk always comes first, containing information about the encoding
format, number of channels, sampling rate, data transfer rate, and byte alignment. The samples
are stored in the data chunk. The way in which the data is stored depends on whether the file is
compressed or not and the bit depth of the file. Optional chunks include the fact, cue, and
playlist chunks. To see this format firsthand, you could try taking a RAW audio file, converting
it to WAV or AIFF, and then see if it plays in an audio player.
More often, however, it is more to-the-point to use a higher level library that allows you
to read and write WAV and AIFF audio files. The libsndfile library serves this purpose. If you
install this library, you can read WAV or AIFF files into your C++ programs, manipulate them,
and write them back to permanent storage as WAV or AIFF files without needing to know the
detail of endian-ness or file formats. The website for libsndfile has example programs for you to
follow. Program 5.3 demonstrates the library with a simple program that opens a sound file
(e.g., WAV), reads the contents, reduces the amplitude by half, and writes the result back in the
same format.
Previous Page Next Page