CSoundResource::ParseWave() function termination

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • CSoundResource::ParseWave() function termination

      I found the book by accident and it's one of the best books I've ever read. I'm not a very experienced Programmer yet, so please forgive me if the following question is stupid.

      The termination criterion for the while-loop in the CSoundResource::ParseWave() function is

      if (m_PCMBuffer && m_PCMBufferSize != 0) return true;

      This only checks if the data-block has been read. Since it is mentioned in the comment before the while loop, that the fmt-block can be placed behind the data block in the .wav-file, I think it is not enough. One could initialize m_WavFormatEx to zero before the while loop

      memset(&m_WavFormatEx, 0, sizeof(WAVEFORMATEX));

      and add it to the check

      if ((m_PCMBuffer && m_PCMBufferSize != 0 && m_WavFormatEx) return true;

      I'm not sure if this is necessary so I'm looking forward to any answer.

      Tanks alot.
    • You should definitely check that you've found the wave format chunk, using something like this.

      // assuming m_WaveFormatEx is a pointer...
      if( (m_PCMBuffer != 0 ) && (m_PCMBufferSize != 0) && (m_WavFormatEx != 0 ) ) return true;

      Also bear in mind that multiple data and format chunks are valid in a single wave file (although this is rarely the case). You might want a way of dealing with this.

      Hope this helped, please post back if you're unsure.

      The post was edited 1 time, last by beebs1 ().

    • m_WavFormatEx isn't a pointer - so you can't check it that way....
      Mr.Mike
      Author, Programmer, Brewer, Patriot