Tiago Ramalho AI research in Tokyo

Rays for android

Another platform I had a go at porting the rays app for was android. This was probably the least enjoyable port I’ve done, not because of the Java language but because there is essentially no decent library to do the kinds of 2D effects the app requires.

I researched a bit on the topic and there were three ways to go about doing this:

  • Use android’s own openGL implementation.
  • Use the NDK to write native code which draws directly to the framebuffer.
  • Use libGDX.

At the time (well over a year ago, before the fancy new android developers redesign) documentation for the first two options was absolutely incomprehensible. Even now I find using the openGL implementation in android quite confusing, although it might be my fault as I never really learned low level openGL. I now feel tempted to use the much improved NDK and do some low level pixel manipulation, but other projects take priority…

I ended up using libGDX. It was also poorly documented (some random wiki pages + code comments) but the API made a lot more sense to me. This is because it was in the vein of some 2D libraries for the NDS such as the venerable PAlib and uLibrary which I used extensively previously (in hindsight, it appears they were not the best libraries in terms of code quality and the simple libNDS would have been a much better choice). The fact that you could instantly play the game on your computer natively without needing an emulator also helped. Though I would recommend just plugging in your android device and debugging directly there, Android’s debugger is truly excellent.

The library was chosen, the code was banged out, et voila! It lives! No antialiasing, no funky glow effects but it lives!

Rays app running on Galaxy S2

One idea I had to make the app more interesting would be to synthesize some musical instrument, something like a violin, where each instrument would be represented by a ray, with the intensity of the sound proportional to its speed. I could not find any satisfactory samples though, since they all come as single notes and I’d rather have some continuous sound produced. It might be more interesting to use some sort of synthesis algorithm to produce an interesting sound and modulate its amplitude, frequency or harmonics with the rays. How to go about it remains a mystery  There aren’t too many synthesis libraries available for android that do what I want. Libpd seems to be a decent option, now I just need to find the time to finish this project.

Since the application has only been tested on a handful of phones, I never did toss it on the play store. Get it here if you want to play with it. You’ll have to allow installation of non market apps.