DEPARTMENT OF COMPUTING

CS 3005: Programming in C++

WAV File Output

This is a continuation of the previous assignment. Please read the instructions there and complete the required programming tasks before starting this assignment.

Introduction

A WAV file is a file format that can be used to store sound data. It is actually a specific use of the RIFF file format. The WAV file consists of single RIFF chuck, that contains the “RIFF” header, a “fmt ” sub-chunk and a “data” sub-chunk. The “RIFF” header describes the file format, and the “fmt ” sub-chunk contains information about the audio format, such as the number of channels, and the “data” sub-chunk contains the actual audio data.

RIFF Header

The “RIFF” header has three pieces of information.

“fmt ” Sub-chunk

The “fmt ” sub-chunk contains information about the audio format, such as the number of channels, and the sample rate. Each of the properties has a specific size and order. Below we describe each of them.

Property Type Size Description
SubchunkID char 4 “fmt “
SubchunkSize int 4 the number of bytes in this subchunk that follow this field. In other words, 16.
AudioFormat int 2 For PCM formats, the value should be 1.
NumChannels int 2 The number of channels, 1 for mono, 2 for stereo.
SampleRate int 4 The number of samples per second. (44100 for “CD Quality”)
ByteRate int 4 The number of bytes per second. SampleRate * NumChannels * BitsPerSample/8.
BlockAlign int 2 The number of bytes per sample, including all channels. NumChannels * BitsPerSample/8.
BitsPerSample int 2 The number of bits per sample, per channel.

We want ByteRate and BlockAlign to be an integers, so we will only allow BitsPerSample to be multiples of 8.

“data” Sub-chunk

This block contains the actual sound data. There is a small header at the beginning of the sub-chunk.

Property Type Size Description
SubchunkID char 4 “data”
SubchunkSize int 4 the number of bytes in the file that follow this field. In other words, the number of bytes in the file minus 44.

This header is followed by the actual sound data. The first sample is written for all channels. Followed by the second sample for all channels, etc.

The maximum integer value depends on the bits per sample. If there are 8 bits, then the maximum integer value is 127. This is the value achieved by setting all but the most significant bit in the integer to 1. Likewise, if there are 16 bits, then the maximum integer value is 32767. For 24 and 32 bits per sample the maximum values are 8388607 and 2147483647.

Assignment

In this assignment, you will finish creating a class, WAVFile that supports the writing of WAV files.

Programming Requirements

Depends on the AudioTrack class. Depends on the endian_io module. Depends on the WAVFile class started in the previous assignment.

Update library-audiofiles/WAVFile.{h,cpp}

WAVFile Class

Data Members:

The WAVFile class should contain data members to track the following information. These data members should be protected or private. They are not allowed to be public.

public Methods:

protected Methods:

Additional Documentation

Grading Instructions

To receive credit for this assignment:

Extra Challenges (Not Required)

Describe possible additions and extensions that could be added without breaking the expected functionality. Careful not to give away too many possible exam tasks.

Last Updated 09/16/2024