DSPRelated.com
Free Books

A Simple Faust Program

Figure K.1 lists a minimal Faust program specifying the constant-peak-gain resonator discussed in §B.6.4. This appendix does not cover the Faust language itself, so the Faust Tutorial, or equivalent, should be considered prerequisite reading. We will summarize briefly, however, the Faust operators relevant to this example: signal processing blocks are connected in series via a colon (:), and feedback is indicated by a tilde (~). The colon and tilde operators act on ``block diagrams'' to create a larger block diagram. There are also signal operators. For example, a unit-sample delay is indicated by appending a prime (') after a signal variable; thus, x' expands to x : MEM and indicates a signal obtained by delaying the signal x by one sample.

Function application applies to operator symbols as well as names; thus, for example, +(x) expands to _,x : +, and *(x) expands to _,x : *, where _ denotes a simple ``wire''. There is a special unary minus in Faust (as of release 0.9.9.4), so that -x is equivalent to 0 - x. However, -(x) still expands to _,x : -, which is a blockdiagram that subtracts signal x from the input signal on _ .

The with block provides local definitions in the context of the process definition.K.3

Other aspects of the language used in this example should be fairly readable to those having a typical programming background. K.4

Figure K.1: Faust program specifying a constant-peak-gain resonator. Input parameters are the resonance frequency fr (Hz), resonance bandwidth bw (Hz), and the desired peak-gain g.

 
process = firpart : + ~ feedback
with {
  bw = 100; fr = 1000; g = 1; // parameters - see caption
  SR = fconstant(int fSamplingFreq, <math.h>); // Faust fn
  pi = 4*atan(1.0);    // circumference over diameter
  R = exp(0-pi*bw/SR); // pole radius [0 required]
  A = 2*pi*fr/SR;      // pole angle (radians)
  RR = R*R;
  firpart(x) = (x - x'') * g * ((1-RR)/2);
  // time-domain coefficients ASSUMING ONE PIPELINE DELAY:
  feedback(v) = 0 + 2*R*cos(A)*v - RR*v';
};

Constants such as RR in Fig.K.1 are better thought of as constant signals. As a result, operators such as * (multiplication) conceptually act only on signals. Thus, the expression 2*x denotes the constant-signal $ 2,2,2,\ldots$ muliplied pointwise by the signal x. The Faust compiler does a good job of optimizing expressions so that operations are not repeated unnecessarily at run time. In summary, a Faust expression expands into a block diagram which processes causal signals,K.5 some of which may be constant signals.


Next Section:
Generating Faust Block Diagrams
Previous Section:
Frequency Response Plot: swanalmainplot.m