Stig Runar Vangen homepage
Blog

Online midlets

Lately I've been working on viewing the mobile games I've made on these pages. Games created for mobile Java, or MIDlets, are not easily runnable nowadays.

J2ME was originally formed through JSR 68 in 2002. The standard has later been abandoned, and nowadays one have to create applications for each target platform.

In order to run MIDlets one has to use an emulator. The most popular one is MicroEmulator. The emulation in this emulator is however not perfect. You do for example need to change your application somewhat for it to be runnable by the emulator.

After modifying the games so that they were runnable by the emulator I ran into problems regarding the audio. For some reason their implementation of the audio libraries only allow you to playback a unique sound once. There were also some problems regarding MIDI playback that stops after a few seconds. In addition there were some problems related to how loading of sounds are implemented, which results in crashes on load. Looking through their code I was not able to figure our how their implementation should be fixed.

What I ended up doing, was to use the reference implementation provided by Sun/Oracle. This implementation shows how to implement their interfaces. These implementations have some methods that reference native calls to the OS. I implemented all these native methods using the J2SE sound API. The end result was a fully working MIDP 2.0 sound API implementation.

Armed with this fully working implementation I patched the emulator. This resulted in an emulator that perfectly emulates the audio calls from the original games. This was the last piece of the puzzle, and I can therefore present these games on these pages.

My games originally needed only sampled and MIDI playback. The original API also defines functionality for playing tones. For the sake of completion, and for the fun of it, I also implemented this API. The biggest challenge here was to convert notes into their respective frequencies. By using a list of frequencies for each note, I managed to get a working formula. Using the reference implementation I didn't have to implement all the special operations, as this was already converted into a simple note for number of milliseconds datastructure. The use of blocks were for example converted into one long sequential sequence. The end result has some noticeable defects when the song turns into low frequent period, which almost sounds like an UFO buzzing away. There are also some clicks between notes sometimes. These errors are mostly related to rounding errors, and might be something I fix at a later date.
Sunday January 27. 2013