Showing posts with label puredata. Show all posts
Showing posts with label puredata. Show all posts

Sunday, 1 January 2012

[Programming] FAUST

FAUST or Functional Audio STream is an amazing discovery. It is a functional language designed purely for writing DSP applications. What makes it really useful is that programs can be compiled to standalone applications (as in the picture above, which also shows almost all of the code written for that app) using the Qt library. More usefully, for me at least, it can be used to compile Pd externals.

It took me a while to understand how to write code in this language but it seems to be fairly simple once you get the hang of it and is definitely much more concise and simple to write than the C++ equivalent and because it is translated to C++ then compiled it runs just as fast.

As well as being able to compile standalone apps and Pd externals it can compile to all sorts of other plugin/app formats (VST, LADSPA, Max/MSP, iPhone and more). 

The code for the above app is as simple as this, and I think I have probably written this badly - I am sure it could be much easier to read - as you can see most of the code is for the positioning and creation of the GUI elements. The actual DSP stuff is quite simple.

declare name "SINES";


import("music.lib");
import("oscillator.lib");
import("math.lib");
import("effect.lib");


samplingFreq = 44100;


osc_group(x) = vgroup("[0]", x);
osc_group1(x) = vgroup("[1]", x);
knob_group(x) = osc_group(hgroup("[1]", x));
knob_group1(x) = osc_group1(hgroup("[1]",x));
kg1(x) = knob_group(hgroup("[1] OSC", x));
kg2(x) = knob_group(hgroup("[2] LFO 1 (SINE)", x));
kg3(x) = knob_group(hgroup("[3] LFO 2 (SINE)", x));
kg4(x) = knob_group(hgroup("[4] LFO 3 (SINE)", x));
kg5(x) = knob_group1(hgroup("[1] Filter", x));
kg6(x) = knob_group1(hgroup("[9] Output", x));
kg7(x) = knob_group1(hgroup("[2] Echo", x));


vol1 = kg1(vslider("[1]Volume [unit:dB] [style:knob] [tooltip: abc]",-30,-120,+4,0.1) : db2linear : smooth(0.999));
freq1 = kg1(vslider("[2]Freq [unit:Hz] [style:knob]", 440,5,200,0.01) : smooth(0.999));
squw1 = squarewave(freq1) *(vol1);
sine1 = oscr(freq1) *(vol1);


vol2 = kg2(vslider("[3]Amount [unit:dB] [style:knob]",-30,-120,+4,0.1) : db2linear : smooth(0.999));
freq2 = kg2(vslider("[4]Freq [unit:Hz] [style:knob]",440,0.01, 10, 0.01) : smooth(0.999));
sine2 = oscr(freq2) *(vol2);


vol3 = kg3(vslider("[3]Amount [unit:dB] [style:knob]",-30,-120,+4,0.1) : db2linear : smooth(0.999));
freq3 = kg3(vslider("[3]Freq [unit:Hz] [style:knob]",1,0.01,10,0.01) : smooth(0.999));
sine3 = oscr(freq3) *(vol3);


vol4 = kg4(vslider("[5]Amount [unit:dB] [style:knob]",-30,-120,+4,0.1) : db2linear : smooth(0.999));
freq4 = kg4(vslider("[5]Freq [unit:Hz] [style:knob]",1,0.01,20,0.01) : smooth(0.999));
sine4 = oscr(freq4) *(vol4);


moog_f = kg5(vslider("[4]Freq [unit:Hz] [style:knob]",5000,1,20000,0.1) : smooth(0.999));
moog_r = kg5(vslider("[5]Q [style:knob]",0.01,0,0.99,0.01) : smooth(0.999));


N = int(2^19);
interp = kg7(vslider("Interpolation [unit:ms] [style:knob]",10,1,100,0.1))*44100/1000.0;
dtime = kg7(vslider("Delay [unit:ms] [style:knob]",0,0,5000,0.1) : smooth(0.999))*44100/1000.0;
fback = kg7(vslider("Feedback [style:knob]",0,0,1,0.01) : smooth(0.999));
dvol = kg7(vslider("Volume [unit:dB][style:knob]",-120,-120,+4,0.1) : smooth(0.999));
skew = kg7(vslider("Skew L [unit:ms][style:knob]",0,0,5000,0.1) : smooth(0.999));
output = kg6(hslider("[4] [unit:dB] [style:knob]",-30,-120,+4,0.1) : db2linear : smooth(0.999));
a = sine1+squw1 <:
_, *(sine2) :>
_ <: _, *(sine3) :> 
_ <: _, *(sine4) :> 
moog_vcf_2b(moog_r, moog_f);


process = a <:
_, ((+ : sdelay(N, interp, dtime)) ~ *(fback)) /(dvol) : 
((+ : sdelay(N, interp, (dtime+skew))) ~ *(fback)) /(dvol)+(a), _+a :
*(output), *(output);




Friday, 11 February 2011

[Pd] Karplus Strong

I am currently staying in Bristol whilst doing the sound for the play Und and it just so happens that one of the people I am staying with is also a Pd programmer. He showed me the Karplus Strong algorithm the other night - I didn't realise it was possible to get such weird sounds from it.

I downloaded an example patch from the Pd tutorial website and added a metronome and a [lores~] filter to the original and added a very simple drum machine (ie [lores~] filtered [noise~] for snare and a blend of [noise~] and [osc~] through another [lores~] filter for kick. There's also a reverb in there for fun. There's also a random, string-ish [phasor~] based sound in there too.

Sounds like very minimalist techno, albeit randomised.

Saturday, 22 January 2011

[Pd] ADSR "Random" Synth


This patch came about as a sort of rewrite of a Max/MSP patch I wrote about a year ago, intended as a backing track for some live improvisation using contact mics. The Pd version is actually a less complicated patch but actually works better than the Max version.

It uses three oscillators the pitch of which is determined by randomly choosing from a set of midi note messages. The ADSR values are different for each synth (although I should experiment randomising the values for these envelopes). The speed of the [metro] can be changed and delay and reverb can be added.

In the end the synth was used as a backing track to a spoken word piece by me and Seth Guy, which will be released as a very limited edition together with doctored earbud headphones.

There are a couple of pieces made with an earlier version of the patch and also some short pieces using the original Max version here.

Thursday, 20 January 2011

[Pd] Video Looping



I recently met a friend of a friend who had some ideas for a project using looped videos. He'd been trying to find a way of doing it with hardware and despite asking around all over London he couldn't find anyone who knew a way of doing it. I reckoned it could be done somehow using software although I'd never worked with video clips before (I tend to work the other way around - using data from my webcam to control patches using OpenCV).

I downloaded a couple of clips from archive.org and cranked up Pd. [pix_film] could play the clip and I could scrub through it easily just using a [number] and I could use a [metro] and [mod] to play back any number of frames at any point in the clip at any speed. Great, but no sound. One of the major goals is to take four clips that can be played at variable rates which will create "music" - the main criterium for choosing a clip is that the sound should be interesting and loop well.

After a bit of research it seemed that the audio from the clip I was using had to be extracted from the .mov file and then synchronised to the video in the Pd patch. I came up with the patch at the top of this post in the end. There are some redundant parts of the patch not relevant to the goal but it works. The clip can be slowed down and speeded up, the section of the clip that we want to loop can be chosen by selecting start and stop points (currently these relate to audio frames). This is fed into a [snapshot~] which has to be banged repeatedly - a bit of bad maths later and the video will loop. As the loops are going to be very short (around a second or two) they stay in sync even though the maths is out by 0.5 of a frame per second (in this case).

One problem is that the clip will not play backwards without stuttering, which is a bit of a pain as it would be great to be able to play the clips in reverse at any speed as well as doing the same thing forwards. Further experimentation is needed.

Another problem is that I would really like to be able to play four clips in the same [gemwin]. If that wasn't enough there needs to be a library of different clips that can be changed on the fly; not only that, the patch needs to be interactive in a way that makes sense to an audience unfamiliar with Pd - at the moment it's looking like I will use OpenCV to achieve this but I am not entirely sure how...