Alok Menghrajani

Previously: security engineer at Square, co-author of HackLang, put the 's' in https at Facebook. Maker of CTFs.


This blog does not use any tracking cookies and does not serve any ads. Enjoy your anonymity; I have no idea who you are, where you came from, and where you are headed to. Let's dream of an Internet from times past.


Home | Contact me | Github | RSS feed | Consulting services | Tools & games

In the 70s and 80s, people were writing the first computer programs that played music. In 1987, Amiga programmers invented a file format called mod (or module). The file contains samples of instruments, patterns describing which sample to play at what speed and a table listing which patterns to play in which order.

The resulting files were very small (about a thousand times smaller than mp3) which was a big deal in a world where software was shared on ~1MB floppy disks. Today, mod files continue to exist, mostly in the chiptune/demoscene culture.

The mod file format is very simple. I therefore decided to write the skeleton of a simple player from scratch. After a few hours of coding, I was able to parse the patterns and play the notes using the Web Audio API and a square wave.

A little later I had a nice visualizer too. The Web Audio API is really fun to play with.

I am only playing a single channel without any effects. The next steps would be to implement the different types of effects (volume, arpeggio, slides, vibrato, tremolo, finetune, loops, etc.) and also pipe the instrument samples into an AudioBuffer.

If you are interested in full-fledged mod players in javascript, make sure to check out http://mod.haxor.fi/ and http://deskjet.github.io/chiptune2.js

If you are looking for mod files, http://modarchive.org/ is the place to go.

Links worth reading:

Source code for various javascript players:

Technical info on the mod file format: