author Ting-Yu Lin <>
Sat, 01 Apr 2023 04:17:05 +0000
changeset 658805 7437637d0b5c2745440bfeba4adb64689d24044f
parent 469641 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Bug 1055894 - Add GetLogicalNormalRect() and adapt some callers of GetNormalRect(). r=emilio This patch makes the API nicer, and shouldn't change the behavior. Differential Revision:

  <title>Test BiquadFilterNode</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<pre id="test">
<script src="webaudio.js" type="text/javascript"></script>
<script class="testbody" type="text/javascript">

function near(a, b, msg) {
  ok(Math.abs(a - b) < 1e-3, msg);

addLoadEvent(function() {
  var context = new AudioContext();
  var buffer = context.createBuffer(1, 2048, context.sampleRate);
  for (var i = 0; i < 2048; ++i) {
    buffer.getChannelData(0)[i] = Math.sin(440 * 2 * Math.PI * i / context.sampleRate);

  var destination = context.destination;

  var source = context.createBufferSource();

  var filter = context.createBiquadFilter();

  source.buffer = buffer;


  // Verify default values
  is(filter.type, "lowpass", "Correct default value for type");
  near(filter.frequency.defaultValue, 350, "Correct default value for filter frequency");
  near(filter.detune.defaultValue, 0, "Correct default value for filter detune");
  near(filter.Q.defaultValue, 1, "Correct default value for filter Q");
  near(filter.gain.defaultValue, 0, "Correct default value for filter gain");
  is(filter.channelCount, 2, "Biquad filter node has 2 input channels by default");
  is(filter.channelCountMode, "max", "Correct channelCountMode for the biquad filter node");
  is(filter.channelInterpretation, "speakers", "Correct channelCountInterpretation for the biquad filter node");

  // Make sure that we can set all of the valid type values
  var types = [
  for (var i = 0; i < types.length; ++i) {
    filter.type = types[i];

  // Make sure getFrequencyResponse handles invalid frequencies properly
  var frequencies = new Float32Array([-1.0, context.sampleRate*0.5 - 1.0, context.sampleRate]);
  var magResults = new Float32Array(3);
  var phaseResults = new Float32Array(3);
  filter.getFrequencyResponse(frequencies, magResults, phaseResults);
  ok(isNaN(magResults[0]), "Invalid input frequency should give NaN magnitude response");
  ok(!isNaN(magResults[1]), "Valid input frequency should not give NaN magnitude response");
  ok(isNaN(magResults[2]), "Invalid input frequency should give NaN magnitude response");
  ok(isNaN(phaseResults[0]), "Invalid input frquency should give NaN phase response");
  ok(!isNaN(phaseResults[1]), "Valid input frquency should not give NaN phase response");
  ok(isNaN(phaseResults[2]), "Invalid input frquency should give NaN phase response");

  SimpleTest.executeSoon(function() {