Sonic Pi and BitScope

Visualizing sound with Sonic Pi and BitScope

Sonic Pi Pretty Bell.

Sonic Pi's default "Pretty Bell" (play 60)

After we installed the latest edition of Raspbian to try BitScope on the Raspberry Pi we started having a look around and were delighted to find Sonic Pi was pre-installed.

Sonic Pi is a sound programming environment developed specifically to teach programming concepts where sound synthesis provides the medium for learning how to program.

We like this idea a lot but we also saw another educational possibility; Sonic Pi makes for an excellent complex waveform generator which is easy to use. It's the perfect tool to help explain what an oscilloscope and spectrum analyzer can do and how they can be used to analyze complex waveforms.

Waveform analysis is a very big topic so we're launching an educational blog to cover it and others in more detail soon.

Sonic Pi and BitScope Mini.

For now, we thought we'd have a brief look at what Sonic Pi can do in terms of basic waveform generation. The first step was to connect the audio output of Raspberry Pi to a BitScope (BitScope Mini in this case). We rigged up an adapter to plug in a stereo 3.5mm jack terminated stereo cable between them but we could have used the standard test probes and a bare 3.5mm socket.

The BitScope is connected to and powered by the Raspberry Pi and it runs both the Sonic Pi programming environment and the BitScope DSO software. We're using an HDMI connected TV as the monitor so we need to switch the audio from HDMI to the stereo output using this command:

sudo amixer cset numid=3 1

which we executed in a terminal. The "1" selects the headphone output. Use "2" to switch back to HDMI or "0" to automatically switch (although we found this did not appear to switch to headphone when we were not using HDMI).

Next we powered up Sonic Pi, power up BitScope DSO, and set it to trace on channel A at 50ms/Div and played the first sound using the play 60 command.

This produced the waveform shown at the top of this page. Sonic Pi calls it pretty_bell and it is indeed a pretty bell sound which you can see looks like an exponentially decaying waveform. It sounds like a bell so we know it cannot be a single sinusoidal waveform so let's have a closer look and see what it is.

Sonic Pi Pretty Bell.

The start of "Pretty Bell" (play 60) in close up

Here we can see the start of the bell playing. It comprises two sinewaves summed.

The play 60 command outputs C4 (Middle C) which is 261.63Hz. The fundamental period is therefore 3.83ms which appears correct looking at the timebase grid of 2ms/Div.

The second sinusoid has four cycles per period of the fundamental. It is four times the frequency of the fundamental (1046Hz) and its amplitude is quite high relative to the fundamental which is what produces the bell like tone of the sound.

So far we have viewed the waveform on a normal oscilloscope display in two different timescales. The waveform period and frequency measurements we made are estimates only.

In a future post we'll explain how to use the spectrum analyzer, cursors and automatic waveform parameters to make more precise measurements of these and many other waveform characteristics. We'll investigate and "reverse engineer" how Sonic Pi works to produce the sounds it does and we'll look at some of the practical limitations from a sound synthesis point of view.

Related Posts

BitScope
Build a powerful mixed signal workstation with one simple 3D print !Sep 3
Raspberry
Raspberry Pi Zero W, a wireless wonder for only $10 !Feb 28
Raspberry
Raspberry Pi 3 Launch and BitScope BladeFeb 29
BitScope
Physical Computing with Raspberry Pi and BitScope!Dec 01
Raspberry
BitScope Micro with Raspberry Pi Touchscreen Display!Sep 09
Raspberry
BitScope, Ozberry & Pimoroni at Sydney Mini Maker Faire!Aug 12
Education
Picademy Workshop with Carrie Anne PhilbinJul 27
Raspberry
BitScope Blade for Raspberry Pi at Hannover Maker Faire!Jun 05
Software
BitScope DSO 2.9 Now Available.Jun 02
BitScope
Getting Started with BitScopeMay 08
BitScope
BitScope Micro In-Line Data AcquisitionApr 02
Raspberry
Bootstrapping Raspberry Pi 2 for BitScopeFeb 05
Raspberry
Raspberry Pi 2 and BitScope PerformanceFeb 02
Raspberry
Raspberry Pi Model A+ or B+ or B+ Slimline?Nov 14
BitScope
BitScope Model 10 or BitScope Micro?Apr 25
BitScope
BitScope Micro, what's in the box?Apr 17
Raspberry
BitScope Micro Questions & AnswersApr 12
Raspberry
BitScope Micro (New Product) for Raspberry Pi!Apr 11
Education
BitScope Workshop at OzBerryPiApr 8
Raspberry
How to Install BitScope DSO on Raspberry PiOct 18
Raspberry
Electronic Projects Lab for Raspberry PiOct 17
Education
BitScope Ed, an Educational Blog about Electronics.Oct 09
Software
BitScope Software Blog LaunchedOct 04
Raspberry
How to Install Raspbian and BitScope on Raspberry PiSep 29
Raspberry
BitScope Software for Raspberry Pi OscilloscopeSep 27
Raspberry
BitScope Raspberry Pi OscilloscopeSep 25
More...