mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 12:37:37 +00:00
23e1abde57
This is the full implementation of the AudioBuffer object. There are two ways to create these objects from an audio context and this patch implements only one of them. The construction of the AudioBuffer object is a two step process: the object should be created with operator new first, and then InitializeBuffers should be called on it. InitializeBuffers is fallible, because it uses the JS API to create the underlying typed arrays, but that's fine, since the length of the buffers comes from web content, and we don't want to use infallible allocations for those anyways. We hold on to the JS objects from the C++ implementation, and trace through all of those objects, so that a GC does not kill those object without us knowing. The buffer should be possible to manipulate from both C++ and JS, and the C++ object probably needs to support a set of methods for the C++ callers at some point.
45 lines
1.5 KiB
HTML
45 lines
1.5 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<head>
|
|
<title>Test whether we can create an AudioContext interface</title>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body>
|
|
<pre id="test">
|
|
<script class="testbody" type="text/javascript">
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
addLoadEvent(function() {
|
|
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
|
|
var ac = new mozAudioContext();
|
|
var buffer = ac.createBuffer(2, 2048, 44100);
|
|
SpecialPowers.gc(); // Make sure that our channels are accessible after GC
|
|
ok(buffer, "Buffer was allocated successfully");
|
|
is(buffer.sampleRate, 44100, "Correct sample rate");
|
|
is(buffer.length, 2048, "Correct length");
|
|
ok(Math.abs(buffer.duration - 2048 / 44100) < 0.0001, "Correct duration");
|
|
is(buffer.numberOfChannels, 2, "Correct number of channels");
|
|
for (var i = 0; i < buffer.numberOfChannels; ++i) {
|
|
var buf = buffer.getChannelData(i);
|
|
ok(buf, "Buffer index " + i + " exists");
|
|
ok(buf instanceof Float32Array, "Result is a typed array");
|
|
is(buf.length, buffer.length, "Correct length");
|
|
var foundNonZero = false;
|
|
for (var j = 0; j < buf.length; ++j) {
|
|
if (buf[j] != 0) {
|
|
foundNonZero = true;
|
|
break;
|
|
}
|
|
}
|
|
ok(!foundNonZero, "Buffer " + i + " should be initialized to 0");
|
|
}
|
|
SpecialPowers.clearUserPref("media.webaudio.enabled");
|
|
SimpleTest.finish();
|
|
});
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|