text: (function(T) {
      "use strict";
  
      function Biquad(samplerate) {
          this.samplerate = samplerate;
          this.frequency = 340;
          this.Q         = 1;
          this.gain      = 0;
  
          this.x1L = this.x2L = this.y1L = this.y2L = 0;
          this.x1R = this.x2R = this.y1R = this.y2R = 0;
          this.b0 = this.b1 = this.b2 = this.a1 = this.a2 = 0;
  
          this.setType("lpf");
      }
  
      var $ = Biquad.prototype;
  
      $.process = function(cellL, cellR) {
          var xL, xR, yL, yR;
          var x1L = this.x1L, x2L = this.x2L, y1L = this.y1L, y2L = this.y2L;
          var x1R = this.x1R, x2R = this.x2R, y1R = this.y1R, y2R = this.y2R;
          var b0 = this.b0, b1 = this.b1, b2 = this.b2, a1 = this.a1, a2 = this.a2;
          var i, imax;
  
          for (i = 0, imax = cellL.length; i < imax; ++i) {
              xL = cellL[i];
              yL = b0 * xL + b1 * x1L + b2 * x2L - a1 * y1L - a2 * y2L;
              x2L = x1L; x1L = xL; y2L = y1L; y1L = yL;
  
              xR = cellR[i];
              yR = b0 * xR + b1 * x1R + b2 * x2R - a1 * y1R - a2 * y2R;
              x2R = x1R; x1R = xR; y2R = y1R; y1R = yR;
  
              cellL[i] = yL;
              cellR[i] = yR;
          }
          this.x1L = x1L; this.x2L = x2L; this.y1L = y1L; this.y2L = y2L;
          this.x1R = x1R; this.x2R = x2R; this.y1R = y1R; this.y2R = y2R;
      };
  
      $.setType = function(type) {
          var f;
          if ((f = setParams[type])) {
              this.type = type;
              f.call(this, this.frequency, this.Q, this.gain);
          }
      };
  
      $.setParams = function(frequency, Q, dbGain) {
          this.frequency = frequency;
          this.Q = Q;
          this.gain = dbGain;
  
          var f = setParams[this.type];
          if (f) {
              f.call(this, frequency, Q, dbGain);
          }
  
          return this;
      };
  
  
      var setParams = {
          lowpass: function(cutoff, resonance) {
              cutoff /= (this.samplerate * 0.5);
  
              if (cutoff >= 1) {
                  this.b0 = 1;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else if (cutoff <= 0) {
                  this.b0 = this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else {
                  resonance = (resonance < 0) ? 0 : resonance;
                  var g = Math.pow(10.0, 0.05 * resonance);
                  var d = Math.sqrt((4 - Math.sqrt(16 - 16 / (g * g))) * 0.5);
  
                  var theta = Math.PI * cutoff;
                  var sn = 0.5 * d * Math.sin(theta);
                  var beta = 0.5 * (1 - sn) / (1 + sn);
                  var gamma = (0.5 + beta) * Math.cos(theta);
                  var alpha = 0.25 * (0.5 + beta - gamma);
  
                  this.b0 = 2 * alpha;
                  this.b1 = 4 * alpha;
                  this.b2 = this.b0; // 2 * alpha;
                  this.a1 = 2 * -gamma;
                  this.a2 = 2 * beta;
              }
          },
          highpass: function(cutoff, resonance) {
              cutoff /= (this.samplerate * 0.5);
              if (cutoff >= 1) {
                  this.b0 = this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else if (cutoff <= 0) {
                  this.b0 = 1;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else {
                  resonance = (resonance < 0) ? 0 : resonance;
  
                  var g = Math.pow(10.0, 0.05 * resonance);
                  var d = Math.sqrt((4 - Math.sqrt(16 - 16 / (g * g))) / 2);
  
                  var theta = Math.PI * cutoff;
                  var sn = 0.5 * d * Math.sin(theta);
                  var beta = 0.5 * (1 - sn) / (1 + sn);
                  var gamma = (0.5 + beta) * Math.cos(theta);
                  var alpha = 0.25 * (0.5 + beta + gamma);
  
                  this.b0 = 2 * alpha;
                  this.b1 = -4 * alpha;
                  this.b2 = this.b0; // 2 * alpha;
                  this.a1 = 2 * -gamma;
                  this.a2 = 2 * beta;
              }
          },
          bandpass: function(frequency, Q) {
              frequency /= (this.samplerate * 0.5);
              if (frequency > 0 && frequency < 1) {
                  if (Q > 0) {
                      var w0 = Math.PI * frequency;
  
                      var alpha = Math.sin(w0) / (2 * Q);
                      var k = Math.cos(w0);
  
                      var ia0 = 1 / (1 + alpha);
  
                      this.b0 = alpha * ia0;
                      this.b1 = 0;
                      this.b2 = -alpha * ia0;
                      this.a1 = -2 * k * ia0;
                      this.a2 = (1 - alpha) * ia0;
                  } else {
                      this.b0 = this.b1 = this.b2 = this.a1 = this.a2 = 0;
                  }
              } else {
                  this.b0 = this.b1 = this.b2 = this.a1 = this.a2 = 0;
              }
          },
          lowshelf: function(frequency, _dummy_, dbGain) {
              frequency /= (this.samplerate * 0.5);
  
              var A = Math.pow(10.0, dbGain / 40);
  
              if (frequency >= 1) {
                  this.b0 = A* A;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else if (frequency <= 0) {
                  this.b0 = 1;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else {
                  var w0 = Math.PI * frequency;
                  var S = 1; // filter slope (1 is max value)
                  var alpha = 0.5 * Math.sin(w0) * Math.sqrt((A + 1 / A) * (1 / S - 1) + 2);
                  var k = Math.cos(w0);
                  var k2 = 2 * Math.sqrt(A) * alpha;
                  var aPlusOne = A + 1;
                  var aMinusOne = A - 1;
  
                  var ia0 = 1 / (aPlusOne + aMinusOne * k + k2);
  
                  this.b0 = (A * (aPlusOne - aMinusOne * k + k2)) * ia0;
                  this.b1 = (2 * A * (aMinusOne - aPlusOne * k)) * ia0;
                  this.b2 = (A * (aPlusOne - aMinusOne * k - k2)) * ia0;
                  this.a1 = (-2 * (aMinusOne + aPlusOne * k)) * ia0;
                  this.a2 = (aPlusOne + aMinusOne * k - k2) * ia0;
              }
          },
          highshelf: function(frequency, _dummy_, dbGain) {
              frequency /= (this.samplerate * 0.5);
  
              var A = Math.pow(10.0, dbGain / 40);
  
              if (frequency >= 1) {
                  this.b0 = 1;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else if (frequency <= 0) {
                  this.b0 = A * A;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              } else {
                  var w0 = Math.PI * frequency;
                  var S = 1; // filter slope (1 is max value)
                  var alpha = 0.5 * Math.sin(w0) * Math.sqrt((A + 1 / A) * (1 / S - 1) + 2);
                  var k = Math.cos(w0);
                  var k2 = 2 * Math.sqrt(A) * alpha;
                  var aPlusOne = A + 1;
                  var aMinusOne = A - 1;
  
                  var ia0 = 1 / (aPlusOne - aMinusOne * k + k2);
  
                  this.b0 = (A * (aPlusOne + aMinusOne * k + k2)) * ia0;
                  this.b1 = (-2 * A * (aMinusOne + aPlusOne * k)) * ia0;
                  this.b2 = (A * (aPlusOne + aMinusOne * k - k2)) * ia0;
                  this.a1 = (2 * (aMinusOne - aPlusOne * k)) * ia0;
                  this.a2 = (aPlusOne - aMinusOne * k - k2) * ia0;
              }
          },
          peaking: function(frequency, Q, dbGain) {
              frequency /= (this.samplerate * 0.5);
  
              if (frequency > 0 && frequency < 1) {
                  var A = Math.pow(10.0, dbGain / 40);
                  if (Q > 0) {
                      var w0 = Math.PI * frequency;
                      var alpha = Math.sin(w0) / (2 * Q);
                      var k = Math.cos(w0);
                      var ia0 = 1 / (1 + alpha / A);
  
                      this.b0 = (1 + alpha * A) * ia0;
                      this.b1 = (-2 * k) * ia0;
                      this.b2 = (1 - alpha * A) * ia0;
                      this.a1 = this.b1; // (-2 * k) * ia0;
                      this.a2 = (1 - alpha / A) * ia0;
                  } else {
                      this.b0 = A * A;
                      this.b1 = this.b2 = this.a1 = this.a2 = 0;
                  }
              } else {
                  this.b0 = 1;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              }
          },
          notch: function(frequency, Q) {
              frequency /= (this.samplerate * 0.5);
  
              if (frequency > 0 && frequency < 1) {
                  if (Q > 0) {
                      var w0 = Math.PI * frequency;
                      var alpha = Math.sin(w0) / (2 * Q);
                      var k = Math.cos(w0);
                      var ia0 = 1 / (1 + alpha);
  
                      this.b0 = ia0;
                      this.b1 = (-2 * k) * ia0;
                      this.b2 = ia0;
                      this.a1 = this.b1; // (-2 * k) * ia0;
                      this.a2 = (1 - alpha) * ia0;
                  } else {
                      this.b0 = this.b1 = this.b2 = this.a1 = this.a2 = 0;
                  }
              } else {
                  this.b0 = 1;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              }
          },
          allpass: function(frequency, Q) {
              frequency /= (this.samplerate * 0.5);
  
              if (frequency > 0 && frequency < 1) {
                  if (Q > 0) {
                      var w0 = Math.PI * frequency;
                      var alpha = Math.sin(w0) / (2 * Q);
                      var k = Math.cos(w0);
                      var ia0 = 1 / (1 + alpha);
  
                      this.b0 = (1 - alpha) * ia0;
                      this.b1 = (-2 * k) * ia0;
                      this.b2 = (1 + alpha) * ia0;
                      this.a1 = this.b1; // (-2 * k) * ia0;
                      this.a2 = this.b0; // (1 - alpha) * ia0;
                  } else {
                      this.b0 = -1;
                      this.b1 = this.b2 = this.a1 = this.a2 = 0;
                  }
              } else {
                  this.b0 = 1;
                  this.b1 = this.b2 = this.a1 = this.a2 = 0;
              }
          }
      };
  
      setParams.lpf = setParams.lowpass;
      setParams.hpf = setParams.highpass;
      setParams.bpf = setParams.bandpass;
      setParams.bef = setParams.notch;
      setParams.brf = setParams.notch;
      setParams.apf = setParams.allpass;
  
      T.modules.Biquad = Biquad;
  
  })(timbre);
  