c++audiowavriff

Can 8-bit (bits per sample) PCM WAV files contain more than one channel?


I realized it is bad for me to neglect this thought, because I haven't read anything about number of channels and bits per sample in this light. My reason is that I'm not sure how the samples of 2-channel 8-bit PCM files will look like.

Is it 1 sample = 1 channel? or 1 sample = 4 bits (left) + 4 bits (right)

Context: I am writing a program that reads WAV files, and it occurred to me that if I come across 8-bit PCM WAV files, and my code reads this way (see below), then my program is unable to properly read multi-channel 8-bit PCM WAV files.


// read actual audio data after obtaining
// the headers
// audioData is a vector of vectors (1 vector per channel)
uint32_t temp;
while( !feof(wavFile) ) {
    for(uint16_t i = 0; i < numChannels; i++) {
        temp = 0;
        fread(&temp,sizeof(uint8_t),1,wavFile);
        audioData.at(i).push_back(temp); 
    }
}

Solution

  • The structure, which typically describes format of WAV audio data, is described in MSDN here: WAVEFORMATEX structure:

    That is, two channel file with 8 bits per sample has nSamplesPerSec pairs for each second of audio data, each pair includes two 8-bit values for every channel of the two.

    (here is an example of where this structure exists in the WAV file - though this is a more complicated case with 24-bits/sample, but you should get the idea).