1

Closed

BlockAlignReductionStream.Read cannot read large chunks.

description

The BlockAlignReductionStream uses a circular buffer to allow unaligned reading from an otherwise block aligned source stream. If the user tries to read more bytes than would fit in the circular buffer, the BlockAlignReductionStream only reads the amount that fits in the circular buffer, but internally advanced the input stream by the actual requested number of bytes. Future read requests will therefore miss a portion of the input stream.

A simple fix would be to clamp the number of bytes read from the input stream to the size of the circular buffer. I could not find the svn url for the source tree or figure out where to submit a patch, so I just attached the modified source file.

file attachments

Closed May 3, 2013 at 3:34 PM by markheath
proposed solution could cause problems elsewhere in NAudio, so no plan to fix this at the moment. Recommend not using BlockAlignReductionStream if you want to read large chunks

comments

markheath wrote Jan 3, 2013 at 2:37 PM

BlockAlignReductionStream is not really designed to be called with large values in the count parameter of Read. The trouble with this solution is that Read could return less than the requested number of bytes even though the stream has not ended, which could cause partially complete buffers to get written to the soundcard.