Converting ogg streams into mp3 ones

This is just an announcement for my newest quick-hack which can be used to on-the-fly convert streams from webradios which use the ogg/vorbis format into the mp3 format which is more widely supported by the various devices out there.

I have created an own dedicated page for the project for those who are interested.

Also, I really got to like github.com, not as the commercial service they intend to be (I’ve already written about the stupidity of hosting your company trade secrets at a company in a foreign country with foreign legislation), but as a place to quickly and easily dump some code you want to be publically available without going through all the hassle otherwise associated with public project hosting.

This is why this little script is hosted there and not here. As I’m using git, even if github goes away, I still have the full repository around to either self-host or let someone else host for me, which is a crucial requirement for me to outsource anything.

Simplest possible RPCs in PHP

After spending hours to find out why a particular combination of SoapClient in PHP itself and SOAP::Server from PEAR didn’t consistenly work together (sometimes, arrays passed around lost an arbitrary number of elements), I thought about what would be needed to make RPCs work form a PHP client to a PHP server.

I wanted nothing fancy and I certainly wanted as less an overhead as humanly possible.

This is what I came up with for the server:

<?php
header('Content-Type: text/plain');

require_once('a/file/containing/a/class/you/want/to/expose.php');

$method = str_replace('/', '', $_SERVER['PATH_INFO']);

if ($_SERVER['REQUEST_METHOD'] != 'POST'){
   sendResponse(array('state' =&gt; 'error', 'cause' =&gt; 'unsuppored HTTP method'));
}

$s = new MyServerObject();
$params = unserialize(file_get_contents('php://input'));
if ( ($res = call_user_func_array(array($s, $method), $params)) === false)
   sendResponse(array('state' => 'error', 'cause' => 'RPC failed'));
if (is_object($res))
   $res = get_object_vars($res);
sendResponse($res);

function sendResponse($resobj){
    echo serialize($resobj);
    exit;

}

?>

This client as shown below is a bit more complex, mainly because it contains some HTTP protocol logic. Logic, which could possibly be reduced to 2-3 lines of code if I’d use the CURL library, but the client in this case does not have the luxury of having access to such functionality.

Also, I’ve already had the function laying around (/me winks at domi), so that’s what I used (as opposed to file_get_contents with a pre-prepared stream context). This way, we DO have the advantage of learning a bit of how HTTP works and we are totally self-contained.

<?php
class Client{
    function __call($name, $args){
        $req = $this-&gt;openHTTPRequest('http://localhost:5436/restapi.php/'.$name, 'POST', array('Content-Type' =&gt; 'text/plain'), serialize($args));
        $data = unserialize(stream_get_contents($req['handle']));
        fclose($req['handle']);
        return $data;
    }
    private function openHTTPRequest($url, $method = 'GET', $additional_headers = null, $data = null){
        $parts = parse_url($url);

        $fp = fsockopen($parts['host'], $parts['port'] ? $parts['port'] : 80);
        fprintf($fp, "%s %s HTTP/1.1rn", $method, implode('?', array($parts['path'], $parts['query'])));
        fputs($fp, "Host: ".$parts['host']."rn");
        if ($data){
            fputs($fp, 'Content-Length: '.strlen($data)."rn");
        }
        if (is_array($additional_headers)){
            foreach($additional_headers as $name => $value){
                fprintf($fp, "%s: %srn", $name, $value);
            }
        }
        fputs($fp, "Connection: closernrn");
        if ($data)
            fputs($fp, "$datarn");

        // read away header
        $header = array();
        $response = "";
        while(!feof($fp)) {
            $line = trim(fgets($fp, 1024));
            if (empty($response)){
                $response = $line;
                continue;
            }
            if (empty($line)){
                break;
            }
            list($name, $value) = explode(':', $line, 2);
            $header[strtolower(trim($name))] = trim($value);
        }
        return array('response' => $response, 'header' => $header, 'handle' => $fp);
   }

}

$client = new Client();
$result = $client->someMethod(array('data' => 'even arrays work'));

?>

What you can’t pass around this way is objects (at least object which are not of type stdClass) as both client and server would need to have access to the prototype. Also, this seriously lacks error handling. But it generally works much better than what SOAP ever could accomplish.

Naturally, I give up stuff when compared to SOAP or any «real» RPC solution:

  • This one works only with PHP
  • It has limitations on what data structures can be passed around, though that’s aleviated by PHP’s incredibly strong array support.
  • It relies heavily on PHP’s loosely typed nature and thus probably isn’t as robust.

Still, protocols like SOAP (or even any protocol with either «simple» or «lightweight» in its name) tend to be so complicated that it’s incredibly hard if not impossible to create different implementations what still correctly work together in all cases.

In my case, where I have the problem of having to separate two pieces of the same application due to unstable third-party libraries which I would not want to have linked into every PHP instance running on that server for which the solution outlined above (plus some error handling code) works better than SOAP on so many levels:

  • it’s easily debuggable. No need for wireshark or comparable tools
  • client and server are written by me, so they are under my full control
  • it works all the time
  • it relies on as little functionality of PHP as possible and the functionality it depends on is widely used and tested, to I can assume that it’s reasonably bug-free (aside of my own bugs).
  • it’s a whole lot faster than SOAP, though this does not matter at all in this case.

Which phone for me?

I’m a quite happy user of my Sony Ericsson W880i / iPod Touch combo: The touch is for listening to podcasts and watching video, the W880i is for SMSing and making a phone call here and then, though it’s mostly for getting called these days. Skype exists and works well.

Now with all the new toysinteresting devices coming out all over the place, maybe it’s time to reevaluate the different options. 3G iPhone? Something Windows Mobile based (though the touch diamond seems to be the way to go)? My old phone? Or a combination of any of them?

I tried to make a tabular comparison, where I’m listing the phones by use cases. And I’m only listening features interesting for me. Your points may differ from the ones presented here. This is, after all, a guide I used to pick a solution.

iPhone Touch Diamond W880i
Phone usage
Quick dialing of arbitrary numbers yes
Acceptable battery life (more than two days) ? ? yes
usable as modem probably not yes yes
usable while not looking at the device limited yes
quick writing of SMS messages yes
Sending and receiving of MMS messages1 yes yes
PIM usage
synchronizes with google calendar/contacts2 maybe yes. Contacts limited
synchronizes with Outlook maybe yes not reliably
usable calendar yes yes
usable todo list yes
media player usage
integrates into current iTunes based podcast workflow3 yes
straight forward audio playing interface yes
straight forward video playing interface4
acceptable video player5 limited yes
hackability
ssh client maybe yes
skype client6 maybe yes
OperaMini (browser usable on GSM) yes yes
WLAN-Browser yes yes

Notes:

  1. While I’m not using it often, here and then I come across something funny which I want to share with my parents or my girlfriend. MMS is the optimal medium for that. I send about one MMS per two months and I receive around 2 MMS per month, so this is probably not as important.
  2. Using Services like GooSync it is possible to synchronize the W880i with the Google services, though Google’s Contact API currently isn’t in a state where it would be useful for actually using it to synchronize contacts with the pone – mainly due to not providing an option to synchronize only certain matching contacts.
  3. iTunes not only downloads Podcasts but also keeps track of playback position and the new/not new state across devices and computers. I’m subscribed to more than 20 podcasts, so such features are essential for me.
  4. Neither the iPhone nor the WinMob devices provide an user experience for playing video that even comes close to match the one the iPhone would provide for Audio files.
  5. The Video player on the iPhone is limited to MP4-packaged H.264 files, whereas there are Media Players for WinMob that can handle whatever you throw at them.
  6. Skype is available as a JavaME application, but in addition to the (horrendous) GPRS charge, Skype also charges you, whether you make or receive calls. This is why I listed skype support as missing on the W880i

What’s missing in the comparison table is one of the upcoming large Windows Mobile devices with built-in keyboards like the Sony Ericcson XPERIA or the Touch Diamond pro. This class of devices does provide more convenient typing, but their usability still doesn’t even come close to matching a pure phones one. You’d still have to browse through menus, search special keys (like umlauts) and stuff. It’s just that typing has become a bit easier.

These little usability benefits do not even come close to offset the weight and especially thickness of these devices which is why I’m not listening them in the table above.

But let’s discuss the tables content for now:

First the obvious: The best phone in the list is… well… the phone. Neither of the two smart phones is capable of bringing a pure phone user experience that comes even close to what a real phone with a real keyboard can provide.

In case you wonder: I’m a heavy user of T9. Typing with a 10-key keypad assisted by T9 feels completely natural to me and the W880i provides really nice T9 functionality with quick access to suggestions and other shortcuts, so I’m actually inclined to say that I’m quicker to type on that phone than I would even be with one of the larger keyboard-based smart phones, mainly due to shorter distances to travel with the finger(s). With my ~100 SMS per month, I consider myself to be a heavy user of SMS, so quick and easy SMS writing and reception is a key feature for me.

Aside of that, the phone is more or less just that: A phone. It doesn’t really shine in every other aspect. Music kind-of works, but is unusable for Podcasts due to not saving playback position between launches of the media application, let alone synchronizing the playback position across devices.

Video, applications and even just browsing beyond the means of what OperaMini can provide are out of the question.

As such, the W880i basically is like grep. Or sort. Or uniq. Or like any other of these little UNIX utilities: It does one thing and it does it well.

The WinMob phones provide not much better media support (they do play video, but for Podcasts they are still not as good as iTunes), but they shine in the realm of hackability and, of course, the PIM synchronization, though there they more or less only work with Exchange. Also, the larger screen provides the user with a lot more possibilities UI-wise.

So while the W880i is the better phone, the WinMob devices are the better PIM solution and better platform to hack on which appeals the geek in me quite more – obviously.

The iPhone is limited in its capabilities as a phone, provides next to no hackability and will probably come with some enforced phone contract here in Switzerland. It does shine in the media department though, but that part is also perfectly well handled by my current iPod Touch to which I can easily (at the cost of $10) add the limited hackability the iPhone is going to get – should I need it.

Looking at this, the iPhone certainly looks like an uninteresting solution: All it would provide I currently have in the touch, aside of the phone, for which I currently have a better solution anyways.

Replacing the W880i/touch combo with either an iPhone or a WinMob solution seems like a stupid thing to do as I’d lose the good usability of the phone and/or the nice Media capabilities of the touch.

So in the end, I have only a couple of options which would work for me:

  • Replace my W880i/touch combo with a W880i/iPhone combo and use the iPhone as an always-connected surf station with limited hackability. This, frankly, is just too expensive to be of any value as it would mean to get a second mobile contract just for surfing here and then, while still forcing me to keep the data option for my W880i because the iPhone is not usable as a modem in case I need to emergency-repair a server or something.
  • Replace the W880i in my combo with the Touch Diamond: With every earlier model of WinMob devices, this would have been completely un-doable due to the thickness of the devices. The Diamond is not much thicker than the W880i, so the Diamond and the iPod Touch would still fit the same pocket in my trousers. I would lose the kick-ass usability of the W880i, but I would gain a real in-bed media player (without transcoding), an emergency SSH client and a completely working PIM with totally working synchronization.
  • Keep my solution as it currently is, while keeping in mind that ever since I got the touch, it provides all the features I would ever need: A kick-ass phone, an acceptable video player, a kick-ass music player and two browsers – one for each type of usage: The OperaMini when I’m forced to use the slow GSM and Safari on the Touch when I have WLAN (you would not want to use Safari over GSM – I tried).

It’s funny: I’m so much in love with technology and gadgets. I’m always on the lookout for new stuff, always trying out new, so called revolutionary technology. I’ve tried to many phone solutions in my life (just look at this blog), but I finally think that I have found a solution I’m willing to stick with.

The current W880i/Touch combo works so well that I don’t see any other solution that would only provide me with advantages. Each and every other new device comes with inherent drawbacks.

I guess, for once, I pass. I’ll stick around with my outdated solution and I’ll wait for the next revolution. What I currently have just works too well.

They just don’t want my money

Mass Effect is a wonderful game. Its story is one of the most interesting I’ve ever witnessed in a game. The atmosphere it brings over is very deep and impressive. It’s science fiction. It contains aliens and explosions, so it’s perfect for my taste.

Also, I like the role playing elements which contain just enough stats to make the leveling process interesting while not being overly complicated.

I bought Mass Effect for the XBox 360 back in December and played through it once, while being annoyed that I had to buy it in the (albeit very good) German version (it’s practically impossible to get English originals here in Switzerland) and annoyed about the awful, awful equipment and inventory handling that made it impossible to really know how you should equip your characters (in fact, I went through half of the game in the starting equipment because I didn’t understand how to actually put the items on).

So despite the immense replayability value of the game, I left it at that one runthrough. But I bought the Mass Effect book telling the story leading up to the events of the game.

And now, the game was re-released for the PC. Considering the fact that I actually bought the Mac Pro I’m currently using with PC-gaming in mind, I pondered with the idea of buying the game again for the PC. In English and with the fixed inventory screen (they actually fixed that in the PC version. yes. so it wasn’t just my stupidity).

This may sound crazy, but as I said, the game provides incredible value to replay it: Different decisions, different choice of squad members, even choosing different classes to begin with (though I would never even have tried to play a caster in the 360 version – the interface was just too painful for that) – everything has influence on elements of the story. Playing through Mass Effect only once is clearly a waste of a very good game.

With a 25 MBit connection to the internet, I though that buying the game online would be a reasonable request too. So here’s what I’ve tried:

  1. Buy the game via Direct2Drive. All seemed to go well and it even asked me for my credit card info. But then, on the final step, it told me that my cart was empty. And a little footnote informed me that Mass Effect has been removed from the cart due to country restrictions. Thanks for telling me in advance!
  2. On the web page of the publisher, there’s a link to the EA store to buy the game online. Whatever I tried, I could only get the shop to actually provide me with the US version of the game which it refused to “ship” (hello? This is a digital download) to Switzerland – despite me trying on June 8th, two days after the official launch in Europe.
  3. I tried to trick the EA store to sell me the game none-the-less by using paypal to pay for it, giving a fake US-“shipping” address. No dice though as paypal refused to bill my account due to the “shipping” address being different from the address I’ve entered in paypal.
  4. Sure that electronic download will not work, I went to the local game store I usually get my games from. Unfortunately, they didn’t have the English version of the game and won’t be getting it.

On a world where digital goods can hop from one corner to the next in milliseconds, on a world where everyone is complaining about rampant piracy, it is impressive how hard it actually is to timely and legally get the digital goods.

Here’s what I did in the end: First I began downloading the pirated version of the game and while that download was running, I went and bought the German version of the game. When I got back from the store, the download of the English version was finished. I’ve installed it, provided it with the serial number of my German original and then played it, using the German DVD as proof of purchase.

Why does it have to be so hard to actually buy a game these days?

A look at my IRC configuration

It has been a while since I’ve last talked about my irc setup. Last time was when I initially started to get my feet wet in IRC. In the three years (three years already? How time passes!), I have been active in IRC to various degrees (with some large wow-related holes, but that’s a different story).

Currently, my rate of IRC usage is back to quite high levels, mostly due to #git which is a place where I actually feel competent enough to help out here and then. Also #nesvideos is fun to be in as ever.

What has changed since 2005 is my setup:

  • Whereas back then, I was mainly working on Windows, I have by now switched over to OSX, so the question of clients is raised again, but see more on that later on.
  • By IRC proxy changed from ctrlproxy to ZNC. It’s easier to configure and I’ve had much better success with that than with any other bouncer I tried. It’s the only bouncer I know so far that does the thing I need bouncers for out-of-the box: Log the channel while I’m away and replay the log when I reconnect.
  • The client has radically changed. While I stayed true to X-Chat after my switch to OSX (using X-Chat Aqua), recently, I have tried other clients as Colloquy (no light-on-dark-theme with colored nicks) and Linkinus (not offering any features making up for the commercial nature), but honestly, Mibbit works best. And it works when I’m on my girlfriend’s computer. And it even (somewhat) works on my iPod Touch. And it looks good. And it provides all the features I need. I’m of course still connecting to my bouncer, but that’s easily configured once you create an account there.

IRC is still a very techie world, but it’s such a nice way to spend time on.

First mail, then office, now IRC. What’s next?

I know that I may be really late with this, but I recently came across Mibbit, a web based IRC client. This is another instance of the recent rush of applications being transported over to the web platform.

In the early days, there were webbased email services. Like Hotmail (or the third CGI script I’ve ever written – the firewall/proxy in my school only supported traffic on port 80 and I didn’t know about tunnels, nor did I have the infrastructure to create a fitting one).

Then came office applications like Google’s offering. And of course games. Many games.

Of course there were webbased chats in the earlier days. But they either required a plugin like java or flash or they worked by constantly reloading the page where the chat is appearing on. Neither of the solution provided what I’d call a full IRC-client. And many of the better solutions required a plugin to work.

mibbit is though. It provides many of the features a not-too-advanced IRC user would want to have. Sure. Scripting is (currently) absent, but everything else is here. In a pleasant interface.

What’s interesting is the fact that so many applications can nowadays be perfectly represented on the web. In fact, XHTML/CSS is perfectly fitted to present a whole lot of data to the user. For IRC for example, there is among the desktop clients to use HTML for their chat rendering aswell.

So in case of IRC clients, both types of applications sooner or later reach the same state: Representing chat messages in good-looking HTML while providing a myriad of features to put off everyone but the most interested and tech-savy user :-)

Still. The trend is an interesting thing to note. As more and more applications hop over to the web, we get more and more independant of infrastructure and OSes. Sometime in the future, maybe we’ll have the paradise of just having a browser to access all our data and applications from wherever we are.

No more software installations. No more viruses and spyware. No more software inexplicably stopping to work. And for the developer: Easy deployment of fixes, shorter turnaround times.

Interesting times ahead indeed.