зеркало из https://github.com/mozilla/gecko-dev.git
b=932400 check feedback delay loop output r=padenot
The delay in the third test is reduced to ensure that some of the output signal has traversed every link in the cycle. The input signal no longer loops for un-muted cycles, to keep it simple. --HG-- extra : rebase_source : 37f555c356cc2c0573e7c93150ed86587da30ad7
This commit is contained in:
Родитель
7a15018557
Коммит
969f61e5af
|
@ -3,6 +3,7 @@
|
|||
<head>
|
||||
<title>Test the support of cycles.</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>
|
||||
|
@ -12,42 +13,29 @@
|
|||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
const sampleRate = 48000;
|
||||
const inputLength = 2048;
|
||||
|
||||
addLoadEvent(function() {
|
||||
function getSineBuffer(ctx) {
|
||||
var buffer = ctx.createBuffer(1, 2048, ctx.sampleRate);
|
||||
var b = buffer.getChannelData(0);
|
||||
for (var i = 0; i < 2048; i++) {
|
||||
b[i] = Math.sin(440 * 2 * Math.PI * i / ctx.sampleRate);
|
||||
function addSine(b) {
|
||||
for (var i = 0; i < b.length; i++) {
|
||||
b[i] += Math.sin(440 * 2 * Math.PI * i / sampleRate);
|
||||
}
|
||||
}
|
||||
|
||||
function getSineBuffer(ctx) {
|
||||
var buffer = ctx.createBuffer(1, inputLength, ctx.sampleRate);
|
||||
addSine(buffer.getChannelData(0));
|
||||
return buffer;
|
||||
}
|
||||
|
||||
function createAndPlayWithCycleAndDelayNode(ctx) {
|
||||
function createAndPlayWithCycleAndDelayNode(ctx, delayFrames) {
|
||||
var source = ctx.createBufferSource();
|
||||
source.loop = true;
|
||||
source.buffer = getSineBuffer(ctx);
|
||||
|
||||
var gain = ctx.createGain();
|
||||
var delay = ctx.createDelay();
|
||||
delay.delayTime = 0.5;
|
||||
|
||||
source.connect(gain);
|
||||
gain.connect(delay);
|
||||
delay.connect(ctx.destination);
|
||||
// cycle
|
||||
delay.connect(gain);
|
||||
|
||||
source.start(0);
|
||||
}
|
||||
|
||||
function createAndPlayWithCycleAndDelayNodeButNullDelayTime(ctx) {
|
||||
var source = ctx.createBufferSource();
|
||||
source.loop = true;
|
||||
source.buffer = getSineBuffer(ctx);
|
||||
|
||||
var gain = ctx.createGain();
|
||||
var delay = ctx.createDelay();
|
||||
delay.delayTime = 0.0;
|
||||
delay.delayTime.value = delayFrames/ctx.sampleRate;
|
||||
|
||||
source.connect(gain);
|
||||
gain.connect(delay);
|
||||
|
@ -103,7 +91,7 @@ addLoadEvent(function() {
|
|||
}
|
||||
|
||||
function getOfflineContext(oncomplete) {
|
||||
var ctx = new OfflineAudioContext(1, 48000, 48000);
|
||||
var ctx = new OfflineAudioContext(1, sampleRate, sampleRate);
|
||||
ctx.oncomplete = oncomplete;
|
||||
return ctx;
|
||||
}
|
||||
|
@ -121,18 +109,16 @@ addLoadEvent(function() {
|
|||
finish();
|
||||
}
|
||||
|
||||
function checkNoisyBuffer(e) {
|
||||
var buffer = e.renderedBuffer.getChannelData(0);
|
||||
for (var i = 0; i < buffer.length; i++) {
|
||||
if (buffer[i] != 0.0) {
|
||||
ok(true, "buffer should be noisy.");
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
function checkNoisyBuffer(e, aDelayFrames) {
|
||||
delayFrames = Math.max(128, aDelayFrames);
|
||||
|
||||
var expected = new Float32Array(e.renderedBuffer.length);
|
||||
for (var i = delayFrames; i < expected.length; i += delayFrames) {
|
||||
addSine(expected.subarray(i, i + inputLength));
|
||||
}
|
||||
ok(false, "buffer should be noisy.");
|
||||
|
||||
compareChannels(e.renderedBuffer.getChannelData(0), expected);
|
||||
finish();
|
||||
return false;
|
||||
}
|
||||
|
||||
function expectSilentOutput(f) {
|
||||
|
@ -142,10 +128,11 @@ addLoadEvent(function() {
|
|||
ctx.startRendering();
|
||||
}
|
||||
|
||||
function expectNoisyOutput(f) {
|
||||
function expectNoisyOutput(delayFrames) {
|
||||
remainingTests++;
|
||||
var ctx = getOfflineContext(checkNoisyBuffer);
|
||||
f(ctx);
|
||||
var ctx = getOfflineContext();
|
||||
ctx.oncomplete = function(e) { checkNoisyBuffer(e, delayFrames); };
|
||||
createAndPlayWithCycleAndDelayNode(ctx, delayFrames);
|
||||
ctx.startRendering();
|
||||
}
|
||||
|
||||
|
@ -158,10 +145,10 @@ addLoadEvent(function() {
|
|||
expectSilentOutput(createAndPlayWithCycleAndNoDelayNodeInCycle);
|
||||
// Those are making legal graphs, with at least one DelayNode in the cycle.
|
||||
// There should be some non-silent output.
|
||||
expectNoisyOutput(createAndPlayWithCycleAndDelayNode);
|
||||
expectNoisyOutput(sampleRate/4);
|
||||
// DelayNode.delayTime will be clamped to 128/ctx.sampleRate.
|
||||
// There should be some non-silent output.
|
||||
expectNoisyOutput(createAndPlayWithCycleAndDelayNodeButNullDelayTime);
|
||||
expectNoisyOutput(0);
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
Загрузка…
Ссылка в новой задаче