It’s Pi-day :D

GCat’s adventures with a credit card-sized computer.

It’s months now since I blogged about the Raspberry Pi. At the time I said I was getting really excited about it. Well, my excitement did start to wane a bit after getting up at 5.45am on the release day (February 29th) only to find the level of interest had practically melted the servers of both supplying companies and there was very little chance of getting hold of one any time soon. I was still intending to buy one when some of the mayhem had died down, but I hadn’t given it so much thought lately. Then suddenly yesterday one of my colleagues walked into my office without any warning and handed one to me!

I couldn’t wait to give it a try. Unfortunately I didn’t have a screen in the office that it could hook up to immediately (it needs HDMI or composite, VGA or DVI monitor plugs are no use) so all I could do was download the software ready to try it out (it needs a custom version of Linux on an SD card) while casting occasional excited glances at the box. But luckily there’s a nice HDMI TV in my living room…

My first reaction was: wow, this thing really is tiny! I mean, I knew it was credit card-sized and all, but even so, it’s still hard to believe just how small it is until you see one in the flesh, so to speak. I was even more amazed by the size of the main processor (the black square chip just by my fingernail in the photo and about the same size!).

Hooking everything up to it reminded me of connecting up one of our old computers and brought back happy memories of geekily spent Christmases and so on. In the picture, the power is coming from my HTC phone charger and going into the micro USB connector on the lower left corner. The SD card with the Linux OS is the blue thing protruding out from underneath the board just by the power connector. The grey plug going into the near side is the HDMI cable to my television. The green cable coiling round the whole thing is ethernet to connect it to the internet (it doesn’t have built in wifi so it needs either a cable connection or an external USB wifi dongle). Finally, the two black plugs next to the ethernet are my ordinary USB keyboard and mouse.

With trepidation, I double checked all the connections and then turned the power on. Would it work? I’d seen reports that certain SD cards wouldn’t work properly so I knew there was a chance I’d got a bad one or that I’d messed up the OS install.

Success! I could see the raspberry logo on the screen and the Linux boot messages scrolling past (looking very tiny in full 1080p resolution). Soon I had the desktop environment running and was verifying that it was indeed capable of viewing pointless web pages.

It was pretty easy to get up and running by following the quick-start instructions on the Raspberry Pi website. It was a little bit sluggish for browsing the net, but that’s to be expected with such a low-powered machine with a chip designed for mobile phones but running a full desktop system. Apparently this will get better once X Windows (the software that provides the graphical user interface on Linux) is using the Raspberry Pi’s rather capable GPU to do most of the drawing instead of doing everything on the main processor as it is at present.

But nice though it was to see my blog on the big screen courtesy of the Pi, I was more interested in getting some of my own code up and running on it. After a quick break to redo the partitioning on the SD card (so that I could use the full 16GB of space rather than the default less than 2) and install my favourite geeky text editor, it was time to delve into the code examples.

As the Raspberry Pi is intended for teaching programming, it comes with some nice example programs showing how to make it do various things (play video, play sound, display 3D graphics, etc.). I’d decided for my first project I was going to try and get one of my emulators up and running on it; the architecture is actually very similar to my phone’s so even though the emulators contain quite a lot of assembly language code that would have no chance of working on a normal PC, they should work on the Pi without too much trouble. I decided to start with the Master System one as it’s a bit simpler than the others.

After an hour or two of hacking, I had something working.

As expected I didn’t need to change very much in the code. I just replaced the “top layer” that previously communicated with the Android operating system with a new bit of code to send the graphics to the Raspberry Pi GPU via OpenGL ES. (Although that’s mainly for 3D graphics, you can do some nice 2D graphics on it too if you more or less just ignore the third dimension).

The emulator isn’t fully working yet… there’s no sound (I need to look at the sound example that came with the Pi but it shouldn’t be too hard), no way to actually control it (that screenshot is just showing the demo running on its own – I need to figure out how to get key presses in the right form), and there are a few other glitches (the graphics seem to extend slightly off the edges of the screen and the timing is a bit off). But overall I’m reasonably pleased with my first few hours with a Pi 🙂

Update: the Master System emulator is now closer to being finished and you can download it from here.

Gapless playback on Android!

I am disproportionately happy about something geeky again today :). I finally found an Android app that supports gapless playback properly.

This has annoyed me ever since my faithful iPod provided the perfect finale to one of the worst weekends of my life back in 2010 by suddenly dying completely and leaving me music-less just before a 5 hour car journey on my own. I decided to save money by getting a big memory card for my HTC Wildfire and putting all my music on there instead of replacing the iPod. Mostly this worked ok, but two things about the default Android music player app began to irritate me quite a lot. One is the fact that once you’ve started playing a song, there doesn’t seem to be any way to go back to the track list for that album or the album list for that artist. If you decide you want a different song by them (which I do quite often), you have to go right back to the start of the process and find them in the alphabetical list of artists again, then the album list, then the track list.

The other annoyance was the lack of gapless playback. On the iPod if you ripped a CD with tracks that were supposed to run straight into each other without a gap (like the first two tracks on Sergeant Pepper to give a well known example), they would play correctly and you wouldn’t even notice the transition. On Android there was always a gap between, no matter how you ripped them. This probably wouldn’t have bothered most people but I am (a) easily irritated when technology doesn’t do what I want, (b) the sort of person who likes to immerse myself in music and that doesn’t really work when there’s suddenly a jarring silence that’s not meant to be there, and (c) a big fan of several artists (Mike Oldfield, The Arcade Fire and Evanescence to name three) that tend to use quite a few gapless tracks on their albums.

I had a hunt around online for ways of getting gapless playback on Android, but it quickly became apparent that not many other people had managed to do it either. There were several apps that claimed they would do it… something called Museek tried to simulate gapless playback by slightly overlapping each track with the next one, the effect of which was, erm, “interesting” but still quite a long way off being seamless. Others could only do gapless if you went back and re-ripped each album as one single huge file instead of individual tracks. Others I think could only do it if they were running on a version of Android that supported it, which mine (2.2) doesn’t.

I was sure it must be possible, though, and last year I started hacking together an app to do it myself. The built in Android audio decoding libraries wouldn’t do gapless properly, but there was no reason you couldn’t bypass those and do the decoding in the app code instead – it would just be more work. After a few days I had an app that was capable of playing two OGG files with no gap whatsoever between them, but I got bored of it and it slipped way down my todo list before I’d got around to making it do anything useful.

And then today I found Poweramp… which uses exactly the same approach as my little app was going to, doing the decoding itself instead of using the Android system libraries. For the last few hours I’ve been stress testing it on all the gapless albums I can find and I’m very impressed. It even makes a decent attempt at removing the gaps when playing a file format that doesn’t support gapless (like standard MP3), though it’s only completely seamless when playing formats that do (OGG, etc.). I’m still using the trial version at the moment but I think this may be the first mobile app I actually end up paying for. Highly recommended 🙂