Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /webaudio/the-audio-api/the-analysernode-interface/test-analyser-output.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<title>Test AnalyserNode passes input to output unmodified</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
promise_test(async t => {
// Use 2048 frames for the test render length, matching the default FFT
// size of AnalyserNode.
const length = 2048;
const sampleRate = 48000;
const context = new OfflineAudioContext(
1,
length,
sampleRate
);
// Generate a 440Hz sine wave to use as the input signal. Using a non-zero
// signal ensures we can verify the AnalyserNode passes it through
// unmodified.
const expectedBuffer = new AudioBuffer({
numberOfChannels: 1,
length: length,
sampleRate: sampleRate
});
const expectedData = expectedBuffer.getChannelData(0);
for (let i = 0; i < length; ++i) {
expectedData[i] = Math.sin(440 * 2 * Math.PI * i / sampleRate);
}
const source = new AudioBufferSourceNode(context, {
buffer: expectedBuffer
});
const analyser = new AnalyserNode(context);
source.connect(analyser).connect(context.destination);
source.start();
const renderedBuffer = await context.startRendering();
const renderedData = renderedBuffer.getChannelData(0);
assert_equals(
renderedData.length,
expectedData.length,
'Output length matches expected length'
);
assert_array_approx_equals(
renderedData,
expectedData,
1e-7,
'AnalyserNode output matches expected input'
);
}, 'AnalyserNode output passes through input signal unmodified');
</script>