About

Flash MOD Player is a MOD player written in the haXe language for Flash 9. It is able to play Protracker, Soundtracker and compatible MOD files up to 32 channels (the channel count is figured out using the MOD's fingerprint number).

Some time ago i got interested in making Flash games, but while the graphics part had advanced to a point where you could do almost anything in Flash - as long as you didnt mind speed since Flash is a very slow platform when to compared to Java or native code - the sound part was really limited. What you can do in Flash up to and including version 8 is load a sound file (WAV or MP3) from embedded data or from some URL and play that file. That was it.

That limitation was true in Flash 9 too, but Flash 9 had a workaround for this problem. I believe they didn't really designed this workaround for this purpose, otherwise they could have added proper sound generation support in the first place (like they did for Flash 10, but now that i write these lines it is still in beta). The workaround idea is simple: using a special loader that loads data from premade arrays of bytes instead of some sort of file or network connection, you "load" a synthesized SWF file that contains the waveform to be played and a command that plays this waveform. Once you do that you dont have any control over the playback beyond stopping all sounds. This is a big drawback to this method because you cannot have nice UV bars or pause the sound or do some sort of crossfade or repeat songs from a given position. And the biggest problems when it comes to MOD playback are memory consumption and precalculation time. On the other hand once the MOD loads, the playback is flawless.

The idea is not new actually. Another player, 8bitboy which used this method was released around a year before FMP. However 8bitboy tries to overcome the problem of precalculating the complete sound wave by calculating in chunks which are streamed to the Flash player once the player fires a "playback done" event. This is actually how most MOD players work, but under Vista the Flash player 9 has a noticable latency to firing this event (and according to Flash developers, this will become worse in Flash 10). So the sound produced with 8bitboy isnt seamless. While FMP's sound isn't totally seamless either, the problem lies within Flash's sound playback routines and the ticking is much less likely to occur when precalculating the whole playback.

But that wasn't really the reason i started making FMP. The reasons were two actually: one is that although 8bitboy was released a year ago, its license - GPL - wasnt friendly to flash game developers. Even the BSD license wouldn't do the trick, as i realized after a first beta release of FMP (BSD requires a bunch of text to be distributed with your binary and be somehow viewable by anyone - in normal binaries that isn't a problem, just drop the license in your program's directory or documentation, but in licensed Flash games where the site licensing the game might require your only copyright statement to be for yourself at most, it is a problem... also the standard BSD license text, even small, it would take most of the screen size in a Credits section given most Flash games' area). The second is i wanted something more than a MOD player: i wanted to be able to generate and play sound effects for the games. Although i never intended this, some people also figured out that the code used in DynSound, my sound playback class for FMP, could be used for playing gapless MP3 files. I don't know what this means, tbh, since i never used MP3 files anyway, but i suspect its good because more people seemed being interested about this than MOD playback :-).

Although it was tempting, i tried to steer clear from 8bitboy's source code. After a while browsing around in several forums, i got a great idea on how the trick is done and after some hours trying to get my head around the Flash 9 API (all i had done up to this point was in Flash 8 and the only reason i went to Flash 9 was the sound trick) and doing a great deal of reading about the SWF file format, both from Adobe and unofficial documents, i got some sound playing. Nothing fancy, just a sine wave, but it was enough :-).

Playing the MOD files was proven harder than i imagined. Although i tried to write a MOD player some years ago in C, so i knew what to look after, i still had many things to keep in mind. And it didn't became easier with the fact that MOD was never standarized from a tracker (being some sort of lower common format and with coders eager to show that their tracker is better than others' it was bastardized beyond any kind of border). Since i dont have an Amiga handy, i decided to use a tracker i consider "good enough" for testing how precise my player is. This tracker is MilkyTracker. Now, dont blame MilkyTracker if your MOD doesn't sound correctly in my player, because i tried my best (mostly). Once i had a decend playback though, i released the player to the public using the zlib license (which seems to be free enough for me - and game developers).

Currently Flash MOD Player supports almost all MOD files and all commands that have nothing to do with playback order (since this is impossible to do with precalculated files). Since version 1.1 it also supports looping and MOD files which use notes outside the classic octaves. It still sounds a little out of tune, but with support for more octaves it got better (no, adding even more octaves wouldn't solve the issue - it has to do with timing probably).