back

Lecture 5 (02.20.21) - Wave File Format

Recorded Lecture

Finish These Before You Leave

  1. Download the starter code for the Wave Parser.
  2. Edit the Makefile according to your OS.
  3. Set up your C++ environment.
  4. Compile the starter code.

Setting Up a C++ Environment

Unix

If you are on a Unix OS like MacOS or Linux, this will be very easy. Just follow this tutorial.

Windows

If you are on Windows, it will be a bit harder:

Now open Bash. You should be able to run $ g++ and $ make. Test both commands and debug as needed.

Wave Parser Code

To compile the code, just run
$ make

If you are on Windows and do not have make installed, you can use this command:
$ g++ -o main main.cpp wave.cpp riff.cpp --std=c++11 -Wall -lws2_32

Wave File Format

Wave File Format

Endianness

Some computers store numbers in reverse order than one would expect. Observe the diagrams:

Endian Endian Pig

There are pros and cons of using each encoding, however the biggest con is that no one can agree on a standard. Therefore, we must waste lots of energy converting between endians.

Fortunately, all operating systems provide the functions “host to network” and “network to host” (hton() and ntoh()). Since all network traffic must use big endian, we now have a guaranteed function that will always give us a big endian output. Then we can just swap the endian to get little endian, the encoding for Wave files.