blob: 2c7344be49c8eab19bd5cc8a58331bfc17b31bd5 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>
Test getFloatFrequencyData With Zero Inputs
</title>
<script src="../../imported/w3c/web-platform-tests/resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../resources/audit-util.js"></script>
<script src="../resources/audit.js"></script>
</head>
<body>
<script id="layout-test-code">
let sampleRate = 48000;
// Render enough data to run the test.
let renderFrames = 2 * 1024;
let renderDuration = renderFrames / sampleRate;
let audit = Audit.createTaskRunner();
// Test that getFloatFrequencyData returns -Infinity when the input is
// all-zeroes.
audit.define('zero input', (task, should) => {
let context = new OfflineAudioContext(1, renderFrames, sampleRate);
// Constant source of 0's.
let source = context.createBufferSource();
source.buffer = createConstantBuffer(context, 1, 0);
source.loop = true;
// Create analyser and use some non-default minDecibels value.
let analyser = context.createAnalyser();
analyser.minDecibels = -123;
source.connect(analyser);
analyser.connect(context.destination);
source.start();
// Suspend after some number of frames and grab the float frequency
// data.
context.suspend(1024 / sampleRate)
.then(function() {
let f = new Float32Array(analyser.frequencyBinCount);
analyser.getFloatFrequencyData(f);
should(f, 'getFloatFrequencyData() with zero-valued input')
.beConstantValueOf(-Infinity);
})
.then(context.resume.bind(context));
context.startRendering().then(() => task.done());
});
audit.run();
</script>
</body>
</html>