Saturday 30 October 2010

nbandroid deprecated error

Recently I purchased the HTC Desire. I am very very very pleased with it!
As with all users of smartphones, I immediately went to the App Market to check out the various apps around. Since I am a foobar2000 user, I found this neat app to remotely control the music playback. Sadly, the app miserably failed.
I've checked another one, but the English of the author is appalling. Yes, I know, I can just get the source, fix it and send it back, but its too much trouble when...

I can do it myself!

It's been a long while since I coded for myself (since I program for a living) so I opened a repo in BitBucket and started my own MusicRemote application (http://bitbucket.org/silverclaw/musicremote).

I fired up Netbeans (I dislike Eclipse) and got the nbandroid plugin to allow development of android applications.
Sadly, the newest SDK for the Android has deprecated some tool and the program fails to build. Took me some muckering around to find how to fix it. Well, its the 3rd commit of my repo!

Apparently, the xml build script is outdated. To fix it, one only has to insert a single line:

arg value="-d"

(between < and > of course. Can't put them here because it breaks the post)

where the apkbuilder tool is configured, line 489 of "build-impl.xml" on the "nbproject" folder. Add it just above the line where the -z option is configured.

This should allow your run process to finish. Keep in mind that, at least on my computer, I need to first start the emulator and then opt to run the app on the already running emulator.

Wednesday 27 October 2010

Subnormal floats

Recently at work I had to write a floating point emulator. Although I did have some background knowledge of floating point operations, I still had to do some research on the matter and found out that, after all, it shouldn't be all that difficult.
The emulator was required to perform mathematical operations at a higher resolution. We are using our own custom hardware with 32 bit registers. I decided to expand the significant bits from the 24 of the standard float into 64 bit significant (actually more than a double) and kept the exponent on the same range (to speed up conversion to and from the simulated float). As a side note, the exponent of the float simply increases the range of representable numbers; it is the significant that increases the amount of intermediary numbers, thus increasing accuracy.
All went well, until our test programs decided to throw subnormal floats at the emulator.

Hell broke lose.

The concept of a subnormal float is simple: instead of flushing the result of the multiplication of the minimum float with a number less than, to zero, the most significant bit of the significant is slowly shifted right with the exponent kept at 0 (a value otherwise reserved to represent zero itself). This is called "gradual underflow". This obviously caused problems, since I used the implicitly set bit explicitly set and used the 0 exponent to check for 0.

The final result was not short on black magic, which was eventually brought to the light side with some assembly level debugging. Since I failed to find resources relating to subnormal float emulation, I figured I might as well share the C version of my emulator, developed on my own free time (not the Company's of course!).

(to be pasted once I figure out how to paste code samples in here)