content/media/webaudio/test/test_convolverNode_mono_mono.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE html>
     3 <html>
     4 <head>
     5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6 <script type="text/javascript" src="webaudio.js"></script>
     7 <script type="text/javascript" src="layouttest-glue.js"></script>
     8 <script type="text/javascript" src="blink/audio-testing.js"></script>
     9 <script type="text/javascript" src="blink/convolution-testing.js"></script>
    10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    11 </head>
    13 <body>
    15 <div id="description"></div>
    16 <div id="console"></div>
    18 <script>
    19 description("Tests ConvolverNode processing a mono channel with mono impulse response.");
    20 SimpleTest.waitForExplicitFinish();
    22 // To test the convolver, we convolve two square pulses together to
    23 // produce a triangular pulse.  To verify the result is correct we
    24 // check several parts of the result.  First, we make sure the initial
    25 // part of the result is zero (due to the latency in the convolver).
    26 // Next, the triangular pulse should match the theoretical result to
    27 // within some roundoff.  After the triangular pulse, the result
    28 // should be exactly zero, but round-off prevents that.  We make sure
    29 // the part after the pulse is sufficiently close to zero.  Finally,
    30 // the result should be exactly zero because the inputs are exactly
    31 // zero.
    32 function runTest() {
    33     if (window.testRunner) {
    34         testRunner.dumpAsText();
    35         testRunner.waitUntilDone();
    36     }
    38     window.jsTestIsAsync = true;
    40     // Create offline audio context.
    41     var context = new OfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
    43     var squarePulse = createSquarePulseBuffer(context, pulseLengthFrames);
    44     var trianglePulse = createTrianglePulseBuffer(context, 2 * pulseLengthFrames);
    46     var bufferSource = context.createBufferSource();
    47     bufferSource.buffer = squarePulse;
    49     var convolver = context.createConvolver();
    50     convolver.normalize = false;
    51     convolver.buffer = squarePulse;
    53     bufferSource.connect(convolver);
    54     convolver.connect(context.destination);
    56     bufferSource.start(0);
    58     context.oncomplete = checkConvolvedResult(trianglePulse);
    59     context.startRendering();
    60 }
    62 function finishJSTest() {
    63   SimpleTest.finish();
    64 }
    66 runTest();
    67 successfullyParsed = true;
    69 </script>
    71 <script src="../fast/js/resources/js-test-post.js"></script>
    72 </body>
    73 </html>

mercurial