5 <script src=
"../resources/js-test.js"></script>
6 <script src=
"resources/compatibility.js"></script>
7 <script type=
"text/javascript" src=
"resources/audio-testing.js"></script>
12 <div id=
"description"></div>
13 <div id=
"console"></div>
16 description("This test verifies that the AudioBasicInspectorNode based nodes work correctly.");
18 var sampleRate
= 44100.0;
19 // We carefully arrange the renderLengthInFrames to be a multiple of the AudioNode rendering quantum (AudioNode::ProcessingSizeInFrames)
20 // so that AudioSourceNode will not feed tailing zeroes into the context and fail this test.
21 var renderLengthInFrames
= 256;
24 var audioDataOne
= 255; // Audio data 1.0 in Uint8 format will be 255.
25 var audioDataZero
= 128; // Audio data 0 in Uint8 format will be 128.
32 function constructCommonGraph() {
33 // Create offline audio context.
34 context
= new OfflineAudioContext(1, renderLengthInFrames
, sampleRate
);
35 constantBuffer
= createConstantBuffer(context
, renderLengthInFrames
, 1);
37 bufferSource
= context
.createBufferSource();
38 bufferSource
.buffer
= constantBuffer
;
40 analyser
= context
.createAnalyser();
41 analyser
.fftSize
= fftSize
;
43 bufferSource
.connect(analyser
);
46 function test1Finished() {
47 var timeDomainData
= new Uint8Array(fftSize
);
48 analyser
.getByteTimeDomainData(timeDomainData
);
50 if (timeDomainData
[0] >= audioDataOne
)
51 testPassed("RealtimeAnalyserNode got pulled when connected from upstream node but not to downstream node.");
53 testFailed("RealtimeAnalyserNode failed to get pulled when connected from upstream node but not to downstream node.");
58 // To verify the realtimeAnalyser can pull data when there is an upstream node connected to it
59 // but it's not connected to a downstream node.
61 constructCommonGraph();
63 bufferSource
.start(0);
65 context
.oncomplete
= test1Finished
;
66 context
.startRendering();
69 function test2Finished() {
70 var timeDomainData
= new Uint8Array(fftSize
);
71 analyser
.getByteTimeDomainData(timeDomainData
);
73 if (timeDomainData
[0] >= audioDataOne
)
74 testPassed("RealtimeAnalyserNode got pulled when connected from upstream node and to destination node.");
76 testFailed("RealtimeAnalyserNode failed to be pulled when connected by upstream node and to destination node.");
81 // To verify the realtimeAnalyser can process normally when there is an upstream node connected to it
82 // and it's also connected to a downstream node which ultimately connect to audio destination.
84 constructCommonGraph();
86 analyser
.connect(context
.destination
);
88 bufferSource
.start(0);
90 context
.oncomplete
= test2Finished
;
91 context
.startRendering();
94 function test3Finished() {
95 var timeDomainData
= new Uint8Array(fftSize
);
96 analyser
.getByteTimeDomainData(timeDomainData
);
98 // If realtimeAnalyser hasn't pulled any data, the data in buffer will be 0.
99 if (timeDomainData
[0] == audioDataZero
)
100 testPassed("RealtimeAnalyserNode didn't get pulled when it should not.");
102 testFailed("RealtimeAnalyserNode been pulled when it should not.");
107 // To verify the realtimeAnalyser will stop pulling if it is connected to a downstream node
108 // which is not ultimatly connected to any audio destination.
110 constructCommonGraph();
112 var gain
= context
.createGain();
113 analyser
.connect(gain
);
115 bufferSource
.start(0);
117 context
.oncomplete
= test3Finished
;
118 context
.startRendering();
122 if (window
.testRunner
) {
123 testRunner
.dumpAsText();
124 testRunner
.waitUntilDone();
127 window
.jsTestIsAsync
= true;