This project has moved. For the latest updates, please go here.

No fmt Header exception when reading "bext" wave files

Oct 30, 2009 at 7:54 PM

I get an exception when I try to read an "bext" wave header file. I fixed it using the following code:

I thought you may want to change it in the source code too.

public static void ReadWaveHeader(Stream stream, out WaveFormat format, out long dataChunkPosition, out int dataChunkLength, List<RiffChunk> chunks)

{
      dataChunkPosition = -1;
      BinaryReader br = new BinaryReader(stream);
      int fmt = br.ReadInt32();
      if (fmt != WaveInterop.mmioStringToFOURCC("RIFF", 0))
      {
          throw new FormatException("Not a WAVE file - no RIFF header");
      }

      uint fileSize = br.ReadUInt32(); // read the file size (minus 8 bytes)
      fmt = br.ReadInt32();
      if (fmt != WaveInterop.mmioStringToFOURCC("WAVE", 0))
      {
           throw new FormatException("Not a WAVE file - no WAVE header");
      }

      fmt = br.ReadInt32();
      if (fmt == WaveInterop.mmioStringToFOURCC("bext", 0))
      {   // support "bext" wave files RBo. 10/29/09
          int dumpSize = br.ReadInt32();
          br.ReadBytes(dumpSize); // skip over the "bext" block
          fmt = br.ReadInt32();
      }

      // now we expect the format chunk
      if (fmt != WaveInterop.mmioStringToFOURCC("fmt ", 0))
      {
          throw new FormatException("Not a WAVE file - no fmt header");
      }
      format = new WaveFormatExtraData(br);
            
      Int32 dataChunkID = WaveInterop.mmioStringToFOURCC("data", 0);
      dataChunkLength = 0;

      // sometimes a file has more data than is specified after the RIFF header
      long stopPosition = Math.Min(fileSize + 8, stream.Length);
            
      // this -8 is so we can be sure that there are at least 8 bytes for a chunk id and length
      while (stream.Position < stopPosition - 8)
      {
                 Int32 chunkIdentifier = br.ReadInt32();               
                 Int32 chunkLength = br.ReadInt32();
                 if (chunkIdentifier == dataChunkID)
                 {
                     dataChunkPosition = stream.Position;
                     dataChunkLength = chunkLength;
                 }
                 else
                 {
                     if (chunks != null)
                     {
                        chunks.Add(new RiffChunk(chunkIdentifier, chunkLength, stream.Position));
                     }
                 }
                stream.Position += chunkLength;
            }
      }
}

Coordinator
Oct 31, 2009 at 8:27 PM

thanks for reporting this. I think I will try to get some arbitrary chunk reading code in there, so it can support anything before the fmt chunk

Mark

 

Nov 2, 2009 at 10:20 PM
You're welcome. Letme know when you have an update please. Thanks.

Sent from my iPhone

On Oct 31, 2009, at 12:27 PM, markheath <notifications@codeplex.com> wrote:

From: markheath

thanks for reporting this. I think I will try to get some arbitrary chunk reading code in there, so it can support anything before the fmt chunk

Mark

Coordinator
Nov 2, 2009 at 10:55 PM

can you try your file with the latest checkin, it should allow the bext chunk through now

Mark

Nov 3, 2009 at 8:06 PM
Hi Mark,
 
Where is the latest checkin?
 
Russell B.

On Mon, Nov 2, 2009 at 2:56 PM, markheath <notifications@codeplex.com> wrote:

From: markheath

can you try your file with the latest checkin, it should allow the bext chunk through now

Mark

Read the full discussion online.

To add a post to this discussion, reply to this email (naudio@discussions.codeplex.com)

To start a new discussion for this project, email naudio@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Coordinator
Nov 3, 2009 at 8:26 PM

Russell

Assuming you are able to build it yourself, you can get the code from: http://naudio.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Mark

Nov 3, 2009 at 9:04 PM
Mark,
Yes I am able to build. everything works fine now. my "bext" file reads fine now too. looks like you nailed it :)
thanks,
russell b.
On Tue, Nov 3, 2009 at 12:26 PM, markheath <notifications@codeplex.com> wrote:

From: markheath

Russell

Assuming you are able to build it yourself, you can get the code from: http://naudio.codeplex.com/SourceControl/ListDownloadableCommits.aspx

Mark

Read the full discussion online.

To add a post to this discussion, reply to this email (naudio@discussions.codeplex.com)

To start a new discussion for this project, email naudio@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com