Creating code to make music
Interview with
Given the right tools, you can almost make music from anything. Pots and pans, conventional instruments, and people have even made whistles out of hollowed out carrots. But what about making music from computer code? One such software, Sonic Pi, was developed by Cambridge University’s Computer Lab, to get children into coding. The creator of Sonic Pi, Sam Aaron, joined Katie Haylor and Georgia Mills in the studio.
Sam - It’s one of a many line of what we call “live coding systems.” These things have been around for many years, but it’s attempting to try and make coding really accessible, really fun, and really engaging by not essentially teaching sorting algorithms but teaching music and using that as a means of engagement to try and get kids and everyone really making code.
Katie - How does it work?
Sam - It’s very simple. You write some text, you press the run button and, if the text is correct, the computer does some interesting sounds, hopefully.
Katie - Do you have to be a coding genius to be able to use this?
Sam - I think that you don’t have to be a genius to do anything. I think it’s really important that you have an open mind and you’re interested, and you just have a go and you’re happy to take risks. And you’re happy also to realise that the first things you do aren’t going to be the best things ever, but if you pick up a violin for the first time it’s not going to sound beautiful. It takes many years to practice and hone those sounds.
Katie - My mother would seriously attest to that with my music instrument playing. Can you give us a couple of very basic examples of coding commands that translate into musical sounds? How do you change the pitch?
Sam - For example, the simplest command is play, and that’s to play a different note, and the number you choose is the pitch. So a higher number will result in a higher pitch and a lower number a lower pitch.
Katie - Can you take us through how it works - maybe give us some code?
Sam - Very, very simply, yes. You download this thing called Sonic Pi - it’s free. It runs on Mac, Windows and Raspberry Pi computer. It opens up with a very simple interface - it’s a blank screen and you put some text inside. The first piece of text you can write, the simplest thing, is the word play to have some fun and a number. In this case I’m going to write play 60. And then higher numbers produce higher notes. And lower numbers lower notes. At this point we can make any note, any pitch and if you write two chords to play, you get chords. If you run play then sleep, you can get a melody. Now that’s very simple but we have the basic of western notation here. We can play note at any time, so we can essentially play any melody, any Daft Punk, any Mozart with these two commands. And the cool thing - is children do.
Georgia - Now, some of us at The Naked Scientists HQ have had a go at Sonic Pi. We spent a couple of hours seeing what we could come up with and we thought you could judge our efforts maybe Sam.
Sam - Fabulous.
Georgia - Here’s the first one [Katie’s music]. Quite understated that one. That’s was by Katie Haylor.
Katie - Thanks very much.
Georgia - Next we have this one [Lewis’ music]
Katie - It’s definitely more beautiful than mine.
Georgia - That was by Lewis Thomson, who is in a band. And finally….[Georgia’s music]
Georgia - Very skillful with the little record scratches there. Sam, what are your thoughts?
Sam - They’re all wonderful and it’s lovely to see that. I assume none of you had played with Sonic Pi before much?
Katie - Could you tell?
Sam - No, I’m just guessing that. No, not at all. My skill would be not to look at the music but to look at the code and to see what kind of code structures you’ve used, and to see what amenability the code has for other kind of modifications.
Katie - Okay. So who was the most inventive. Let’s park our efforts at the Naked Scientist office and talk about kids because Sonic Pi was designed to help kids get into coding - is that right? So how is it being used in schools?
Sam - Absolutely. It’s first rendition was to focus particularly on the new computer science curriculum that the UK introduced a few years ago. The schemes of work they had created were crazy titles like “Have Fun with Sorting” and “Give Binary a Try,” which was supposed to excite children into making computer code be interesting and I don’t think it worked. I think that the music aspect provides a motivational force for the children to actually do some programming. They don’t realise they’re programming, they think they’re making music but, actually, they’re coding. This system’s been used all around the world to teach basic computer science and computational thinking. It’s really a great way to get started because it has such a low barrier to entry.
Katie - If you’re going to start coding, is it better to do that when you’re younger because it’s like learning a language?
Sam - I think it’s best to do it when you have an open mind and, typically, children often have very open, very experimental minds, and they’re happy to take risks.
Katie - What kind of music though have people made with this?
Sam - A whole range of different things. I make my own weird dance music, but I’ve heard pieces of music from Baroque classical music to opera, to Indian tabla style music to even rock music.
Katie - Is there anything that you can play us?
Sam - I can play you some crazy dance music if that’s what you want. Let’s get something going…
Comments
Add a comment