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

Generating a MIDI Synthesizer for PD

The faust2pd script (introduced in §9 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.18. 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 18: 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 : 
                 adsr(attack, decay, sustain, release));
    filter = vgroup("2-filter", (firpart : + ~ feedback));
    R = exp(-PI*bw/SR); // pole radius
    A = 2*PI*freq/SR;   // pole angle (radians)
    RR = R*R;
    firpart(x) = (x - x'') * (1-RR)/2;
    // time-domain coefficients ASSUMING ONE-SAMPLE FEEDBACK DELAY:
    feedback(v) = 0 + 2*R*cos(A)*v - RR*v';

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 © 2017-07-21 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University