Now with sound! (kind of)


(As usual, don't take any of this seriously. Goo reading.)


Howdy fellow Damnplugers!

This week end, I was able to dedicate some hours to this highly anticipated game-of-the-year game boy/color time killer named Damn Plug It!
And after some tinkering with colors and some kind of level abstraction (allowing more levels, yay!), I was in my thinking ttk.Treeview() and I said to myself, yes I said to myself : ?"Golly, what a perfect game. But I know what it lacks, emotions! And what is the best way ton convey emotions? Emoticons? No, the game already have that... Music. Yes, music, that's it!".
And so started my quest to make music on the game boy.

But what kind of music can the GB do?

Well, blips and blops, that's it. When you don't master the fine and delicate art of composition that is. To vastly simplify, the GB have 4 channels (it can "play" 4 sounds at the same time), and each channel is particular. You see, it's not as if one can just send an mp3 to a channel and call it a day.

First of all, the cartridge is black, so that won't work. What do you mean, what's the link? Easy, the cartridge aims to be 32kb, so that would be an awfully short music, even if it took all the available space.
Then, decompressing any kind of computational heavy media is a no go. Don't forget, even is cute, the CPU is damn old and 8 bits. That means no native floating point operation and slow math functions (if you don't want to cheat with fixed decimal that is).
Lastly, the hardware just can't play waveform sounds. Well, kinda, but not truly. As I said earlier, each channel is special and can do some things, and nothing else.

- The first channel can play tones in squarish waveforms and perform pitch and volume automatic increase/decay,
- The second channel can play tones in squarish waveforms too, but can only perform volume automatic increase/decay,
- The third channel can play a sample. A super short 32 4bits points=s one, not even truly loop-able,
- The fourth channel can generate some noise. Not like horrendous distorted music, like real whitish noise (think the shhhh when you can't tune to a radio station. Ho wait, no one listen to radio nowadays. Well, the snow when you can't get any TV channel! Wait, cathodic TV are long gone... Okay, like when you say "Shh!" to ask to be quiet but they don't listen and you get to be yelled at by the teacher instead of your noisy friend (what do you mean too precise?)).

The last channel is the... oh wait, there is no more. Or is it? The fifth channel kinda exists, as the cartridge itself can generate music and pass it to the game boy to mix with what she generates (Yes, I do declare that the Game Boy is a She in France...).
Lastly, you can control the volume of each channel (down to mute it), and which channel plays in which earphone (Left, Right or off).

But then, how did the music in my childhood games sounded so good?

First of all, you were a child in the 90's. So the music was, well, okayish for the time. Then, you probably only remember the very good ones (and you are probably still traumatized by the awfully bad ones).
Lastly, some composers and programmer were genuinely good at making nice things for the old grey brick.
The Game Boy is far from powerful, but when you know how to use it, you can make wonderful tunes (

An example of a catchy GB song. Notice how the channels are displayed here, and you can see how crude they are and yet, how the final mix sounds).

Okay, so you will make nice music for DamnPlugIt! ?

Nope. Because using 100% of the GB CPU to make nice music (like the example before) is not doable : the game must run too.
So, I need to generate the music when the game is doing nothing, and using the fewest resources as possible.
Basically, I have two choices:
1) Make my own "music engine", Pro: I know what I do and can finely tune the memory and power requirement to my game. Cons: It's a lot of work, it won't have many possibilities, and I don't know assembly, so even if I did something, it would be mediocre optimisation wise.
2) Use an already existing engine. Pro: Lot of musical possibilities and speed optimised, some are well documented, probably works with somewhat well known file format. Cons: I have to research multiple engines to compare them, I need to learn how to use them and generate files for them, I hope I can fit a music in the small place I have (if the engine is not designed for small simple music, they can take as much memory as complex music).

I fiddled a bit with the 1. But clearly, it would only lead to blips and blops, and I prefer to spend time on the game instead of the music engine.
So, after having a look at 2, I found gbtplayer. Seems relatively easy to use, can munch on well known tracker files (no, I won't explain what a track is here. Other will do it way better.), and doesn't seems too memory and CPU hungry.
I make a POC (Proof Of Concept) and make it play some music, but I was still doubtful.

Fortunately, a friend of mine is used to compose for the GB. Soooo, I nicely ask him what was the best engine for my need, and without hesitation : "Use hUGETracker already, you dodo!"
hUGE what now? It's a new game changer in the field it seems, so let's give it a try!
And, boy, if I wasn't so stubborn, it could have been a smooth ride. All I had to do was downloading the tracker and the GB driver, export an example file and compile the whole.

But I was too stubborn, so I grab an old archive, and tryed to compose my own music. Obviously some functions didn't work, it was deprecated, so I grabbed the last release on git hub, installed Lazarus, installed the dependencies, mixed some old DLL from my rotten deprecated archive, and finaly tried to compile the tracker.
It fails miserabbly, but hey, I learnt something in the way, right?
So I just downloaded the windows program from the official website, and everything worked first try.

Great, so you will make nice music for DamnPlugIt!, right?

Haha, nope. I am clearly not a musician, but at least, the game will use an engine that could allow good composers to make nice stuff.
So, that means that I will learn how to use it, and maybe, just maybe, the music of my next game in ten years won't be awful.
One can always dream.

I hope you enjoyed this little article.
Please, don't hesitate to comment and share your knowledge.
Don't forget that I simplified how things work to keep this article, well, simple tho.

See ya!

Files

Damn Plug It (20211121 build) 32 kB
Nov 23, 2021

Get Damn! Plug it!

Leave a comment

Log in with itch.io to leave a comment.