Archive | February, 2015

SonicPi on Raspberry Pi

12 Feb

One of these days, I’m going to do something on the Raspberry Pi that is going to work the first time.  Today . . . is not that day.  Liz and Eben Upton sent me a Raspberry Pi B+ and I was dying to see what’s new on it.  I had some struggles getting NOOBS to work on it, so I downloaded a new version and it worked fine.  I installed the new version of Raspbian and a few things that I noticed that were new are: 1) It has the GPIO version of Scratch already installed  2) It doesn’t have the Midori browser anymore  and 3) There’s a new program called Sonic Pi installed.

Sonic Pi is a program that allows you to use code to create music.  You can generate drum sounds, guitar sounds, sample music clips, loop sound effects, and apply envelopes, fades, etc.  For example, if you type “play 44,” it plays the 44th key on the piano.  If you type “sleep 1,” it waits for one second, and if you type “sample :sound_slow,” it plays a sound called sound_slow.  It’s fun to play with and you really can create some great music.  Here’s an example of a person who coded “Flight of the Bumble Bee” with over 1,200 lines of code! http://raspi.tv/wp-content/uploads/2013/10/Bumble-Sonic-Pi.mp3

I played around with Sonic Pi for a while and went through the first few simple tutorials.  It was fun.  Then, I wanted to save my song to use in this blog.  If you click “Save,” it saves your code and not your song.  Then there’s a button that says “Record” that will save the song itself as a wav file . . . or so you’d think.  I couldn’t find any instructions for the record button in the tutorials or even online with a simple google search.  So, I just tried it.  I pressed record and then played the song.  When I clicked record again to stop the recording, it asked me to name the file and I chose to put in on the desktop.  Simple, right?  Then I went to the desktop and the file wasn’t there.

I had to do some research to figure out how to find a file in Linux.  I couldn’t get the “find” feature in the terminal to find the file (or maybe it turns out that it wasn’t there), so I installed a program called “mLocate” that works a little better.  It turned out that the file just wasn’t there.  I tried to save it with a different name, save it in a different folder, and repeated over and over and it just wouldn’t save the file.  In researching how to fix this, I found out that there is a new version of Sonic Pi available and I hoped that this would fix all of my problems.  Once I installed Sonic Pi version 2, the program seemed pretty much the same, so I wrote a quick song and tried to record it.  The process was the same and this time, it seemed to work.  But when I used mLocate to find the file, it didn’t find anything.  This time, though, it was my mistake.  Before you use mLocate, you have to update its database where it searches the Raspberry Pi for files and makes a list.  So, when I type “sudo updatedb”, this   updates mLocate’s list and then it found the file.  Now, you just type “locate word” and it will find files, folders, and programs that contain the letters “word” in them.  It seems as though if I type “locate word” it only looks at the present folder, but if I type “sudo locate word,” it checks the entire computer.

But, the wav file wouldn’t play.  It was using Jack Audio to play the file and it crashed every time I tried.  Then, I found out that Alsa can be used to play wav files.  My file was named practice.wav so I typed “sudo aplay practice.wav” and now it plays fine.  If yours doesn’t play, it might be because you have the Pi set to play from HDMI and you have headphones plugged in or vice versa.

That’s as far as I got with Sonic Pi because it took a while for reinstalling, restarting, and researching.  Overall, it was fun and I will definitely use it again.

Materials:

Raspberry Pi B+ Starter Kit: http://amzn.to/1vG1OS3

Sonic Pi Software (if your OS doesn’t already have it): http://sonic-pi.net/