| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 | 3 |
| 4 <head> | 4 <head> |
| 5 <script src="../../resources/js-test.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audio-testing.js"></script> |
| 8 </head> | 9 </head> |
| 9 | 10 |
| 10 <body> | 11 <body> |
| 11 <script> | 12 <script> |
| 12 description("Test if ChannelMergerNode runs correctly in a cycle."); | |
| 13 window.jsTestIsAsync = true; | |
| 14 | 13 |
| 15 // This specific sample rate is chosen to avoid the round/truncation error | 14 // This specific sample rate is chosen to avoid the round/truncation error |
| 16 // in delay time. See: crbug.com/448801 | 15 // in delay time. See: crbug.com/448801 |
| 17 var sampleRate = 32768; | 16 var sampleRate = 32768; |
| 18 | 17 |
| 19 // Web Audio API's rendering quantum. | 18 // Web Audio API's rendering quantum. |
| 20 var renderingQuantum = 128; | 19 var renderingQuantum = 128; |
| 21 | 20 |
| 22 // 4x of rendering quantum. This is to make the rendered result long enough | 21 // 4x of rendering quantum. This is to make the rendered result long enough |
| 23 // so that we can observe the delayed output. | 22 // so that we can observe the delayed output. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 53 merger.connect(delay); | 52 merger.connect(delay); |
| 54 merger.connect(context.destination); | 53 merger.connect(context.destination); |
| 55 source.start(); | 54 source.start(); |
| 56 | 55 |
| 57 context.startRendering().then(function (buffer) { | 56 context.startRendering().then(function (buffer) { |
| 58 // Expected output values: the output of delay node will be a stereo | 57 // Expected output values: the output of delay node will be a stereo |
| 59 // signal of [1, 0]. When it feeds back to the 2nd input of merger node, | 58 // signal of [1, 0]. When it feeds back to the 2nd input of merger node, |
| 60 // the stereo channel will be summed to mono resulting in 0.5. | 59 // the stereo channel will be summed to mono resulting in 0.5. |
| 61 var expected_left = []; | 60 var expected_left = []; |
| 62 var expected_right = []; | 61 var expected_right = []; |
| 62 var success = true; |
| 63 | 63 |
| 64 for (var i = 0; i < renderLength; i++) { | 64 for (var i = 0; i < renderLength; i++) { |
| 65 // Note that the delayed channel will be zero for the first 128 sample
s | 65 // Note that the delayed channel will be zero for the first 128 sample
s |
| 66 // due to the cyclic audio graph, the second 128 sample will be also | 66 // due to the cyclic audio graph, the second 128 sample will be also |
| 67 // zero because of 128 samples delay. | 67 // zero because of 128 samples delay. |
| 68 expected_left[i] = 1.0; | 68 expected_left[i] = 1.0; |
| 69 expected_right[i] = (i < renderingQuantum * 2) ? 0.0 : 0.5; | 69 expected_right[i] = (i < renderingQuantum * 2) ? 0.0 : 0.5; |
| 70 } | 70 } |
| 71 | 71 |
| 72 for (i = 0; i < buffer.numberOfChannels; i++) { | 72 var actual_left = buffer.getChannelData(0); |
| 73 var actual_left = buffer.getChannelData(0); | 73 var actual_right = buffer.getChannelData(1); |
| 74 var actual_right = buffer.getChannelData(1); | 74 success = Should("Left channel", actual_left) |
| 75 for (var j = 0; j < renderLength; j++) { | 75 .beEqualToArray(expected_left) && success; |
| 76 if (expected_left[j] !== actual_left[j]) { | 76 success = Should("Right channel", actual_right) |
| 77 testFailed('The value ' + actual_left[j] + | 77 .beEqualToArray(expected_right) && success; |
| 78 'in the left channel did not match the expected value ' + | |
| 79 expected_left[j] + ' at the index ' + j + '.'); | |
| 80 done(); | |
| 81 return; | |
| 82 } | |
| 83 if (expected_right[j] !== actual_right[j]) { | |
| 84 testFailed('The value ' + actual_left[j] + | |
| 85 'in the right channel did not match the expected value ' + | |
| 86 expected_left[j] + ' at the index ' + j + '.'); | |
| 87 done(); | |
| 88 return; | |
| 89 } | |
| 90 } | |
| 91 } | |
| 92 | 78 |
| 93 testPassed("ChannerMergerNode passed cyclic audio graph test."); | 79 Should("ChannelMergerNode cyclic audio graph test", success) |
| 80 .summarize("passed", "failed"); |
| 81 |
| 94 done(); | 82 done(); |
| 95 }); | 83 }); |
| 96 | 84 |
| 97 }); | 85 }); |
| 98 | 86 |
| 99 audit.defineTask('finish', function (done) { | 87 audit.defineTask('finish', function (done) { |
| 100 finishJSTest(); | |
| 101 done(); | 88 done(); |
| 102 }); | 89 }); |
| 103 | 90 |
| 104 audit.runTasks( | 91 audit.runTasks( |
| 105 'merger-cyclic-graph', | 92 'merger-cyclic-graph', |
| 106 'finish' | 93 'finish' |
| 107 ); | 94 ); |
| 108 | 95 |
| 109 successfullyParsed = true; | 96 successfullyParsed = true; |
| 110 </script> | 97 </script> |
| 111 </body> | 98 </body> |
| 112 | 99 |
| 113 </html> | 100 </html> |
| OLD | NEW |