Maxmod
|
Here is a guide to step through the basics of installation/usage in a DS project. This tutorial will assume that you are using one of the templates of BlocksDS.
Firstly, libmm9 must be added to your library references. Add -lmm9 to the LIBS in your makefile like this:
Next, you need to tell the makefile to make a soundbank file for you. What is a soundbank file? It's a file that contains all the samples and modules for your project!
Add a new directory to your project; I'll call it "audio". Then, set the variable AUDIODIR
to point to that folder:
The Makefile will look for all .mod
, .s3m
, .xm
, .it
and .wav
files in that folder and generate a soundbank from it.
If you're using NitroFS in your project, the soundbank will be stored in the NitroFS filesystem. If not, it will be added to the ARM9 binary as data, and it will be available in memory from the start.
Keeping it in memory means that you won't be able to use that memory for anything else! If you're making a very small game, that's okay. If not, by keeping the soundbank in the filesystem, Maxmod will only load the parts that are required for the songs and audio efects that you're playing right in that moment, leaving more RAM available for you to use however you want.
Now it's time to initialize Maxmod. maxmod9.h has the definitions for the ARM9 side, include it in your source files. Also, include the generated soundbank header too.
There are multiple ways of setting up Maxmod to fit your needs. The easiest way is to use the mmInitDefault() or mmInitDefaultMem() functions. mmInitDefault() is used when your soundbank is in the filesystem, mmInitDefaultMem() is used when your soundbank is loaded into memory (as described above).
Let's have a look at the soundbank header generated by the Maxmod Utiltiy.
Definitions prefixed by MOD_ are module IDs. Definitions prefixed by SFX_ are sample IDs. MSL_NSONGS is the total number of modules in the soundbank, MSL_NSAMPS is the total number of samples, and MSL_BANKSIZE is the total number of modules plus samples (useful for alternate setup process).
Before playing a song, the song must be loaded into memory. Use mmLoad() to load songs into memory (or acknowledge their existence in memory).
Now that MOD_TITLE is loaded. You may begin playing it with mmStart().
There are two modes for playback: MM_PLAY_ONCE and MM_PLAY_LOOP. If MM_PLAY_ONCE is used, then the module will stop playing after it finishes the last pattern. If MM_PLAY_LOOP is used, then the module will start playing again from its restart position if it reaches the end.
When you are finished with a module, unload it from memory with mmUnload().
To load a sound effect into memory, use mmLoadEffect().
Now it can be played with mmEffect().
mmEffectEx() is a more flexible version of mmEffect(). It will let you specify all of the attributes for the sound.
Both mmEffect() and mmEffectEx() return a sound effect handle that can be used later to modify the sound.
If the effect isn't so important, you can mark it for interruption. This means it can be overridden by music and other effects (if there are no other channels available).
You can stop a sound effect like this:
When you are done using a sound effect, you can unload it from memory with mmUnloadEffect().
For a better understanding, please have a look at the source code for the DS examples.