Next: , Previous: myProcess(), Up: Anatomy of a MarSystem


10.2.5 myUpdate() vs. myProcess()

Taking a real-world example, consider a simple one-pole high/low-pass filter where we wish to perform the following operations:

     mrs_real fc = ctrl_fc ->to<mrs_real>()();
     mrs_real tanf = tan( PI * fc / 44100.0);
     mrs_real c = (tanf - 1.0) / (tanf + 1.0);
     
     // main loop
     for (t=1; t < inSampes_; t++) {
         az = c*in(0,t) + in(0,t-1) - c*out(0,t-1);
         out(0,t) = (1-az)/2;
     }

Since tanf and c only depend on fc, they may be computed inside myUpdate() instead of myProcess(). If fc has not changed, we can use the old value c to perform the loop over our sound buffer; if the value of fc has changed, then c will be recomputed inside myUpdate().