Quantcast
Channel: naudio Work Item Rss Feed
Viewing all articles
Browse latest Browse all 738

Closed Issue: Format header read for some wav files are incorrect [10105]

$
0
0
The problem is if the header length is not quite correct. fool.wav is a wave file that plays correctly in most players and reads correctly through the mm api, but fails in naudio

The solutions was to hack WaveFormat to set the binary reader to the correct position

/// <summary>
/// Reads a new WaveFormat object from a stream
/// </summary>
/// <param name="br">A binary reader that wraps the stream</param>
public WaveFormat(BinaryReader br)
{
int formatChunkLength = br.ReadInt32();
--> ADDED long chunkStartPosition = br.BaseStream.Position;

if(formatChunkLength < 16)
throw new ApplicationException("Invalid WaveFormat Structure");
this.waveFormatTag = (WaveFormatEncoding) br.ReadUInt16();
this.channels = br.ReadInt16();
this.sampleRate = br.ReadInt32();
this.averageBytesPerSecond = br.ReadInt32();
this.blockAlign = br.ReadInt16();
this.bitsPerSample = br.ReadInt16();
if (formatChunkLength > 16)
{

this.extraSize = br.ReadInt16();
if (this.extraSize > formatChunkLength - 18)
{
Console.WriteLine("Format chunk mismatch");
//RRL GSM exhibits this bug. Don't throw an exception
//throw new ApplicationException("Format chunk length mismatch");

this.extraSize = (short) (formatChunkLength - 18);
}

// read any extra data
// br.ReadBytes(extraSize);

}

ADDED--> br.BaseStream.Position = chunkStartPosition + formatChunkLength;
}
Comments: released in NAudio 1.6

Viewing all articles
Browse latest Browse all 738

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>