4 <title>Test Biquad Tail Output
</title>
5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/compatibility.js"></script>
7 <script src=
"resources/audio-testing.js"></script>
12 description("Test Biquad Tail Output");
13 window
.jsTestIsAsync
= true;
15 // A high sample rate shows the issue more clearly.
16 var sampleRate
= 192000;
17 // Some short duration because we don't need to run the test for very long.
18 var testDurationSec
= 0.5;
19 var testDurationFrames
= testDurationSec
* sampleRate
;
21 // Amplitude experimentally determined to give a biquad output close to 1. (No attempt was
22 // made to produce exactly 1; it's not needed.)
23 var sourceAmplitude
= 100;
25 // The output of the biquad filter should not change by more than this much between output
26 // samples. Threshold was determined experimentally.
27 var glitchThreshold
= 0.0129;
29 // Test that a Biquad filter doesn't have it's output terminated because the input has gone
30 // away. Generally, when a source node is finished, it disconnects itself from any downstream
31 // nodes. This is the correct behavior. Nodes that have no inputs (disconnected) are
32 // generally assumed to output zeroes. This is also desired behavior. However, biquad
33 // filters have memory so they should not suddenly output zeroes when the input is
34 // disconnected. This test checks to see if the output doesn't suddenly change to zero.
36 var context
= new OfflineAudioContext(1, testDurationFrames
, sampleRate
);
38 // Create an impulse source.
39 var buffer
= context
.createBuffer(1, 1, context
.sampleRate
);
40 buffer
.getChannelData(0)[0] = sourceAmplitude
;
41 var source
= context
.createBufferSource();
42 source
.buffer
= buffer
;
44 // Create the biquad filter. It doesn't really matter what kind, so the default filter type
45 // and parameters is fine. Connect the source to it.
46 var biquad
= context
.createBiquadFilter();
47 source
.connect(biquad
);
48 biquad
.connect(context
.destination
);
52 context
.startRendering().then(function(result
) {
53 // There should be no large discontinuities in the output
55 success
= success
&& Should("Biquad output", result
.getChannelData(0)).notGlitch(glitchThreshold
);
57 testPassed("Biquad tail output correctly completed.");
59 testFailed("Biquad tail output not correctly completed.");
60 }).then(finishJSTest
);
64 successfullyParsed
= true;