Game Development Reference
In-Depth Information
Decoding tracker music using ModPlug
Mobile devices are always limited on resources compared to the desktops. These limitations
are both in terms of computing power and the amount of available storage. High-quality
MPEG-1 Layer 3 or the Ogg Vorbis audio iles occupy a lot of space even at modest bitrates.
For example, in a 20 Mb game, two tracks of size 5 Mb each would be unacceptable. However,
there is a good trade-off between quality and compression. A technology originated in the
eighties known as the tracker music — sometimes called chiptune or 8-bit music ( http://
en.wikipedia.org/wiki/Music_tracker ). Tracker music formats don't use pulse-
code modulation to store the entire soundtrack. Instead, they use notes and effects, which
are applied to samples and played in several channels. Samples are small PCM encoded
sounds of musical instruments. Notes correspond to the playback speed of a sample. We use
the libmodplug library to decode the most popular tracker music ile formats, such as .it ,
.xm , and .mod .
Getting ready
Check out the most recent version of libmodplug at http://modplug-xmms.
sourceforge.net .
How to do it...
1.
The ModPlug library allows us to implement another class derived from
DecodingProvider , called ModPlugProvider . The library supports direct
decoding of the memory blocks, so we don't have to implement any kind of I/O
callbacks:
class ModPlugProvider: public DecodingProvider
{
2.
As a state, this class contains the ModPlugFile structure:
private:
ModPlugFile* FModFile;
3.
The sole constructor initializes the ModPlugFile ield:
public:
explicit ModPlugProvider( const clPtr<Blob>& Blob )
: DecodingProvider(Blob)
{
FChannels = 2;
FSamplesPerSec = 44100;
FBitsPerSample = 16;
 
Search WWH ::




Custom Search