Alok Menghrajani

Security engineer at Square. Previously co-author of Hack and put the 's' in https at Facebook. Maker of CTFs.

Home | Contact me | Github | Twitter | Facebook

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 and

If you are looking for mod files, is the place to go.

Links worth reading:

Source code for various javascript players:

Technical info on the mod file format: