forked from mirrors/gecko-dev
Bug 1882685 use async/await to manage asynchronicity in some PannerNode tests r=padenot
Differential Revision: https://phabricator.services.mozilla.com/D203083
This commit is contained in:
parent
9bc3553854
commit
8a163574a0
2 changed files with 28 additions and 50 deletions
|
|
@ -17,15 +17,7 @@ var types = [
|
||||||
"HRTF"
|
"HRTF"
|
||||||
]
|
]
|
||||||
|
|
||||||
var finished = 2 * types.length;
|
async function testMono(type) {
|
||||||
|
|
||||||
function finish() {
|
|
||||||
if (!--finished) {
|
|
||||||
SimpleTest.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function testMono(type) {
|
|
||||||
var ac = new OfflineAudioContext(1, BUF_SIZE, 44100);
|
var ac = new OfflineAudioContext(1, BUF_SIZE, 44100);
|
||||||
|
|
||||||
// A sine to be used to fill the buffers
|
// A sine to be used to fill the buffers
|
||||||
|
|
@ -76,13 +68,11 @@ function testMono(type) {
|
||||||
monoBuffer.getChannelData(0)[i] = gain * monoBuffer.getChannelData(0)[i];
|
monoBuffer.getChannelData(0)[i] = gain * monoBuffer.getChannelData(0)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
ac.startRendering().then(function(buffer) {
|
const buffer = await ac.startRendering();
|
||||||
compareBuffers(buffer, monoBuffer);
|
compareBuffers(buffer, monoBuffer);
|
||||||
finish();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testStereo(type) {
|
async function testStereo(type) {
|
||||||
var ac = new OfflineAudioContext(2, BUF_SIZE, 44100);
|
var ac = new OfflineAudioContext(2, BUF_SIZE, 44100);
|
||||||
|
|
||||||
// A sine to be used to fill the buffers
|
// A sine to be used to fill the buffers
|
||||||
|
|
@ -126,23 +116,21 @@ function testStereo(type) {
|
||||||
|
|
||||||
panner3.connect(ac.destination);
|
panner3.connect(ac.destination);
|
||||||
|
|
||||||
ac.startRendering().then(function(buffer) {
|
const buffer = await ac.startRendering();
|
||||||
compareBuffers(buffer, stereoBuffer);
|
compareBuffers(buffer, stereoBuffer);
|
||||||
finish();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function test(type) {
|
async function test(type) {
|
||||||
testMono(type);
|
await testMono(type)
|
||||||
testStereo(type);
|
await testStereo(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
addLoadEvent(function() {
|
add_task(async function() {
|
||||||
types.forEach(test);
|
for (const panningModel of types) {
|
||||||
|
await test(panningModel);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
SimpleTest.waitForExplicitFinish();
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</pre>
|
</pre>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -14,15 +14,7 @@ var types = [
|
||||||
"HRTF"
|
"HRTF"
|
||||||
]
|
]
|
||||||
|
|
||||||
var finished = types.length;
|
async function test(type) {
|
||||||
|
|
||||||
function finish() {
|
|
||||||
if (!--finished) {
|
|
||||||
SimpleTest.finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function test(type) {
|
|
||||||
var ac = new OfflineAudioContext(1, 128, 44100);
|
var ac = new OfflineAudioContext(1, 128, 44100);
|
||||||
var osc = ac.createOscillator();
|
var osc = ac.createOscillator();
|
||||||
var panner = ac.createPanner();
|
var panner = ac.createPanner();
|
||||||
|
|
@ -37,27 +29,25 @@ function test(type) {
|
||||||
|
|
||||||
osc.start();
|
osc.start();
|
||||||
|
|
||||||
ac.startRendering().then(function(buffer) {
|
const buffer = await ac.startRendering()
|
||||||
var silence = true;
|
|
||||||
var array = buffer.getChannelData(0);
|
var silence = true;
|
||||||
for (var i = 0; i < buffer.length; i++) {
|
var array = buffer.getChannelData(0);
|
||||||
if (array[i] != 0) {
|
for (var i = 0; i < buffer.length; i++) {
|
||||||
ok(false, "Found noise in the buffer.");
|
if (array[i] != 0) {
|
||||||
silence = false;
|
ok(false, "Found noise in the buffer.");
|
||||||
}
|
silence = false;
|
||||||
}
|
}
|
||||||
ok(silence, "The buffer is silent.");
|
}
|
||||||
finish();
|
ok(silence, "The buffer is silent.");
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add_task(async function() {
|
||||||
addLoadEvent(function() {
|
for (const panningModel of types) {
|
||||||
types.forEach(test);
|
await test(panningModel);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
SimpleTest.waitForExplicitFinish();
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</pre>
|
</pre>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue