Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- This WPT test may be referenced by the following Test IDs:
- /webaudio/the-audio-api/the-audiobuffer-interface/audiobuffer.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<html>
<head>
<title>
audiobuffer.html
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit-util.js"></script>
<script src="/webaudio/resources/audit.js"></script>
</head>
<body>
<script id="layout-test-code">
let sampleRate = 44100.0
let lengthInSeconds = 2;
let numberOfChannels = 4;
let audit = Audit.createTaskRunner();
audit.define('Basic tests for AudioBuffer', function(task, should) {
let context = new AudioContext();
let buffer = context.createBuffer(
numberOfChannels, sampleRate * lengthInSeconds, sampleRate);
// Just for printing out a message describing what "buffer" is in the
// following tests.
should(
true,
'buffer = context.createBuffer(' + numberOfChannels + ', ' +
(sampleRate * lengthInSeconds) + ', ' + sampleRate + ')')
.beTrue();
should(buffer.sampleRate, 'buffer.sampleRate').beEqualTo(sampleRate);
should(buffer.length, 'buffer.length')
.beEqualTo(sampleRate * lengthInSeconds);
should(buffer.duration, 'buffer.duration').beEqualTo(lengthInSeconds);
should(buffer.numberOfChannels, 'buffer.numberOfChannels')
.beEqualTo(numberOfChannels);
for (let index = 0; index < buffer.numberOfChannels; ++index) {
should(
buffer.getChannelData(index) instanceof window.Float32Array,
'buffer.getChannelData(' + index +
') instanceof window.Float32Array')
.beTrue();
}
should(
function() {
buffer.getChannelData(buffer.numberOfChannels);
},
'buffer.getChannelData(' + buffer.numberOfChannels + ')')
.throw(DOMException, 'IndexSizeError');
let buffer2 = context.createBuffer(1, 1000, 24576);
let expectedDuration = 1000 / 24576;
should(
buffer2.duration, 'context.createBuffer(1, 1000, 24576).duration')
.beEqualTo(expectedDuration);
task.done();
});
audit.run();
</script>
</body>
</html>