Moments of Inertia by Rachel Crawford

About     Archive     Categories     Tags     Feed     Projects     Podcast Recommendations    


On Saturday I attended Edinburgh Uni Game Dev Society’s ChillJam, a one-day game jam with a relaxed atmosphere. I teamed up with Norgg to make a little game about making a cup of tea.

You can play it here.

It’s very broken, as you’d expect for something made in about 9 hours, but I’m quite pleased with how it turned out. I really like the idea, too – I think it would be lovely to someday make a webpage people can visit and simulate making a cup of tea (or some other kind of beverage!), filled with all kinds of nice, rich interactions. A warm, comforting place on the web.

If you’re curious, you can check out the Unity project source on GitHub. My favourite commit message is “Added steam integration”.

Also, Norgg’s daughter helped by drawing the pictures you can see on the mug and kettle, which was the sweetest thing ever.

Enormous thanks to the organizers of the jam for creating such a fantastic event and to all the other participants for sharing their amazing creativity. I am already looking forward to the next one!

Finally, you cannot drink the tea. Don’t worry about it.

Pitch to BPM

Before this blog, I had another blog, and another blog before that blog, and so on until the beginning of time. At the moment I’m trying to dig up the best stuff I put on those old sites and re-post it here. This serves two purposes:

  • Maybe some of this stuff is actually worth preserving.
  • I get to put off writing actual new posts for a bit longer.

So here is a post I wrote in university, re-hashed a bit but otherwise unchanged.


When we were making the musical platformer AMPS, I had a problem to solve.

Objects in the game world use a song’s beat like a clock. The song is a group of FMOD Events which function as layers, all playing at once. We wanted to speed up the song and thus speed up the clock. The problem is that the FMOD::Event class1 doesn’t provide a method for changing the speed of playback. It does, however, provide SetPitch and GetPitch functions.

FMOD increases the pitch of audio tracks without worrying about smart pitch-shifting (no, I don’t know what the technique to increase pitch independently of tempo is actually called), so that increasing the pitch doesn’t just make the song sound higher, it makes it sound like it’s being played faster. Imagine making a record play faster than the RPM it’s meant to be played at.

So we can just modify the pitch to make it play faster or slower, but how do we keep our game objects in time with the beat of the song?

Event::SetPitch and Event::GetPitch measure pitch as follows: a pitch of 0.0 is the base pitch of the audio sample. Nothing has been altered about it. A pitch of 1.0 means the pitch has been shifted up by one pitch unit, and -1.0 means it’s been shifted down by one pitch unit. Obviously.

What are “pitch units”? Semitones, tones or octaves. It depends what you pass to Event::SetPitch or Event::GetPitch as the second parameter. The options are FMOD_EVENT_PITCHUNITS_SEMITONES, FMOD_EVENT_PITCHUNITS_TONES, FMOD_EVENT_PITCHUNITS_OCTAVES. e.g.

event->setPitch(new_pitch, FMOD_EVENT_PITCHUNITS_SEMITONES);

I use semitones. There are 12 semitones in an octave, so the stuff below should be adaptable to not-using-semitones.

You need to know the base BPM (beats-per-minute) of the track you are pitch-shifting.

Here’s the general formula to pitch up from 0.0 semitones to n semitones:

new BPM = base BPM * (2 ^ (n / 12))

e.g. pitching up by a semitone…

105 bpm * (2 ^ (1 semitone / 12)) = 111.24 bpm.

…pitching down by a semitone:

105bpm * (2 ^ (-1 semitone / 12)) = 99.11 bpm.

Pitching up increases BPM more than pitching down decreases it, because pitch scales logarithmically.


We’re using a ‘song-based delta-time’ for updating game objects. Normally the delta-time would be the time since the last frame, but in this case it’s the amount of time the song has progressed since the last frame, so basically the same thing. To account for music going faster or slower, we make world go faster or slower by multiplying this delta-time by a variable equal to (new bpm / base bpm).

BPM to Pitch

Where m is the number you’re multiplying the base BPM by to get the new BPM:

new pitch-shift amount (in semitones) = 12 * (ln(m) / ln(2))
new pitch-shift amount (in octaves) = (ln(m) / ln(2))
  1. We were using the FMOD Ex API, I think (?), but I can’t find a reference online to link to. There is, however, this article about the differences between that API and more recent versions of FMOD. 

Urban Wildlife

Here is a sub-500-word story that I wrote for the 4th PodCastle flash fiction contest that ran through July and August 2017, with the three winning stories aired on episode 499 of the podcast in December. Telling any story in less than 500 words is an interesting challenge, and what I ended up producing trades more in tone and tension than in plot or payoffs. It was received fairly well and made it into the semifinals, but there were many stories that were better-written, more interesting and much more deserving of the prize. A lot of fun was had in the process, anyhow, and I’m proud of this little story and myself for finally getting some fiction out into the world, however short it may be.

I’m hugely thankful to David Ferguson who provided feedback and editing on the story. Without his great input it would be utter rubbish.

I hope you enjoy it! Let me know what you think in the comments below or on Twitter.

They came into the cities like countless other wild creatures had before them. At first they were cautious, caught by humans only in brief glimpses when they darted through the glow beneath lampposts and windows. On the walk home a person might see a pair of reflective eyes watching from the bushes, cold and wary, before they disappeared in a blink. They were mostly silent, which helped them go unnoticed, and when one did make sounds it was easy to mistake its yowling for a cat’s or even a baby’s. They ran from adults but did not mind children. In fact when a child was alone they would observe it closely, curiously, almost as if trying to remember something.

As their numbers grew so did their confidence. They rummaged in bins and fouled on lawns. They stole food and trinkets through open windows. They were seen breaking into containers, smashing them with rocks or prying them open with sticks. They would peer in the windows of family homes, hiding the moment an adult turned to look. Sometimes a ground floor window would have a new crack in it in the morning. People would wonder.

Their nests became larger and easier to find. The media buzzed for a morning about the novelty of abandoned nest found on the twenty-first floor of a construction site. Perhaps its inhabitants had lived off builders’ unfinished lunches, or the rich pickings that could be raided from the alleyways behind nearby restaurants. Footage surfaced online of one appearing to beckon to a toddler who was alone in a garden, and a clip showing a group catching pigeons went viral.

People got wiser about living in their presence. The popular advice went like so: don’t leave doors or easy-to-reach windows open, don’t encourage them by leaving food out, and put locks on bins. The less-given, less-taken advice was to nail a horseshoe above the door, but it sounded far too superstitious for most. Regardless of the precautions people took, they got smarter in response. It turned out they could open doors, teaching each other the technique. It was rumoured they could even pick locks.

In the countryside they had merely survived. In the city, they thrived. Newspapers and politicians began to talk about “pest control” as they went from curiosity, to nuisance, to threat.

It was near midsummer when a baby girl went missing from her ground-floor bedroom. At first it was a routine investigation, given little more than a paragraph buried near the middle of the national papers, but it quickly became clear something was different. Something the police were avoiding questions about.

The questions stopped when the girl was found.

Then the struggle began.

2017 in Reading

One of my goals for 2018 is to ready 20 books. That’s about 2 books per month! So far I’m enjoying doing more reading, because over the last few years the amount of books I’ve managed to get through has really dropped off.

Time to reflect on some of what I read last year.

The Economics of Enough

A book by Diane Coyle (who incidentally was on Planet Money’s The Indicator podcast this week). I read this towards the end of 2016 and finished it in January 2017, so I don’t remember the details very well, but I do remember finding it interesting. Being a book about the future of civilisation, it has its share of gloomy forecasts, but it has a positive message, too. We can, in fact, solve (or at least handle) these problems that face us in the 21st century: climate change, the financial meltdown cycles of capitalism, overcompetition for natural resources, economic inequality, the crisis in democracy…

There’s a lot of them. Diane’s presents some of her solutions as almost inevitable, sooner or later, and that the longer they are delayed the more damage will fill the gap until their implementation becomes unavoidable. Her main suggestions are, in brief and broadly:

  • Improve how progress and production is measured and statistically analysed. How are we to address any issues if we cannot fully understand their scale and their causes?
  • Encourage saving of money and discourage spending, in particular on high-carbon consumption. She advocates taxation on consumption. Promote investment in projects with long-term benefits, rather than short-term returns.
  • Austerity is okay if you convince the public that it’s for a good reason.Cuts in public expenditure are “inevitable” as is “reforming the provision of services”. Yeah, uh.
  • Reduce income inequality.
  • Experiment in how to re-engage disengaged citizens with public policy-making processes. With the Internet?
  • The Office for Budget Responsibility is a good thing, in principle, because it has “an explicit duty to take account of the long-term and future generations”.
  • Countries should just go ahead and address the issues of climate change as best they can, with or without international agreement. They certainly shouldn’t wait around for that to happen, anyway.

The Mythology of Work

I don’t remember much about this. It comes from the right place, one of deep skepticism about the mores that bind us to the millstone, but it is not written well or accessibly. I found it a little masturbatory, to put it bluntly. And not in the good way.

Which made me sad. I would like to be able to recommend a book on this subject to people.

The Goblin Emperor

I enjoyed this! It’s about a guy who gets catapulted overnight from royal family reject to improvisational imperial majesty. The reader shares his POV as he navigates his way through the tumultuous waters of his first year of emperor-hood, dodging schemes and plots galore. The setting is kinda cool, with baroque, almost steampunky elements, and some excellent made-up names, like Varenechibel and Edonomee.

Take my review with a pinch of salt. I read the book on the flights to and from San Francisco, and I appreciated perhaps more than I would have otherwise because it allowed me to escape into a fantastical world in which people have leg room.

The story has progressive leanings, but I find myself agreeing with Lyta Gold’s opinion that

Novels like The Goblin Emperor are especially disappointing because they’ll go out of their way to include genuinely progressive elements – acknowledgement of inequality, protagonists of color, gay characters, heroines who persist – but consistently stop short of portraying anything resembling large-scale political or societal change.


Scotland the Brave

Something about the past and future of Scotland as a place in the world. Positive!

The Knowledge Corrupters

Isn’t it great how much effort some factions put into undermining the ability of people to reach political consensus, or indeed any kind of agreement at all, by sowing distrust in scientific sources and demolishing the integrity of the journalistic profession? All so they can make more money?


Chuck Wendig continues his flawless streak as the writer of Miriam Black, hardcore detective extraordinaire who can see how you die. This is pure edge-of-your-seat excellence, like the preceding three novels in the series. Not much more to say about it than that. It’s just good.

The Shepherd’s Crown

It took me a long time to get around to reading this one because it felt like finally saying goodbye to an author whose books played a massive part in raising me from childhood to young adulthood, laughing, crying and thinking all the way. He’ll never really be gone, though. Not while his characters are still taking readers like me on adventures they’ll never forget.

The Gates of Azyr

A horror story. I am not referring to the novel, but to the following sentence: I read a Warhammer novel. My first. And the really scary part? It’s not my last.

The Joy of Tax

Richard Murphy on what exactly tax is, and how it’s an indispensible tool for shaping the economy and addressing social ills like economic inequality and excessive carbon consumption. We should all care about it a lot more, and put to flight the school of thought that says that tax is inherently evil. He proposes a lot of ways to improve the United Kingdom’s tax system, as well as providing some useful lessons on how money works.

Here is Richard Murphy defending his book against David Cameron, who made a joke of it at the Conservative Party conference. That will probably make you want to read it more.

Rethinking the Economics of Land and Housing

More economics. A guided tour of how badly messed up the market for land in the United Kingdom and a number of other Western economies is, and how it messes up other areas of those economies. The book is in agreement with The Joy of Tax about a number of things, like how bad council tax is, and how we should probably tax land ownership. I found it quite interesting, but a little dry and technical in places, like its title. I might re-read it to see if I understand some more of it.