Visualizing sound with Sonic Pi and BitScope
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.
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:
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.
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.
Copyright © 2023 BitScope Designs