in development

an infinite number of earworms for you

Procedural generation fascinates me. I take a sneaky pride in the fact that all the textures and models for Gas Food Lodging are assembled client-side from pure code. In the next gaming project, I’ll be adding audio, and I plan to generate it on the fly.

My first crack at the problem? An algorithmically generated soundtrack. Click the button below to hear it.


Okay, it’s not the greatest. Source is here. A few points in no particular order:

I’m using the A Minor Pentatonic scale. I tried C Major and C Blues, but neither of them sounded right. I think it’s a problem of dissonance. Both the major and blues scale have dissonant intervals, and the pentatonic scale really doesn’t. Anything you play in a pentatonic scale is guaranteed to sound—well, not “good”, but “acceptable”. Dissonance requires a more intelligent algorithm to manage.

My cross-browser solution to the audio problem was the old standby, generating a base64 representation of the PCM data and producing a URI string from that. I found a helpful library called riffwave to do the heavy lifting. (Thanks to Pedro Ladaria.)

I originally used a Markov chain to generate the “riffs”, and the results were even worse: no recognizable motifs emerging, just random noodling. Music needs repetition, though not too much—just enough to keep the pattern-hungry brain happy.

So, I’m putting this aside. Fun project, but I doubt I’ll take it much further. Bits of it are going into a sound effects generator. But keep it running if you like. I’m sure there’s a symphony in there somewhere.