Skip to content
This repository has been archived by the owner on Feb 2, 2020. It is now read-only.

Alovchin91/vorbis-winrt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ogg Vorbis for Windows Runtime

vorbis-winrt is a work in progress for a simple Windows Runtime component for decoding (so far) Ogg Vorbis files. It is being written completely in C++/CX, and is based on original libvorbis and libvorbisfile C libraries version 1.3.4 source code. It is available for C# and C++/CX developers writing Windows Store apps for Windows (Phone) 8.1 and higher.

Ogg Vorbis for Windows Runtime currently only exposes a decoding functionality found in original libvorbisfile library. If you think encoder and low-level Vorbis API access are necessary, feel free to contribute ;) Still, as far as Windows Runtime matures and becomes a technology that can be used in desktop development as well, Ogg Vorbis for Windows Runtime will also update and add necessary functionality.

Sample usage

vorbis-winrt's API is similar to original Vorbisfile API, except that it's object-oriented. The main class that you will use to decode an Ogg Vorbis file stream is Vorbisfile.WindowsRuntime.OggVorbisFile class. Instantiate the class and then call OggVorbisFile.Open to initialize the stream decoder. To get samples from the decoder, simply use OggVorbisFile.Read method.

Coming soon: Example solution containing sample Windows Phone 8.1 background audio project that uses Ogg Vorbis for Windows Runtime.

Here's the sample usage. Assume you have a managed helper class with OggVorbisFile _vorbisFile field that is supposed to help you wrap all the decoder logic. Here's how you initialize the decoder:

public void Initialize(IRandomAccessStream fileStream)
{
    this._vorbisFile.Open(fileStream);
    
    if (!this._vorbisFile.IsValid)
        throw new InvalidOperationException();
}

Note that if something goes wrong, the OggVorbisFile.Open() method will throw an exception with HResult equal to one of libvorbis' return codes, but still it's recommended to check for OggVorbisFile.IsValid each time you call any OggVorbisFile API.

Now, to get a sample from the decoder, you can write a simple method like this:

public IBuffer GetSample(int length)
{
    if (!this._vorbisFile.IsValid)
        throw new InvalidOperationException();
    
    return this._vorbisFile.Read(length);
}

How to build

vorbis-winrt includes all the necessary source code to build the libraries. Ogg Vorbis for Windows Runtime solution includes original Vorbis libraries and their dependencies, including libogg, and contains libvorbisfile_winrt project that is the main output of the solution.

You will need Visual Studio 2013 or higher to build the library for Windows (Phone) 8.1 or higher. All the projects currently are set up to build for Windows Phone 8.1, but it's easy to retarget them for Windows 8.1 or higher.

How to create a MediaStreamSource

Please see the dedicated Wiki page.