September 2, 2009

Chiptune tracker music

This is a quick guide (in progress) supposed to help game developers reduce the size of their music files, using impulse tracker modules.


Chiptune tracker music
How to reduce the size of game music.


Requirements

* Modplug Tracker : to create modules and edit instruments.
* GM Bassmod (if you're using game maker) : a music dll/extention to play tracker modules.


Introduction :

Although mp3 or ogg files are great for high quality game music, they take a lot of disk space wich doesn't make sense when it comes to chiptune music. Using tracker modules is the best way to create low size music for your game and can be played in game maker with the GM Bassmod dll/extension.

We will look at various ways to reduce the size of tracker modules :

1) Multiple tunes in one module.
2) Instrument optimization.
3) Sample optimization.


***

1) Multiple tunes in one module.

Instead of creating multiple modules for each level of your game (level_01.it, ..., level_08.it, etc.) containing more or less the same samples, you can save a lot of space by managing only one module (with one set of samples) for your entire game with several tunes following each other in it.

Let's say for example :
- the level_01 tune starts at pattern order 00 of the module, and ends at 07.
- the level_02 tune : 08-15.
- the level_03 tune : 16-24.
- etc.

To make the level_01 tune loop instead of going on with the next tune, write the effect "B00" at the last row of the pattern order 07 to make the music jump to pattern order 00 and restart the tune.
- B08 at the end of order 15 for the level_02 tune.
- B16 at the end of order 24 for the level_03 tune.
- etc, do the same at the end of each tune to make them loop.

In Game Maker, with the GM Bassmod dll/extension, you can start a module from any position in the song with the function bmod_play_ext(index,order,row).
Select the correct order to start the tune you wish to play :
- Level_01 : bmod_play_ext(index,0,0);
- Level_02 : bmod_play_ext(index,8,0);
- Level_03 : bmod_play_ext(index,16,0);

Note : When you are finished and happy with your tunes, don't forget that the most basic way to lower the size of a module is to get rid of all the unused patterns, samples and instruments. Modplug Tracker has an option to do this (edit -> cleanup the song).

***

2) Instrument optimization.

You can create a lot of very different instruments with only one sample.
You can map multiple samples in only one instrument.

You can combine the two techniques.

In the impulse tracker format (*.it modules), the score is played by instruments controling the way the samples are played. An intrument is composed of :

- 3 envelops (volume, panning, and pitch or filter).
- a CutOff Frequecy (filter).
- a resonance factor.
- An association of each note of the keyboard from C0 to B9 with a sample and a note.

All this data is optionnal, so one instrument is usually associated with one sample, played the same note as the note pressed on the keyboard, fading out when the note is released. But the 3 envelops and the note-sample association are essential to create the best sound quality and variety with the lowest size possible.


a) Multiple instruments from the same sample.

If you load a simple wave sample (typically less than 100 octets) you can then create a lot of different instruments to play this sample in many different ways. That's basically how chiptune music was produced in the beginning.

Here is a quick example : one_sample.zip (4 Ko)
It contains 10 instruments with only 1 sample.

You can hear the 56 kbps mp3 version of it below (783Ko) :



It could be better, but there's everything needed : bass, drums, lead, chords, fx,... You could make an entire soundtrack with one sample.

But tracker modules usually contain more than one sample, so this technique can be combined with the next one :


b) Multiple samples in the same instrument.

Usually a sample will sound good only over 3 or 4 octaves while the other octaves are never played. Then if two instruments have basically the same envelops for two different samples, you can use just one instrument with the first sample mapped to the first octaves (from C0 to B4) and the second sample mapped to the last otavs (from C5 to B9). Then erase the second instrument (its sample won't be erased as it is now mapped to the first instrument).

Let's say you have created some really good envelops for an instrument, one way to add variety to your music without adding any octet is to map 2 or 3 of the other samples to it. Or, if you want to create a drum kit instrument, you can also map one sample per note.

Another reason to do this is to bypass the limit of 199 instruments by module : there is no limit to the number of samples, so you can virtually double or triple the number of instruments with this method.
It sounds a bit ambitious but you might want to work with a large set of instruments to create your tunes with more freedom (199 instruments, without samples, = only 124 Ko).

***

2) Sample optimization.

There is two main solutions to reduce the size of samples :
- Sound quality reduction.
- Sound decomposition.


a) Quality reduction

One way to reduce the size of a sample is to "shrink" the definition of the wave signal by half (the [><] button in the sample editor of Modplug). The loss of quality and brilliance can be problematic but you can apply a high value for the CutOff filter to reduce the noise and add some resonance to regain brilliance in the instrument editor.

b) Sound decomposition : attack, loop and volume envelop.

Very often, recorded instrument sounds can be analized as a highly recognizable attack resolving in a standard sinewave decreasing in volume. Pianos, organs, vibraphones, bells, guitars, flutes and other instruments can usually be decomposed this way.

Look at this piano sample :



1. Try to find the first sinewave in the sample after the attack and create a loop with it (see above, highlited in gray and below, zoomed in).
Listen carefully to the pitch of the loop (the frequency is in opposite ratio of the loop length) : it must be in tune with the rest of the sample.
Also notice that the vertical coordinate of the wave must be the same at the beginning and at the end of the loop, otherwise the sound will be altered.




2. Then in the instrument editor, create a volume envelop that will copy the decrease of the original sample. You can also add a decreasing filter envelop to simulate the piano harmonics fading down.




3. If it sounds good you can erase the rest of the sample after the loop and save a lot of space (Modplug can automatically erase the part after the loop with the option : edit -> cleanup samples). Here our original 32Ko piano sample is cut down to a 2Ko sample, decomposed in an attack and a loop :




4. You can also add a light and slow vibrato in the sample editor (depth 1, rate 12) to simulate a more realistic and warm sound. This can be combined also with loops in the volume or filter envelops to obtain a really sophisticated sound.

***

Here is a compilation of 100 impulse tracker instruments, sorted by category, inside a 130Ko module. All samples and instruments have been heavily edited to maintain high quality for an average of 1Ko per instrument :



If you want to use any of those instruments in your tunes, go to the instrument editor of the module, press the save to disk button and don't forget to select the *.iti format otherwise you will loose all the filter data :




***

No comments:

Post a Comment