-
Notifications
You must be signed in to change notification settings - Fork 51
Music
NOTE: This tutorial is for gbt-player. Some of the concepts here can be applied to hUGETracker too, only it comes with its own tracker so you don't need OpenMPT or any other external software. You can select which driver you want for your game in the Makefile. For this tutorial you need to make sure that the MUSIC_PLAYER is declared like this:
MUSIC_PLAYER = GBT_PLAYER
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. Finally, the data output is played by gbtplayer.
The most typical workflow is:
- Open the template file with OpenMPT
- Modify it and save it with a different name.
- Copy or move it to the res/music folder of your project
- In StateGame.c include Music.h and 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
#include "Music.h"
DECLARE_MUSIC(<filename_without_extension>);
- At the end of the Start method of StateGame.c call PlayMusic
void START() {
...
PlayMusic(<filename_without_extension>, 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 is going to be hard!
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. Each of the four columns is a sound channel, and that they are presented in the same order as I explained above. 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 what command/effect it uses. "Cxx" is the command for volume settings. You can read a complete list of the available commands / effects in this document.
Examine the template mod file and the different patterns (clicking in the pattern order or pressing +/-). Play it and try changing some parameters and notes here and there to experiment by yourself. If you want to begin a tune from scratch, use this option: Edit/Cleanup and check the boxes as following.
You can start writing notes in the columns using your QWERTY keyboard. Use the letter keys to input different pitches and use the arrow keys to scroll through the pattern. You can select, copy, cut and paste using your mouse and shortcuts as in any text editor.
If you add a new pattern (the icon just below "General"), it will be automatically added in the pattern order list. If you want to edit the pattern order, you can use keys such as Insert (to repeat), Del, etc. Check the OpenMPT reference!
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.
Possibilities are endless, but if you think a little bit about what to do with each channel, you can have a nice starting point:
- Use the noise channel as percussion: try to imitate the sound of a hihat or a snare drum with it!
- Use the wave channel as bass: try something repetitive which adds some content to the rhythm created by the noise channel.
- Use the second channel as melody: use this channel to represent the most iconic melodic lines of your song (what you may hear in your head).
- Use the first channel as accompaniment: you will probably use this channel for sound effects too, so in your mod file, use this for complementary melodies and echo effects.
Once you're finished, don't forget to save your work and to name the file properly!
- The template file included has some tuning issues, so don't expect great accuracy from it.
- You need to have some kind of note on every channel in the first row of the first pattern. If there's nothing, you may get unwanted (and loud) beeps in your game.
- You can have a new and empty ZGB project that can be modified quickly in order to test the tunes before including them in the actual game.
- 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 envelopes, so keep your tunes simple and try to focus on melody and overall mood.
- Even if you have previous experience with Amiga tracking, mind that the .mod format used here is extremely limited. Read the docs!
- 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.