开发者

WaveChannel32 gives me an exception: Offset and length were out of bounds

开发者 https://www.devze.com 2022-12-15 03:23 出处:网络
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 messa

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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消