Rob at Dot Net North

I’m back on the road again. Dot Net North have kindly invited me to be the speaker at their first in-person event since the pandemic kicked off. Really looking forward to the event. I’m going to be talking about making music with hardware. There will be devices you can build, devices you can marvel at and hopefully devices that work in front of an audience.

The event is in Manchester on the evening of Tuesday 20th September. You can sign up here.

Sending messages to Pure Data using fudi

Isn’t this exciting? I’m just on the brink of sending useful messages between my PICO powered controller (which has buttons and a display) and a Pure Data patch running on a Raspberry Pi. Last time I got the comport working now that I can send raw data bytes between the devices. Now I want to see about sending packets of useful data.

The man behind Pure Data (Miller Puckette) has thought of this. He’s invented the FUDI protocol for sending messages. It’s a very simple text based protocol which means that it will be very easy to make the PICO assemble FUDI messages for the Pure Data patch to read.

Lets take a look at the kind of message that I might want to send from the controller to a Pure Data patch:

encoder 97 5;

The controller generates messages like this when an encoder is turned. The word encoder tells the receiver that a new encoder value is coming The first number (97) is the new encoder value. The second number (5) is the number of the encoder. The encoder message is generated by Circuit Python running inside a PICO which is connected to the encoders and sends messages out over the serial port. The Python code that sends these messages is:

b1 = int(self.active_config.serial_channel)
b2 = int(self.active_config.controller_value)
message = "encoder " + str(b1) + " " + str(b2) + ";\n"
send_buffer = bytes(message,"ascii")
print("Sending to serial:", send_buffer)
self.client.serial_port.write(send_buffer)

This code takes the two values and puts them into the variables b1 and b2. Then it creates the message string. Next it makes a byte array containing the message in ASCII. Finally it uses the serial_port_write method provided by the serial port to send the entire string out to the Pure Data patch. Now lets take a look at how this serial data stream is received.

My blog post here shows how to get a Pure Data patch to receive data from a com port. At the bottom of the patch you can see a data flow coming out of the comport object and ending in a rather enigmatic way. The patch decodes the input message and routes it to the required destination. It uses a Pure Data loop to assemble the message (which is a line of text) and then uses FUDI (Fast Universal Digital Interface) to parse the text and extract a message which is then routed to the appropriate destination.

Remember that what is happening is that individual bytes are arriving, one at a time, and need to be assembled into a line of text. The text is terminated by a newline character (10) or a return (13).

The sel object at the top of the patch takes the input stream and feeds it to one of three outputs. If the input value is 10 or 13 (the characters that mark the end of the list) the list is triggered to push its contents into the fudiparse object. If the input value is anything else (this is what the right hand output from sel is for) the newly received character is added to the start of the list, building up the line of text.

The fudiparse block takes the buffer containing the incoming message (in our case “encoder 97 5” and uses it to generate a Pure Data message that contains the values “encoder”, 97 and 5. This message is then sent into a route object. This looks at the first item in the message and then sends the rest of the message (the values 97 and 5) to the output that matches that name. In the case of the patch above, this means that the two encoder value are sent to a message endpoint called “encoderReceived”. Patches in other parts of the of the application can receive these messages and act on them.

You should be able to work out that the decoder above can also respond to an incoming message called button, which tells the Pure Data application when a button was pressed.

Using the comport object in Pure Data

I’m building a Raspberry Pi 4 based device that uses a thing called Pure Data to play sounds in response to incoming MIDI messages. The device also has a controller and display which is controlled by a Raspberry Pi PICO. I’ve connected the hardware for a serial connection and discovered how to send serial messages from the Circuit Python program in the PICO. Now I need to get the messages from the PICO into my music making software. This is how to do it.

The above patch fragment (is that even a thing?) shows how it we can surface serial data in a Pure Data patch. However, before we can do this we have to add the comport object to your Pure Data installation. If you re using a Raspberry Pi it turns out that this is very easy:

sudo apt install pd-comport

This console command installs the comport object. Now we can add one to our patches. The patch above shows that we can send it messages to make it do things. The message on the left sets the device name. The second messages sets the baud rate. The third message asks the comport to display all the available comports that Pure Data has found.

When the above patch is triggered by a message on the inlet it will set up a comport and set the baud rate to 19200. Any messages that we send to the comport object will be sent out of the comport. These need to just lists of bytes. If the comport receives any bytes from these are sent out of the bottom of the comport object. In a while we’ll take a look at how we can encode and decode messages that we want to send over the serial connection.

Auto-Start a Pure Data Patch on Raspberry Pi Bootup

Today I needed to find a way to auto start a Pure Data patch when a Raspberry Pi boots up. This is so that the Chocolate Synthbox (patent pending) can play sounds without the owner having to do anything to get it going.

Above you can see how I did it. The /etc/xdg/lxsession/LXDE-pi/autostart file contains commadns that are obeyed once the desktop has loaded. I used this command to start the editor:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart

I added the line you can see at the bottom:

sudo pd /home/pi/Desktop/Synthbox/ChocSynthboxMain.pd

This works well for me because the file Synthbox on my desktop contains the file ChockSynthMain.pd If you want to use it you change this to the location of your Pure Data patch.

You can use this technique to start any other programs on power up.

Developer Developer Developer Videos now live

A few weeks ago I had a great time talking about making music with the Raspberry Pi PICO and Pure Data at the Developer Developer Developer Conference. All the videos are now online. You can find them on the conference YouTube channel here.

If you want to watch my video (and why would you not) you can click on the link above.

Routing controller messages in Pure Data

Controller patch.png

I’m quite proud of the above Pure Data patch. What’s Pure Data? I hear you ask. What’s a patch? you add. Why don’t you get out more? Well, that’s just not a very nice question.

Anyhoo, Pure Data is programming environment that you can use to process audio data. It is graphical (see above). A Pure Data program is called a “patch” and is comprised of objects that are linked together with “patch cords” which are drawn as lines. And, I do get out. Quite a bit as it happens.

One of the things that you might want to do in a Pure Data is get controller values and use them to control stuff in your patches. A controller is something with a control on it. This could be a knob you can twist or a slider you could slide. For example, you could use a knob to control the volume of a signal. You can buy controllers or you can make your own. I’ve just made one using a PICO device.

Controllers are connected to your computer using a protocol called MIDI (Musical Instrument Digital Interface). This specifies an electrical standard and a message standard. You can buy devices with MIDI sockets and connect them using MIDI cables. However, MIDI also works over USB connections. In other words you can buy a MIDI controller, plug it into your computer and it will be recognised as a MIDI device. Then you just need something that understands MIDI messages. The Pure Data environment can both talk and listen to MIDI.

You then tell Pure Data about your MIDI device and you can start to receive control messages in your music patches and use them to manage the behaviour of your digital instrument. But how does this work, and what is the best way to do it?

Pure Data provides an object called ctlin which accepts MIDI control messages and makes them available to a patch. Each time the user changes the value by moving a control, the ctlin object sends out data values as messages. To use ctlin you don’t need to do anything more than just plonk a ctlin object in your patch and start using the output values that it sends.

The ctlin object produces three outputs, the patch above uses two, the value that represents the position of the controller, and the number of the controller generating that value. Perhaps I might want to use the value from controller 21 to control the attack value of a sound, the value from 22 to control decay, and so on.

That’s what the patch above does. The left hand path through the patch takes the control value and uses it to assemble a send message to send out the value to any patches that wish to receive it. The right hand path uses the controller number to index a list of message destination names so that controller number 21 is sent to attack, 22 to decay and so on.

Then, anywhere that I want to receive the latest decay value, I just have to use a receive object:

receive block.png

The tiny bit of Pure Data above receives the decay value and then multiplies it by 8 before sending it on to another component.

An interesting thing about Pure Data is that send and receive are effectively broadcasts. Any patch can use the decay value. Probably not something you’d be keen on if you worry about global variables in conventional programs, but great if you have lots of components that all have to react to a particular value.

The great thing about my little controller patch is that you can add new messages for additional controller numbers just by changing the contents of the list.

If this is the first time that you’ve seen Pure Data, I’d strongly advise you to take a proper look at it. It really is great fun to play with, very immediate and a great way to introduce people to programming without having to actually write anything. And you can make some interesting sounds. You can find out more here.

The Crackers Controller Lives!

20211003_083230689_iOS (2).jpg

After another fun day of coding (I really know how to enjoy myself) the “Crackers Controller” now lives. You can adjust settings by turning the encoders and the value is displayed on the pixel ring. If you press the encoder in you can switch to another setting value (above we have “blue” and “yellow” settings. The settings are sent out as MIDI control change messages. The controller works with the MIDI cheesebox you can see on the left, which will provide the note input. Now I need to write the Pure Data patch that will make all the sounds.

"Crackers" PICO Midi Controller takes shape

external.jpg

I’m building a partner device for the “PICO Midi CheeseBox”. This gives four rotary controllers with pixel ring feedback displays which you’ll be able to use to control MIDI playback. It’s called the “Crackers PICO Midi controller”. Why? Take a look inside..

internals.jpg

The wiring is a bit crazy, but it worked first time. I’ve got a new build technique called “making the design and writing the drivers before I build the device”. You can see the circuit diagram and the Circuit Python code creates controller instances for each of the four inputs.

The controller will be making an appearance in a future HackSpace magazine, when I’m going to be using it to control a Pure Data synthesizer.

Pure Data in HackSpace Magazine

hacksspace47.jpg

The October issue of HackSpace magazine is out. You can find it here, or in “all good newsagents” as they say. It’s a good read in spite/because of an article that I wrote. I’ve been playing with Pure Data music programming for a while (ever since I got an Organelle last year to play with during lockdown) and so I thought I’d write an article about it. Pure Data is a really good way to create applications that work with streams of audio data. Well worth a look.

Waveshare WM8960 Audio Hi-Fi Sound Card HAT

soundcard.jpg

I’ve been looking for a soundcard that will let me let me create a PureData powered musical instrument based on a Raspberry Pi device. This one looked like it might fit the bill. It even has two tiny microphones and comes with a pair of speakers.

The hardware isn’t directly supported by the Raspberry Pi operating system, so you have to do a mildly complicated install which involves downloading GitHub repository and then running an init script. My pro tip: rather than using Git clone from the command line (which will insist on you giving a GitHub username and password that you’d really rather not) use the browser to download the zip archive and then unzip the files onto your desktop.

I couldn’t get it to work (which is nothing new for me). I filed an online support request from the product page and was very surprised to get a prompt response offering help. Buoyed by this I had another go, starting from a brand new fresh install of Raspian. This worked a treat. Better yet, both the speakers and the microphone work perfectly with PureData (as long as I remember to start PureData in supervisor mode):

sudo puredata

If you are looking for an “all in one” audio solution for your Pi this is a very good bet. The speakers are OK for their size. The only thing it is missing is line audio in. You can only record from the onboard microphones. However, they do supply a full schematic, so if you are handy with a soldering iron and fine wire you might be able to make your own. And the support is very good. They even got back to me to ask how I was getting on after their first response.

How to make a Kick Drum in PureData

kickdrum.jpg

I’ve been writing an article about PureData for HackSpace magazine. I sent it off on Friday and with a bit of luck and a following wind it will be in next issue. I didn’t have room for the above illustration, which is rather sad. I’ve put it up here instead.

The program on the left shows how a linear ramp is converted into a drum sound. The three graphs on the right hand side show how the waveform starts as a straight line before being converted into a curve and then finally a sequence of sound waves.

The sound wave graph is compressed at the left hand side because the first part of the drum sound will be high frequencies. The spaced out waves at the right hand end (so to speak) are the low frequency parts that give the drum its kick sound.