Tyrrrz's picture


I've spent all day trying to find a C# vorbis/ogg decoder that can decode a stream to PCM buffer without trying to play it. Anyway, i've assembled a library, consisting entirely of 3rd party sources (more than one party as well), that lets you do exactly that.
Library compiled against .NET 4.0
You can use ILMerge to merge it with your managed code.

Usage of the library:

using VorbisDecoder;
... // Decode the stream into buffer and some other data
public Ogg(MemoryStream ms)
            OggDecoder decoder = new OggDecoder();
            decoder.Initialize(ms, false);
            _sampleRate = decoder.SampleRate;
            _channels = decoder.Stereo ? 2 : 1;
            _data = decoder.SelectMany(chunk => chunk.Bytes.Take(chunk.Length)).ToArray();
...//Use that array to init OpenAL buffer
public void SomeFunctionName(Ogg sndf)
            _index = AL.GenBuffer();
            _source = AL.GenSource();
            ALFormat audioFormat =
                    sndf.Channels == 1 ? ALFormat.Mono16 :
                    sndf.Channels == 2 ? ALFormat.Stereo16 :
            AL.BufferData(_index, audioFormat, sndf.Data, sndf.Data.Length, sndf.Rate);

Something along those lines