Cabbage Logo
Back to Cabbage Site

A simple game using Csound and p5js

You may or may not know, but the Csound devs have been crazy busy of late working on web interfaces for Csound. Their work is progressing along nicely, and I recently had some time to sit down with it and create a simple generative music game. The entire source, complete with some questionable JS code can be found here

If you just want to play the game you can play it in your browser by visiting this link. The same link will work for your Android phone, but once the page loads, click ‘Add to home-screen’ in your browser menu. Then close the page and launch it from the home screen. Keep the phone relatively flat in order to avoid burning up in space!


The music is based on 5 simple melodic fragments that are played back with a very simple lofi synth. Its lofi sound is down to using a very short table with the oscillators.

The drums are also about as simple as can be. The pattern they play is updated each time an 10 coloured objects have been shot down. Some simple JS code simply updates a the ‘drumChange’ channel.

As the player progresses, each of the layers becomes active or inactive. After about 30 or so points the fragments will start undergoing some simple transformations based on random probabilities. Some voices will be muted, others will be transposed. Some will have the order of their notes moved around. The triggering of these transformations is based on a modulo operation so they will keep happening for as long you the user plays the game.

The fire sounds is also very simple. It consists of two parts, the initial ‘fire’ and the ‘explosion’ that follows.

These are triggered using the readScore method which simply triggered instruments when called.

The only thorny thing from a Csound perspective was making sure all the voices stayed in sync. I was getting some bad oscillator drift over the course of 5 minutes or more. I fixed this using a combination of tab opcodes and a single master clock index.

In conclusion, I have to say working with p5js and Csound is pretty cool, once you accept certain platform limitations. Many thanks for Steven Yi and Victor Lazzarini for all they work they’ve put into the Csound web stuff in the past few weeks. They sheer amount of work they have got through is breathtaking.

1 Like

Geniuses. bloody geniuses . The lot of yous!

Don’t confuse me with Victor and Steven, those guys operate on a different level altogether! :joy: