As a longtime electronic music enthusiast and hobbyist, I look at any piece of technology as a source of sound. Since C.H.I.P. has built-in audio, battery power capabilities, and a convenient USB jack, I knew it would make an excellent small, portable, interactive noise-box, capable of a huge variety of excellent sounds.
The first step to realizing C.H.I.P.-MAS (an acronym that embeds an acronym!) was to find a good platform for programming a synthesizer. There are several different paths one could choose: C++ and an audio framework such as asoundlib or Jamoma, python and Pyo, a specialized language such as Faust or, if you wanted to do something simple with samples, Pygame or Pysound. I chose Pure Data (aka Pd), an open-source, extensible, graphical programming environment. Pure Data is designed to generate and process sounds, and is a great way to quickly prototype and create new ways of making music.
Once I decided on a programming environment, it was time to develop the synthesizer. I used one of the more interesting but low-CPU use examples from the Pure Data examples (C08.analog.sequencer.pd), since it had an interesting wavetable synthesizer combined with a sequencer. I did a lot of work to make the synth have more sonic variety, as well as integrate a MIDI keyboard to create arpeggiating sequences.
Read on how to make C.H.I.P. a fun and bizarre synthesizer!
The basic recipe is to
- Boot C.H.I.P.
- Install Pure Data
- Get the Git (repo)
- Setup synth to launch at boot
The first step is to install the Pure Data program. Pure Data comes in the "extended" and "vanilla" version. As you might expect, "extended" gives you more features, however, I didn't need or want the additional features, so I installed "vanilla." It's easy to install from the command line on C.H.I.P.:
sudo apt-get update s
Optionally, you can use the Synaptic Package Manager (from "Computer Things!" menu) using the mouse and keyboard in the CHIP operating system and install Pure Data from there.
Humans are very sensitive listeners. One of the challenges of music programming is to get the time from "action performed" (press a key on the piano keyboard) to "sound heard" as small as possible. This is called "latency" and is a huge topic of compromise for electronic music producers and programmers alike!
Pure Data is best given a high priority for the operating system, and can be done so with a bit of configuration. Edit a configuration document in the nano editor:
sudo nano /etc/security/limits.conf
Where you add lines:
@audio - rtprio 99 @audio - memlock unlimited
to the end of the file. Now you can reboot C.H.I.P. to ensure that this takes effect
For this stuff to really work, Pure Data needs to be launched from the CHIP terminal with the "realtime" flag, like so:
If you want to make your own synthesizer or modify the one I made, you may also want to install Pure Data application on your "everyday" computer. Don't get me wrong, C.H.I.P. is an awesome computer, but if you have a faster computer with a higher resolution display, you'll probably find it easier to program with Pure Data, which tends to use a lot of screen space.
Go to your Documents folder, and pull the git repo:
cd ~/Documents git clone https://github.com/nyboer/CHIPMAS.git
It is worth mentioning a few things here if you are interested in how the synthesizer works. In making the synth, I wanted to be able to create a large variety of sounds: percussive, noisey, bright, simple, clean, aggressive and more. However, I didn't want to gobble up a lot of CPU. I chose a wavetable synthesizer design that can scan the table at varying sizes, resulting in several complex waveforms from a single wave. I then created a few tables that could be blended, making for a lot of possible timbres. Add in the synchronized low-pass filter, amplitude, and table-scan envelopes, and we have a very versatile synth.
All parameters can be controlled via Open Sound Control (OSC), meaning this tiny synthesizer is networkable. But for the simple case, I designed it around a cheap Akai Synth Station 25 keyboard that I had lying around. This way I can plug in the USB MIDI controller, power up C.H.I.P., and have a complex synthesizer voice in hand.
You'll notice the git repo also has a file called "graintable.touchosc" which is a file for the Touch OSC app for Android and iOS. This gives you control over several parameters in C.H.I.P.-MAS, and options for using your phone's motion sensors to control the sound .
I designed this work with any MIDI keyboard. All you do is press down a chord and the notes will play in the order you press the keys. Use the Modulation and Pitch Bend wheels to change the filter cutoff frequency and crossfade between wavetables. If you use the Akai Synth Station 25 keyboard, you can use six of the eight buttons to change presets (top row of buttons) or change the tempo (up or down, in increments of 4 BPM).
You will need to connect the keyboard before you power up C.H.I.P. for the keyboard to be found by the program.
Just press keys on the keyboard, move the pitchbend and modulation wheels and enjoy some sonic weirdness!
Finally, we want to make this a *Thing*, meaning, plug in the keyboard, turn on the CHIP, plug in your headphones, and jam out.
This relies on making a
systemd service script that boots at the right time. It's really easy to do, and the necessary service file is included in the git repository. This service script just tells Linux to open our synthesizer patch after a particular service is available. You should double-check the line:
ExecStart=/usr/bin/pd -nogui -rt /home/chip/Documents/CHIPMAS/CHIPMASsynth.pd
To make sure the absolute paths to pd and C.H.I.P.-MASsynth.pd are correct.
Change your directory to wherever you have the git repo, then copy the service file in the repo to the right place:
sudo cp chipmassynth.service /etc/systemd/system/chipmassynth.service
Now we'll need to let
systemd know about this new service:
sudo systemctl daemon-reload sudo systemctl enable chipmassynth.service
You can test out the service with these commands:
sudo systemctl start chipmassynth
systemctl status chipmassynth
sudo systemctl stop chipmassynth
The Pure Data patch has a couple special messages in the "pd init" subpatch that make sure it can grab the first MIDI device, turn off audio input, and turn on the first audio input (C.H.I.P.'s built-in audio) to guarantee the synth is playable right after C.H.I.P. boot.
After all that, you should be to plug in a MIDI keyboard, power up C.H.I.P., plug in some speakers (or headphones) and make some crazy sounds. It's that simple!
It's the options that make it great. Here's some things I did that made development faster so I could transfer files more easily from my development machine to C.H.I.P.
Make C.H.I.P. Unique
C.H.I.P. has "zero configuration networking" enabled with `avahi`, but I wanted to take full advantage of that. I have several C.H.I.P.s around, so it's better if they have unique names.
This is detailed at the C.H.I.P. documentation site, but, for the sake of posterity, here's how you do it.
In short, you need to edit a couple files and change "chip" to "synth" (or whatever name you want)
sudo nano /etc/hostname sudo nano /etc/hosts
Also, I am on a Mac, so I like to add apple services:
sudo nano /etc/avahi/services/afpd.service
And add this content:
sudo /etc/init.d/avahi-daemon restart
Password free login
It's also nice to be able to use `ssh` and `scp` to control and copy files to C.H.I.P. without having to enter a password every time.
Generate an SSH keypair on your computer
ssh-keygen -t rsa
and save it to
Copy it to the C.H.I.P.s:
scp ~/.ssh/id_rsa.pub chip@:~/
On C.H.I.P., you'll need to install
rsync, set it up for ssh (if it hasn't already been done), then copy the public key to it's authorized keyfile:
cd ~/ sudo apt-get install rsync mkdir .ssh cat id_rsa.pub >> .ssh/authorized_keys rm id_rsa.pub chmod go-w ~ chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
After all that, on your host machine, it's now easy to move all the PureData patches over without having to bother with login:
rsync -avzu CHIPMAS/ email@example.com:~/Documents/CHIPMAS
I'm pretty stoked to have completed a simple synth for so cheap on the C.H.I.P. Even thought I set out to build something pretty simple, there's actually quite a bit of signal calculation going on in this synth, since it's scanning 4 wavetables simultaneously and mixing them, along with the noise signal, and modulating them all with envelopes.
Even though it's not optimized, it still only takes around 25% of C.H.I.P.'s cpu. Down the road, I think the synth could be simplified and fixed to turn things off that aren't being used. It could also use some oversampling to improve the sound quality, and the more CPU-intensive, but better sounding Moog-emulating "bob~" filter could be dropped in place of Pure Data's "vcf~".
Finally, C.H.I.P.'s built-in networking needs to be exploited. C.H.I.P.s are so cheap, it's not unreasonable to run six to eight of these synths on separate C.H.I.P.s, synchronized and controlled over a network. Now THAT would be a happy holiday!