Lofi Interstellar

Interstelofi if you're a cool kid

Lofi Hiphop makes for good work music, and so does the Interstellar soundtrack, so why not combine them. This was made in Logic Pro X all with built-in instruments (no samples from the actual Interstellar soundtrack), and I've had to program in all the MIDI by hand as I left my keyboard at uni. Painful. Anyway, here are some things I found:

  • Logic's pianos sound pretty terrible, but they sound a lot less painful if you add a huge amount of reverb, take out the highs, and boost the lows. That's what was done to the piano in the middle bit, where everything drops out, and it sounds pretty spicy.
  • Adding lots of reverb seems to be a substitute for actual good samples, even if it makes everything a bit muddy
  • Sidechain compression is fun
  • The Alchemy Synthesizer is fun
  • Adding drums to music is not a substitute for actually making Lofi Hiphop
  • The ChromaVerb interface looks absolutely incredible

Nord-Keytar Gigging Setup

How to look like a prat live on stage

The Rockband 3 Wireless Keytar has no reason to have a midi-out port, or a mod wheel and pitch bend control, octave up-down buttons, program change buttons, a velocity-sensitive 2 octave keybed, or a wireless USB receiver. And yet, it has all of these things. It costs less than £40 secondhand, comes with a strap, and I'm currently using it as a wireless controller for my Nord Electro 6.


Because I was so preoccupied with whether or not I could, I didn’t stop to think if I should.


The USB receiver on the keytar allows it to be plugged into a computer, and some sort of driver/midi software combo can be leveraged to turn this into a fully functioning midi device. I really don't like bringing my laptop to gigs though, so in comes the Raspberry Pi.

Keytar -> Wireless Receiver -> Pi -> USB Midi cable -> Nord

A kind soul has made a driver that converts the raw output of the keytar into midi messages. After installing this on the pi with a fair amount of difficulty and swearing, and getting the script to start at boot without the need for any user input, the pi becomes a plug 'n' play device for Nord-keytar communication. Finally, I can take my funk solos with style, as long as I remember to keep an eye on the keytar battery life. At least if the batteries run out I can preserve some dignity.


The Easiest Headphone Holder

headphone holder

Small things can really make a difference. I spend a lot of time at the computer, and if I think about it, I probably put on and take off my headphones unreasonably frequently. Having nowhere to put them grates at my soul, chipping away at my mindset slowly but surely. If we approach desk-sitting like Team Sky approach cycling, we should be considering marginal gains when trying to improve, and so I present the g-clamp headphone stand. Easy to implement, easy to use, fits on any desk, simple and effective. Gone are the anarchic days of madness when I put my headphones in a random spot on the desk. Those crazy times are over. I now know where my headphones are at any time, anywhere.

But wait, I hear you cry, how can I, too, achieve such a state of elegance with my desk-headphone setup? I'm glad you asked, because I made a set of instructions that you can follow to reproduce my configuration. Yes, you too can achieve this marginal gain. Imagine the increased productivity, the saved time, the improved mood! You can find said instructions right here.


Flock/Shoal Simulation

The birds and the bees (and fish)

There are many animals that exhibit flocking behaviour, including humans. This is an attempt to recreate that behaviour using three simple rules:

  • Separation - avoid crowding neighbors (short range repulsion)
  • Alignment - steer towards average heading of neighbors
  • Cohesion - steer towards average position of neighbors (long range attraction)

Unfortunately, due to the nature of the problem this is an O(n^2) algorithm, as every fish/bird/thing has to check the position and velocity of every other entity (without doing special trickery like bin-lattice subdivision). Here's the link to the source code. If you're familiar with Java and LibGDX this should be pretty simple to run and modify. If not, it might be worth writing this in Javascript, I've seen some pretty successful examples online.

So what are the uses except for making pretty (but intensive) screensavers? Well I guess a similar, but probably more complex, simulation could be used to see how crowds of people react in certain situations. I can't for the life of me find the source, but I remember reading that putting a pillar in the middle of a doorway can speed up entry and exit of a tube station, as it forces commuters to line up. At present however, it just makes for a pretty video.


The New Blog!

Basically Wordpress but worse better..? worse

Welcome to the new blog. It's better than the old one.
Hey it's even got https. That's for me not you though, I don't want middle men snooping on my admin password.
Want one for yourself? Get the code on Github


  • Markdown. Look at these lovely bullet points
  • Online editor complete with live markdown preview and image uploads, no more SSHing/SFTPing ever!
  • Near-static auto-generated content. There's a wee bit of JQuery but that's all
  • Auto-generated unique urls for each post
  • Upvotes. These are unlimited because there are no user accounts and I'm scared of the GDPR police coming for me if I go down the cookies route
    • (Plus is it reaaally a problem having unlimited upvotes?)
      • Unless it gets upvoted so hard the int overflows and comes back round the other end
        • Probably should do something about that
  • Password-protected draft posts area
  • Pagination
  • Auto publish date
  • Custom urls
  • Tags

The nitty gritty

Flask backend, Jinja2 templates are a dream to use, Redis for upvote storage, plain old text file for posts storage (works fine, no real need to mess around with a database), JQuery for the actual upvoting. Find out more on Github
All posts are stored in one big file at the moment. The admin console effectively gives you free reign over editing the file, so you can change past posts, publish dates, post urls, at your leisure. Due to the potential for the utter destruction of all posts ever if you or some nefarious individual deletes everything, post backups are made every time the admin console is used.

As a neutral third party, I'd definitely recommend using this blogging engine.


Python Twitter Competition Bot

Python Twitter Competition Bot

I spent a short amount of time writing a fairly crude Twitter bot in Python, using Tweepy. It listens to a stream of tweets, looking for ones with keywords like 'win', 'RT', and 'fav'. After passing through a couple of filters to try and determine if this is a genuine competition tweet, it will follow, favourite, and retweet.

It's been running for just over a week now and I've won a few things, most of them digital so far, and all of them pretty much worthless. Included in my winngs are: A random Fortnite account, a cupcake from a stand in Manchester, Grave Danger for PS4, Fear the Wolves beta key on steam, the book 'Fliers' by Laura Mae, and an entire £0.05 sent to me on Paypal.

He said it was meant to be £0.10 but the Paypal fees were too large.


My New MicroKorg

I picked up a MicroKorg for a very reasonable price and haven't been able to stop playing with it since. As a classically trained pianist I always used to (internally) turn my nose up at these sorts of machines - how could you ever make something interesting with so few keys. The MicroKorg has 32 small keys, and it was initially quite difficult to get used to their size and hit notes accurately, but after spending time with it I'm loving it.

I play in a funk band and use a Wii Rockband controller as a wireless keytar (don't laugh), it's actually a great Midi controller and the wireless feature is a plus because I can wander around the stage. Anyway the first time I used it in a performance, I did my solo on the 32 key keytar instead of my usual 88 key keyboard, and the restriction, instead of limiting my options, opened up a world of opportunity. Normally with these solos I fumble about the blues scale using vague, fast runs to compensate for lack of imagination, but when confined to a small set of keys I came up with something new and interesting.

I think something similar happens when I play the MicroKorg, its limitation is not actually a limitation, but an opportunity. Plus is has a huge range of sounds, being a digital synthesizer. You can combine various oscillators, filters, envelopes, LFOs, and much more to create a massive variety of noises, from classic synth sounds to Hammond Organ-esque tones. The vocoder has huge potential.

This inspires me to try and make an analogue synth (the MicroKorg is digital).


Experimenting with Edge Detection

Java Edge Detection

I'm experimenting with simple edge detection in Java. The result above is from an incredibly simple algorithm which subtracts the highest contrast neighbouring pixel from each pixel in the image: for each pixel, find the neighbour with the highest contrast relative to the original pixel and subtract its value from the original pixel. Pixels surrounded by similarly valued pixels will get a value of 0 whereas pixels with high contrast neighbours will get a higher value.

Where next? There's a lot that can be done to improve this simple algorithm, starting with pre-processing like increasing the contrast on the original image. I'd eventually like to turn this into a 'Camscanner' style application, which transforms an image of a document into an upright rectangular viewing format. To do this I'd need to find the four edges of the largest rectangle in the image (very likely to be the document), then use a simple transformation to do the rest of the work.


Adventures with Markov Chains

A Markov chain is an incredibly simple model describing a sequence of events in which the probability of each event depends only on the state attained in the previous event. And yes I did lift that from Wikipedia but it can explain it much better than I. Basically the idea is that you have a number of states, like whether it's raining or not, and the probability of a certain state tomorrow only depends on the state today. In other words the probability of it raining tomorrow depends on whether it's raining today.

I've used this model to generate text in particular styles. You feed the model a huge amount of text, and it builds up a probability table of what the next word may be given the previous word. You then use a random number generator to generate chains of text.

I experimented a bit with order and token choice. I found that training the model on individual letters produced pronouncable garbage. Any words more than a couple of letters long were not real words, it was incomprehensible but pronouncable. If I wanted to make an English-sounding fake language this is probably how I'd do it. I wanted some generated text chains that made sense, however, so I trained it on individual words instead. I found that a first order model (looking back only one word) didn't produce very good sentences, and a third-order model (looking back 3 words) tended to reproduce the input data because I didn't have enough of it. The second-order model seemed like a good middle ground.

I trained the model on a variety of corpuses. Generated wine tasting notes were suprisingly believable, as were generated Trump tweets and dreams. Here are some generated wine-tasting notes:

"This wine combines weight and a low altitude vineyard. It's packed with both power and makes it refreshing too. Drink now."

"A kitchen-sink blend of 90% Sangiovese and the wine is still closed but delivers a creamy, textural wine. Those body powder and lime aromas are less attractive."

"The voluble, opinionated Jean-Luc Colombo has crafted this classic Gewurztraminer. It's plush on the finish."

"Clove aromas are outweighed by a touch of volatility along with dried apricot while the palate shows ripe aromas of sweet oak tones that will age well. Drink from 2016."

These are, of course, hand-picked, but the generated sentences were of unreasonably good quality in general. The wine-tasting notes worked especially well, which may be because I had a huge amount of data.


My Attempt at a Chess Bot

My bot vs a randomly moving one

I made a chess bot in Java. Really I made a variety: randomly moving pieces around, greedily choosing the best next move, and finally using the minimax algorithm with alpha-beta pruning. The biggest challenge here was not the bot itself, but making a chess engine that efficiently generates possible moves, because even with alpha-beta pruning there is a massively fast growth in possible moves as you look more turns ahead. Consider generating moves for White's bishop. Not only do you need to generate the possible board positions, but for each board position you need to check that your King is not in check, or it is an illegal move. To do this you need to scan through the enemy pieces and see if, with the bishop in the new position, taking the white King is legal. It's easy to see how fast this grows as you go down the minimax tree.

I had grand plans to pit the bot against itself over and over again, until I realised that this deterministic machine would result in identical games on subsequent tries.

The result is a chess bot that beats me at chess, although I'm not the best benchmarking tool.