OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <head> |
| 4 <title> |
| 5 automatic-pull-node.html |
| 6 </title> |
| 7 <script src="../../resources/testharness.js"></script> |
| 8 <script src="../../resources/testharnessreport.js"></script> |
| 9 <script src="../resources/audit-util.js"></script> |
| 10 <script src="../resources/audit.js"></script> |
| 11 </head> |
| 12 <body> |
| 13 <script id="layout-test-code"> |
| 14 // This test verifies that the AudioBasicInspectorNode based nodes work |
| 15 // correctly |
2 | 16 |
3 <html> | 17 let audit = Audit.createTaskRunner(); |
4 <head> | |
5 <script src="../../resources/testharness.js"></script> | |
6 <script src="../../resources/testharnessreport.js"></script> | |
7 <script src="../resources/audit-util.js"></script> | |
8 <script src="../resources/audit.js"></script> | |
9 </head> | |
10 | 18 |
11 <body> | 19 let sampleRate = 44100.0; |
| 20 // We carefully arrange the renderLengthInFrames to be a multiple of the |
| 21 // AudioNode rendering quantum (AudioNode::ProcessingSizeInFrames) so that |
| 22 // AudioSourceNode will not feed tailing zeroes into the context and fail |
| 23 // this test. |
| 24 let renderLengthInFrames = 256; |
| 25 let fftSize = 64; |
12 | 26 |
13 <script> | 27 let audioDataOne = 255; // Audio data 1.0 in Uint8 format will be 255. |
14 // This test verifies that the AudioBasicInspectorNode based nodes work correctl
y | 28 let audioDataZero = 128; // Audio data 0 in Uint8 format will be 128. |
15 | 29 |
16 var audit = Audit.createTaskRunner(); | 30 let context; |
| 31 let constantBuffer; |
| 32 let bufferSource; |
| 33 let analyser; |
17 | 34 |
18 var sampleRate = 44100.0; | 35 function constructCommonGraph() { |
19 // We carefully arrange the renderLengthInFrames to be a multiple of the | 36 // Create offline audio context. |
20 // AudioNode rendering quantum (AudioNode::ProcessingSizeInFrames) so that | 37 context = new OfflineAudioContext(1, renderLengthInFrames, sampleRate); |
21 // AudioSourceNode will not feed tailing zeroes into the context and fail this | 38 constantBuffer = createConstantBuffer(context, renderLengthInFrames, 1); |
22 // test. | |
23 var renderLengthInFrames = 256; | |
24 var fftSize = 64; | |
25 | 39 |
26 var audioDataOne = 255; // Audio data 1.0 in Uint8 format will be 255. | 40 bufferSource = context.createBufferSource(); |
27 var audioDataZero = 128; // Audio data 0 in Uint8 format will be 128. | 41 bufferSource.buffer = constantBuffer; |
28 | 42 |
29 var context; | 43 analyser = context.createAnalyser(); |
30 var constantBuffer; | 44 analyser.fftSize = fftSize; |
31 var bufferSource; | |
32 var analyser; | |
33 | 45 |
34 function constructCommonGraph() { | 46 bufferSource.connect(analyser); |
35 // Create offline audio context. | 47 } |
36 context = new OfflineAudioContext(1, renderLengthInFrames, sampleRate); | |
37 constantBuffer = createConstantBuffer(context, renderLengthInFrames, 1); | |
38 | 48 |
39 bufferSource = context.createBufferSource(); | 49 function test1Finished(should) { |
40 bufferSource.buffer = constantBuffer; | 50 let timeDomainData = new Uint8Array(fftSize); |
| 51 analyser.getByteTimeDomainData(timeDomainData); |
41 | 52 |
42 analyser = context.createAnalyser(); | 53 should( |
43 analyser.fftSize = fftSize; | 54 timeDomainData[0] >= audioDataOne, |
| 55 'RealtimeAnalyserNode got pulled when connected from upstream node b
ut not to downstream node') |
| 56 .beTrue(); |
| 57 } |
44 | 58 |
45 bufferSource.connect(analyser); | 59 // To verify the realtimeAnalyser can pull data when there is an upstream |
46 } | 60 // node connected to it but it's not connected to a downstream node. |
| 61 audit.define('test1', function(task, should) { |
| 62 constructCommonGraph(); |
47 | 63 |
48 function test1Finished(should) { | 64 bufferSource.start(0); |
49 var timeDomainData = new Uint8Array(fftSize); | |
50 analyser.getByteTimeDomainData(timeDomainData); | |
51 | 65 |
52 should(timeDomainData[0] >= audioDataOne, | 66 context.startRendering() |
53 "RealtimeAnalyserNode got pulled when connected from upstream node but not
to downstream node" | 67 .then(function() { |
54 ) | 68 test1Finished(should); |
55 .beTrue(); | 69 }) |
56 } | 70 .then(task.done.bind(task)); |
| 71 }); |
57 | 72 |
58 // To verify the realtimeAnalyser can pull data when there is an upstream node | 73 function test2Finished(should) { |
59 // connected to it but it's not connected to a downstream node. | 74 let timeDomainData = new Uint8Array(fftSize); |
60 audit.define("test1", function (task, should) { | 75 analyser.getByteTimeDomainData(timeDomainData); |
61 constructCommonGraph(); | |
62 | 76 |
63 bufferSource.start(0); | 77 should( |
| 78 timeDomainData[0] >= audioDataOne, |
| 79 'RealtimeAnalyserNode got pulled when connected from upstream node a
nd to destination node') |
| 80 .beTrue(); |
| 81 } |
64 | 82 |
65 context.startRendering() | 83 // To verify the realtimeAnalyser can process normally when there is an |
66 .then(function () { | 84 // upstream node connected to it and it's also connected to a downstream |
67 test1Finished(should); | 85 // node which ultimately connect to audio destination. |
68 }) | 86 audit.define('test2', function(task, should) { |
69 .then(task.done.bind(task)); | 87 constructCommonGraph(); |
70 }); | |
71 | 88 |
72 function test2Finished(should) { | 89 analyser.connect(context.destination); |
73 var timeDomainData = new Uint8Array(fftSize); | |
74 analyser.getByteTimeDomainData(timeDomainData); | |
75 | 90 |
76 should(timeDomainData[0] >= audioDataOne, | 91 bufferSource.start(0); |
77 "RealtimeAnalyserNode got pulled when connected from upstream node and to
destination node" | |
78 ) | |
79 .beTrue(); | |
80 } | |
81 | 92 |
82 // To verify the realtimeAnalyser can process normally when there is an upstream | 93 context.startRendering() |
83 // node connected to it and it's also connected to a downstream node which | 94 .then(function() { |
84 // ultimately connect to audio destination. | 95 test2Finished(should); |
85 audit.define("test2", function (task, should) { | 96 }) |
86 constructCommonGraph(); | 97 .then(task.done.bind(task)); |
| 98 }); |
87 | 99 |
88 analyser.connect(context.destination); | 100 function test3Finished(should) { |
| 101 let timeDomainData = new Uint8Array(fftSize); |
| 102 analyser.getByteTimeDomainData(timeDomainData); |
89 | 103 |
90 bufferSource.start(0); | 104 // If realtimeAnalyser hasn't pulled any data, the data in buffer will |
| 105 // be 0. |
| 106 should( |
| 107 timeDomainData[0] == audioDataZero, |
| 108 'RealtimeAnalyserNode didn\'t get pulled when it should not') |
| 109 .beTrue(); |
| 110 ; |
| 111 } |
91 | 112 |
92 context.startRendering() | 113 // To verify the realtimeAnalyser will stop pulling if it is connected to |
93 .then(function () { | 114 // a downstream node which is not ultimatly connected to any audio |
94 test2Finished(should); | 115 // destination. |
95 }) | 116 audit.define('test3', function(task, should) { |
96 .then(task.done.bind(task)); | 117 constructCommonGraph(); |
97 }); | |
98 | 118 |
99 function test3Finished(should) { | 119 let gain = context.createGain(); |
100 var timeDomainData = new Uint8Array(fftSize); | 120 analyser.connect(gain); |
101 analyser.getByteTimeDomainData(timeDomainData); | |
102 | 121 |
103 // If realtimeAnalyser hasn't pulled any data, the data in buffer will be 0. | 122 bufferSource.start(0); |
104 should(timeDomainData[0] == audioDataZero, | |
105 "RealtimeAnalyserNode didn't get pulled when it should not") | |
106 .beTrue();; | |
107 } | |
108 | 123 |
109 // To verify the realtimeAnalyser will stop pulling if it is connected to a | 124 context.startRendering() |
110 // downstream node which is not ultimatly connected to any audio destination. | 125 .then(function() { |
111 audit.define("test3", function (task, should) { | 126 test3Finished(should); |
112 constructCommonGraph(); | 127 }) |
| 128 .then(task.done.bind(task)); |
| 129 }); |
113 | 130 |
114 var gain = context.createGain(); | 131 audit.run(); |
115 analyser.connect(gain); | 132 </script> |
116 | 133 </body> |
117 bufferSource.start(0); | |
118 | |
119 context.startRendering() | |
120 .then(function () { | |
121 test3Finished(should); | |
122 }) | |
123 .then(task.done.bind(task)); | |
124 }); | |
125 | |
126 audit.run(); | |
127 | |
128 </script> | |
129 | |
130 </body> | |
131 </html> | 134 </html> |
OLD | NEW |