NullReferenceException when loading audio

Jan 7, 2015 at 5:40 PM
Stacktrace:
at NVorbis.VorbisCodebook.InitTree(DataPacket packet) in e:\Programming\Nvorbis\NVorbis\VorbisCodebook.cs:line 125
at NVorbis.VorbisCodebook.Init(DataPacket packet) in e:\Programming\Nvorbis\NVorbis\VorbisCodebook.cs:line 42
at NVorbis.VorbisCodebook.Init(VorbisStreamDecoder vorbis, DataPacket packet, Int32 number) in e:\Programming\Nvorbis\NVorbis\VorbisCodebook.cs:line 20
at NVorbis.VorbisStreamDecoder.LoadBooks(DataPacket packet) in e:\Programming\Nvorbis\NVorbis\VorbisStreamDecoder.cs:line 265
at NVorbis.VorbisStreamDecoder.TryInit() in e:\Programming\Nvorbis\NVorbis\VorbisStreamDecoder.cs:line 104
at NVorbis.VorbisReader.NewStream(Object sender, NewStreamEventArgs ea) in e:\Programming\Nvorbis\NVorbis\VorbisReader.cs:line 94
at NVorbis.Ogg.ContainerReader.GatherNextPage() in e:\Programming\Nvorbis\NVorbis\Ogg\OggContainerReader.cs:line 436
at NVorbis.Ogg.ContainerReader.Init() in e:\Programming\Nvorbis\NVorbis\Ogg\OggContainerReader.cs:line 74
at NVorbis.VorbisReader.LoadContainer(IContainerReader containerReader) in e:\Programming\Nvorbis\NVorbis\VorbisReader.cs:line 82
at NVorbis.VorbisReader..ctor(Stream stream, Boolean closeStreamOnDispose) in e:\Programming\Nvorbis\NVorbis\VorbisReader.cs:line 46
at NVorbis.VorbisReader..ctor(String fileName) in e:\Programming\Nvorbis\NVorbis\VorbisReader.cs:line 33
at CDF.Audio.LoadOgg(String fileName) in e:\Programming\CDF\CDF\Audio.cs:line 203
at CDF.Audio.GetEffect(String path) in e:\Programming\CDF\CDF\Audio.cs:line 184
at CDF.Audio.<SetNextMusic>b__7() in e:\Programming\CDF\CDF\Audio.cs:line 94
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

Local variable 'codewords' is null.

You can find the audio file at http://exong.net/loyalists.ogg .

As far as I can tell, NVorbis is intended to be able to load this file.
Coordinator
Jan 24, 2015 at 2:31 PM
Interesting... Looks like a sparse codebook is confusing the codebook header reader... I need to check the file & code against the spec for this part to see what went wrong.

Sorry I haven't been able to look at it until now; Other (paying) obligations have been eating up all my time.
Coordinator
Jan 24, 2015 at 3:51 PM
The file appears to have a sparse codebook with no entries, but NVorbis expects at least one. Here's a patch that addresses the issue, but be forewarned that it synthesizes very subtly different output than libvorbis (so subtle I don't think anyone can hear the differences). I'll investigate further to see if I missed something in the spec (I didn't find a reference to the situation in a quick review, but I may have just missed it).

Here's the patch:

In VorbisCodebook.cs, insert the following at line 88:
            if (sparse && MaxBits == -1)
            {
                // this codebook does not have any used entries...  just assume it is unused by the stream and move on
                MaxBits = 0;
                PrefixList = new System.Collections.Generic.List<HuffmanListNode>();
                PrefixBitLength = 0;
                PrefixOverflowTree = null;
                return;
            }
Jan 27, 2015 at 1:25 AM
Thanks for taking a look! Everything appears to be working fine now.