Interested in Leopard / Mac OS 10.5?

It might pay off to search the internet for NSOperationQueue

Posted in cocoa, tech | Leave a comment

Cocoa Worker Thread

For Kompressor.app, I’ve written a group of Foundation classes for implementing a worker-thread paradigm in Objective-C. The general idea is you have some non-trivial amount of processing you want done and then (optionally) be notified when it’s done.

This implementation has a number of advantages compared to others:

  • Threads are created once and reused, no expensive thread creation for each work unit.
  • Non-polling (using NSConditionLock).
  • Low communication overhead (e.g. no Distributed Objects).
  • Small (although the code is spread out over 3 classes / files).

How do you use it?

  1. Create an instance of SIWorkManager (usually there should only be one); by default it creates as many worker threads as CPU cores are available.
  2. For each unit of work, create an SIWorkUnit object (which contains the target object and selector where the actual computation is done, as well as an optional didEndSelector which is called on the main-thread of your application with either the result of calling [target selector] or the originally given argument). The target and argument are retained by the work unit.
  3. Tell the work manager object about the work unit (via addWorkUnit:).
  4. Done!

If you want to wait for a batch of N work units to be done, create an NSConditionLock L, and at the end of the work selector, you do [L lock]; [L unlockWithCondition:[L condition] + 1];. After dispatching all the work units in the main thread (or wherever), you wait with [L lockWhenCondition:N]; [L unlockWithCondition:0];.

An (untested as I am only on a Linux machine at the moment) example demonstrating both simple usage as well as waiting for a batch to be finished is in BatchExample.m.

Remember to only access shared data structures (or your user-interface) in the didEndSelector. SIWorkManager also has messages for removing work on or referring to a given object. Use nil to remove all pending work units.

Here is the source code with all required files. Feedback / fixes appreciated.

Posted in cocoa | 6 Comments

Music for 2007

While coding during the last month I’ve been listening to a lot of music via Pandora (a music recommendation service / internet radio station). I’m listing some of the stand-out tracks / artists I’ve enjoyed here

  • Röyksopp – The Understanding (Norwegian, kinda groovy, kinda poppy)
  • Amos Lee – Keep It Loose, Keep It Tight (relaxed)
  • UNKLE – Reign (electronic strings + big beats)
  • Crooked Fingers – Dignity and Shame (piano with slightly odd vocals)
  • Cat Power – I Found a Reason (via V for Vendetta)
  • The Prodigy – Voodoo People (Pendulum Remix) (more aggressive and faster than the original)
  • Kasabian – Club Foot (from Tony Hawk’s Project 8 trailer)
  • Frou Frou – Details (pop-rock with nice female vocals, now part of Imogen Heap)
  • M83 – Teen Angst (from the A Scanner Darkly trailer)
  • Alpinestars – Carbon Kid (from the Test Drive Unlimited soundtrack, sounds like guest vocals from Placebo)
  • Rosie Thomas – When We Were Small (Farewell, Wedding Day, Bicycle Tricycle)
  • Ryan Star – Songs from the Eye of an Elephant (piano ballads)
  • Beazley Phillips Band – Shooting Ghosts (see above)
  • Camera Obscura – Pen and Notebook (female vocals + piano)
  • Apparat – Komponent (supposedly intelligent dance music (IDM), reminded me a lot of The Notwist)
  • Apparat & Ellen Allien – Orchestra of Bubbles (this actually is IDM, song tip: Rotary)
  • Statistics – Leave Your Name & Often Lie (alternative rock with some electronica, try A Number, Not a Name or Nobody Knows Your Name)
Posted in music | Leave a comment

Kompressor.app and Wavelet Image Compression Library 3.3.3

Shortly before the year is out (and as result of my vacation), there is some fresh software to be had… :)
I’ve now written an Mac OS 10.4 application called Kompressor.app to compress, inspect and display WKO images. This release goes hand in hand with version 3.3.3 of the wavelet image compression library itself.
Because this is the first (semi-)proper Mac-application I’ve written, I would welcome any form of testing or feedback people can provide, especially on the user-interface side. The application is universal and thus should work on PPC and Intel Macs.
Here’s a bit (all of it actually) of the supplied online help to get started… Continue reading

Posted in wavelet | 14 Comments

Phoenix Wright 2 – Justice for All

I’ve imported the Japanese DS version of this – which is a budget release as it’s “only” a direct remake of the GBA version, which can also be played completely in English. The translation is very well done and the humour is as good as ever, although there are two or three spelling mistakes I’ve noticed so far.

The game itself is typical Phoenix Wright silliness (probably a bit more silly than its predecessor actually) with quite a lot of recycled content. Still, if you enjoyed the first Phoenix Wright, you’ll enjoy this too, although some of the music and certain coincidences are more hamstrung than before.

Posted in games | Leave a comment

Low-Level Libraries and High-Level Languages

If you want to write a library that could relatively easily be used in embedded systems (say Xbox 360 / PS3) as well as being generally portable (Windows, Linux, Mac OS), then you end up in a bit of a bind. You can use C and be on the safe side, but for some types of programming C is rather cumbersome (see for example the Io language). You can use C++ (or one of its subsets), but now any client of the library has to understand the C++ ABI (which AFAIK only C++ does). Another option is to use whichever language is best suited to solving the problem you’re addressing in the library, but that usually imposes constraints on what can use or bridge to the library (e.g. if I were to write a library in Python, how do I use that from an application written in C++?).

Now, if whatever you’re coding is a low-level component, then this restriction becomes even more imposing because many higher-level pieces are now depending on and interacting with the library itself.
If you restrict yourself to running on Windows only (as that is the only platform where you can realistically rely on the CLR run-time being available) and don’t mind its overhead, then using .NET and the CLR will solve this problem for you nicely. For running on anything else, you’re pretty much screwed… :(

Posted in tech | Leave a comment

What’s happening?

Work is keeping me fairly busy (preparing for a conference in Toulouse), and not that much terribly exciting has happened. I (un-)am patiently waiting for my Mac Pro (having chosen a decent 3D card as well as 802.11 has moved the ETA to mid-September), Rhythm Tengoku (Rhythm Heaven) is great (I am still looking for the song from the festival-stage), and Chromehounds is regularly taking up my evenings.

This game has gotten very unfair reviews, founded on its mediocre single-player mode, but the squad-based persistent online war redeems it (although there still are a number of annoying bugs left to be ironed out by the upcoming patch). The way in which it encourages teamplay is cleverly designed, and it is the main reason I play. There is nothing else like it. If your are looking for a twitch-shooter, stick to Halo 2, but if you’re lusting for something more strategic and substantial (with endless options for building your own mech), this might be for you. Some comments from Penny Arcade might help explain what makes this game good. :)

Posted in games, general, review | 2 Comments

Vernor Vinge – “Rainbows End”

As you may have noticed, I really enjoy Vinge’s books. As an aside, I noticed his books via a mention of one of them by John Carmack during an interview…

Anyway, on to the book itself. It’s rather short, in particular for a Vernor Vinge “novel” at approximately 370 pages, which translates into about three enjoyable evenings. Considering only the hardcover version is currently out, this may be a bit steep for some.

The time it is set in feels very similar to Neal Stephenson’s “Snow Crash”, so it’s definitely near future extrapolation and often arrives at the same conclusions (or solutions to current problems) that Stephenson does. It does not involve as much action, though, although things speed up towards the end of the book.

As is common with Vinge, the distinction between who is good and who is bad is not clear cut. Nevertheless, there is (at least) one near enough villain (if only due to the measures he is willing to take to achieve his ultimate goal). At first, there don’t seem to be any genuinely likeable characters, although all of them are intriguing and you can see why they act the way the do.

The novel does use some sort of annoying semi-XML convention for showing silent messages between characters, which makes those a tad hard to parse, but in some ways can also be seen as elaborate set-up for jokes on cryptography conventions. Actually, the whole novel is full of humour (and cynicism) and some very nice word-play. It is intelligent, but neither forcedly so nor does it hit in the face with an attitude of “I’m proper literature”. Even the title has a funny twist…

Thankfully, the book is not all fun and some very real problems (just scan chapter titles for some obvious examples) are being looked at. Some in detail, some in passing, but usually without passing judgement – that is very much left to the reader, which IMO is a good thing. It is also fairly suspenseful, although not with as much of an overall feeling of dread as “A Deepness in the Sky” or “A Fire upon the Deep”.

It has a good beginning, it has a good middle part, and – most important of all – it has a good ending. Very recommended.

Posted in review | Leave a comment

Black (Xbox)

I’ve been playing (and finishing ;) ) Black on my Xbox 360, as it is one (if not the only one) of the more recent Xbox games that are backwards-compatible. Technically, it is a very good showcase of what is possible on the Xbox / PS2 (as we are used to from Criterion), although there still are some glitches in the emulator (hanging, black overlay on the screen so can’t see anything (which goes away while you open the guide, incidentally)).

The game plays differently enough to other first person shooters (focus on headshots, nearly every enemy has some form of body armor, blowing stuff up, taking cover, big “Matrix Lobby” shoot-outs), but there is not too much variety; but then the game is rather short (which I didn’t mind). The “story” / video sequences are useless and going back to these indiviual missions (which are set in the same region) after the cohesive single-player campaign of something like GRAW feels jarring.
I found it was quite challenging on Normal, you really have to move fairly slowly, going in guns blazing usually ended with me being dead. No infinitely respawning enemies is a plus, a big minus for reinforcements being teleported in according to the scripted progression, though.

Not worth full-price IMO, but if you find it used / discounted (I bought it for 20 quid from Amazon) and like blowing stuff up, it’s well worth it.

Posted in games, review | Leave a comment

Rate-Distortion Graph

I’ve invested a bit of time in getting some nice rate-distortion graphs out of my wavelet image compression library. Now that it’s embedded, the process is fairly easy: Compress once into a single file and then decompress only enough bits from the file until the desired rate is achieved. As such, the graph also shows the quality over the progress of the file.

Here is an example of one such graph, for a 708×1024 image of Mena Suvari (which unfortunately comes from a JPEG source and thus has block noise), as the Lena image (notice the name similarity? ;) ) is past its prime IMO, especially the color version has plenty of noise in the blue channel. The image was encoded in the YCoCg colour-space, which explains the slightly higher quality of the green channel and why even the highest rate is not lossless. Compared to the RGB version, the YCoCg representation incurs a mean-square error of ~0.25 (which results in the root mean-square error of 0.5 shown).

Rate / Distortion curve for a colour image of Mena Suvari

In theory, the rate/distortion graph should have a negative, but monotonically increasing derivative (which in normal language means something like “bigger improvements are closer to the beginning of the file”). We try achieve this by scheduling data units (which are essentially bitplanes of blocks) by how much they reduce the error in the coded image for each bit of their size. There are two reasons for this “close-but-not-quite-monotonically-increasing-slope”. One is that the error (distortion) is not computed exactly; instead I use an approximiation that based on the wavelet transform used. The other is the fact that we deal with packets / data units / blocks of finite size, and as soon as more than one channel is written to a single file, it becomes evident that a single packet will only improve a single channel – which in turn means the other channels have a stagnating improvement (zero derivative) for the size (or duration) of that packet.

These plots also make it easier to spot differences (usually either improvements or regressions) for changes in the code, so I’ve created graphs for all my test images, so that I can make these comparisons more easily in the future.

I’ve also taken an old pre-3.1 version (thank you, darcs!) that still used the recursive quantizer selection to produce similar plots (taking much longer as the image had to be compressed anew for each rate) and the result was pretty much a draw, in spite of the embedded version having to store a bit more sideband data (number of bitplanes for each block in the header, and which block is coded next in the bitstream itself). All of which makes the embedded version the “better choice”, due to its other advantages such as simpler code and “compress once, decompress at any rate”.

Posted in wavelet | Leave a comment

Patenting CPU instruction sets and $150 PCs

Via a blurb on ArsTechnica about a Chinese $150 PC, I’ve stumbled upon the Story of Lexra, a now out-of-business semiconductor IP provider. A few things in that article struck me as interesting, namely

  • You cannot patent an instruction set.
  • “You can patent designs and methods that are necessary to implement a particular unusual instruction that is part of the instruction set.
  • Guess what Intel has patents for MMX instructions on… Although this point is now moot, as AMD and Intel have cross-licensing agreements, it was an interesting way to stop AMD from offering “fully compatible” CPUs (which resulted in AMD offering 3Dnow).
  • “One interesting problem with the patent system is that one institution, the PTO, determines whether a patent is valid but a different institution, the courts, determine whether one infringes. It is entirely possible for the two institutions to interpret a patent differently and for either a non-infringer to be wrongly convicted or an infringer to get away with their crime.

Scary, isn’t it?

Posted in tech | Leave a comment

Phoenix Wright – Ace Attorney (Nintendo DS)

Phoenix Wright is a bit an odd title for Western gamers, but I sincerely hope that more niche titles like it make their way over here from Japan. It’s a strongly structured adventure (although some would argue it is not much more than a heavily scripted visual novel), but that is not to its detriment in my opinion.

In your role as defense attorney, you alternatingly look for clues / evidence, and then progress to the actual trial, where you cross-examine witnesses to uncover contradictions in their testimonies. While that may not sound like much, the contradictions become increasingly hard to find and the overall story (as in the crimes themselves with their motivations and their relation to each other) meshes all of that into an interesting narrative.

There are 5 cases altogether, 4 of which are ported from the Japanese GBA game, and a much longer 5th case, which was specifically written for the DS and uses many of the system’s features very well (touch-screen, microphone, 3D graphics). Overall, the game took me about 10-12h to complete, and I very much enjoyed finding clues and contradictions, although as mentioned before, the structure is very rigid and usually there is only one correct way of doing things.

Posted in games, review | Leave a comment