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

Adding a GUI

To illustrate automatic generation of user-interface controls, we will add two ``numeric entry'' fields (nentry) and one ``horizontal slider'' (hslider) to our example of Fig.5. These controls will allow the application or plugin user to vary the center-frequency, bandwidth, and peak gain of the constant-peak-gain resonator in real time. A complete listing of cpgrui.dsp (``Constant-Peak-Gain Resonator with User Interface'') appears in Fig.11.

Figure 11: Listing of cpgrui.dsp--a FAUST program specifying a constant-peak-gain resonator with three user controls. Also shown are typical header declarations.

  declare name "Constant-Peak-Gain Resonator";
  declare author "Julius Smith";
  declare version "1.0";
  declare license "GPL";

  /* Controls */
  fr = nentry("frequency (Hz)", 1000, 20, 20000, 1);
  bw = nentry("bandwidth (Hz)", 100, 20, 20000, 10);
  g  = hslider("peak gain", 1, 0, 10, 0.01);

  /* Constants (FAUST provides these in math.lib) */
  SR = fconstant(int fSamplingFreq, <math.h>);
  PI = 3.1415926535897932385;

  /* The resonator */
  process = firpart : + ~ feedback
  with {
    R = exp(-PI*bw/SR); // pole radius
    A = 2*PI*fr/SR;     // pole angle (radians)
    RR = R*R;
    firpart(x) = (x - x'') * g * (1-RR)/2;
    // time-domain coefficients ASSUMING ONE-SAMPLE FEEDBACK DELAY:
    feedback(v) = 0 + 2*R*cos(A)*v - RR*v';

Note that GUI element specifications such as ``nentry(<string>,<number>,...)'' and
``hslider(<string>,<number>,...)'' should be regarded as predefined block diagrams having one slow output (and also a signal input, in the case of vbargraph() and hbargraph(), and the string and number arguments are all compile-time constants. There is no partial application (§2.8) or alternate notations such as ``widget(x) = <string>,<number>,x:widget'' for GUI elements, principally because strings are not elements of the FAUST language. While output-only GUI elements have no alternate syntax, bar graphs have two equivalent forms, e.g.,
x:vbargraph(<string>,<min>,<max>) and vbargraph(<string>,<min>,<max>)(x).

Because GUI widget outputs are ``slow'', expressions involving them are moved out of the inner-loop by the compiler, which is very helpful for reducing CPU load. We can then choose audio block size to trade CPU load against GUI responsiveness. Thus, the ``control rate'' (often called ``K rate'', at least since Csound) equals the audio sampling rate divided by audio block size.

Next  |  Prev  |  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 © 2024-05-01 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University