Making smooth sounds for music

by Sean from spookshow.studio
March 2021 Update

Synthesizing Music

Spook Show Studio will allow creators to write their own songs. This is made possible by the synthesizers I'm creating, that will convert note information into sound waves.

I wanted to give everyone a peek into what making a synthesizer is like. It's an esoteric topic, but it's a lot of fun too because you can come up with ideas, and hear the result!

What is Sound?

Digital sound is just a stream of numbers, ranging from -1 to 1. So, for example, -0.2, 0.1, 0.2, 0.3, ... etc. These numbers become the location of the speaker diaphragm, which produces sound waves in the air. The goal of a synthesizer is to create a stream of numbers that sound pleasing.

Music has a lot of numbers. Most music you listen to has 48,000 numbers every second. That means a 3 minute song is 8.6 million numbers!

Simple Waves

In sound synthesis, the most basic waves you can create are sine, square, sawtooth, and triangle. Click the play buttons below to hear each wave:

These might sound familiar to you -- they're used in a lot of chiptune and retro music, like on the Gameboy and NES.

Aliasing

Please take a closer listen to the sounds above. You might need headphones.

If you listen very closely, the square and sawtooth sound a little weird. It sounds a little dirty. There are extra wobbles and hums in the background.

This is called aliasing, and happens because of the vertical lines in the waves.

It can be surprising that there are ugly artifacts in such simple functions. After all, isn't the simplest square wave just alternating between -1 and 1?

The real explanation takes a lot of mathematics, but the short answer is that you simply can't physically move a speaker diaphragm from one location to another instantly.

Ideal Waves

Luckily, we can construct perfect square and sawtooth waves if we're willing to cut out higher frequencies! Here are two examples:

Compare these to the originals at the beginning. Hopefully you can hear how these new waves sound cleaner.

Problem solved, right? Well, not really. Those perfect waves take a lot of computer power to produce. We need to do something similar, but hopefully using less CPU.

Oversampling

There are a lot of different ways to get closer to the perfect wave. They have funny names like PolyBLEP or PolyBLAMP -- but the one I'm using at the moment is simply to filter out the higher frequencies.

The idea is instead of generating a sound at 48,000 samples per second, generate one at 480,000 samples per second (10x). These will be dirty, but the dirty part will be easier to target with a normal filter.

The end result isn't perfect, but it's better than the original:

Is It Worth It?

You might be saying to yourself: sure, maybe I can barely hear a difference, is all this really worth it?

The more notes and sounds you layer on top of each other, the more noticeable the problem becomes. For example, one common technique is to layer lots of sawtooth waves to create a cool effect:

That same effect with an aliased sawtooth wave sounds a lot worse. You can hear the static in the background:

The world of sound synthesis is really interesting, and at times very surprising!

Thanks for following along, I'll see you next month!

- Sean aka @velipso

Website: spookshow.studio

@velipso