music for parallel consumption: web audio version

Some call me stubborn; I say I’m tenacious. Once I start something I rarely give up, even if it doesn’t go so well. Weakness, strength, or both, this is what probably makes and made me a composer and a programmer. (Oh dear…this is starting to sound like a cliched answer to an interview question.) The challenge of not being able to do something with a computer that I really wanted to do has led me down many a horror-filled wormhole. The Javascript Web Audio API was one of the worst I’ve ever encountered.

Back in my early days of programming, probably around 1993, when samplers were really restricted with regards to memory, mainly, I wanted an application that could stream and mix many, potentially long sound files from disc. To this end I programmed a complete application, with user interface and MIDI input, for the NeXT computer, using Objective C—a language I had no clue about. We’re talking about the pre-web era here, so the only resources I had were some existing projects whose source code was open along with a book or two. (I don’t remember using internet bulletin boards for this.) I just jumped in and hacked at it until it worked. I’d only programmed in the dynamically-typed and comparatively easy/idiot-friendly language Common Lisp until that point, so it was a steep learning curve and completely arse-about-face. Only afterwards did I learn about the language more formerly, and C in general, with its pointers and strict data types. That paid off though, as my first job outside of university was programming in C and C++.

So I don’t know if I’m just getting old and tired—or the Web Audio API is the monumental excrescence it appears to be—but a couple of years back I tried implementing my MaxMSP music app music for parallel consumption for web browsers using this Javascript system. After a few days the basic infrastructure was there but I eventually gave up in disgust because, while it might work with browser A on Operating System (OS) X, it didn’t work with browser B on OS X, and certainly not with browser A on OS Y. Don’t even get me started on mobile devices. So for pretty much the first time I gave up on a programming project. Or did I?

Just recently I wanted to see what all the hype was about regarding to co-developing code with ChatGPT. I turned back to my music app, which had never really stopped niggling. ChatGPT had a lot of insights, some of which were wrong of course, or let’s say incomplete, but it got me there in the end, which, given the journey, was quite something. I won’t say it was easy but it was a game-changer1. The complexity of developing music apps in Javascript with Web Audio, and making it work with all browsers etc., remains incredibly difficult. Using just a search engine in order to gain the necessary insights would probably have taken me a couple of weeks. Not only that, it would have been incredibly frustrating, as the main code was there already: the MaxMSP app was made, fundamentally, with Javascript, so there was an awful lot of code that I could just drop in and reuse. The code I had to co-develop with ChatGPT was also there very quickly but the tweaking required to make it work with all browsers etc. was a horrendous process. Luckily I had time in airports and on trains so instead of twiddling my thumbs I tweaked my code.

One of the main challenges, apart from browser/OS issues, was handling the rather large chunks of audio in the app. There are 118 sound files in the piece, with durations ranging from less than a second to 3:43. These are triggered by the Javascript code at precise points so I did not want to download them during playback—that might lead to synchronicity problems. So the user downloads them all before playback begins. The webpage is therefore quite resource-hungry. So my mobile phone, for instance, simply backs out at the download stage, whereas my iPAD and all browsers on my computers have no problem. Not ideal but almost there. By the way, I didn’t want these sound files to be openly accessible, so they’re stored in a separate protected directory which is then accessed by a PHP file and fed to the browser’s audio system by the main Javascript code.

You can listen to the piece at https://michael-edwards.org/mpc I might regret writing this, but let me know if you hit any problems in your browser of choice.

 

 

 

  1. So much so that I’ve used ChatGPT in a couple of different environments recently, e.g. to generate a LUA script for use in reaper that drops in about 200 ascending MIDI programme changes on one track at the start points of items on another track

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *