content/media/webaudio/test/test_pannerNodeHRTFSymmetry.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_pannerNodeHRTFSymmetry.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test left/right symmetry and block-offset invariance of HRTF panner</title>
     1.8 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +  <script type="text/javascript" src="webaudio.js"></script>
    1.10 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.11 +</head>
    1.12 +<body>
    1.13 +<pre id="test">
    1.14 +<script class="testbody" type="text/javascript">
    1.15 +
    1.16 +SimpleTest.waitForExplicitFinish();
    1.17 +
    1.18 +const blockSize = 128;
    1.19 +const bufferSize = 4096; // > HRTF panner latency
    1.20 +
    1.21 +var ctx = new AudioContext();
    1.22 +
    1.23 +function isChannelSilent(channel) {
    1.24 +  for (var i = 0; i < channel.length; ++i) {
    1.25 +    if (channel[i] != 0.0) {
    1.26 +      return false;
    1.27 +    }
    1.28 +  }
    1.29 +  return true;
    1.30 +}
    1.31 +
    1.32 +function startTest() {
    1.33 +  var leftPanner = ctx.createPanner();
    1.34 +  var rightPanner = ctx.createPanner();
    1.35 +  leftPanner.setPosition(-1,0,0);
    1.36 +  rightPanner.setPosition(1,0,0);
    1.37 +
    1.38 +  // Test that PannerNode processes the signal consistently irrespective of
    1.39 +  // the offset in the processing block.  This is done by inserting a delay of
    1.40 +  // less than a block size before one panner.
    1.41 +  const delayTime = 0.7 * blockSize / ctx.sampleRate;
    1.42 +  var leftDelay = ctx.createDelay(delayTime);
    1.43 +  leftDelay.delayTime.value = delayTime;
    1.44 +  leftDelay.connect(leftPanner);
    1.45 +  // and compensating for the delay after the other.
    1.46 +  var rightDelay = ctx.createDelay(delayTime);
    1.47 +  rightDelay.delayTime.value = delayTime;
    1.48 +  rightPanner.connect(rightDelay);
    1.49 +
    1.50 +  // Feed the panners with a signal having some harmonics to fill the spectrum.
    1.51 +  var oscillator = ctx.createOscillator();
    1.52 +  oscillator.frequency.value = 110;
    1.53 +  oscillator.type = "sawtooth";
    1.54 +  oscillator.connect(leftDelay);
    1.55 +  oscillator.connect(rightPanner);
    1.56 +  oscillator.start(0);
    1.57 +
    1.58 +  // Switch the channels on one panner output, and it should match the other.
    1.59 +  var splitter = ctx.createChannelSplitter();
    1.60 +  leftPanner.connect(splitter);
    1.61 +  var merger = ctx.createChannelMerger();
    1.62 +  splitter.connect(merger, 0, 1);
    1.63 +  splitter.connect(merger, 1, 0);
    1.64 +
    1.65 +  // Invert one signal so that mixing with the other will find the difference.
    1.66 +  var gain = ctx.createGain();
    1.67 +  gain.gain.value = -1.0;
    1.68 +  merger.connect(gain);
    1.69 +
    1.70 +  var processor = ctx.createScriptProcessor(bufferSize, 2, 0);
    1.71 +  gain.connect(processor);
    1.72 +  rightDelay.connect(processor);
    1.73 +  processor.onaudioprocess =
    1.74 +    function(e) {
    1.75 +      compareBuffers(e.inputBuffer,
    1.76 +                     ctx.createBuffer(2, bufferSize, ctx.sampleRate));
    1.77 +      e.target.onaudioprocess = null;
    1.78 +      SimpleTest.finish();
    1.79 +    }
    1.80 +}
    1.81 +
    1.82 +function prepareTest() {
    1.83 +  // A PannerNode will produce no output until it has loaded its HRIR
    1.84 +  // database.  Wait for this to load before starting the test.
    1.85 +  var processor = ctx.createScriptProcessor(bufferSize, 2, 0);
    1.86 +  var panner = ctx.createPanner();
    1.87 +  panner.connect(processor);
    1.88 +  var oscillator = ctx.createOscillator();
    1.89 +  oscillator.connect(panner);
    1.90 +  oscillator.start(0);
    1.91 +
    1.92 +  processor.onaudioprocess =
    1.93 +    function(e) {
    1.94 +      if (isChannelSilent(e.inputBuffer.getChannelData(0)))
    1.95 +        return;
    1.96 +
    1.97 +      oscillator.stop(0);
    1.98 +      panner.disconnect();
    1.99 +      e.target.onaudioprocess = null;
   1.100 +      startTest();
   1.101 +    };
   1.102 +}
   1.103 +prepareTest();
   1.104 +</script>
   1.105 +</pre>
   1.106 +</body>
   1.107 +</html>

mercurial