FAUST (programming language): Difference between revisions

Content deleted Content added
Mzuther (talk | contribs)
m update latest release version and date
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Line 22:
* Block diagrams, even if purely textual as in FAUST, promote a modular approach to signal processing that complies with sound engineers' and audio developers' habits.
A FAUST program doesn’t describe a sound or a group of sounds, but a [[Digital signal processing|signal processor]]. The program source is organized as a set of ''definitions'' with at least the definition of the keyword <code>process</code> (the equivalent of <code>main</code> in C):
<sourcesyntaxhighlight lang=haskell>
process = ...;
</syntaxhighlight>
</source>
 
The FAUST [[compiler]] translates FAUST code into a [[C++]] [[Object-oriented programming|object]], which may then interface with other C++ code to produce a full program.
Line 36:
==Example code==
FAUST programs define a <code>process</code> function that operates on incoming data. This is analogous to the <code>main</code> function in most programming languages. The following is an example that produces silence:
<sourcesyntaxhighlight lang=haskell>
process = 0;
</syntaxhighlight>
</source>
The second example copies the input signal to the output. It involves the <code>_</code> primitive that denotes the [[identity function]] for signals:
<sourcesyntaxhighlight lang=haskell>
process = _;
</syntaxhighlight>
</source>
Another example sums a stereo signal into a mono signal using the <code>+</code> primitive:
<sourcesyntaxhighlight lang=haskell>
process = +;
</syntaxhighlight>
</source>
[[File:Faust-simple-block-diagram.jpg|thumb|Block diagrams generated by Faust from some simple programs]]
Most FAUST primitives are analogous to their C counterpart on numbers, but lifted to signals. For example, the FAUST primitive <code>sin</code> operates on a signal X by applying the [[C (programming language)|C]] function <code>sin</code> to each sample X[t]. All C numerical functions have their counterpart in FAUST.
Line 70:
 
Using the sequential composition operator <code>:</code> the output of <code>+</code> can be routed to the input of <code>abs</code> to compute the [[absolute value]] of the signal:
<sourcesyntaxhighlight lang=haskell>
process = + : abs;
</syntaxhighlight>
</source>
Here is an example of parallel composition using the <code>,</code> operator that arranges its left and right expressions in parallel. This is analogous to a stereo cable.
<sourcesyntaxhighlight lang=haskell>
process = _,_;
</syntaxhighlight>
</source>
These operators can be arbitrarily combined. The following code multiplies an input signal with 0.5:
<sourcesyntaxhighlight lang=haskell>
process = _,0.5 : *;
</syntaxhighlight>
</source>
The above may be rewritten in [[currying|curried]] form:
<sourcesyntaxhighlight lang=haskell>
process = *(0.5);
</syntaxhighlight>
</source>
The recursive composition operator <code>~</code> can be used to create block diagrams with cycles (that include an implicit one-sample delay). Here is an example of an integrator that takes an input signal X and computes an output signal Y such that Y(t) = X(t) + Y(t−1):
<sourcesyntaxhighlight lang=haskell>
process = + ~ _;
</syntaxhighlight>
</source>
 
==Generating full applications==