Sign in

username:

password:



Not a member?

Search Online Books



Search tips

Free Online Books

Sponsor

Industry's highest performing at the lowest power DSPs now as low as $5.00*
Start development today!
*volume pricing for 10ku

Chapters

See Also

Embedded SystemsFPGAElectronics
Chapter Contents:

Search Introduction to Digital Filters

  

Book Index | Global Index


Would you like to be notified by email when Julius Orion Smith III publishes a new entry into his blog?

  

A Look at the Generated C++ code

Running Faust with no architecture file, e.g.,

  > faust cpgrir.dsp
causes the C++ signal-processing code to be printed on the standard output, as shown for this example in Fig.K.6. Notice how the constant subexpressions are computed only once per instance in the instanceInit member function. Also, even in instanceInit, which is only called once, repeated computation of $ R^2$ is avoided by use of the temporary variable fConst1, and division by 2 is converted to multiplication by $ 0.5$.

Figure: C++ code emitted by the shell command
faust cpgrir.dsp (and reformatted slightly).

 
  class mydsp : public dsp {
  private:
    float fConst0;    float fConst1;
    int   iVec0[2];   float fConst2;
    int   iVec1[3];   float fConst3;   float fRec0[3];
  public:
    virtual int getNumInputs()    { return 0; }
    virtual int getNumOutputs()   { return 1; }
    static void classInit(int samplingFreq) { }
    virtual void instanceInit(int samplingFreq) {
      fSamplingFreq = samplingFreq;
      fConst0 = expf((0 - (314.159271f / fSamplingFreq)));
      fConst1 = (fConst0 * fConst0);
      for (int i=0; i<2; i++) iVec0[i] = 0;
      fConst2 = ((2 * fConst0) * cosf((2764.601562f
                               / fSamplingFreq)));
      for (int i=0; i<3; i++) iVec1[i] = 0;
      fConst3 = (0.500000f * (1 - fConst1));
      for (int i=0; i<3; i++) fRec0[i] = 0; }
    virtual void init(int samplingFreq) {
      classInit(samplingFreq);
      instanceInit(samplingFreq); }
    virtual void buildUserInterface(UI* interface) {
      interface->openVerticalBox("faust");
      interface->closeBox(); }
    virtual void compute (int count, float** input,
                                     float** output) {
      float* output0 = output[0];
      for (int i=0; i<count; i++) {
        iVec0[0] = 1;
        int iTemp0 = iVec0[1];
        iVec1[0] = (1 - iTemp0);
        fRec0[0] = (((fConst3 * (1 - (iTemp0 + iVec1[2])))
                                   + (fConst2 * fRec0[1]))
                                   - (fConst1 * fRec0[2]));
        output0[i] = fRec0[0];
        // post processing
        fRec0[2] = fRec0[1]; fRec0[1] = fRec0[0];
        iVec1[2] = iVec1[1]; iVec1[1] = iVec1[0];
        iVec0[1] = iVec0[0];
      }
    }
  };


Previous: Testing a Faust Filter Section
Next: Generating a Pure Data (PD) Plugin

Order a Hardcopy of Introduction to Digital Filters


About the Author: Julius Orion Smith III
Julius Smith's background is in electrical engineering (BS Rice 1975, PhD Stanford 1983). He is presently Professor of Music and Associate Professor (by courtesy) of Electrical Engineering at Stanford's Center for Computer Research in Music and Acoustics (CCRMA), teaching courses and pursuing research related to signal processing applied to music and audio systems. See http://ccrma.stanford.edu/~jos/ for details.


Comments


No comments yet for this page


Add a Comment
You need to login before you can post a comment (best way to prevent spam). ( Not a member? )