// get the RIFF header
int riffSignature = m_spIO.readInt();
int goalSignature = ('R' << 24) | ('I' << 16) | ('F' << 8) | ('F');
if (riffSignature != goalSignature)
throw new JMACException("Invalid Input File");
m_spIO.readInt();
// read the data type header
int dataTypeSignature = m_spIO.readInt();
goalSignature = ('W' << 24) | ('A' << 16) | ('V' << 8) | ('E');
// make sure it's the right data type
if (dataTypeSignature != goalSignature)
throw new JMACException("Invalid Input File");
// find the 'fmt ' chunk
RiffChunkHeader RIFFChunkHeader = new RiffChunkHeader();
RIFFChunkHeader.read(m_spIO);
goalSignature = (' ' << 24) | ('t' << 16) | ('m' << 8) | ('f');
while (RIFFChunkHeader.cChunkLabel != goalSignature) {
// move the file pointer to the end of this chunk
m_spIO.seek(m_spIO.getFilePointer() + RIFFChunkHeader.nChunkBytes);
// check again for the data chunk
RIFFChunkHeader.read(m_spIO);
}
// read the format info
WaveFormat WAVFormatHeader = new WaveFormat();
WAVFormatHeader.readHeader(m_spIO);
// error check the header to see if we support it
if (WAVFormatHeader.wFormatTag != 1)
throw new JMACException("Invalid Input File");
// copy the format information to the WAVEFORMATEX passed in
WaveFormat.FillWaveFormatEx(m_wfeSource, WAVFormatHeader.nSamplesPerSec, WAVFormatHeader.wBitsPerSample, WAVFormatHeader.nChannels);
// skip over any extra data in the header
int nWAVFormatHeaderExtra = (int) (RIFFChunkHeader.nChunkBytes - WaveFormat.WAV_HEADER_SIZE);
if (nWAVFormatHeaderExtra < 0)
throw new JMACException("Invalid Input File");
else
m_spIO.seek(m_spIO.getFilePointer() + nWAVFormatHeaderExtra);
// find the data chunk
RIFFChunkHeader.read(m_spIO);
goalSignature = ('a' << 24) | ('t' << 16) | ('a' << 8) | ('d');
while (RIFFChunkHeader.cChunkLabel != goalSignature) {
// move the file pointer to the end of this chunk
m_spIO.seek(m_spIO.getFilePointer() + RIFFChunkHeader.nChunkBytes);
// check again for the data chunk
RIFFChunkHeader.read(m_spIO);
}
// we're at the data block
m_nHeaderBytes = (int) m_spIO.getFilePointer();
m_nDataBytes = (int) RIFFChunkHeader.nChunkBytes;
if (m_nDataBytes < 0)
m_nDataBytes = m_nFileBytes - m_nHeaderBytes;
// make sure the data bytes is a whole number of blocks
if ((m_nDataBytes % m_wfeSource.nBlockAlign) != 0)
throw new JMACException("Invalid Input File");
// calculate the terminating byts
m_nTerminatingBytes = m_nFileBytes - m_nDataBytes - m_nHeaderBytes;
}