Next  |  Prev  |  Top  |  REALSIMPLE Top

Generating Faust Block Diagrams

When learning the Faust language, it can be helpful to generate a block diagram using the -svg option. For example, the command

  > faust -svg cpgr.dsp
creates a subdirectory of the current working directory named cpgr-svg which contains a ``scalable vector graphics'' (.svg) file for each block-diagram expression in cpgr.dsp.7For this example, there is a block diagram generated for the process line, and for each of the last five lines in the with clause (not counting the comment).

Figure 2 shows the block diagram generated for the main process block from Fig.1:

  process = firpart : + ~ feedback
The dot on each block indicates its standard orientation (analogous to a ``pin 1'' indicator on an integrated circuit chip). The small open square at the beginning of the feedback loop indicates a unit sample delay introduced by creating a signal loop. Needless to say, it is important to keep track of such added delays in a feedback loop.

Figure 2: Main process block for the constant-peak-gain resonator.
\resizebox{4in}{!}{\includegraphics{\figdir /cpgr-process.eps}}

Figure 3 shows the block diagram generated for the firpart abstraction:

  firpart(x) = (x - x'') * g * ((1-RR)/2);

Figure 3: FIR-part ((x - x'') * g * ((1-RR)/2)) in Faust.
\resizebox{5in}{!}{\includegraphics{\figdir /cpgr-firpart.eps}}

Similarly, Fig.4 shows the block diagram generated for the feedback path:

  feedback(v) = 0 + 2*R*cos(A)*v - RR*v';
If not for the added sample of delay in the feedback loop (indicated by the small open square in Fig.2), the feedback-path processing would have been instead 0 + 2*R*cos(A)*v' - RR*v''.

Figure 4: Feedback block (0 + 2*R*cos(A)*x - RR*x') in Faust.
\resizebox{5in}{!}{\includegraphics{\figdir /cpgr-feedback.eps}}

Note that the block diagrams are drawn as though all details of the expression are to be evaluated every sample. However, the Faust compiler instead computes constant expressions at init time and allocates memory locations for them. More generally, the Faust compiler separately optimizes full-rate signals at the sampling rate (calculated in the inner loop), slowly varying signals (updated at the ``buffer rate'' outside of the inner loop--currently every 64 samples), and constant signals (evaluated once at initialization time).


Next  |  Prev  |  Top  |  REALSIMPLE Top

Download faust.pdf

``Signal Processing in Faust and PD'', by Julius O. Smith III,
REALSIMPLE Project — work supported by the Wallenberg Global Learning Network .
Released 2010-07-29 under the Creative Commons License (Attribution 2.5), by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA