content/media/webaudio/test/test_audioParamGain.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webaudio/test/test_audioParamGain.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,61 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<head>
     1.7 +  <title>Test AudioParam with pre-gain </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 +var ctx = new AudioContext();
    1.19 +var source = ctx.createOscillator();
    1.20 +var lfo = ctx.createOscillator();
    1.21 +var lfoIntensity = ctx.createGain();
    1.22 +var effect = ctx.createGain();
    1.23 +var sp = ctx.createScriptProcessor(2048, 1);
    1.24 +
    1.25 +source.frequency.value = 440;
    1.26 +lfo.frequency.value = 2;
    1.27 +// Very low gain, so the LFO should have very little influence
    1.28 +// on the source, its RMS value should be close to the nominal value
    1.29 +// for a sine wave.
    1.30 +lfoIntensity.gain.value = 0.0001;
    1.31 +
    1.32 +lfo.connect(lfoIntensity);
    1.33 +lfoIntensity.connect(effect.gain);
    1.34 +source.connect(effect);
    1.35 +effect.connect(sp);
    1.36 +
    1.37 +sp.onaudioprocess = function(e) {
    1.38 +  var buffer = e.inputBuffer.getChannelData(0);
    1.39 +  var rms = 0;
    1.40 +  for (var i = 0; i < buffer.length; i++) {
    1.41 +    rms += buffer[i] * buffer[i];
    1.42 +  }
    1.43 +
    1.44 +  rms /= buffer.length;
    1.45 +  rms = Math.sqrt(rms);
    1.46 +
    1.47 +  // 1 / Math.sqrt(2) is the theoretical RMS value for a sine wave.
    1.48 +  ok(fuzzyCompare(rms, 1 / Math.sqrt(2)),
    1.49 +      "Gain correctly applied to the AudioParam.");
    1.50 +
    1.51 +  ctx = null;
    1.52 +  sp.onaudioprocess = null;
    1.53 +  lfo.stop(0);
    1.54 +  source.stop(0);
    1.55 +
    1.56 +  SimpleTest.finish();
    1.57 +}
    1.58 +
    1.59 +lfo.start(0);
    1.60 +source.start(0);
    1.61 +
    1.62 +</script>
    1.63 +</pre>
    1.64 +</body>

mercurial