It’s all coming together

This evening, I pretty much finished the last few significant lines of code required for Couch to 5 K, now renamed “Get Running”! It’s a brilliant feeling to have finally got here, and to be pretty damn sure that the whole thing actually works!

Okay – yes, there’s still quite a bit to do, but most of it really is there now, and what is left is mostly tuning style sheets and tweaking colours to make thing look lovely (I hope).

My brother, Sam, came to stay with Misa, Robi and myself at the weekend, so as well as him doing some baby sitting for us while we went to see the new Star Trek (which was damn good fun), we had a good chance to chat about the Get Running artwork, and try ideas out together.

Just before Sam left on Tuesday (to finish his stay in London by trying out a Recumbent Bike in Dulwich Park), Sam played me an audio check, hot out of the email pipes, recorded by a friend of his back in Norwich. I’m really happy with the results, and so they’re going to go ahead and record a complete script this weekend, which will provide a voice for the male running coach.

In the meantime, I’m meeting up with a friend Clare, and her husband Rico tomorrow. Clare has a wonderful Irish accent, and her husband is a musician with a whole lot of sound recording experience, and together we’ll record the audio for the female running coach character.

Before any of this sound recording can go ahead, I need to finish writing at least a semblance of a real script, so that is my work for tonight!


Run 1

I went out last night with an almost new iPod touch containing the latest cut of my Couch25K software and a brand new pair of really cheap trainers and, and I did my first run!

It was brilliant! I think I’m about as unfit as I expected, as the 8 runs of just 1 minute had me pretty wiped out by the end! To anyone who runs regularly, this must sound hilarious, but for me it was a real challenge, and I felt incredibly happy at the end that I had seen my way through it. I think it got difficult at about the 5th run, where I was heading back homeward up a very slight hill. The 6th was a little hard too, but after that the last two, 7 and 8 weren’t too hard (perhaps because they were on the flat).

I’m so impressed with the trainers. I went out to buy just about the cheapest pair I could find, having read that cheap trainers are as good as expensive ones, and spent 40 quid in the end. They have absolutely amazing cushioning in the heel. It’s like running about on huge springs 🙂

I’m actually looking forward to running again Tomorrow!

*satire* But enough about running – the really important thing is that the software worked near flawlessly, and was actually extremely helpful!

It was great being able to look at the screen and review how far I’d got and what I was supposed to be doing. For the most part I simply followed the voice cues telling me when I should jog and when I should run.

I’ve added a feature instructing me to turn round at the half way point, and that also worked really well, getting me back to almost exactly my starting point.

Audio Update

The audio of C25K is working after a late session last night. Listening to myself talking really makes me want to find someone else to record the audio track!

I thought I felt good enough to do some more work this morning, before going for a swim with Robi. I’m sitting down in the quiet kitchen. I’ve drunk my coffee, and I’ve had my breakfast, but the cogs are turning very slowly this morning. 

I’m pretty pleased with how the code worked out. As you are jogging along, the C25K app is talks to you to tell you what to do at the moment (probably while you’ve also got music playing). It’s also going to have a simple on screen display that will show you what you should be doing, and that will give you a quick précis of your progress with the run.

I’ve got a RunPlayer object that will spool through data for a run firing audio samples at appropriate points, and allowing the run to be paused and resumed. I think it is going to be relatively easy to extend this object to also fire out events to external listeners. These events can drive updates of the in run display.

The other side of the audio work I did is support for generating data files that describe the run structure. I’ve got a simple scheme for naming the audio files so that they encode where in a run they occur. I’ve written a Ruby script that will run through all these files and build up XML data to describe how the runs should play out. I guess I could have done this in Objective C, but it’s really very easy in Ruby.

An advantage of this approach is that I think it will make the application easy to localise if I get in to that, and it will allow me to supply more than one commentary track, which would be a nice feature. I guess it might even be possible to have user submitted audio tracks.

Audio Time

Today I’m going to work on C25K’s audio. I woke up at about 4.00 in the morning… no, Robi woke Misa and I up at about 2.00, so we let him get in to bed with us and fall asleep. I gave up trying to sleep at 4.00. That’s how it was.

I thought for a while about a game I want to write as a project at some point after C25K, and then decided that as I wasn’t falling asleep again, I’d go and do some work. I managed to sneak off in to Robi’s deserted bedroom and work out the screen play (is that they right expression?) for the runs of the first week of C25K before having breakfast.

I’m going to spend this morning recording the audio segments, and try to put together a dead simple app that can play them. At this point, it’s prototype and feasibility evaluation. I expect to scrap pretty much all of this work (except for perhaps the wording of the audio). I’m hoping that I can find someone with a nicer and more interesting voice than myself to provide the voicing, and I know that my first cut of code is going to blow.

For anyone interested in the details, I’m going to be using Audacity for the sound recording and editing. I’ve no idea if its actually any good, but there was a FLOSS podcast about it, and it sounded cool. Oh – I just found this Collection of manuals for open source software which includes a manual for Audacity that could well be useful.

I’m getting quite excited about C25K. I need to check that the audio really works well, and the only way to do that is to start running again myself using it. With luck, I’m going to be able to borrow an iPod Touch this weekend, and then I can start running next week with a simple audio demo playing. I just need to get some running shoes, and hope that the weather holds up 🙂

As I write this, I am literally sitting on a couch with my laptop, and not feeling too healthy. Perhaps my current unfitness is going to be an asset, as I’ll be able to empathise properly C25K’s users, and really make sure that it is appropriate to them!

Geeky details

I worked on C25K again today. This post is detail about developing using CALayer in the iPhone SDK.

I want C25K to have a 3d feel to it. Most of this is going to be faked up with static, hand drawn art work, but part of the 3D display needs to interactively slide in and out of the screen. This really needs actual 3d rendering.

Apple’s iPhone OS (and OS X) supports a relatively light weight scene graph style of programming in the form of the CALayer class hierarchy. What seems to be happening in the background is that CALayers are rendered in to openGL textures and composited on to the screen as textured rectangles. This makes CALayers extremely quick to render because all modern machines can do this with eye watering speed using their 3d rendering hardware.

The cool thing is that although it pretends to be 2D most of the time, the CALayer scene graph actually tracks all the CALayer objects using homogenous 3D co-ordinates. By making a tweak (that is barely documented by Apple), it is possible to make your scene spring dramatically in to the third dimension.

Apple show how to unleash the feature in Listing 2 of their Core Animation Programming Guide. To find out how to actually use this, take a look at the Core Animation: 3D Perspective article in Watching Apple. It could also be useful to have Wikipedia’s Perspective Projection article to hand.

The attraction of this over diving down in to openGLes for rendering is that that I’m pretty rusty with openGL. Hey! It’s been a while, okay?! I’m finding that this developing software for your self is quit a big deal, and I want to minimise my risks at the moment by removing chunks of unknown. So – using Apple’s finely crafted work is attractive.

But is it finely crafted? Well, it does seem to actually work pretty well. I’ve found a few wrinkles, but I’d expect a little bit of faffing.

Here’re some troubleshooting points…

I found that CASrollLayer defaults to clipping its sub layers. I didn’t originally want to bother setting the scroll layer’s bounds, and thought it wouldn’t clip them. That’s easy to fix up though.

There seems to be something a bit strange with the 3d culling of sub layers. I found that my sub layers would clip while still visible. I managed to fix this by giving their parent view a bounds that included its children.

Things didn’t work well when I set up a perspective transform matrix for the “transform” property of the layer of the containing view. I think others I have found this. I rectified this by setting up the layer’s “sublayerTransform” as a perspective transform instead.

The main issue I’ve found is that I’m looking at my CALayer from the side. This means that over its surface, the texture is at several different resolutions. What ever rendering Apple have put in place isn’t dealing well with this. Maybe I need to explicitly set up mipmaps somehow, but I think I would need anisotropic filtering anyway, and I’m not sure the hardware even supports that. I’ve worked round this by limiting the high frequency content of the layer to prevent it jittering too badly, but it’s not an ideal solution. For background on what I’m gassing about here, the Wikipedia Anisotropic Filtering entry gives the gist.


Misa and I made sourdough bread earlier, and I just tried a piece with some vegan Pate she made at the weekend, and a good scrape of very not vegan butter. It was fantastically scrumptious!

We’ve tried sourdough before, and it was never especially successful. In the end, we accidentally ate our sourdough starter to death, so the experiment ended. Some friends came over from the Czech Republic last weekend, bringing a new sourdough starter with them. While here, they taught us how to make bread from it.

I’m pretty sure that bringing a yeast colony in to the country is a violation of the import laws on food, but no one seemed to mind. Besides, this particular sourdough starter is descended from one first incubated fifteen years ago, so if it was going to make a bid for world domination, I think it would have done it by now.

I think we need to make the bread a few more times before I can claim success, but the first effort is lovely (even after some initial worry that the starter didn’t seem to be rising). Once we’ve got the formula down pat, I’ll put it here.

What I’m Working On

I’m actively developing two applications for the iPhone at the moment. The first, Spirotron, is a pretty simple graphical jamming tool thang – it’s a silly bit of fun. It’s in the vein of the Jeff Minter Tripatron tools that used to run on the Atari ST, and is a bit like an interactive spirographs. Except that it’s animated and draws much stranger patterns.

Spirotron is tantalisingly close to being finished. To be complete, it needs some artwork for its icons, it needs to start up showing a nicer pattern that the current random ones, and most importantly, it needs to be tested on some actual hardware, rather than just in the simulator!

The second application I’m working on is a tool for helping people (including me) to get fit by starting running. There is an absolutely fantastic program called the Cool Running Couch To 5 K Program that is also described in another dedicated C25K site. A quick summary is that starting out as an unfit couch potato who feels ill after running for the bus, you slowly build up your fitness over nine weeks, until by the end you are able to jog continuously for half an hour!

Each week you do three exercise sessions that, with warming up and cooling down, take less than forty minutes. In the first week you jog for just one minute, and then walk for a minute and a half. You repeat this until you’ve done eight jogs, and then cool down again. The whole process is finished in half an hour. On a beautiful day like today, that would be a perfect start before getting on with work!

In the second week, the runs are a little longer, but by that time you are ready for them. Each week the intensity slowly increases, but as you are getting better along with the exercise, you never find it becomes difficult or unpleasant.

I started this with my wife, Misa, about three years ago. It really did seem to work. It wasn’t a complete breeze, but it was completely achievable, and it was paced in a way that made the small increments each week manageable. It was easy to really get in to it, and feel a fantastic sense of achievement from completing the runs.

In the fourth week or so, we discovered Misa was pregnant with our Son Robi, and so we stopped running together. I signed up with a gym near work that had Body Pump lessons (which are also brilliant, but not the subject of this post).

Right now, having done no significant exercise for about ten months, I am aware several times a day, that my body is slowly shrinking back in to something slow and stagnant. It’s quite a horrible experience! I’m really ready to start out with some exercise again, and I think getting running is going to be my goal.

I think running is ideal for me at the moment because all that’s required is somewhere to run, and a good pair of shoes. There are no gym fees or membership! Also, summer is on its way, and I want something that’s going to get me out of the house each day (my current office) for longer than it takes to take out the bins!

In case you’re starting to wonder, it’s not my goal to get myself in to super buff shape, or be able to run a marathon 🙂 I just want reach a level of fitness where I can play football with my son, swim for a good long time in the sea, and move along with a spring in my step again, rather than a droop in my shoulder. Pulling my stomach back in to line is a priority too, but I’m not expecting to replace it with a wrought iron, wash board, peck deck.

Back when Misa and I started the Couch to 5 K program, the major trouble I had wasn’t the exercise, but instead working out whether I was meant to be running or walking while also bouncing along. I’d be trying to read the tiny numbers on my phone’s stopwatch with my eyes jiggling about, up and down in their sockets, checking the ground for things not to run in to, and attempting to compute whether 7 minutes and 27 seconds means it’s time to run now or walk, for Week 2’s running pattern.

A friend suggested that I could record a message on my phone that would play continuously during the run. It would be mostly silence, but now and then would prompt me with what I should be doing. “Keep running for another minute”. “You’ve got 30 seconds left”. “Okay, now walk for 2 minutes. You’ve got three more runs to do”. That kind of thing. Instead of just recording the message, which would take a whole half an hour or something, I decided to write a computer program to generate them for me, which took much longer of course. The programming turned out to be more tricky than I had imagined. I suggested it to James Gray, and he turned it in to Ruby Quiz 82.

The other problem Misa and I found, was that occasionally, we would forget which runs we had done and when we’d done them. This was frustrating, as it meant we didn’t know if we’d definitely done all of the three runs for a week, or if we’d done a run a time too many and should have moved on. I didn’t solve that at the time.

A few weeks back I got talking to the same friend who gave me the recording idea, and somehow we came up with the idea of turning Couch to 5 K in to an iPhone application. I checked on the App store, and in fact, someone has already done this, which is great. I think I could write a much groovier application though.

I want the application to look beautiful, but at the same time, present all the information that you need in a really clear and concise way. Of course, it’s got the audio part too, and I that too must also be excellent. The app must help me and others see clearly what we have chosen to achieve and it will help us through the experience. Getting yourself fit is a great thing, and something to feel proud and positive about. I want the application to complement that. In a way, it is like going to the shop and buying a nice new pair of running shoes. The desire to put them on, and feel the lovely spring of a cushioned heel, helps you to be enthusiastic about the first few runs!

I’ve got a pretty good idea of how I want the app to look and behave now. My brother is an artist, so he’s working on putting together the application’s art work. In fact, he works at an animation school and so knows some voice actors, which might be really useful in finding someone who can speak the voice of the running coach.

So today, I think I’m going to do some work on C25K, and leave Spirotoron alone for a little.