DerelictVorbis



Introduction

DerelictVorbis is a D binding to Xiph.org's Ogg Vorbis codec.  Vorbis is a compressed audio format similar to mp3, but allows smaller filesizes with the same level of audio quality and is also patent-free and open source.

The Vorbis library is divided into three parts.  The codec library itself has many lower-level functions for dealing directly with compressed Vorbis streams.  VorbisFile is a higher-level API built on top of the codec for decoding Vorbis files; and VorbisEnc is an API for encoding raw audio data to the Vorbis format.  VorbisFile and VorbisEnc should be enough for most projects.

VorbisEnc is not yet supported by DerelictVorbis

Using

  1. Always make sure the DerelictVorbis source modules are available on your import path.
  2. In modules that make use of the Vorbis codec or VorbisFile, you will need to import the derelict.ogg.vorbis module.
  3. Before calling any Vorbis codec functions, you need to make a call to DerelictVorbis.load(). This will load the shared library.
  4. Before calling any VorbisFile functions, you need to make a call to DerelictVorbisFile.load(). This will load the shared library.

The following is a complete program that loads DerelictVorbis and DerelictVorbisFile.  It may be rare that you'll use both at the same time, but this is for demonstration purposes:

import derelict.ogg.vorbis;

void main()
{
	DerelictVorbis.load();
	DerelictVorbisFile.load();
	
	// now you can call Vorbis and VorbisFile functions
}

Take a look at vorbisfile_example.d in the /examples folder for a complete program that reads header info (Artist, channels, etc.) from Ogg Vorbis files and also decodes them.

As with other Derelict packages, DerelictVorbis will throw an exception if an error occurs while loading the shared library. For more information on Derelict exceptions, see the documentation for Loading/Unloading Shared Libraries.

Finally, the functions DerelictVorbis.unload() and DerelictVorbisFile.unload() are provided for convenience. In normal practice you do not need to call these functions, as Derelict will unload the library automatically when the app exits. You generally should only use this function if you need to unload either library while the application is running.

Dependencies

DerelictUtil
DerelictOgg