Wednesday, February 4, 2015


here is a small (wrapper / extension) library that can be used to manipulate libmodplug decoded buffers in terms of rows and patterns with sample accuracy:


Friday, December 19, 2014

#AS3 KeyboardHandler

(i've posted this as a comment in Starling bug report from a user)

for performance crucial sections such as keyboard interaction i would not use anything but callbacks.
the flash event system, and the alternatives such as signals are nice for higher level management, but they can't really beat callbacks for performance. what Starling does with the enhanced events is also fast, but here is my point.
the virtual machine and the garbage collector already provide you with the flexibility of one of the core features - everything is an Object including Function.
"functors" or function pointers is something that even languages like C++ don't handle that well, so you really should take advantage of this low level, yet still high level feature.
since the only way in flash to see if a key is pressed is via the KeyboardEvent, use that and build a callback system on top of it. only maintain the stage events and propagate manually not display objects but rather objects of interest.
check this concept i wrote quickly:
  • KeyboardHandler is a state machine that tracks keyboard isDown states for a keyCode and calls your registered callback.
  • it uses the native stage
  • it's super fast
  • it's worker safe
  • you can stop it at any time using "enabled = false"
  • it does call event.preventDefault(), event.stopImmediatePropagation(), but you can mod that yourself or simply call "enabled = false" when needed.
  • once a key is down it no longer registers as down until it up, this forces you to write your key logic smart.
  • if you don't track a key state yourself (which would be faster) at any time you can call supportedKeyIsDown(...) to see if a key is currently down. this allows easy checks for key combinations e.g ALT + SHIFT + LEFT.

Friday, September 13, 2013

#fast IEEE 754 double to int32 @ music-dsp

at the music-dsp mailing list there was a short discussion about a "double -> int" rounding hack present in the JUCE library. i've posted an alternative solution that does the same without IEE 754 arithmetic. i'm sure similar solutions can be found in libraries and for CPU's that don't have a floating point co-processor unit. code is for c99.

can be summarized into:
1) separate double into mantissa, exponent, sign bit
2) depending on exponent value shift the mantissa left or right by the difference of the exponent and the amount of bits in the mantissa
3) truncate and receive a 32bit integer, while applying the original double's sign


Tuesday, September 10, 2013

#flash cs6 compiler bug

i have to work with tools like the one mentioned in the title. here is a bug that only happens if you assign code to a frame in the (main) timeline. target version is and could be fixed in later interations.

you can try the following:
// Array can be used here instead, for 'list'
var list:Vector.<String> = Vector.<String>(["hello", "world"]);
trace(list); // hello,world
var vlen:uint = list.length;
trace(vlen); // 2
const clen:uint = vlen; // this works but 'vlen' is zero at this point
trace(clen); // 0
const len:uint = list.length; // list is a null object reference

results in:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Untitled_fla::MainTimeline()

what happens here is that the as3 compiler tries to play smart and traverses for 'const' declarations, and once it finds 'len' it decided to assign a value to the address where it will be stored in the 'constant pool' and then to be referenced by bytecode. but since 'list' is not a 'const' declaration itself the object is simply not constructed yet and 'list' is a null reference.

same does not happen if:

- 'const list:...' is used, but one may not want that
- if the same code is written in an external document class instead on the timeline

if this is by design it may cause compatibility issues with class written code and simply confuse developers. after all, constant declarations after variable declarations should make perfect sense. in general, i wouldn't recommend writing anything more important on timeline frames, but use classes with ENTER_FRAME listeners or attempt to use addFrameScript() on MovieClip instances instead.

Monday, May 6, 2013

#robotic arm flashbacks

i remember programming this machine with an apple 2 clone, when i was quite young. it was a educational robotic arm i had access to in a laboratory in the early/mid 80's.


it had pretty good mobility, small error margin and it could lift up a kilo or so. here is a sheet photo where you can see some Tesla ICs and a voltage regulator:


Thursday, February 21, 2013

#android 4.2.2 and RSA encryption

i was doing some testing recently with the "Android Debug Bridge" ADB, but the device was refusing APK upload. it appears that the recent JB 4.2.2 has a security update:

which means that you will need to update your Android SDK and copy / use the adb.exe (and all dependencies from "/platform-tools"), which should be version >= 1.0.31 as of this point.


Friday, February 8, 2013

#bulls and cows: open source game in ANSI C

here is an open source "bulls and cows" game written in ANSI C:

pre-compiled win32 executable included.

i wrote that after a simple challenge proposed by some of my friends, and now apparently they even play it from time to time.

if you are a C programmer, try guessing out why the 0xDA special case happens and how volatile it is.

Monday, January 28, 2013

#starling framework video tutorials

here are a nice set of video tutorials by +Hemanth Sharma to get you started with the starling framework:

if you don't use proprietary software like "flex builder", mind that you can set everything on the command line using the flex tools "mxmlc", "adl", "adb". i'm sure there are examples on how to do that online. flex is open source as is now maintained by the "apache software foundation".


Tuesday, January 22, 2013

#CFG2 - an INI-like parser

i wrote a simple INI-like parser some time ago called CFG2.
it's released in the "public domain" with source code at


Thursday, December 13, 2012

#clipboard managers

i've been using ClipX on windows for quite some time, but it seems the latest version (which haven't been updated for quite some time) has some bugs, or perhaps it's windows 7 with something installed or used at the moment.

from time to time it did not catch all the "ctrl + c" events from text editors, so a couple of months ago i've moved to Ditto, which has much more features, yet at the same time can remain quite simple when in action. it can store a very large number of entries in a database that can be cleared any time and is still quite responsive when retrieving something (perhaps slightly slower that ClipX).

on the linux side of things, the only one i've tried is parcellite, which apparently to a majority of users is the best one out there.

perhaps future OS's will have native implementations of clipboard (history) managers pre-bundled.