1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
4 <script src=
"../resources/js-test.js"></script>
5 <script src=
"resources/compatibility.js"></script>
6 <script src=
"resources/audio-testing.js"></script>
10 <div id=
"description"></div>
11 <div id=
"console"></div>
14 description("Test AnalyserNode getFloatTimeDomainData");
16 var sampleRate
= 44100;
17 // Render length and FFT length. Hence this must be a power of two.
18 var sampleFrameLength
= 2048;
24 function checkResult() {
25 var fftSize
= analyser
.fftSize
;
26 renderedData
= new Float32Array(fftSize
);
27 analyser
.getFloatTimeDomainData(renderedData
);
29 var trueData
= src
.buffer
.getChannelData(0);
32 // Verify that the received time domain data is exactly equal to the actual time domain
33 // data. This is true only because the render length and FFT size are the same.
34 for (k
= 0; k
< fftSize
; ++k
) {
35 if (trueData
[k
] != renderedData
[k
]) {
36 testFailed("Data mismatch at index " + k
37 + ". Expected " + trueData
[k
]
38 + " but got " + renderedData
[k
]
46 testPassed("Received expected float time domain data.");
48 testFailed("Received float time domain data did not match expected result.");
55 if (window
.testRunner
) {
56 testRunner
.dumpAsText();
57 testRunner
.waitUntilDone();
60 window
.jsTestIsAsync
= true;
62 context
= new OfflineAudioContext(1, sampleFrameLength
, sampleRate
);
64 // Use a simple linear ramp as the source.
65 src
= context
.createBufferSource();
66 src
.buffer
= createLinearRampBuffer(context
, sampleFrameLength
);
68 analyser
= context
.createAnalyser();
69 analyser
.fftSize
= sampleFrameLength
;
71 src
.connect(analyser
);
72 analyser
.connect(context
.destination
);
75 context
.oncomplete
= checkResult
;
76 context
.startRendering();
80 successfullyParsed
= true;