Question

I am working on a project using DirectSound and am trying to make it so that the header information for the sound file is passed to the processing method. WAV files have a RIFF chunkID at the start. In a call to the ProcessWaveFile method, I pass the filepath as well as the header information. The 'RIFF' chunkID is stored in a char. I need to be able to check individual characters of the chunkID against the actual file chunkID to ensure the file is correct. This is a snippet of my code:

    if((waveFileHeader.chunkId[0] != chunkID[0]) || (waveFileHeader.chunkId[1] != chunkID[1]) ||
    (waveFileHeader.chunkId[2] != chunkID[2]) || (waveFileHeader.chunkId[3] != chunkID[3]))
{
    MessageBox(hwnd, L"ChunkID not in the right Format.", L"Error", MB_OK);
    return false;
}

chunkId is the file's actual ID whereas chunkID is the ID passed through the function to check. As you can see I'm trying to handle it like an array here. The chunkId is stored in a char[]. Should I store the chunkID in an array too? How would I specify it?

    bool ProcessWaveFile(char*, IDirectSoundBuffer8**, HWND, int, char, char, char, char, std::string, int, int);

Above is the header file line for the ProcessWaveFile method. The chunkID is specified as one of the chars. I could change it to char[] but the difficulty comes when actually calling the method. Here is an example call:

    result1 = ProcessWaveFile("../terrain_sky/data/sound01.wav", &m_secondaryBuffer1, hwnd,
    44100, 'RIFF', 'fmt ', 'WAVE', 'data', "WAVE_PCM_FORMAT", 16, 2);

How could I declare the array values containg RIFF in this call without disrupting the chain of variables?

Was it helpful?

Solution

If you are looking for a convenient way to check that the file starts with 'RIFF', there may be a more convenient way for you to find out. Since the ChunkID is 4 bytes long, you may want to store what you expect 'RIFF' in a datatype that is also 4 bytes long (instead of a char array of length 4), then parse the first four bytes as, for example, an int.

I have a wav file that starts with RIFF here, here's what number you get when you interpret the first four bytes as an int.

od -ci -N4 ./test.wav
0000000  R   I   F   F
            1179011410

So the option -ci first prints each byte as its ASCII equivalent (RIFF), and then prints each set of 4 bytes as an integer. So really, 1179011410 = 'RIFF' and the integer may be easier for you to check for.

But as an aside, I'm not really sure why you need to pass 'RIFF' into the ProcessWaveFile() function. If you only ever deal with RIFF files, you might get away with having that information stored in the ProcessWaveFile() function itself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top