5 <script src=
"resources/compatibility.js"></script>
6 <script type=
"text/javascript" src=
"resources/audio-testing.js"></script>
7 <script src=
"../resources/js-test.js"></script>
8 <script src=
"resources/convolution-testing.js"></script>
13 <div id=
"description"></div>
14 <div id=
"console"></div>
17 description("Tests ConvolverNode processing a mono channel with mono impulse response.");
19 // To test the convolver, we convolve two square pulses together to
20 // produce a triangular pulse. To verify the result is correct we
21 // check several parts of the result. First, we make sure the initial
22 // part of the result is zero (due to the latency in the convolver).
23 // Next, the triangular pulse should match the theoretical result to
24 // within some roundoff. After the triangular pulse, the result
25 // should be exactly zero, but round-off prevents that. We make sure
26 // the part after the pulse is sufficiently close to zero. Finally,
27 // the result should be exactly zero because the inputs are exactly
30 if (window
.testRunner
) {
31 testRunner
.dumpAsText();
32 testRunner
.waitUntilDone();
35 window
.jsTestIsAsync
= true;
37 // Create offline audio context.
38 var context
= new OfflineAudioContext(2, sampleRate
* renderLengthSeconds
, sampleRate
);
40 var squarePulse
= createSquarePulseBuffer(context
, pulseLengthFrames
);
41 var trianglePulse
= createTrianglePulseBuffer(context
, 2 * pulseLengthFrames
);
43 var bufferSource
= context
.createBufferSource();
44 bufferSource
.buffer
= squarePulse
;
46 var convolver
= context
.createConvolver();
47 convolver
.normalize
= false;
48 convolver
.buffer
= squarePulse
;
50 bufferSource
.connect(convolver
);
51 convolver
.connect(context
.destination
);
53 bufferSource
.start(0);
55 context
.oncomplete
= checkConvolvedResult(trianglePulse
);
56 context
.startRendering();
60 successfullyParsed
= true;