Hey, let’s build a retro synth music player! (Part 2)

To make a music synthesizer, we need to understand how audio works. It’s a complicated subject and my goal isn’t to explain it fully here. I’ve provided links to better resources. We just need a minimal of understanding to build our synthesizer.

Audio is made by vibrations. Your computer’s speaker vibrates, causing the air around it to vibrate, and that air’s vibration is picked up by your ears.

A musical note is generated by vibrations (waves) at specific frequencies (the note’s pitch). A vibration at 440 Hz (i.e. having your speaker vibrate back and forth 440 times in one second) is heard as an A note. (Hz is short for Hertz and is a unit of frequency that just means “cycles per second”.) Notes on a musical scale each vibrate at specific frequencies and loudness. The higher the frequency, the higher the pitch of the note. Scales are a complicated subject, so I won’t go into too much more detail. The loudness of a note is dictated by the amplitude of the wave.

Our music synthesizer is going to emulate how retro game systems and consoles from the ’80s worked. These generated sounds by playing tones with specific shapes, aka “waveforms”, that were easy to easy to produce by these chips. These were typically square waves, triangle waves, or “noise” (randomness).

Watch this visualization of the Legend of Zelda theme to see what I mean. Each quadrant is playing an instrument, and you can clearly see the shape of each one. The bass tones are in the lower left and the snare drum effect is in the bottom right.

Listen to how each shape sounds and notice how the higher pitch sounds make a wave with more peaks and troughs in the same amount of space (or time). See how bass in the lower left has fewer peaks and troughs since it’s playing at a lower frequency than the square waves in the top two quadrants? Pay attention to the amplitude of the waves as well. Towards the end of the song, you can see them gradually decrease until they go silent.

Look at how the snare drum sound is achieved with a really noisy looking wave. That’s because it’s a noise wave, which looks like random peaks and troughs. Noise waves were typically used in old game systems for explosion sounds, crowd noise, ocean waves, and snare drums.

There’s one last thing to note in the video: there are only ever four instruments playing at any one time! Old game systems and computers were often limited in the number of instruments they could play at once. Our synthesizer will limit itself to a fixed number of instruments as well just to make it authentic.

Finally, watch the video below by The 8-Bit Guy for a really good summary of how old game systems played audio. This is how we’re going to do things too!

Okay, that’s enough for today. Next time we’ll talk about ADSR envelopes.

For a way deeper article on musical synthesis, see this article.

Hey, let’s build a retro synth music player! (Part 1)

Just for fun, I’m going to build up a synth music player from the ground up. The goal will be to come up with a functioning music player that can play music as you’d hear it on something like an old NES from ’80s.

In the end, we’ll have working code that can play music like this:

I made that video from 2011, so I’ve tackled this before. I want to re-do it because I love good design principles and figured this would be a great way to help others who are learning about software development.

Software development is not just about good design, but good planning and good engineering. We have to make trade-offs as we build anything, and in this blog I’ll try to illustrate how we make these trade-offs to get good results quickly and efficiently. I’m a big fan of Lean Software Development principles, so my decisions will be driven by those principles.

This will take several blog posts, of course, and hopefully you’ll learn something along the way. Stay tuned!

Oh yeah, you’ll find all the code here: https://github.com/allenu/Synthie