English 中文(简体)
WaveChannel32 gives me an exception: Offset and length were out of bounds
原标题:

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签