| OLD | NEW |
| (Empty) |
| 1 <!doctype html> | |
| 2 <html> | |
| 3 <head> | |
| 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/audit-util.js"></script> | |
| 8 <script src="resources/audio-testing.js"></script> | |
| 9 </head> | |
| 10 | |
| 11 <body> | |
| 12 <script> | |
| 13 description("Test Biquad Tail Output"); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | |
| 16 // A high sample rate shows the issue more clearly. | |
| 17 var sampleRate = 192000; | |
| 18 // Some short duration because we don't need to run the test for very long
. | |
| 19 var testDurationSec = 0.5; | |
| 20 var testDurationFrames = testDurationSec * sampleRate; | |
| 21 | |
| 22 // Amplitude experimentally determined to give a biquad output close to 1.
(No attempt was | |
| 23 // made to produce exactly 1; it's not needed.) | |
| 24 var sourceAmplitude = 100; | |
| 25 | |
| 26 // The output of the biquad filter should not change by more than this muc
h between output | |
| 27 // samples. Threshold was determined experimentally. | |
| 28 var glitchThreshold = 0.012968; | |
| 29 | |
| 30 // Test that a Biquad filter doesn't have it's output terminated because t
he input has gone | |
| 31 // away. Generally, when a source node is finished, it disconnects itself
from any downstream | |
| 32 // nodes. This is the correct behavior. Nodes that have no inputs (disco
nnected) are | |
| 33 // generally assumed to output zeroes. This is also desired behavior. Ho
wever, biquad | |
| 34 // filters have memory so they should not suddenly output zeroes when the
input is | |
| 35 // disconnected. This test checks to see if the output doesn't suddenly c
hange to zero. | |
| 36 function runTest() { | |
| 37 var context = new OfflineAudioContext(1, testDurationFrames, sampleRate)
; | |
| 38 | |
| 39 // Create an impulse source. | |
| 40 var buffer = context.createBuffer(1, 1, context.sampleRate); | |
| 41 buffer.getChannelData(0)[0] = sourceAmplitude; | |
| 42 var source = context.createBufferSource(); | |
| 43 source.buffer = buffer; | |
| 44 | |
| 45 // Create the biquad filter. It doesn't really matter what kind, so the
default filter type | |
| 46 // and parameters is fine. Connect the source to it. | |
| 47 var biquad = context.createBiquadFilter(); | |
| 48 source.connect(biquad); | |
| 49 biquad.connect(context.destination); | |
| 50 | |
| 51 source.start(); | |
| 52 | |
| 53 context.startRendering().then(function(result) { | |
| 54 // There should be no large discontinuities in the output | |
| 55 var success = true; | |
| 56 success = success && Should("Biquad output", result.getChannelData(0))
.notGlitch(glitchThreshold); | |
| 57 if (success) | |
| 58 testPassed("Biquad tail output correctly completed."); | |
| 59 else | |
| 60 testFailed("Biquad tail output not correctly completed."); | |
| 61 }).then(finishJSTest); | |
| 62 } | |
| 63 | |
| 64 runTest(); | |
| 65 successfullyParsed = true; | |
| 66 </script> | |
| 67 </body> | |
| 68 </html> | |
| OLD | NEW |