Next  |  Prev  |  Top  |  REALSIMPLE Top

Generating a MIDI Synthesizer for Pd

The faust2pd script (introduced in §7 above) also has a mode for generating MIDI synthesizer plugins for pd. This mode is triggered by use of the -n option (``number of voices''). For this mode, the Faust program should be written to synthesize one voice using the following three parameters (which are driven from MIDI data in the pd plugin):

The parameters freq and gain are set according to MIDI note-number and velocity, respectively, while the gate parameter is set to 1 on a MIDI ``note-on'' and back to zero upon ``note-off''. The faust2pd script handles instantiation of up to 8 instances of the synth patch, and provides the abstraction midi-in.pd for receiving and decoding MIDI data in pd.

Let's make a simple 8-voiced MIDI synthesizer based on the example Faust program cpgrs.dsp (``Constant-Peak-Gain Resonator Synth'') listed in Fig.15. In addition to converting the frequency and gain parameters to the standard names, we have added a classic ADSR envelope generator (defined in Faust's music.lib file) which uses the new gate parameter, and which adds the four new envelope parameters attack, decay, sustain, and release.

Compiling the example is the same as for a pd plugin, except that the -n option is used (8 voices is the maximum):

  > faust -xml -a puredata.cpp -o cpgrs-pd.cpp cpgrs.dsp
  > g++ -DPD -Wall -g -shared -Dmydsp=cpgrs \
        -o cpgrs~.pd_linux cpgrs-pd.cpp
  > faust2pd -n 8 -s -o cpgrs.pd cpgrs.dsp.xml

Figure 15: Listing of cpgrs.dsp--a Faust program specifying a simple synth patch consisting of white noise through a constant-peak-gain resonator.

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

  /* Standard synth controls supported by faust2pd */
  freq = nentry("freq", 440, 20, 20000, 1);	// Hz
  gain = nentry("gain", 0.1, 0, 1, 0.01);	// frac
  gate = button("gate");			// 0/1

  /* User Controls */
  bw = hslider("bandwidth (Hz)", 100, 20, 20000, 10);

  import("music.lib"); // define noise, adsr, PI, SR, et al.

  /* ADSR envelope parameters */
  attack  = hslider("attack", 0.01,0, 1, 0.001); // sec
  decay	  = hslider("decay",  0.3, 0, 1, 0.001); // sec
  sustain = hslider("sustain",0.5, 0, 1, 0.01);	 // frac
  release = hslider("release",0.2, 0, 1, 0.001); // sec

  /* Synth */
  process = noise * env * gain : filter
  with {
    env = gate : 
          vgroup("1-adsr", 
                 adsr(attack, decay, sustain, release));
    filter = vgroup("2-filter", (firpart : + ~ feedback));
    R = exp(0-PI*bw/SR); // pole radius [0 required]
    A = 2*PI*freq/SR;      // pole angle (radians)
    RR = R*R;
    firpart(x) = (x - x'') * ((1-RR)/2);
    // time-domain coeffs ASSUMING ONE PIPELINE DELAY:
    feedback(v) = 0 + 2*R*cos(A)*v - RR*v';
  };


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