Flight of the Bumble Bee: sample based for Sonic Pi

freebumblebeepic400Picture from www.public-domain-image.com

Having worked on a sample based Piano voice for Sonic Pi, I determined to tackle a much more ambitious project to add a Xylophone based sample voice and then to transcode Rimsky Korsakov’s Flight of the Bumble Bee for Sonic Pi 2. I know that there is at least one version out there already for Sonic Pi 1, written by Alex Eames of Raspi-TV, which  used a single synth, and numerical coding for the notes with just the solo instrument, but I wanted to reproduce as realistic an instrument sound as possible, with a piano accompaniment as well as the solo Xylophone.

In the event this turned out to be a bigger challenge than I had envisaged. On the way I discovered that currently, there is a limit of 16216 bytes on a workspace in Sonic Pi 2, and if you exceed this limit it won’t play. In the event, by ditching nearly all the comments, and rewriting some code more efficiently in space terms, I managed to complete the project with 37 bytes to spare! I would still like to add a few further notes right at the end, but it is quite performable “as is”. It also was quite a challenge to work out how to play the parts, with long running sections of semiquavers for both Xylophone and Piano, as well as sections with chords on the piano. I had to write all the functions to deal with playing both of these, written ultimately to call a sample command for every note played. Five different parts were played using threads, One of these parts played all the chords. It was quite a long job debugging all the notes and timings, as inevitably mistakes were made initially in writing these. All the threads played together, but the contents of some were delayed, sometimes for 80 bars, and others had big gaps in the middle between different played sections. I had to keep the number of notes in the chords to 3, so that Sonic Pi could cope. The piece also plays with a long set_sched_ahead_time! of 12 seconds, so each change took some time to check. I also included the ability to transpose the whole piece (I couldn’t use the normal with_transpose command but had to write my own sample based one). This was not just for fun, but because the top notes in the Xylophone register didn’t sound so realistic, so I transposed 7 semitones down. (It is am amazing feeling to change one number and have all those notes shift!)
I will not release the program at this time, because I would wish to tidy it up and add some comments in again first, once Sam Aaron has overcome the space limitation (the same in the Mac version but a lower limit of about 9000 characters applies) which he hopes to do for version 2.1 of Sonic Pi. However until then you can enjoy the audio, recorded from Sonic Pi 2.0.1 playing on a Raspberry Pi, and then converted from a .wav to a .mp3 file using the open source editor Audacity.

Enjoy!                       The Flight of the Bumble Bee for Sonic Pi 2

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s