SamplerBox and Pure Data: Theory and Practice
Started by bbishop




14 posts in this topic
bbishop

33 posts 7 threads Joined: May 2021
19-08-21, 23:09 -
#1
Hello everyone,

for the past few months I have been (successfully) working on integrating SamplerBox with Pure Data, and after many conversations with Hans we decided to open up forum dedicated to the subject. Hopefully others find this intriguing, and are interested in trying it themselves, but first a quick introduction to Pure Data.

Pure Datahttps://puredata.info/ ) is an open source visual programming language developed by Miller Puckette, similar to Max/MSP (..which was also originally developed by Miller Puckette). It was developed with the idea of making programming accessible to artists and musicians, it is able to to process audio, control art installations, or build entire virtual synthesizers.

Once you understand the basics it's incredibly easy and fast to use (some musicians and performance artists use it for live coding, creating unique compositions and sounds on stage). Previously it was relegated to use on desktop computers or laptops, and was a fairly obscure tool, but as the raspberry pi has gotten more powerful it has experienced a bit of a resurgence and is showing up as the basis for many dedicated hardware instruments, such as standalone Synthesizers, Eurorack modules, and effects processors.

coding in Pure Data is very much like operating a modular synthesizer, or putting together a pedal board. You have individual objects (such as oscillators, math functions, logic gates, audio effects, etc etc) that you connect together using virtual patch cords. These patch cords can be changed and manipulated in real time, completely changing the program. For our purposes we wont be doing any sort of live code manipulation, but this makes it incredibly easy to develop and test our program.

a basic Pure Data file (called a Patch) looks like this:

   


there are lots of resources online for learning PD, as well as many examples (like the one above) included in the pure data help menu.

I found the examples in this tutorial to be particularly helpfull http://www.pd-tutorial.com/
there are also lots of incredible examples over at pure data patch repo but most are too complicated for the Pi to run
and patch storage has dedicated pages for pure data as well as several Pi and PD based instruments (those can get pretty hardware and OS specific and take some work to adapt)

Patch Storage: pd-vanilla
Patch Storage: ORAC
Patch Storage: Organelle
Patch Storage: Bella

Integration with SamplerBox

My initial idea with this was to add a non-sampled digital synthesizer voice to accompany the sampled instruments, making SamplerBox function something like the Prophet X by Sequential Instruments, but really the sky is the limit (or rather... CPU power is the limit) in what we could do, from basic audio processing to granular synthesis (you could directly record a few bars from SamplerBox and then using that as the source for granular synthesis, and have that play in tandem with the live audio from SamplerBox) or custom midi sequencers.

a side benefit of offloading audio effects from samplerbox to PD is that they are separate processes, and will run on separate cores, freeing up CPU resources for each, and as multiple instances of Pure Data can be opened at the same time (with as many audio inputs/outputs as you want, feeding into each other) we can further break down our individual audio processes for more efficient hardware usage. Using CPU heavy effects like Reverb directly in SamplerBox can cause issues with headroom and limit what it's capable of, but by offloading the effect to pure data we no longer have that problem, as each will operate on separate cores.

to create and test my Pure Data patches directly on the Raspberry Pi I've installed a desktop environment and am using a VNC to access it, but everything can be setup to boot and run "headless", so we wont need the desktop to run our pure data patches (I have yet to actually set this up though).

here are some videos of the setup working. These are a bit dated as I've been completely rebuilding the synth engine.

sampled DX7 and pure data based drum machine

piano from samplerbox and custom FM synth from pure data

a drum machine, sequencer, and BPM based dual delay made entirely in pure data

a closer look at the FM synth engine

to feed the audio from SamplerBox we are going to use a two audio cards, I'm using a HiFiberry clone as the default card for samplerbox, and a USB audio card with stereo audio in and out to be the default card for Pure Data (I'm using a behringer UCA202), we simply use RCA cables to feed the output of samplerbox into the USB audiocard. If you didn't care to process the audio from samplerbox itself you could use a setup with separate stereo outs for each program, as well as stereo in for pure data (making a device more akin to the organelle)

(for those following along this is an update to my previous method of using Jack Audio to internally route the audio from samplerbox to pure data, which had it's share of problems)

Future Development/Plans/wishes

Intercommunication and Menu System: I would like to get pure data and python directly talking to each other, namely I want samplerbox to send menu data as message to pure data, or the reverse, and relay those combined messages to a microcontroller and display. Theres a few ways to go about this but I've only just begun investigating. the existing pure data based hardware synths out there use OSC to talk to python and create a menu system, but instead of going to the trouble of implementing that I would rather use serial communication (the "comport" extension object in pure data) to the microcontroller,  and TCP/UDP (Netsend/netrecieve in PD and Sockets in Python), or somehow using this python extension in PD pyext, or have each send info to the microcontroller separately. Final and tedious possible method would be to assign each message a MIDI CC number and value, as I'm already able to connect everything to midi via Jack, but this would mean that any changes I make to the PD patch will have to be redefined 

oscilloscope: you may have noticed the oscilloscope in pure data, I find it very helpful in understanding how a sound is being changed/effected. theoretically I should be able to regularly dump the oscilloscope data as coordinates and plot them on a display (using serial plot on the arduino), I then would simply need to create an argument to switch to displaying the menu data whenever a midi CC control is changed


I would like to completely offboard the reverb effect, as it eats up too much CPU and could limit the possibility of polyphony in the synth engine. I've started working on adapting a circuit that uses 4 PT2399s (a very cheap digital delay IC that was made for adding delay/reverb effects to karaoke machines, I bought a tube of 12 of them for $24) to create a simulated spring/plate reverb effect. They run on 5v so it should be relatively simple to integrate, without any special power supply needs.

I'm also interested in adding an analog voltage controlled filter to the signal path (digital filters sound fine but there's nothing like the real thing), using these reproduction VCF ICs AS3320, and using a digital to analog converter to output a control voltage from the raspberry pi for an LFO and midi controls, but these require +-15V, so I would also need a switching power supply for that, and a step down converter and regulator for powering the pi such as this, which is getting a bit complicated and may be an idea reserved for a future project (the overly ambitious part of my brain is imagining a digital/analog hybrid synth, using PD as a multi-engine and CV source. you could apply digital FM to analog oscillators! or use wavetables for an LFO! or even have a touch screen for drawing waveforms! and that's just the CV output. anyways...)

--Bryan
This post was last modified: 20-02-22, 01:11 by bbishop.


Attached Files Thumbnail(s)
   


Messages In This Thread
SamplerBox and Pure Data: Theory and Practice - by bbishop - 19-08-21, 23:09