| OLD | NEW |
| (Empty) |
| 1 <!DOCTYPE html> | |
| 2 <html> | |
| 3 | |
| 4 <head> | |
| 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 if ChannelMergerNode runs correctly in a cycle."); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | |
| 16 // This specific sample rate is chosen to avoid the round/truncation error | |
| 17 // in delay time. See: crbug.com/448801 | |
| 18 var sampleRate = 32768; | |
| 19 | |
| 20 // Web Audio API's rendering quantum. | |
| 21 var renderingQuantum = 128; | |
| 22 | |
| 23 // 4x of rendering quantum. This is to make the rendered result long enough | |
| 24 // so that we can observe the delayed output. | |
| 25 var renderLength = renderingQuantum * 4; | |
| 26 | |
| 27 // 1x rendering quantum of delay. | |
| 28 var delayTime = renderingQuantum / sampleRate; | |
| 29 | |
| 30 // Use 2 channels as a test case. | |
| 31 var numberOfChannels = 2; | |
| 32 | |
| 33 var audit = Audit.createTaskRunner(); | |
| 34 | |
| 35 audit.defineTask('merger-cyclic-graph', function (done) { | |
| 36 | |
| 37 var context = new OfflineAudioContext( | |
| 38 numberOfChannels, renderLength, sampleRate | |
| 39 ); | |
| 40 var merger = context.createChannelMerger(2); | |
| 41 var delay = context.createDelay(); | |
| 42 var source = context.createBufferSource(); | |
| 43 | |
| 44 // Create a mono source buffer filled with '1'. | |
| 45 source.buffer = createConstantBuffer(context, renderLength, [1]); | |
| 46 | |
| 47 delay.delayTime.value = delayTime; | |
| 48 | |
| 49 // Connect the source to input 0 of the merger. Connect the output of | |
| 50 // the merger to a delay node whose output is then connected to input 1 | |
| 51 // of the merger. See: crbug.com/442925 | |
| 52 source.connect(merger, 0, 0); | |
| 53 delay.connect(merger, 0, 1); | |
| 54 merger.connect(delay); | |
| 55 merger.connect(context.destination); | |
| 56 source.start(); | |
| 57 | |
| 58 context.startRendering().then(function (buffer) { | |
| 59 // Expected output values: the output of delay node will be a stereo | |
| 60 // signal of [1, 0]. When it feeds back to the 2nd input of merger node, | |
| 61 // the stereo channel will be summed to mono resulting in 0.5. | |
| 62 var expected_left = []; | |
| 63 var expected_right = []; | |
| 64 | |
| 65 for (var i = 0; i < renderLength; i++) { | |
| 66 // Note that the delayed channel will be zero for the first 128 sample
s | |
| 67 // due to the cyclic audio graph, the second 128 sample will be also | |
| 68 // zero because of 128 samples delay. | |
| 69 expected_left[i] = 1.0; | |
| 70 expected_right[i] = (i < renderingQuantum * 2) ? 0.0 : 0.5; | |
| 71 } | |
| 72 | |
| 73 for (i = 0; i < buffer.numberOfChannels; i++) { | |
| 74 var actual_left = buffer.getChannelData(0); | |
| 75 var actual_right = buffer.getChannelData(1); | |
| 76 for (var j = 0; j < renderLength; j++) { | |
| 77 if (expected_left[j] !== actual_left[j]) { | |
| 78 testFailed('The value ' + actual_left[j] + | |
| 79 'in the left channel did not match the expected value ' + | |
| 80 expected_left[j] + ' at the index ' + j + '.'); | |
| 81 done(); | |
| 82 return; | |
| 83 } | |
| 84 if (expected_right[j] !== actual_right[j]) { | |
| 85 testFailed('The value ' + actual_left[j] + | |
| 86 'in the right channel did not match the expected value ' + | |
| 87 expected_left[j] + ' at the index ' + j + '.'); | |
| 88 done(); | |
| 89 return; | |
| 90 } | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 testPassed("ChannerMergerNode passed cyclic audio graph test."); | |
| 95 done(); | |
| 96 }); | |
| 97 | |
| 98 }); | |
| 99 | |
| 100 audit.defineTask('finish', function (done) { | |
| 101 finishJSTest(); | |
| 102 done(); | |
| 103 }); | |
| 104 | |
| 105 audit.runTasks( | |
| 106 'merger-cyclic-graph', | |
| 107 'finish' | |
| 108 ); | |
| 109 | |
| 110 successfullyParsed = true; | |
| 111 </script> | |
| 112 </body> | |
| 113 | |
| 114 </html> | |
| OLD | NEW |