Gameboy Programming : Sound

After looking at Graphics, the next logical step is to look at sound, music and sound effects. This tutorial will look at how to make the basics of Gameboy sound design.

The Sound Channels

The Gameboy has four sound channels : two square waves with adjustable duty. a programmable wave table and a noise generator. Each of these has some kind of frequency or pitch control. The first square channel also has an automatic frequency sweep unit to help with sound effects. The squares and noise each have a volume envelope unit to help with fading notes and sound effects.,while the wave channel has only limited manual volume control.

Each sound channel has a length counter that can silence the channel after a preset time, to handle note durations. Each channel can be individually panned to the far left, center or far right. The master volume of the left and right outputs can also be adjusted.

For those interested a full explanation of the sound as well as a complete look at the hardware of the Gameboy can be found in the video below

The Code

How sound functions in the Gameboy is part of specific registers. Registers are specific addresses in memory that control hardware.

You must set these registers up the exact order in the example above or the sound functions will not work. The interesting aspect of this code is the second register that gets set. The Gameboy only has one speaker, however, when you put headphones in you will get stereo sound. Hence the call to both the left and right channels in NR50_REG.

Making Some Noise

Now for the rest of the main function, I am going to demonstrate how to make specific noises. The first seems like a jumping noise you would hear in a platformer.

NR10 = register NR channel 1. The sweep time is set to 1. The third bit is 1 and increased in pitch. The final set of values is how much it should shift in pitch or step up.

This piece of code on its own effectively doesn’t do anything. This sets up our Sweep. Onto the next piece of code.

This controls how long the wave cycle is going to last – depending on these values we can change the length of the sound. In this code its a fairly long sound.

This batch of code controls the volume – the initial volume and if it goes up and down. In this case it starts loud and then gets quieter.

This piece of code sets the frequency . The next piece of code dictates the playback – so how long that the sound should play on for.

For a more detailed explanation regarding sound, please check the video below out

The complete code should look like:

When you build your file and run it on the emulator you should hear this jumping style sound.

I’m certainly no expert on sound design for the Gameboy but I hope that this primer helps you understand it better.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s