Science Interviews


Mon, 21st Dec 2015

Uncoding music

Dr Sam Aaron, University of Cambridge

Listen Now    Download as mp3 from the show Top Scientific Moments of 2015

This summer we did a whole show on computer programming in front of a liveRaspberry Pi audience in Cambridge. Other than being more than a little stressful for just about everyone involved, it was also huge fun. It was particularly great when Kat got to explore her musical interests with Sam Aaron, the man behind Soni Pi; a programme that can be used to code music.

Sam -  I mean, weíve just heard about how important it is to get people to code. In my opinion, itís not just about getting people to be professional programmers but also use code to express themselves. In the same way we write and read, we write diaries, we write poems, we could also use code in the same way to express ourselves in really exciting new ways. And so, Sonic Pi is software which allows you to write code, basic words, press a special magic button and hear amazing sounds.

Kat - As a musician, I'm really excited by this and I know a lot of computer musicians, they're using programs like Ableton and things like that that cost hundreds and hundreds of pounds to make music and often, I play with them. So, how is this different? Why did you make this? I mean, I downloaded it earlier for free.

Sam - Absolutely. So, you heard Eben earlier talking about lowering the barrier to entry. I mean, part of the deal about the Raspberry Pi, itís extremely affordable. And so, the software I've written is also extremely affordable. Itís entirely free. And so, the idea is, if you donít have any money, it doesnít matter. You can use the software. Also, it runs on all computers. It runs on a Raspberry Pi, but also runs on a Windows or a Mac. So, if you already have a computer, use that, but if you donít, then get one of these Raspberry Pis because they're really wicked fun.

Kat - Now, is this just a way of basically tricking kids and tricking even adults into doing a bit of coding or is it actually genuinely a musical tool? Could you make musical compositions that would stand up on this?

Sam - I mean, is writing poetry tricking kids into grammar? Right? Clearly not, right? So, this is not tricking people into making code.

Kat - Maybe a little bit.

Sam - Code is an amazing expressive form and itís just shown people that potential. And yes, Sonic Pi is a new musical instrument that you can use today to perform in nightclubs and venues to make music and itís a lot of fun.

Kat - Right. Well, enough talking about it. Letís see it. So, weíve got a computer screen up. We got a little Raspberry Pi sort of naked circuit boards sitting there. And on the screen, I can see just some lines and lines, and lines of code. They look like words, sleep, bit, crusher, soul, sustain. What is this?

Sam - Yes. So, I'm showing you here one of the examples. So, when you start up Sonic Pi, you have a help system. The help system contains a bunch of examples. This is one of the pre-canned examples just to show you what you can do with the system. So, shall we hear it?

Kat - Yeah. Letís play something.

Sam - Letís give it a go.


Sam - So weíre getting some of that dance music. This is all generated in real time on the Raspberry Pi using lots of fancy mathematics to make the sounds. The synthesisers are all real time generated. So, this little Raspberry Pi is an extremely capable machine, itís able to do this. So, I use the same system to perform on stage at night clubs.

Kat - That is incredible. Itís kind of pumping. Weíre all like, ďCome on. Hands on the air people!Ē

Sam - They're going wild.

Kat - Reach for the lasers.

Sam - Calm down people! Calm down!

Kat - Never thought Iíd say on the radio. So, what have we got going on here? So itís making drums and synths and all sorts of things.

Sam - Absolutely. So, shall I show you how to get started?

Kat - Okay, letís have a go. Letís make a tune, banging tune.

Sam - So, the first word to learn in Sonic Pi is the word play because weíre playing a note, but also playing. Weíre having fun, right? So I write the word Ďplayí and then I choose a number to play. Letís choose 80. We hear a little beep. Thatís it. Thatís your first programme. How easy is that to write?

Kat - Yeah, that was, even I, I think. As the kind of notes, a paper musician could do that

Sam - So, once you write your first programme, the next thing is how to change these things. So now, we can change this number 80 because numbers can go up and down. Notes can also go up and down. So, if I chose a lower number like 60, you get a low note, right?

Kat - Yes. Itís much lower, okay.

Sam - If Iíd said 90 Iíd get a higher note, right? So, done. So now, we can play all the notes we can imagine then we need a way to make a melody. So, if I play note 60 then I need to have a way of saying, ďWell, wait for a bit. Letís sleep for a second and then play another note. Play 65, say and then letís sleep for half a second and play 72.Ē So this way, weíre able to play different notes and make a little melody, right?

Kat - I like that.

Sam - At this point, with these two commands, Ďplayí and Ďsleepí, we can play pretty much all western notation. So, if you take any Bach, or Mozart, or Beethoven with two commands, you can reproduce those things. Itís not slamming beats yet, but weíve already done classical music.

Kat - Okay. Can we make it a bit more funky? Can we get it kind of going?

Sam - So, the next thing we do is once you got playing, we need some programming structures to help us to manipulate this stuff. So, I've invented something called the live loop. A live loop is just a thing which can loop. So, letís play a sample loop Amen which is Amen Break.

Kat - Is that the Amen Break? Very well known.

Sam - Sleep for the one length of that sample.

Kat - Thatís what drum and bass is made of fans.

Sam - And now weíve got this loop going around, but whilst itís playing, I can now change the rate, say to be half, and now, we got it half and I can bring it back up to 1 again. I'm just changing one number here. Letís go reverse, minus one. Letís add some bass and then letís add some slicer to slice the volume in and out. So, I just choose where to start the slicer, where to end it. And so, just by adding a simple piece of code on top of another simple piece of code.

Kat - I think weíve got a number one hit here already. I mean, itís fairly boring and repetitive, but there you go.

Sam - Thatís what dance music is.

Kat - Exactly.

Sam - You have to be able to dance to it. So, you say itís fairly boring and repetitive, but weíve only got 9 lines of code here.

Kat - How long would it take someone like me to actually make a tune, a kind of a song with a beginning, a middle, an end, some structure?

Sam - It depends on how complicated the tune would be. I went to a school in New Castle, Benton Park Primary School where they have a Sonic Pi Orchestra and theyíve been teaching themselves, the kids have been teaching themselves. And the primary school kids have been teaching their local teachers how to do the stuff. This is 10-year olds. Okay, so you just need some time and some creativity and some fun and some patience. In a few days, you can get the basics down and then depending on how much time you want to put into it, in the same if you want to learn a violin, how much practice you put into it, you can get to do some wicked things pretty quickly.

Kat - Is there transferable skills from learning to write these kind of stuff?

Sam - Absolutely! This system is written in the same language that Twitter was originally written in.

Kat - And thatís boring and repetitive.

Sam - Using exactly the same structures as Twitter was originally written in. All the UK government work is all written in the same language. This language called Ruby.

Kat - Also boring and repetitive.

Sam - Absolutely transferable. But code is not boring. It can be repetitive, but the computer does the repetition, not you.

Kat - So, weíre going to have a little bit of time now. I want you to show me what you can do because you play in night clubs, donít you? Youíve played this stuff out and people do dance to it.

Sam - Absolutely, yes. So, letís choose one of the examples in a way to start. So, this is an example called (ďTilburgĒ)(music playing). So, this is going and so, I've got my basic tune around. Itís very hard to play that. I canít fully hear myself. Normally, these beats are bashing out. So, I can turn the randomization off.

Kat - I do like my house music and this sounds pretty good.

Sam - Itís nice, yeah. I start and stop it. Sorry, I made a mistake. So, you can make mistakes all the time. Itís totally fine. So turn off bits, turn of the bass drum and then get the rhythm going again, and then drop a kick in again. Now, off we go. So, all I'm doing there is editing some very simple lines to make that happen.



Subscribe Free

Related Content


Make a comment

See the whole discussion | Make a comment

Not working please enable javascript
Powered by UKfast
Genetics Society