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);




1 comment:

  1. I have a: "???? : -1 : ERROR : undefined symbol : squarewave"

    ReplyDelete