Csound in Pure Data on Raspberry-Pi

Today I got Csound running inside Pure Data (using the [csoundapi~] object) on Raspberry-Pi.

These instructions assume you have already installed pd-extended on R-Pi. See this post to learn how. https://reactivemusic.net/?p=4930

Install Csound

# sudo apt-get install cloud

Install csoundapi~

# sudo apt-get install pd-csound

Copy csoundapi~ library into the pd-extended extras folder

# cd /usr/lib/pd/csound/extras
# sudo cp csoundapi~.pd_linux ../../pd-extended/extra

Here’s a test patch:

Here’s the Csound source file (should be in the same folder as the test patch)

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>
;Example by Joachim Heintz

sr = 44100
nchnls = 2
0dbfs = 1
ksmps = 8

giSine    ftgen     0, 0, 2^10, 10, 1

instr 1
kFreq     invalue   "freq"
kAmp      invalue   "amp"
aSin      oscili    kAmp, kFreq, giSine
          outs      aSin, aSin
endin

</CsInstruments>
<CsScore>
i 1 0 10000
</CsScore>
</CsoundSynthesizer>

Here are the source files:

http://zerokidz.com/rpi/csound/cstest2.pd

http://zerokidz.com/rpi/csound/control.csd

Here’s the command line to run the test:

# pd-extended -nogui -noadc cstest2.pd

Here are general instructions on running csound in Pure Data from Victor Lazzarini:

http://booki.flossmanuals.net/csound/_draft/_v/1.0/csound-in-pd/

 

csoundapi~ in Pd

notes

A preliminary test before trying this in Raspberry-Pi, I used the general instructions for csound in pd from Victor Lazzarini found here:

http://booki.flossmanuals.net/csound/_draft/_v/1.0/csound-in-pd/

to get csound running in pd-extended in Mac OS.

Looks pretty straightforward – biggest question will be compiling the external if it doesn’t install via package manager.

local test files are in tkzic/rpi/pd/csound

Here’s something from Victor Lazzarini which shows csound running on R-Pi

http://csound.1045644.n5.nabble.com/csound-on-raspberry-pi-td5718623.html

Here is installation instructions from Richard Dobson

http://csound.1045644.n5.nabble.com/Raspberry-Pi-w-Csound-td5717410.html

 

 

Car engine enhancement with Max and OBD-II

Much of our driving experience is wrapped up in sounds that happen when you press the pedal to the metal. Like Superman emerging from a phone booth, this 2006 Jetta seems different.  The project connects RPM data from an OBD2 diagnostic sensor with the input of the car radio. Via synthesizers.

[update 11/2013 – source code is available at https://github.com/tkzic/automax  – this version features

  • V8 engine
  • Jet engine
  • Spaceship
  • Star Trek TOS transporter button
  • Korg nano-control Midi controller interface]

This project uses the RPM data from an automobile OBD-II port to control the engine speed of an engine simulation from Andy Farnell’s book “Designing Sound”

Here’s the patch that polls and translates OBD-II data

patch is tkzic/automax/rpm4.maxpat

Here’s a Max version of the Farnell car engine simulation:

patch is tkzic/automax/waveguide_engine2e-1.maxpat

 

 

 

Raspberry-Pi Osc synthesizer

A variation on the Midi synthesizer from this post: https://reactivemusic.net/?p=4960

The synthesizer was built in PureData (Pd extended) using the visual interface on a MacBook. Then the pd file was run in command line mode on the r-pi. The sound card is a Griffin i-Mic, running at 22.5 Khz sample rate. Although there’s no reason why you couldn’t use the builtin DAC on the r-pi.

The r-pi is connected via the ethernet port to a wi-fi network which receives Osc (Open Sound Control) messages from an iPod running touch-Osc. The network connection could have been made using a USB wifi adapter.

All together the cost of this arrangement (less the iPod) would be less than $50. The software is all open source.  The huge financial barriers to working with music synthesis and signal processing, that have been associated with these fields for years, simply don’t exist anymore.

Alternative ways of controlling the synth – if a wiFi router is not available, include:

  • USB keyboard (usually free)
  • USB Midi Keyboard ($25)
  • switches or dials via the GPIO pins (spare parts)
  • direct ethernet connection to another device.
Here is a screenshot of the Pd Patch.

Notes:

Pd file: tkzic/rpi/pd/piSynth1_OSC.pd

recieve port is 8000 – and it uses page 1 of the simple touchOSC template

pd-extended -nogui -noadc  piSynth1_Osc.pd

Note: there is some special code to prevent seg faults when you go from page 2 to page 1 of the touchOSC template

Here’s a great tutorial on using OSC with Pure Data

http://en.flossmanuals.net/pure-data/network-data/osc/

 

 

 

Pd synth examples

notes

A collection of Pd synth patches that might run on Raspberry Pi.

 

Raspberry Pi with Pd: audio test

notes

In an audio pass-through test using Pd, with a USB sound card (Griffin iMic), the maximum stereo sample rate before ‘breakup’ is 32000.In mono, it sounds “ok” at 44100. Latency seems low enough to use for music but I’m too sleepy to figure out the numbers.

I don’t know enough about Linux audio to say if the performance deficit is due to ALSA drivers, the sound card, background processes, pd, the CPU, or what?Anyway I ‘m guessing R-Pi will spawn interesting synths and lo-fi FX processors. They’re cheap enough you could use them in parallel.

Prediction: They’ll double the speed, and sell a million more by the end of the year. We’ll see a range of ‘Pi’ clones which run the same Linux distributions, but offer various speeds and IO options. It feels like the democratization of manufacturing has taken another huge leap.

pd-extended on Raspberry Pi

notes

Using installation instructions from Pd site:

http://puredata.info/downloads/pd-extended-0-43-3-on-raspberry-pi-raspbian-wheezy-armhf

Installation worked fine. I tried running the GUI under xterm and it was a disaster. Then, using this post, I was able to get a test patch (sine wave with LFO) running in terminal mode:

http://log.liminastudio.com/programming/running-puredata-on-the-raspberry-pi

Note: I changed the actual command to this due to the fact I’m running pd-extended and a USB sound card:

pd-extended -nogui -noadc testPatch.pd

This post from same source has instructions for installing pd-extended (disaster) but a very nice version of the test patch called testPatchExtended.pd

http://log.liminastudio.com/writing/tutorials/how-to-build-pd-extended-on-the-raspberry-pi

(another update) running Midi:

To run midi you need to specify the device on the command line. First I plugged in the m-audio key station 49 and rebooted RPi

To get a list of devices use:

pd-extended -nogui -listdev

Then to run a patch with midi

pd-extended -nogui -noadc -midiindev 1 testMidi.pd

Here is a page with more information on command line options

http://crca.ucsd.edu/~msp/Pd_documentation/x3.htm#s4

(another update) Testing with Griffin iMic. Bad news when doing an ADC->DAC passthrough, sample rates above 32000 don’t work in stereo. However 44100 and 48000 sound fine in mono.

At the higher rates in stereo, the audio breaks up. Oh well. Need to try the Behringer audio box, but I’m assuming there will be no difference. Only possibility would be to somehow devote more system resources to audio.