Like many others, I ran into this issue when decoding.
As some who've read the code have noticed, Bits.cs:48 defines a DefaultBufferSize of 1024 bytes, and if you pass an input buffer/length larger than this size to the Decode method, you'll get this exception.
Reading further through the code, it appears that there's no inherent limitation on the input size besides the fact that the internal bytes buffer never gets reallocated - a very simple fix.
Adding the following lines of code at Bits.cs:104 (i.e. beginning of ReadFrom()) solved this issue for me:
// added 2011-11-27 OG to support buffers > 1K
if (bytes.Length < len)
bytes = new byte[len];
// end added code
This way, I don't have to decode in 1K chunks...
Cristoph - any chance you could add this to the source? (Or explain why the decoding should only happen in smaller chunks)? FWIW, decoding like this has worked for me for large buffer sizes (e.g. original input buffer lengths of 64000 bytes which
compressed to about 6000 bytes).
p.s. BTW, the other "gotcha" is that the fourth parameter passed into the SpeexDecoder.Decode() method - the short array, appears to have to be exactly sized like the one that was passed into SpeexEncoder.Encode(). (And of course this array
size needs to be a multiple of SpeexEncoder.FrameSize). Assuming you are encoding/decoding in chunks like I am, and may have variable-sized chunks: I solved this issue by prefixing each encoded chunk with its pre-encoding short array size,
in order to make sure I have the proper size for the short array to pass into the Decoder.