Bug 867876 - Add some tests for the AudioParam automation events; r=roc

This commit is contained in:
Ehsan Akhgari 2013-05-02 01:13:27 -04:00
Родитель f4ef30f478
Коммит fedd33c510
4 изменённых файлов: 129 добавлений и 1 удалений

Просмотреть файл

@ -26,6 +26,8 @@ MOCHITEST_FILES := \
test_AudioContext.html \
test_AudioListener.html \
test_AudioParam.html \
test_audioParamExponentialRamp.html \
test_audioParamLinearRamp.html \
test_audioBufferSourceNode.html \
test_audioBufferSourceNodeLazyLoopParam.html \
test_audioBufferSourceNodeLoop.html \

Просмотреть файл

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AudioParam.exponentialRampToValue</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.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 context = new AudioContext();
var V0 = 0.1;
var V1 = 0.9;
var T0 = 0;
var T1 = 2048 / context.sampleRate;
var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
sourceBuffer.getChannelData(0)[i] = 1;
}
var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
var t = i / context.sampleRate;
expectedBuffer.getChannelData(0)[i] = V0 * Math.pow(V1 / V0, (t - T0) / (T1 - T0));
}
var destination = context.destination;
var source = context.createBufferSource();
source.buffer = sourceBuffer;
var gain = context.createGain();
gain.gain.setValueAtTime(V0, 0);
gain.gain.exponentialRampToValueAtTime(V1, 2048/context.sampleRate);
var sp = context.createScriptProcessor(2048, 1);
source.connect(gain);
gain.connect(sp);
sp.connect(destination);
source.start(0);
sp.onaudioprocess = function(e) {
is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
sp.onaudioprocess = null;
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
};
});
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -0,0 +1,63 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AudioParam.linearRampToValue</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.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 context = new AudioContext();
var V0 = 0.1;
var V1 = 0.9;
var T0 = 0;
var T1 = 2048 / context.sampleRate;
var sourceBuffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
sourceBuffer.getChannelData(0)[i] = 1;
}
var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
for (var i = 0; i < 2048; ++i) {
var t = i / context.sampleRate;
expectedBuffer.getChannelData(0)[i] = V0 + (V1 - V0) * ((t - T0) / (T1 - T0));
}
var destination = context.destination;
var source = context.createBufferSource();
source.buffer = sourceBuffer;
var gain = context.createGain();
gain.gain.setValueAtTime(V0, 0);
gain.gain.linearRampToValueAtTime(V1, 2048/context.sampleRate);
var sp = context.createScriptProcessor(2048, 1);
source.connect(gain);
gain.connect(sp);
sp.connect(destination);
source.start(0);
sp.onaudioprocess = function(e) {
is(e.inputBuffer.numberOfChannels, 1, "Correct input channel count");
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
sp.onaudioprocess = null;
SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
};
});
</script>
</pre>
</body>
</html>

Просмотреть файл

@ -24,7 +24,7 @@ function expectTypeError(func) {
}
function fuzzyCompare(a, b) {
return Math.abs(a - b) < 5e-5;
return Math.abs(a - b) < 9e-3;
}
function compareBuffers(buf1, buf2,