Design a site like this with WordPress.com
Get started

The tale of clownaudio – Part 4

“In the next part, I’ll cover the first step in clownaudio’s transition from a component in a Cave Story mod to a standalone audio library.”

It’s almost two years late, but let’s continue where we left off:

At this point in time, clownaudio was still just the nameless audio subsystem of my Ogg Vorbis music mod for Cave Story (a mod that gave the original 2004 version of Cave Story the ability to play music in the Ogg Vorbis format), and today clownaudio is a standalone audio engine library that exists entirely separately from that old mod. So how did this happen? Well, it began with a request…

Back in the pre-apocalypse days of 2018, I received a message from a Cave Story modder called zxin; he was interested in adding Ogg Vorbis support to his own mod, but didn’t want to bundle my entire mod into his: he just wanted the audio subsystem.

At the time, the audio subsystem was tangled with the rest of the mod’s code, so it took a lot of refactoring to separate it all neatly. Once I had the audio subsystem separated, I placed its code in a directory which I named ‘audio_lib’. I then wired the audio library into the code of zxin’s mod, and listened to it spring to life. Noob-y 2018 me found it so novel to have this code work completely outside of the environment it was designed for. Even now, code reusability is something that I aim for in all of my projects.

zxin had one more request, however: rather than use libvorbis directly, he wanted my audio library to leverage the libsndfile library. libsndfile is a wrapper around libvorbis and multiple other libraries, meaning that, by using libsndfile, my audio library would gain support for many more audio formats than just Ogg Vorbis, including FLAC, WAV, and AIFF.

I found libsndfile to be pretty cool, so, after integrating it into zxin’s mod, I tried backporting it to my mod. However, I eventually realised that its licensing would be a problem: unlike libvorbis, libsndfile is under a copyleft licence (the LGPL), and I didn’t want to force modders who use my mod to deal with a bunch of complicated copyleft obligations. To resolve this, I decided to make libsndfile optional.

I achieved this in a similar way to how I made the SDL2 backend optional in Part 3: I split the libvorbis code to its own source file, created another source file that implemented the same API using libsndfile, and made the build script select between one of the two files based on an option.

These would be the first of clownaudio’s many decoder backends: within days, I added decoder backends for libFLAC (for playing FLACs), libopenmpt (for playing tracker formats), and even snes_spc (for playing SNES music). In the following months, I also added support for libtremor (an integer-only Ogg Vorbis decoder) and PxTone (a chiptune format made by the same person that originally made Cave Story – Daisuke “Pixel” Amaya).

But, more to the point, this was also the start of clownaudio’s life as a standalone library. Being shared by two projects, even if only briefly, was enough to make me whip the code into shape, encapsulating it from the surrounding code. This made it easy to drop into future projects, most notably CSE2, but that particular can of worms is a topic for another time.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: