Musical Algorithms

An octave on a piano marked as from C to the next C labelled as C1 and C2
Image (edited) by OpenClipart-Vectors from Pixabay

How can a machine generate music? It needs an algorithm to follow: instructions to tell it what to do, step by step. Here are two simple games to play that compose a random tune by algorithm.

Writing Notes

We need a way to write notes. We use letters A to G as on a piano. They repeat all the way up the white keys, so after G comes different higher versions of A, B, C again. We will use notes running from what is called Middle C in the middle of the piano to the next C up. This is called an octave. We will call the two Cs, C1 and C2.

Game 1: Random Jumps

Roll two dice and add the numbers. Write down the note given in the table for Game 1, so if they add to 2 or 3 write down C1, if 4 write down D…If 7 then you get to roll again, and so on. Keep going until you have written 15 notes to make a tune of 15 notes.

Table for Game 1 showing dice rolls and notes
2 or 3 - C1
4 - D
5 - E
6 - F
7 - Roll again
8 - G
9 - A
10 - B
11 or 12 - C2
Game 1 by CS4FN

Game 2: Up and Down

The second algorithm uses one die. First write down C1 then roll the die and do what it says in the Game 2 table. Each new note is based on the last note. If you roll a 1 then write down D (the next note UP from C1). Rolling a 6 means add a pause in the tune (write a dash). If the roll takes you beyond either C then you bounce back: so rolling a 4 when you last wrote C1 means you write C1 again. Rolling 5 from C1 bounces you up to E. Continue until you have 15 notes.

Table for Game 2 showing die rolls and action
1 - UP 1 note
2 - UP 2 notes
3 REPEAT note
4 - DOWN 1 note
5 - DOWN 2 notes
6 - PAUSE
Game 2 by CS4FN

Play your tunes

Play your tunes on any instrument or use a free online piano (see https://bit.ly/pianoCS4FN).

Are they any good? Does either game give better tunes? 

Good music isn’t just random notes. That is why we pay composers to come up with the really good stuff! Both human and machine composers learn more complicated patterns of what makes good music.

What do you think of our musical masterpiece?

On Game 1 we rolled 6 4 8 8 8 | 5 9 4 9 6 | 5 6 9 9 10 so our tune is F D G G G | E A D A F | E F A A B

Make your tunes special!

See how on the Bach Google Doodle page.

A cloud of stars
Starburst by CS4FN

Here’s what our tune sounds like once harmonies have been added.

Could you improve your tunes by tweaking the notes? Some people use simple algorithms to spark human creativity like that. Rock legend David Bowie helped write a program he then used to write songs. It took random sentences from different places, split them in half and swapped the parts over to give him ideas for interesting lyrics. It was possibly the first algorithm to help write hit songs.

A ‘note’ on bias

Think about the numbers that are rolled and the number of different ways that each number can be produced. For example with two dice (let’s call them ‘left’ and ‘right’) you can make the number 9 twice by rolling a 5 with the left and 4 with the right, or 4 with the left and 5 with the right. Same with 6 and 3. There are only two ways to roll a 2 (both dice have to show 1) or a 3 (a 1 and a 2 or a 2 and a 1). This is baked in to the process and so will affect the notes that appear most often.

Jo Brodie and Paul Curzon, Queen Mary University of London


More on…

We have LOTS of articles about music, audio and computer science. Have a look in these themed portals for more:


The Music and AI pages are sponsored by the EPSRC (UKRI3024: DA EPSRC university doctoral landscape award additional funding 2025 – Queen Mary University of London).

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


The day the music didn’t die

Computer Scientists are working to support traditional music from around the world.

A seperewa is a traditional “harp-lute” musical instrument of the Akan people in Ghana, Africa. It has strings that are plucked a bit like a guitar. It is dying out because of the rise of western music. Researchers are now testing AIs that were trained on western music to see if they still work with such different seperewa music. They are also trying to understand exactly how this traditional music is different.

Protecting traditional instruments

Colonisers introduced European guitars to Ghana in the late 1800s and their sound began to influence and even replace seperewa music. Worried by this, in the mid-1900s people made recordings to preserve endangered seperewa music and to remind people what it sounds like. Ghanaian musicians are now reviving the seperewa, so we might continue to hear more of its lovely sound in future.

A view of a historical seperewa instrument side-on showing a large sounding box with strings attached to a neck, and stretched taut for playing.
A seperewa, adapted from a public domain image on Wikipedia.

AI to the rescue

A team of computer scientists and music experts have investigated recordings of seperewa music to see how well western AI tools can analyse that style of music, given it is tuned in a completely different way, so plays different notes to a western instrument.

First the team used one AI tool to separate the sounds of the seperewa from the singing. It struggled a bit and left some of the singing in the seperewa track and vice versa but overall did a good job,

They then used a different AI to analyse the sounds of the seperewa. The found that the seperewa music had its own, unique musical fingerprint, revealing a rich tapestry of sound that was clearly different from western music.

The research is helping to preserve a vital part of Ghanaian culture. It has shown in detail how their music is different to anything western and so that something unique and precious would be lost if it died out.

Jo Brodie and Paul Curzon, Queen Mary University of London


Watch …

Hear what a seperewa / seprewa sounds like at this YouTube video: The seprewa – the original African guitar [EXTERNAL]

More on…

We have LOTS of articles about music, audio and computer science. Have a look in these themed portals for more:

Getting technical…


The Music and AI pages are sponsored by the EPSRC (UKRI3024: DA EPSRC university doctoral landscape award additional funding 2025 – Queen Mary University of London).

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


Composing ancient Korean music

600 years ago King Sejong the Great of Korea published ‘Hangul’, a new and improved writing system for his people. To celebrate he asked his court scholars to write an epic poem in Hangul, then asked his musicians to compose music to accompany it. The result was Yongbieocheonga, or ‘Songs of the Dragon Flying to Heaven’.

It was performed by musicians playing wind and stringed instruments. The musical instruments the AI composed for are Daegeum and Piri (wind instruments), Haegeum and Ajaeng (bowed string instruments) and Geomungo and Gayageum (plucked string instruments). Each instrument had its own melody written out for the musician to follow. Only one piece of the written music survives fully intact (it is still performed!). Melodies of other pieces of music have survived but only for a single instrument. That means those pieces can’t be played by a group of musicians because all the other harmonies are missing.

A team of computer scientists decided to recreate the missing 15th century Korean harmonies from just the single melodies (in the way the Bach Google Doodle does, see You’ll Be Bach!). They wanted to expand the ability of their AI tools to make sense of music beyond western music.

They first taught their AI musician to recognise Korean music written in Hangul. Then, it learnt which notes sound best played together by different instruments. Finally, to generate music that could be played, it matched melodies and rhythms. 

It created a melody for each different instrument. The researchers then asked Korean musicians to perform the whole piece and to judge how well the AI musician had done. Happily, they thought that the music worked well and sounded correct. They could perform it with only a few small tweaks. 

You can listen to one of the performances and find out more below.

Jo Brodie and Paul Curzon, Queen Mary University of London


Watch…

More on …

We have LOTS of articles about music, audio and computer science. Have a look in these themed portals for more:

Getting technical…


The Music and AI pages are sponsored by the EPSRC (UKRI3024: DA EPSRC university doctoral landscape award additional funding 2025 – Queen Mary University of London).

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


Separate your stems

Two cartoon faces, both purple, but the one on the left is a bluer purple and the one on the is a redder purple. Two speech bubbles say "I have more blue" for the bluer purple and "I have more red" for the redder purple.
Image by CS4FN

AI can unmix music and isolate vocals

Purple can be created by mixing together red and blue paint. You can probably tell which of the faces in the image has more blue and which has more red. Does music work the same way?

Your brain can recognise the red and blue in purple while still seeing it as a whole colour. Music is similar. When you listen to a song your ears and brain hear all the sounds at once. The singing, guitars, drums and keyboard parts are mixed together, but you can also focus on the singing, or the keyboards or ….

Computer scientists have gone a step further with Artificial Intelligence. By training AI tools on lots of different songs they have taught them to do “source separation” – unmixing a recorded song back into its separate bits. Those separate bits are called stems. It is like taking purple paint and unmixing it to give blue and red again!

A wide grey vase with two flowers in it (one red, one blue) at opposite ends of the vase with their stems definitely very separated.
Stems adapted from a plant pot image by HASSAN DYB from Pixabay.

“Not that kind of stem!”

Did you know?

Photographer Todd McLellan photographs gadgets he’s carefully taken apart, to show all the pieces (search the web for his “Things Come Apart”). When a piece of music is blended together and an AI separates it again it’s a bit more like trying to un-bake a cake!

Jo Brodie and Paul Curzon, Queen Mary University of London


More on…

We have LOTS of articles about music, audio and computer science. Have a look in these themed portals for more:


The Music and AI pages are sponsored by the EPSRC (UKRI3024: DA EPSRC university doctoral landscape award additional funding 2025 – Queen Mary University of London).

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


Jamming with JAM_BOT – an AI musician

A robot with a keyboard stomach playing the keyboard.
Image by CS4FN

Jordan Rudess is a rock keyboard player whose concerts sell out around the world. He works with a team of computer scientists at the MIT Media Labto make his synthesisers do amazing things. Together they created an AI musician called JAM_BOT to play with him on-stage.

Jordan’s bot learnt the different ways he plays by the team giving it lots of his music. It learned about the rhythms and melodies he uses. It could then compose its own versions of his music when prompted.

JAM_BOT AI plays along on-stage

Jordan also trained JAM_BOT to play with him. It could carry on playing music that Jordan had started, or create a backing track to music he was currently playing. Jordan was able to choose how JAM_BOT played with him on stage using the keys on his keyboard.

What happened next?

The resulting concert was a mix of performer and AI with a delighted audience (and computer science team). Afterwards Jordan said “It’s been pretty mind-blowing to create this tech-based version of myself – like looking into a real-time musical mirror.”

Jo Brodie and Paul Curzon, Queen Mary University of London

More on …

  • A model of virtuosity (2024) MIT News [EXTERNAL]
    • Acclaimed keyboardist Jordan Rudess’s collaboration with the MIT Media Lab culminates in live improvisation between an AI “jam_bot” and the artist.

We have LOTS of articles about music, audio and computer science. Have a look in these themed portals for more:

Getting Technical


The Music and AI pages are sponsored by the EPSRC (UKRI3024: DA EPSRC university doctoral landscape award additional funding 2025 – Queen Mary University of London).

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


You’ll be Bach! – create music with the Bach Google Doodle

The Bach Google Doodle is an AI musician which has learned the patterns in over 300 pieces of music from Johann Sebastian Bach, a famous 18th century German composer. The AI musician will take the notes you give it and suggest harmonies in Bach’s style. It takes a melody and creates backing melodies for different instruments that sound pleasing. 

Visit the Bach Google Doodle, put some notes together, press ‘Harmonize’ and see what you think of the result. If you don’t like its first suggestion you can press Harmonize to try again.

How to use it

Once on the page click the large play symbol (a white triangle) to open the doodle, and then again to run the intro demo (which you can skip on later visits).

Use your mouse to place notes at different positions on the five horizontal lines. If you hover over a note an X will appear so you can delete it and place it somewhere else. If you press and hold a note an option will appear to let you sharpen it (raise it by a semitone) or flatten it (lower it by a semitone). You can press the play icon to hear what your composition sounds like. Then press HARMONIZE to activate the AI. It will look at your piece of music and suggest the backing track (harmonies). You can then click a smiley or cross face if you like it or didn’t like it.

Hover your mouse cursor over all the other bits of the page too – there are lots of fun things to play with including some Easter eggs.

About the doodle

🎹 Celebrating Johann Sebastian Bach was Google’s first-ever AI-powered doodle and “is an interactive experience encouraging players to compose a two measure melody of their choice. With the press of a button, the Doodle then uses machine learning to harmonize the custom melody into Bach’s signature music style (or a Bach 80’s rock style hybrid if you happen to find a very special easter egg in the Doodle…”

▶️ You can also watch Google’s short video ‘Behind the Doodle’ on YouTube.

Jo Brodie and Paul Curzon, Queen Mary University of London


The Music and AI pages are sponsored by the EPSRC (UKRI3024: DA EPSRC university doctoral landscape award additional funding 2025 – Queen Mary University of London).

Subscribe to be notified whenever we publish a new post to the CS4FN blog.


Listening to the machines

Clear sound image by Sunrise from Pixabay

In older films computers are sometimes shown doing a calculation while making lots of bleeps and bloops – sounds that indicate ‘something technical is happening’. In reality computers are generally very quiet (you might hear the sound of the fan, that’s just keeping everything cool) and they don’t normally make a peep. But computer scientists have been wondering if some sound added in might help people make sense of what’s going on.

People who use artificial intelligence tools often have no idea what is happening inside (it’s a bit hidden, like a ‘black box’), or even how much they can trust the results they produce. Explainable AI (“XAI”) is the idea that people should have a better understanding of how an AI tool has reached its answer.

Cars that are powered by batteries don’t have a physical engine so don’t make as much noise (other than the sound of the tyres on the road) but car manufacturers have added in artificial ‘engine sounds’ to make it easier for pedestrians and cyclists to know that a car is heading towards them. This is ‘sonification’, adding sounds that aren’t naturally there to make things more audible. Computer scientists have begun to consider whether it might be possible to sonify the way some language generating AI tools process and produce information, to make their inner workings easier for people to interpret. Whether that might be a microwave-style ‘ping’ to let you know when it’s done something, or a tuneful melody to accompany the AI’s processes remains to be seen…

Jo Brodie, Queen Mary University of London


Other added sounds

Can you think of other examples where a sound has been added (sonification) to help people make sense of something?

Examples include these, which are also helpful for visually impaired people

  • ‘This vehicle is turning left / reversing’ warnings from lorries
  • A lift / elevator making a ‘ping’ sound to alert you that it’s arrived
  • At pedestrian crossings the traffic lights might make an audible sound when the little red man goes green.

More on…


Related Magazine …


Subscribe to be notified whenever we publish a new post to the CS4FN blog.


The art of animatronics, or how to build a believable dinosaur

How do you create a full-sized dinosaur without a hint of computer graphics? The answer is through the amazing art of animatronics. Animatronics is a field of special effects that uses sculpture, mechanics, electronics and computer engineering to create life-size moving creatures for films and theme parks. They’re like puppets only much bigger, much smarter and much scarier. While today many film creatures are created using computer graphics in post-production, some filmmakers prefer to have their creatures ‘live’ on the set so the human actors have a real co-star to act along with. In a theme park, animatronics can put a weird creature, like a zombie pirate or a great white shark, right there and in your face. Famous movie animatronics stars include the shark in Jaws, the gigantic Spinosaurus in Jurassic Park III and the lovable alien in ET. How are these amazing effects created? Let’s get primeval with some state-of-the-art computer science.

On and off the drawing board

An animatronic creature starts out in life as a sketch on the drawing board. In some cases it’s a new creature-tastic idea thought up by the designer. In the case of dinosaurs, the sketches are created with the help of expert paleontologists. The sketches are then converted into a scale model, called a maquette. This scale model allows the designers to examine and correct their design plans before the big money is spent bringing the creature to full size ‘life’.

Growing up

Here’s where the model goes from the small to the large. The mini maquette is laser scanned, capturing all the detail of the model sculpture and feeding it into a computer aided design (CAD) software package. From this data whirring, computer-controlled blades automatically sculpt a full sized model using blocks of polyurethane foam. The blocks are assembled like a big 3D jigsaw, and sculptors add the extra fine detail. Now it’s big, it’s real and it’s ready for its screen test!

Pouring in the skin

If the full-sized version shows that star quality, it gets molded. Using the life-size model a set of moulds are made to allow the outside skin of the creature to be created. With the outside finished, now you have to think about the insides – namely, the skeleton, the mechanics of which depend on how the creature will be expected to move. Using a rough shape corresponding to the form of the core skeleton innards, the outer foam rubber skin can be poured in so that it only fills the negative space between the outside creature shape and in the inside skeleton. This reduces the weight of the skin and allows more believable, flexible movements.

More than just the bare bones

Skin done, now the technology really kicks in. The animatronics skeleton inside the creature is where all the smart stuff happens. It’s clever and custom made. It has to be – it’s the part that moves the outside skin to make it look believable. Attached around the main skeleton frame, which is often built with strong-but- light graphite and looks a lot like the real creature’s skeleton, we find the actuators. These are little clumps of clever computing that move the pieces around to make the creature look alive. Computer science abounds here, along with other state-of-the-art techniques. Mechanical and electronic engineering combined with computer-controlled motors are used to move small expressive bits like eyes, or to control the more heavy-duty hydraulic systems that move limbs. The systems may be pre-programmed for characteristic behaviours like blinking or swiping a claw. In essence the animatronics under the skin produce a gigantic remote controlled lifelike puppet for the director to play with.

Does my bum look big in this?

Putting the skin over the animatronics isn’t always easy. As each of the sections of foam rubber skin are added to the skeleton the construction team needs to check that the new bit of skin added doesn’t look too stretched, or too baggy with lots of unsightly flabby folds. One cunning way to help the image conscious creature is to use elastic bungee cords to connect areas of the skin to the frame. These act like tendons under the skin, stretching and bunching when it moves, and making the whole effect more relaxed and natural. Once the skin is on, it’s a quick paint job and the creature is ready for its close up. Action – grrrr -– shriek! Computer science takes centre stage.

Paul Curzon, Queen Mary University of London

More on …


Related Magazine …


Subscribe to be notified whenever we publish a new post to the CS4FN blog.


The Decline and Fall of Ada: Who’s popular now?

Audience image by Pexels from Pixabay

Ada (the language), is not the big player on the programming block these days. In 1997 the DoD1 cancelled their rule that you had to use Ada when working for them. Developers in commerce had always found Ada hard to work with and often preferred other languages. There are hundreds of other languages used in industry and by researchers. How many can you name?

Here are some fun clues about different languages. Can you work out their names?
(Answers at the end.)

  1. A big snake that will squash you dead.
  2. A famous Victorian woman who worked with Babbage.
  3. A, B, __
  4. A, B, __ (ouch)
  5. A precious, but misspelled, thing inside a shell.
  6. A tiny person chatting.
  7. A beautiful Indonesian island.
  8. A french mathematician and inventor famous for triangles.

(You can try an online version of our quiz here)

Today, the most popular programming languages are, well we don’t know, because it depends when you are reading this! Because what is fashionable, what is new is always changing. Plus it’s hard to agree what ‘the most popular’ means for languages (and pop stars!). Is it the most lines of code in use today? The favorite language of developers? The language everyone is learning? In July 2015 one particular website rated programing languages using features such as number of skilled software engineers who can use the language; number of courses to learn the language; search engine queries on the language and came up with the order.

  • 1) Java
  • 2) C
  • 3) C++
  • 4) C#
  • 5) Python

Where is Ada? 30th out of 100s! The same website had shown Ada (the language) as 3rd top in 1985! What a fall from grace.

But have no fear, Ada still survives and lives on in millions of lines of avionics2, radar systems, space, shipboard, train, subway, nuclear reactors and DoD systems. Plus Ada is perhaps making a comeback. Ada 2012 is just being finalised, heralded by some as the next generation of engineering software with its emphasis on safety, security and reliability. So Ada meet Ada, it looks like you will be remembered and used for a long time still.

Github is a place where lots of programmers now develop and save their code. It encourages programmers to share their work. A kind of modern day, crowd sourced ‘mass of shared facts’ but coders would probably not say they did this just to ‘amuse their idle hours’. Popular coding tools on this platform are JavaScript. Java, Python, CSS, PHP, Ruby, C++. Ada doesn’t really feature, well not yet.

Jane Waite, Queen Mary University of London

  1. United States Department of Defense ↩︎
  2. Avionics (aviation electronics) includes all the electronics and software needed to fly aircraft safely. ↩︎

Related Magazine …

This article was originally published on page 19 of issue 20 of the CS4FN magazine. You can download a copy at the link below, and all of our previous magazine issues (free) here.


Subscribe to be notified whenever we publish a new post to the CS4FN blog.


Answers to the quiz…

Answers: 1) Python 2) Ada 3) C 4) C# (C sharp) 5) Perl 6) Smalltalk 7) Java 8) Pascal

Victorian volunteers needed – the start of citizen science

What was Ada Lovelace thinking about when she wrote:
“If amateurs of either sex would amuse their idle hours with experiments on this subject, and would keep an accurate journal of their daily observations, we should have in a few years a mass of registered facts to compare with the observation of the scientific”.

Yes, crowdsourcing science experiments! Now we call it Citizen Science. She had just read a book by a Baron von Reichenbach on magnetism in which he had suggested a whole host of experiments, such as moving magnets up and down a person’s body, showing people magnets in the dark, and holding heavy and light magnets and asking them if they felt any sensations. She could see that he had some great ideas, but she was not convinced by his examples alone.

Ada was not the only Victorian to ask the general public for help collecting data. Charles Darwin, the Origin of Species man, wrote to gardeners, diplomats, army officers and scientists across the world asking for information about the plants they grew and the animals (including people) they saw. This all helped him build up the concrete evidence that natural selection was the way evolution works. People even sent him gifts of live animals in the post. A Danish gentleman sent him a parcel of live barnacles. When they did not arrive on time, Darwin, desperate to dissect the species, panicked and got ready to offer a reward in the Times newspaper. Luckily they arrived intact, fresh and not too smelly!

Today we might take part in the RSPB’s Big Garden Bird Watch1, contribute to a blog, ‘favourite’ or ‘like’ a post on social media or vote for your favorite performer in a talent show. We participate, and ‘amuse our idle hours’ sometimes in the pursuit of science, sometimes not. Public research is a big new topic, with governments and companies looking to use people power. Innovations such as shared mapping systems ask users to upload details about a place, add photographs, rectify mistakes. Wikipedia is sourced by volunteers, with other volunteers checking accuracy. Galaxy Zoo volunteers even found a whole new planet that orbits four stars!

What would Ada be asking us to research? Test your own DNA and send in the results? Measure air quality and keep a record on a central database? Build your own ‘find a barnacle’ app? But rather than writing a journal or sending a parcel of barnacles, you would log it on line, click a link or design your own survey. Ada’s computers are in on the act again.

Why not find a Citizen Science project on something you are interested in. Sometimes called public science or science outreach projects they might be run by local universities, museums, your council, charities or through crowdsourced internet projects such as www.zooniverse.org. Share what you do with others and spread Ada’s word to be a modern day volunteer.

Jane Waite, Queen Mary University of London

  1. 23-25 January 2026: RSPB Big Garden Birdwatch – “Spend an hour watching the birds in your patch, between 23 and 25 January, and record the birds t allhat land.” You can also get your school involved in the Big School’s Birdwatch 2026. If you’re reading this after 25 January 2026 make a note in your diary to remind you to check next year! ↩︎


Related Magazine …

This article was originally published on page 13 of issue 20 of the CS4FN magazine. You can download a copy at the link below, and all of our previous magazine issues (free) here.


Subscribe to be notified whenever we publish a new post to the CS4FN blog.