"These are the elements of life/"

Monday, August 17, 2020

My web-based Amiga Protracker MOD music player

Back in 2013 I took a web coding course, and for the class project, I wrote a PHP and JavaScript-based MOD player.  Back then, I didn't yet know the concepts of resampling well enough to get the DSP portion of the MOD player correct in time for the submission due date.  It would play the correct rhythms but the samples sounded like static.  It was also doomed from the start to not sound at all musical, because even though I was pulling samples with correct byte order from the MOD files, when calculating a value I was naively using ^ for power, which is of course Exclusive-OR.  Oops!  No wonder the samples sounded bad!

A year or so later, I implemented in the embedded software for a pathogen detection instrument some resampling routines, and I realized that was the knowledge I needed to make my MOD player work.  For many years the desire to finish my MOD player was on the back of my mind, until this year, when I finally decided to finish it.

When fixing my MOD player, I first tried just playing back the samples that it read from the MOD files, and I knew something was wrong simply by the way they sounded at a fixed and reasonable playback rate.  I thought maybe it had to do with how I was doing byte-swapping, but all that code looked okay.  Then I noticed I was using XOR instead of a power, changed it to some repeated multiplies, and BAM all of a sudden the samples sounded like they came from the song!  I was pretty ecstatic.

I then kept working from there, making it properly resample the data to get the right notes.  I incrementally added effects to get songs that required them to sound right.

As I had started it in 2013, I didn't want to deal with anything but getting it to work, so I begin development in 2020 on the same computer with an old version of Mozilla.  After I got it playing songs nicely, I then moved my development to a newer computer, and to my dismay, discovered that the Mozilla-specific moz audio functions had been deprecated.  At first I was annoyed, but after I got it to work using WebAudio, I realized that it was a great benefit, because most people use the spy browser anyway, so nobody would visit it if they had to use Mozilla Firefox, etc.  Also, it now works on phone, which is pretty fun.

Currently it needs the 0xA command implemented, and the related effects that also attenuate the volume of a sample over time.  At this point I think it sounds good enough to share, though.

I don't know JavaScript well enough to really write it in a thought out, object-oriented manner, like I would if I had written it in Java or C++.  It suffers as a result, that effects that need to bend pitch will be really hard to implement, so I probably just won't.  Also, adding support for 8 channel mods will be ugly, but possible, instead of just instantiating more channels, or something.

When I started the project, I didn't know of other JavaScript MOD players.  I then discovered the one made by Gasman.  I think his is still reliant on the old Mozilla moz audio functions.  This year, I have also discovered the JavaScript MOD player that is used by files.scene.org, and the one used by the MOD Archive (though that one is very resource heavy, and super choppy on my phone.)  There is also a pretty good one made by a Finnish guy, and another one on github too.

The value of mine is that it is super fun to use.  It is light weight and works on phones, and has a bunch of MODs uploaded and ready to be enjoyed.  I sporadically add new MODs to it as I hear ones that make me excited to put on my MOD player.  I usually hear them on Nectarine Demoscene Radio, and then download them from Modland or Amiga Music Preservation.

Here is the link to my MOD player: http://pwh.sdf.org/web_mod_player/

I hope you enjoy the great music!

No comments: