Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search


Function Definition

FAUST is a functional programming language [7]. From this point of view, every block diagram may be seen as a function mapping its input signals to its output signals.

A fully general function definition in FAUST is of the form

  f(a) = b;
where f is a name, and a and b are block diagram specifications. In principle, the compiler must recognize the block diagram a flowing into the symbol f and replace all that by b, with any occurrences of a within b appropriately wired up to the original input a. Function arguments are normally a simple parallel bank of named signals, such as f(x,y,z) = b, where b is a block-diagram expression that may contain symbols x, y, and z which will be bound to the input signals as expected. Naming input signals in this way is often the easiest and most readable way to copy input signals within a block-diagram expression:
  sum_and_diff_unnamed = _,_<:_,_,_,_:+,-;

  sum_and_diff_named(x,y) = x+y, x-y;
More general cases will be discussed in §2.23 below (``pattern matching'').

Function definitions can appear in any order; thus, FAUST statements can appear in any order; however, there is one exception: When defining a function differently for different argument patterns2.23), statement order matters because pattern-matches are tried in the order given.

Unused definitions (unused by process, either directly or indirectly) are discarded by the FAUST compiler and have no effect on the generated code:

  x=1;
  y=2;  // no effect
  process = x;
Sometimes we have to force inclusion of inaudible processing using the attach primitive. For example, the following cases appear equivalent, even in the generated block diagram, but only levelmeter2 makes it into the generated C++ code (levelmeter1 gets optimized away by the compiler):
smoother(s) = *(1.0 - s) : + ~ *(s); // unity-dc-gain lowpass filter
levelmeter1 = abs : smoother : vbargraph("Level 1 [unit:dB]",-70,10);
levelmeter2 = abs : smoother : vbargraph("Level 2 [unit:dB]",-70,10);
sol1 = _ <: _,levelmeter1 : _,!;
sol2 = _ <: attach(levelmeter2);
process = sol1,sol2;

In summary, every definition-statement defines a function mapping its name (together with any function-arguments) to a block diagram. Only functions encountered via the process function are used, unless retained in the compilation using attach.


Next  |  Prev  |  Up  |  Top  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

Download aspf.pdf
[Comment on this page via email]

``Audio Signal Processing in Faust'', by Julius O. Smith III.
Copyright © 2022-05-05 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA