-
Notifications
You must be signed in to change notification settings - Fork 51
Music
If you want to write your own music for your games, you will need an additional music tracking software. The most compatible and versatile music tracking software for Windows is OpenMPT, but there are many others. Any of them will do it as long as the software can handle .mod files, which is a classic Amiga music format.
If you are used to tools like LSDJ, some of the concepts here will be familiar to you, but the approach is completely different. Think about the differences between the sounds of electronic chiptune scene and classic game soundtracks! You need to use the CPU for lots of things, not just for the music!
The current music system is based on a template file in .mod format, that has to be parsed and converted by mod2gbt, which is included in ZGB.
The most typical workflow is:
- Open the template file with OpenMPT
- Modify it and save it with a different name. Don't forget to include in what bank the music should be (level1.b3.mod for example).
- Copy or move it to the res/music folder of your project
- In StateGame.c declare a extern UINT8* array named [filename]_mod_Data. For example, if your file is named game.mod then you should declare it like this
extern UINT8* game_mod_Data[];
- At the end of the Start method of StateGame.c call PlayMusic
void Start_STATE_GAME() {
...
PlayMusic(game_mod_Data, 3, 1);
}
- Compile your game so you can test if the music is being played properly.
Writing music is a skill that can take a lifetime to learn and develop, so this is just a very basic guide for you to get started. If you don't know anything about music tracking or music in general, this short guide is for you.
You should read the OpenMPT manual to get to know the basics of this software. If you want to read more in-depth about music tracking, you should give The Tracker's Handbook a try, which is an old classic reference.
The first thing you need if you want to write music for the Game Boy is to know a little bit about its sound hardware.
To keep it short: the console has four channels, which means that you can have up to four things sounding at the same time. Those things are usually notes or sound effects. If you are used to MIDI sequencing, mind that Game Boy channels are monophonic, unlike MIDI channels.
- Channels one and two provide pulse waves, which are very rich harmonically speaking. They both have four duty cycles, which are four different "flavors" of the pulse wave. The first channel has an extra feature: the frequency sweep, which allows to modify its frequency up or down (nice for vibrato or glissando effects).
- Channel three is the wave channel, that can play a variety (user defined) of waveforms as an oscillator. Due to the limited system that mod2gbt offers, there's a limited set of pre-defined waveforms. It does not have volume envelope.
- Channel four is the noise channel, that can play a variety of noise colors. It's often used for percussion and sound effects.
Open your template file in OpenMPT. You'll see there are four main tabs:
- General: you won't need to change anything here (you can write the title of the track!)
- Patterns: here is where the action takes place. You will see a pattern order and a pattern editing window. Patterns are essentially pages where you write music. You can fill them with your music and sort them as you like.
- Samples: here is where you can test what sounds are available in this music system. If you explore the different sample numbers and press random keys in your qwerty keyboard, you'll notice what kind of sounds you'll have in your palette. We will use these samples to "emulate" the Game Boy sound in OpenMPT, but our beloved handheld console doesn't use them! The console generates its own waveforms using the configuration of our mod file. Notice that the name of each sample, specifies the channels it can be used in! Sample no. 3 is called "ch12_3.wav", which means that you can only use it in channels 1 and 2. Sample no. 27 is named "ch4_12", which means that you can only use it in channel 4.
- Comments: you won't need to change anything here, but you can see a nifty sample list.
If you hit play (F5) you'll start listening to the demo music. Notice how the playback order is from top to bottom, in a Matrix-style column scroll. Notes that are in the same row will be played at the same time. In the pattern order, you'll see how it scrolls from left to right. When the playback reaches the end, it loops from the first pattern again.
You'll see that notes are written this way: G-4 02 .. C40 This means that:
- You are playing the G in the fourth octave
- This note will use the second sample of the sample list (named ch12_2.wav)
- The volume of the playback is 40.
Every note written should define: the pitch itself, what sample it triggers and with what command/effect it should sound. "Cxx" is the command for volume settings. You can read a complete list of the available commands / effects in (this document)[https://github.com/AntonioND/gbt-player/blob/master/mod2gbt/mod_instructions.txt].
- The template file included has some tuning issues, so don't expect great accuracy from it.
- You can have a new and empty project that can be modified quickly in order to test the tunes in an emulator.
- The first channel is the most versatile for playing certain sound effects, so use the second channel for the most important parts of your tunes. It's OK to lose some background musical elements (chords, echoes, comping, etc.) if a sound effect is being played, but try to keep the main element sounding.
- The current system lacks some basic Game Boy sound features, like volume envelope, so keep your tunes simple and try to focus on melody and overall.
- Even if you have previous experience with Amiga tracking, mind that the .mod format used here is extremely limited.
- The default keymap for OpenMPT may not be the best for you. Try other maps in Setup/Keyboard/Import Keys and browse Program Files/OpenMPT/ExtraKeyMaps. If you use the portable version, there should be a similar path to find the extra keymaps.
- A very useful thing you can do to learn how Game Boy music is written, is toggling on and off the different channels to learn how they sound in an emulator. This will give you an insight and ideas about how the Game Boy music works in terms of arrangement.