views:

93

answers:

2

With the NAudio library I'm trying to mix some audio using a WaveMixerStream32 so I'm using WaveChannel32 to feed it the streams in the proper format. I've got an exception with the following message:

Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

The minimum example I could make that also throw that error didn't include WaveMixerStream32 at all with took me to the conclusion that the problem was in how I'm using WaveChannel32. The code is this:

var audio = new WaveFileReader(OriginalAudioFileName);
var audio32 = new WaveChannel32(new WaveFileReader(OriginalAudioFileName));
WaveFileWriter.CreateWaveFile(PublicAudioFileName + "audio.wav", audio);
WaveFileWriter.CreateWaveFile(PublicAudioFileName + "audio32.wav", audio32);

audio.wav is generated just fine. audio32.wav is 58 bytes and that line thrown the exception.

What is wrong?

+2  A: 

I got a repro pretty easily. This looks like a basic bug in WaveChannel32.Read(), it doesn't handle .wav files with multiple channels properly. The numBytes argument looks like the size of the file, not the stream.

Let the project owner know. You'll add your issue to a rather long list though.

Hans Passant
Ok, done: http://naudio.codeplex.com/WorkItem/View.aspx?WorkItemId=11377Any ideas for a workaround? Both channels are actually the same, so I wouldn't mind picking only one, if that's possible.
J. Pablo Fernández
+1  A: 

Yes, this is a bug in NAudio. Thanks for reporting it. I've checked in a fix (was a problem with WaveChannel32.GetSourceBuffer). You also need to know that you must set PadWithZeroes to false on your WaveChannel32 before calling WaveFileWriter.CreateWaveFile or you will create a never-ending WAV file, slowly filling up your hard disk.

Mark Heath