alogg - an Ogg/Vorbis addon library for Allegro version 1.3.3
alogg is a library which makes it easier to use Ogg/Vorbis streams with
Allegro. It offers facilities to decode, stream, and encode Ogg/Vorbis
streams with thread support and experimental URL streaming, and integrates
those facilities with Allegro's datafile and sample loading routines.
alogg's homepage can be found at http://lyrian.obnix.com/alogg/
alogg is Copyright 2002, 2003 Vincent Penquerc'h and is distributed under
the terms of a modified Lesser General Public License (LGPL). See file
lgpl.txt in the archive for more information about the LGPL.
The examples are under a BSD like license, as libvorbvis' examples, and
the grabber plugin is giftware, as it is an adaptation of Allegro's
SAMPLE plugin.
See the LICENSE file in the archive for more information on alogg's license.
#include <std_disclaimer.h>
"I do not accept responsibility for any effects, adverse or otherwise,
that this code may have on you, your computer, your sanity, your dog,
and anything else that you can think of. Use it at your own risk."
Ogg/Vorbis is an audio encoding format (Vorbis) using a particular bistream format (Ogg). Its specification is in the public domain, and it features similar properties to MPEG layer 3 audio format. Ogg/Vorbis supports fixed and variable bitrate encoding.
Ogg/Vorbis was designed by the Xiphophorus company: http://www.xiph.org/
Tremor is a fixed point implementation of the Ogg/Vorbis decoder from the Xiphophorus company.
alogg requires the following:
libogg-1.0rc3 (or newer, available at http://www.vorbis.com/) libvorbis-1.0rc3 (or newer, available at http://www.vorbis.com/) allegro-4.1.1 (or newer, available at http://alleg.sf.net/)
To compile with Tremor, a fixed point implementation of the Ogg/Vorbis decoder, you also a copy of the Tremor library. As of September 2002, Tremor is still only available as CVS snapshots, which can be found at http://www.xiph.org/.
To compile with URL support, you also need libcurl 7.10 or newer. libcurl is a library for transferring data specified with URL syntax, available at http://curl.haxx.se. Note that URL streaming is experimental is not ready for production use yet. In particular, I have not yet tried to stream off an Icecast server.
To compile with threaded streaming support, you also need pthreads. pthreads is the most widely used library for thread support, and is supplied with most operating systems. You can even get a version of pthreads for MS-DOS and MS-Windows. For the latter, it can be found somewhere at http://www.redhat.com.
Previous versions of Allegro will probably work, though integration with Allegro's load_sample requires Allegro 4.1.1. If you have an older version of Allegro and want to be able to use load_sample to load Ogg/Vorbis streams, you can patch Allegro this way:
cd /home/user/allegro # or wherever you put Allegro patch -p1 < /home/user/alogg-1.3.3/sample.diff # or wherever you put alogg
You also have to link against the Ogg/Vorbis libraries in order for the grabber to link. If you use Unix, DJGPP or Mingw32, the supplied linker scripts will do this for you automatically. If you use another platform, or want to use Tremor, you will have to apply a patch to Allegro's makefile. If you want to use libvorbis, use libs.diff; if you want to use Tremor, use tremor.diff. The datogg grabber plugin needs to be told that Tremor is to be used instead of libvorbis, and Allegro has no support for plugin specific compile time scripts, so this must be done by hand. You can apply the patch to the Allegro distribution like this:
cd /home/user/allegro # or wherever you put Allegro patch -p0 < /home/user/alogg-1.3.3/libs.diff # or wherever you put alogg
or, if using Tremor:
cd /home/user/allegro # or wherever you put Allegro patch -p0 < /home/user/alogg-1.3.3/tremor.diff # or wherever you put alogg
If you do not have patch, then your mileage may vary. You might have to modify a project file, depending on how your compiler does this.
alogg is written in C, and should be compilable with any C compiler that
can build Allegro. It was written using GCC 2.95 on Linux, and has been
reported to build on DOS/DJGPP and Win32/Mingw32.
If you are using GCC and GNU make, then building is a very simple matter:
makeYou may also want to install the library:
make installor, if you want to install it somewhere else than /usr/local:
make install PREFIX=/home/user/alogg
Note that if you specify flags when building alogg, you should specify the exact same flags when installing it. For instance, if you build alogg using:
make FOO=1 BAR=1then you should install it using:
make install FOO=1 BAR=1
You can build alogg as a shared library too:
make SHARED=1To install, you must specify this flag too:
make install SHARED=1
To build with the Tremor fixed point implementation of the Ogg/Vorbis decoder, you have to specify this when building alogg:
make TREMOR=1Note that since Tremor is only a decoder, neither the encoding part of alogg nor alogg_encode will be compiled in.
To build in the URL streaming support, you need to specify it when building alogg:
make CURL=1
To build in the threaded streaming support, you also need to specify it when building:
make PTHREAD=1
You can of course mix these, so to build alogg as a shared library with Tremor, URL streaming, and pthreads support:
make SHARED=1 TREMOR=1 CURL=1 PTHREAD=1
A separate part of alogg is datogg, a plugin for Allegro's grabber utility.
It allows one to create Ogg/Vorbis stream objects. Since the grabber only
recognizes plugins at compile time, you will have, after having compiled
and installed alogg, to copy the files datogg.* in the plugins directory,
located in tools/plugins where you have put your Allegro tree, or symlink
them.
Then, go to the main Allegro directory, and type:
make depend makeThe first command will make Allegro notice a new plugin was added, and the second will recompile it with support for datogg. See above for instructions on how to link the Ogg/Vorbis libraries to the grabber if your platform can't use the supplied linker scripts.
If you use Tremor and you have followed the steps to patch Allegro's makefile detailed above, the grabber should have been built with Tremor.
When this is done, the grabber (don't forget to install it first, or you'll likely be running an old version) will be able to create and load Ogg/Vorbis streams, which you can then use in your programs.
Using alogg is very simple: you need only include the file:
#include <alogg/alogg.h>
If you want to add advanced features, such as URL support or thread support, you will have to include the appropriate header as well:
#include <alogg/aloggpth.h> #include <alogg/aloggurl.h>
To help using alogg in your program, you can use the alogg-config script. The two most useful options are --cflags, which prints on stderr the compile flags necessary to compile with alogg, and --libs, which prints on stderr the link time flags necessary to link against alogg:
gcc `alogg-config --cflags` -c alogg_user.c gcc `alogg-config --libs` alogg_user.oNote that the --cflags and --libs options will pull in the appropriate options for the libraries alogg depends on, that is Allegro and Ogg/Vorbis. Allegro is dealt with using its own allegro-config, but Ogg/Vorbis is expected to live in a standard directory (that is, already in a path which can be reached by the compiler/linker).
If you have compiled alogg to use Tremor, libcurl or pthreads, the alogg-config script will automatically supply the right compilation and link flags to compile programs with the right libraries.
Note that the only change in alogg's API when using Tremor instead of libvorbis is that the encoding routines will not be compiled in, since Tremor contains only the decoder part of libvorbis.
Following are some macros useful for allowing building with different versions of alogg. For instance, earlier versions didn't have the ability to create a SAMPLE structure from a loaded DATAFILE object. Testing these macros with cpp directives can allow you to selectively compile in or out different bodies of code depending on the version of alogg available.
ALOGG_MAJOR This is the major number of alogg's version. It is the x in x.y.z.
ALOGG_MINOR This is the minor number of alogg's version. It is the y in x.y.z.
ALOGG_PATCH This is the patch number of alogg's version. It is the z in x.y.z.
ALOGG_MAKE_VERSION This helper macro allows one to build a version number in the format of ALOGG_VERSION from the major, minor and patch numbers, ready to be tested against ALOGG_VERSION.
ALOGG_VERSION This is the patch number of alogg's version. It is a decimal number made up of the three version number components presented above. It is equal to ALOGG_VERSION * 10000 + ALOGG_MINOR * 100 + ALOGG_PATCH, which makes it easy to test if alogg x.y.z or newer is available with a simple comparison.
ALOGG_ID This text string identifies alogg and its version in a suitable form for displaying to the user.
ALOGG_USE_TREMOR This macro is defined if alogg is built with the Tremor fixed point implementation of the Ogg/Vorbis decoder. This macro is not defined in the header file, but is supplied at compile time by the alogg-config script. If you don't use alogg-config, you will have to set if by hand. Any program can use ALOGG_USE_TREMOR to compile different code depending on whether alogg uses Tremor or not.
ALOGG_USE_CURL This macro is defined if alogg is built with URL streaming support supplied by libcurl. This macro is not defined in the header file, but is supplied at compile time by the alogg-config script. If you don't use alogg-config, you will have to set if by hand. Any program can use ALOGG_USE_CURL to compile different code depending on whether alogg uses libcurl or not.
ALOGG_USE_PTHREAD This macro is defined if alogg is built with pthreads support. This macro is not defined in the header file, but is supplied at compile time by the alogg-config script. If you don't use alogg-config, you will have to set if by hand. Any program can use ALOGG_USE_PTHREAD to compile different code depending on whether alogg uses the pthreads library or not.
See also: alogg_exit, datogg_init.
See also: alogg_init.
See also: alogg_init.
See also: alogg_save_ogg.
See also: alogg_save_ogg.
See also: alogg_load_ogg, alogg_save_ogg_param, alogg_start_encoding.
Note that streaming uses Allegro's AUDIOSTREAM facilities, which means once a stream is being played, the usual routines that apply on AUDIOSTREAM can be used. Just get a pointer to the AUDIOSTREAM (alogg_get_audio_stream), and call the Allegro routine (eg voice_set_volume).
Note that if you use threaded streaming, you have to lock the relevant thread before using the stream in any way.
alogg supports streaming directly from a URL if it was compiled with libcurl support. Note that this is experimental code and is likely to have flaws and quirks. Most notably, playback will suffer lags if the connection is not very fast.
Chaining is supported, with the caveat that chained streams must use the same format (eg bit depth, frequency, etc). This should be true for most streams, as servers usually resample their input to offer a constant format.
See also: alogg_start_streaming_datafile, alogg_start_streaming_url, alogg_start_streaming_callbacks, alogg_update_streaming, alogg_stop_streaming, alogg_get_vorbis_file.
See also: alogg_start_streaming, alogg_start_streaming_callbacks, alogg_update_streaming, alogg_stop_streaming.
See also: alogg_start_streaming, alogg_start_streaming_callbacks, alogg_update_streaming, alogg_stop_streaming.
See also: alogg_start_streaming, alogg_start_streaming_datafile, alogg_start_streaming_url, alogg_update_streaming, alogg_stop_streaming.
See also: alogg_start_streaming, alogg_stop_streaming.
See also: alogg_start_streaming.
See also: alogg_update_streaming, alogg_get_audio_stream.
See also: alogg_update_streaming, alogg_read_stream_data.
See also: alogg_start_streaming.
Note that the encoding related routines are not included when alogg is built using the Tremor fixed point implementation of the Ogg/Vorbis decoder.
Also note that the encoding routines will use a random serial number. Since alogg itself does not seed the random number generator since this could get in the way of your program, you will have to do this yourself if you want to.
PACKFILE *f=pack_fopen("output.ogg",F_WRITE); alogg_start_encoding(2,44100,0.8f,0,NULL,&pack_write,f);This makes it easy to encode stream data and output it in whatever way is appropriate for your program. Note that it is valid for write to be NULL, in which case no output will be made. Comments can be added to the output stream. While comments can have any format, it is recommented that they follow the Vorbis standard format, which is similar to a Unix environment variable. Note that comments are encoded as UTF-8, so non ASCII characters can safely be used.
See also: alogg_update_encoding, alogg_stop_encoding.
See also: alogg_start_encoding, alogg_stop_encoding.
See also: alogg_start_encoding.
alogg can create threads to manage a stream, so you don't have to poll an alogg_stream regularly, as this is handled directly by the thread. Note that if you use this capability, you must ensure that only one thread is accessing the alogg_thread and its associated stream at any one time. For this, alogg supplies thread locking capabilities.
See also: alogg_destroy_thread, alogg_stop_thread.
See also: alogg_create_thread, alogg_is_thread_alive, alogg_stop_thread.
See also: alogg_stop_thread.
See also: alogg_is_thread_alive, alogg_destroy_thread.
See also: alogg_unlock_thread, alogg_try_lock_thread.
See also: alogg_lock_thread, alogg_unlock_thread.
See also: alogg_lock_thread, alogg_try_lock_thread.
See also: alogg_create_thread.
The alogg distribution comes with five examples to show you how to use alogg.
alogg_play plays a single Ogg/Vorbis file. It can be either a normal file (eg foo.ogg) or an Allegro datafile object (eg foo.dat#bar). Playing involves loading the whole file in memory, so it best suited for small files.
alogg_stream streams, that is, it only reads data as it is needed to be played. This method can play arbitrarily long streams, as the data does not need to be loaded in memory in entirety before being played. alogg_stream also shows how to use the lower level alogg_read_stream_data function to gain access to the decoded data, and apply transformations to it. As an example, alogg_stream adds a simple echo effect to the stream. As alogg_play, alogg_stream can stream either from a normal file or from an Allegro datafile object, but it can also stream off an URL is alogg was compiled with libcurl support.
alogg_encode is a very simple encoder. Encoding is done with variable bit rate only, with a selectable quality. The input file must be an audio format known to Allegro. The default output file will have the same name with the extension replaced with ".ogg", but can be changed from the command line. Note that alogg_encode will not be available is alogg is built with the Tremor fixed point implementation of the Ogg/Vorbis decoder.
alogg_dat shows how to use Ogg/Vorbis streams placed in datafiles using the datogg grabber plugin. Such streams can be decoded in a SAMPLE structure (this makes Ogg/Vorbis a nifty way to encode your normal samples to save space in your distribution), or streamed off memory. To select which Ogg/Vorbis stream to use, specify the name of the datafile to use, then the name of the object in this datafile. Do not use the usual Allegro compound notation foo.dat#name.
alogg_thread shows the use of thread streaming. Taking a number of streams as arguments, alogg_thread creates a new thread for each one of them, and plays them in parallel. Hitting digit keys (1, 2...) will stop and restart the associated thread, showing how to manage thread lifetime.