1

Closed

Seeking using VorbisReader.DecodedTime causes exception on next ReadSamples

description

Hi!

I updated to the latest version and tried it to see if it's safe to update to, and found an issue with one of my Ogg files.

In the OggStream class that's in the repository, I set VorbisReader.DecodedTime to TimeSpan.Zero in order to loop playback seamlessly, and generally this works, but with at least one of my Ogg files, doing so causes an ArgumentOutOfRange exception to be thrown :

Non-negative number required.
Parameter name: offset

at System.IO.FileStream.Read(Byte[] array, Int32 offset, Int32 count)
at NVorbis.StreamReadBuffer.ReadStream(Int32 readStart, Int32 readCount, Int64 readOffset) in C:\Users\Renaud\Documents\Visual Studio 2010\Projects\NVorbis\NVorbis\StreamReadBuffer.cs:line 454
at NVorbis.StreamReadBuffer.FillBuffer(Int32 startIdx, Int32 count, Int32 readStart, Int32 readCount, Int64 readOffset) in C:\Users\Renaud\Documents\Visual Studio 2010\Projects\NVorbis\NVorbis\StreamReadBuffer.cs:line 391
at NVorbis.StreamReadBuffer.EnsureAvailable(Int64 offset, Int32& count) in C:\Users\Renaud\Documents\Visual Studio 2010\Projects\NVorbis\NVorbis\StreamReadBuffer.cs:line 198
at NVorbis.StreamReadBuffer.ReadByte(Int64 offset) in C:\Users\Renaud\Documents\Visual Studio 2010\Projects\NVorbis\NVorbis\StreamReadBuffer.cs:line 165
at NVorbis.BufferedReadStream.ReadByte() in C:\Users\Renaud\Documents\Visual Studio 2010\Projects\NVorbis\NVorbis\BufferedReadStream.cs:line 154
at NVorbis.Ogg.Packet.ReadNextByte() in C:\Users\Renaud\Documents\Visual Studio 2010\Projects\NVorbis\NVorbis\Ogg\OggPacket.cs:line 85

It gets caught in VorbisStreamDecoder.DecodeNextPacket() but gets rethrown from there.

I've attached the Ogg file that causes this issue to pop, I can reproduce it by using it as a test file in OpenTKStreamingTest and enabling looping on it.

It occurs in the master branch as well as the current 0.8testing branch.

Any ideas? :)
Thanks!

file attachments

Closed Jan 16 at 4:33 PM by ioctlLR
Released

comments

ioctlLR wrote Dec 30, 2013 at 6:57 PM

Gah! I apparently borked the ogg reader in 0.8... Quickly trying to debug it, I think the issue is in StreamReadBuffer.CalculateRead(...). I don't have time to really debug it right now, but I'll get to it as soon as possible.

If you'd like to try debugging it, go ahead. The StreamReadBuffer is supposed to cut down on the disk i/o by buffering chunks of the file (this also helps provide a minor degree of "seekability" for forward-only streams). Calculating the buffer moves & indexes appears to be the issue.

If you need something that works, feel free to stick with 0.7.4 (commit 74a6998bf967).

ioctlLR wrote Jan 13 at 2:42 PM

I think I've found it, though it starts to "hitch" after about the 3rd loop in the test app... StreamReadBuffer.cs lines 322-326 (in PrepareBufferForRead) should be commented out, like so:
                if (newSize <= _maxSize)
                {
                    newBuf = new byte[newSize];

                    //if (_discardCount > 0 && newSize == _maxSize)
                    //{
                    //    // we need to discard everything... move it out
                    //    moveCount += _discardCount;
                    //}
                }
                else
                {
                    throw new InvalidOperationException("Not enough room in the buffer!  Increase the maximum size and try again.");
                }
If I'm right, I'll remove them from the mainline source code and push a new 0.8 release.

ioctlLR wrote Jan 16 at 4:33 PM

OK, I've released this. The "hitch" turned out to be something in the OpenAL code (I have no idea what, but it works brilliantly with the simple NAudio looping playback code I hacked together).

Enjoy!

renaudbedard wrote Jan 17 at 2:49 AM

Yup, many thanks for the quick fix! Works fine now. :)