DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (c68fe15a81fc)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
<!DOCTYPE HTML>
<html>
<head>
  <title>Test IIRFilterNode GetFrequencyResponse</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="webaudio.js"></script>
  <script type="text/javascript" src="biquad-filters.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
  // Modified from WebKit/LayoutTests/webaudio/iirfilter-getFrequencyResponse.html
  var sampleRate = 48000;
  var testDurationSec = 0.01;
  var testDurationSec = 0.01;

  // Compute a set of linearly spaced frequencies.
  function createFrequencies(nFrequencies, sampleRate)
  {
    var frequencies = new Float32Array(nFrequencies);
    var nyquist = sampleRate / 2;
    var nyquist = sampleRate / 2;
    var freqDelta = nyquist / nFrequencies;

    for (var k = 0; k < nFrequencies; ++k) {
        frequencies[k] = k * freqDelta;
    }
    }

    return frequencies;
  }

  // Number of frequency samples to take.
  // Number of frequency samples to take.
  var numberOfFrequencies = 1000;

  var context = new OfflineAudioContext(1, testDurationSec * sampleRate, sampleRate);

  var frequencies = createFrequencies(numberOfFrequencies, context.sampleRate);
  var frequencies = createFrequencies(numberOfFrequencies, context.sampleRate);

  // 1-Pole IIR Filter
  var iir = context.createIIRFilter([1], [1, -0.9]);

  var iirMag = new Float32Array(numberOfFrequencies);
  var iirPhase = new Float32Array(numberOfFrequencies);
  var trueMag = new Float32Array(numberOfFrequencies);
  var truePhase = new Float32Array(numberOfFrequencies);

  // The IIR filter is
  //   H(z) = 1/(1 - 0.9*z^(-1)).
  //
  //
  // The frequency response is
  //   H(exp(j*w)) = 1/(1 - 0.9*exp(-j*w)).
  //
  // Thus, the magnitude is
  //   |H(exp(j*w))| = 1/sqrt(1.81-1.8*cos(w)).
  //   |H(exp(j*w))| = 1/sqrt(1.81-1.8*cos(w)).
  //
  // The phase is
  //   arg(H(exp(j*w)) = atan(0.9*sin(w)/(.9*cos(w)-1))

  var frequencyScale = Math.PI / (sampleRate / 2);
  var frequencyScale = Math.PI / (sampleRate / 2);

  for (var k = 0; k < frequencies.length; ++k) {
    var omega = frequencyScale * frequencies[k];
    trueMag[k] = 1/Math.sqrt(1.81-1.8*Math.cos(omega));
    trueMag[k] = 1/Math.sqrt(1.81-1.8*Math.cos(omega));
    truePhase[k] = Math.atan(0.9 * Math.sin(omega) / (0.9 * Math.cos(omega) - 1));
  }

  iir.getFrequencyResponse(frequencies, iirMag, iirPhase);
  compareChannels(iirMag, trueMag);
  compareChannels(iirMag, trueMag);
  compareChannels(iirPhase, truePhase);

  // Compare IIR and Biquad Filter
  // Create an IIR filter equivalent to the biquad filter. Compute the frequency response for both and verify that they are the same.
  // Create an IIR filter equivalent to the biquad filter. Compute the frequency response for both and verify that they are the same.
  var biquad = context.createBiquadFilter();
  var coef = createFilter(biquad.type,
                          biquad.frequency.value / (context.sampleRate / 2),
                          biquad.Q.value,
                          biquad.gain.value);
                          biquad.gain.value);

  var iir = context.createIIRFilter([coef.b0, coef.b1, coef.b2], [1, coef.a1, coef.a2]);

  var biquadMag = new Float32Array(numberOfFrequencies);
  var biquadPhase = new Float32Array(numberOfFrequencies);
  var iirMag = new Float32Array(numberOfFrequencies);
  var iirPhase = new Float32Array(numberOfFrequencies);
  var iirPhase = new Float32Array(numberOfFrequencies);

  biquad.getFrequencyResponse(frequencies, biquadMag, biquadPhase);
  iir.getFrequencyResponse(frequencies, iirMag, iirPhase);
  compareChannels(iirMag, biquadMag);
  compareChannels(iirPhase, biquadPhase);
  compareChannels(iirPhase, biquadPhase);

  SimpleTest.finish();
});
</script>
</pre>
</pre>
</body>
</html>