0

[Sheriff] Revert "Deflake preservesPitch tests"

This reverts commit 7b6c400789.

Reason for revert: 

Post this change, preservesPitch seems to consistently fail.

https://ci.chromium.org/p/chromium/builders/ci/Mac10.14%20Tests

Original change's description:
> Deflake preservesPitch tests
> 
> This CL changes preservesPitch tests to wait until the audioElement's
> currentTime is at least 0.5 seconds before trying to detect the pitch.
> Without this check, the test can try to detect the pitch before the
> audio has played enough, which can return a dominant frequency of 0Hz
> and fail the test.
> 
> The CL also makes a few stylistic changes, and fixes an off-by-one error
> in the number of increments used to calculate frequencies.
> 
> Bug: 1096238
> Change-Id: I6e98e172862a47bea1c4026737138293914f7906
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2298281
> Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
> Commit-Queue: Philip Jägenstedt <foolip@chromium.org>
> Reviewed-by: Philip Jägenstedt <foolip@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#788535}

TBR=tguilbert@chromium.org,foolip@chromium.org

Change-Id: I0042f73ca9c5de7d82be1200794c45b46a003f9b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1096238
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2299183
Reviewed-by: Roger McFarlane <rogerm@chromium.org>
Commit-Queue: Roger McFarlane <rogerm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#788626}
This commit is contained in:
Roger McFarlane
2020-07-15 14:46:58 +00:00
committed by Commit Bot
parent e3017a7bcc
commit f19f340437
2 changed files with 28 additions and 35 deletions
third_party/blink/web_tests/external/wpt/html/semantics/embedded-content/media-elements

@@ -16,15 +16,14 @@ function getPitchDetector(media, t) {
sourceNode.connect(analyser);
analyser.connect(audioContext.destination);
return () => getPitch(analyser);
// Returns the frequency value for the nth FFT bin.
var binConverter = (bin) => audioContext.sampleRate*(bin/FFT_SIZE);
return () => getPitch(analyser, binConverter);
}
function getPitch(analyser) {
// Returns the frequency value for the nth FFT bin.
var binConverter = (bin) =>
(analyser.context.sampleRate/2)*((bin)/(analyser.frequencyBinCount-1));
var buf = new Uint8Array(analyser.frequencyBinCount);
function getPitch(analyser, binConverter) {
var buf = new Uint8Array(FFT_SIZE/2);
analyser.getByteFrequencyData(buf);
return findDominantFrequency(buf, binConverter);
}
@@ -41,8 +40,9 @@ function findDominantFrequency(buf, binConverter) {
}
}
// The spread of frequencies within bins is constant and corresponds to
// (1/(FFT_SIZE-1))th of the sample rate. Use the value of bin #1 as a
// shorthand for that value.
// The distance between bins is always constant and corresponds to
// (1/FFT_SIZE)th of the sample rate. Use the frequency value of the 1st bin
// as the margin directly, instead of calculating an average from the values
// of the neighboring bins.
return { value:binConverter(bin), margin:binConverter(1) };
}

@@ -56,34 +56,27 @@ function testPreservesPitch(preservesPitch, playbackRate, expectedPitch, descrip
audio.playbackRate = playbackRate;
setPreservesPitch(audio, preservesPitch);
function waitUntil(time) {
return new Promise((resolve) => {
audio.ontimeupdate = () => {
if (audio.currentTime >= time) {
resolve();
}
};
});
function promiseTimeUpdate() {
return new Promise((resolve) => audio.ontimeupdate = resolve);
}
function verifyPitch() {
var pitch = detector();
// 25Hz is larger than the margin we get from 48kHz and 44.1kHz
// audio being analyzed by a FFT of size 2048. If we get something
// different, there is an error within the test's calculations (or
// we might be dealing a larger sample rate).
assert_less_than(pitch.margin, 25,
"Test error: the margin should be reasonably small.")
assert_approx_equals(pitch.value, expectedPitch, pitch.margin,
"The actual pitch should be close to the expected pitch.");
}
await test_driver.bless("Play audio element", () => audio.play() )
// Wait until we have at least played some audio. Otherwise, the
// detector might return a pitch of 0Hz.
await waitUntil(0.5);
var pitch = detector();
// 25Hz is larger than the margin we get from 48kHz and 44.1kHz
// audio being analyzed by a FFT of size 2048. If we get something
// different, there is an error within the test's calculations (or
// we might be dealing a larger sample rate).
assert_less_than(pitch.margin, 25,
"Test error: the margin should be reasonably small.")
assert_approx_equals(pitch.value, expectedPitch, pitch.margin,
"The actual pitch should be close to the expected pitch.");
.then(promiseTimeUpdate)
.then(verifyPitch);
}, description);
}