Categories
blog Games

Psychedelic Snake Charmer – Customized Shepard Tone

The music of the game is not beautiful enough to be described as music, but just a sound. Working on a primitive technology, which is not actually meant for full-fledged game development, limits the usage of sound. It is possible to use pre-recorded sound in the game, but I decided to program it instead because of the sound requirements.

Shepard Tone:

I want the sound to create an infinite increase in tension as the game progresses. This can be achieved by increasing the frequency of the sound as the snake progresses through the game. We need to increase the level of the sound as the snake either eats food, or loses, or restarts the game. But we cannot keep on increasing the frequency forever, because human ears have a limit. This is where the Shepard tone is used.

Shepard tone is an audio illusion that gives you a feeling of forever increasing or decreasing frequency without actually moving beyond a given frequency range. How it works is amazing. A note of a certain frequency is played along with the notes which are an octave away from it. The next note is played, or the frequency of the sound is slowly increased to match that of the second note along with all its octaves. The frequency is slowly increased till the octave completes and is then looped around. This creates an illusion of increasing frequency. But how does it combat the problem of an unusual jump from the last note to the first note during the end of the loop, which could potentially break the illusion.

The simple trick is to let the first sound which starts at the least frequency, start from a zero amplitude and build itself up as the frequency increases. And do the same, but in reverse to the last one. The last sound, which ends with the highest frequency, should slowly diminish itself. This creates a sound which fades in with the lower frequency notes, then keeps on rising and fades out as it reaches the higher frequencies.

Customization:

The sounds could be produced on any software that deals with sound, and then be used in the game. This is a good idea, but I’m already provided with tools which are primitive, but efficient enough to produce sine waves. They can also produce other type of basic sound waves, such as triangle, square and saw. Since the latter three contain higher frequencies, which I’m trying to avoid for a more psychedelic feel, I choose to work with the sine wave.

I’m not well versed in music, or in sound theory, so from the basics that I’ve learned about sound design, I’ve collected the list of frequencies associated to the keyboard notes C2 to B5, and decided to work with them. This covers a total of four octaves. I’ve declared four sine waves. We can modify their frequency or their amplitude at any time during the gameplay. Initially, the first sine’s frequency is set to the one that corresponds to C2, the next sine’s to the C3, and the same to the third and the forth. When the level rises, by the action of the player, the first sine’s frequency is updated to C2#, and the same with the other three sine waves. This is done till the first sine wave reaches B2, and then loops back to C2.

The amplitude is also modified accordingly. The first sine wave’s amplitude increases with the frequency from zero to the maximum. The second and third are constant at the maximum set amplitude. The forth sine’s amplitude decreases with its frequency from the maximum value to zero at the end. This will give us an illusion of ever increasing frequency. The reverse can yield the opposite result. Saw waves can be used to produce a video game like sound effect, but I ditched the idea as addition of higher frequencies produces unpleasant sound.

There are few changes I added later on. Anyone with the right software and decent knowledge in sound design can try adding reverb and delay to produce a soothing sound. I’ve decided to stay primitive and made few changes to the sine waves itself. The four notes C2, C3, C4, C5 played together provide a decent sound, but I’ve decided to decrease the maximum amplitude of the latter two by five times and have observed a decent change in output. The sound is more comfortable to listen to now.

The image shows amplitude against the frequencies. There are other ways to achieve the effect of the Shepard tone, but the fundamental principle governing them remains the same.

Sound is panned to indicate the direction of food with respect to the snake.

Get the game at: https://rk-jain.itch.io/psy-snake-charmer
Github: https://github.com/rk-jain/psy-snake-charmer

Read more about the game at: https://uox.home.blog/2020/05/05/psychedelic-snake-charmer/

One reply on “Psychedelic Snake Charmer – Customized Shepard Tone”

Leave a comment