Bug 1656438 - Tighten estimated frequency check by accounting for drift factor. r=padenot

Differential Revision: https://phabricator.services.mozilla.com/D89987
This commit is contained in:
Andreas Pehrson 2020-09-17 06:13:42 +00:00
Родитель 87bb8fdaac
Коммит ae9340d553
4 изменённых файлов: 9 добавлений и 9 удалений

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

@ -42,7 +42,7 @@ class AudioVerifier {
}
}
uint32_t EstimatedFreq() const {
float EstimatedFreq() const {
if (mTotalFramesSoFar == PreSilenceSamples()) {
return 0;
}
@ -52,7 +52,8 @@ class AudioVerifier {
if (mZeroCrossCount <= 1) {
return 0;
}
return mRate / (mSumPeriodInSamples / (mZeroCrossCount - 1));
return mRate /
(static_cast<float>(mSumPeriodInSamples) / (mZeroCrossCount - 1));
}
// Returns the maximum difference in value between two adjacent samples along

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

@ -171,7 +171,7 @@ class MockCubebStream {
return mFramesProcessedEvent;
}
MediaEventSource<Tuple<uint64_t, uint32_t, uint32_t>>&
MediaEventSource<Tuple<uint64_t, float, uint32_t>>&
OutputVerificationEvent() {
return mOutputVerificationEvent;
}
@ -248,8 +248,7 @@ class MockCubebStream {
AudioVerifier<AudioDataValue> mAudioVerifier;
MediaEventProducer<uint32_t> mFramesProcessedEvent;
MediaEventProducer<Tuple<uint64_t, uint32_t, uint32_t>>
mOutputVerificationEvent;
MediaEventProducer<Tuple<uint64_t, float, uint32_t>> mOutputVerificationEvent;
MediaEventProducer<void> mErrorForcedEvent;
};

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

@ -271,11 +271,11 @@ void testAudioCorrection(int32_t aSourceRate, int32_t aTargetRate) {
ad.mDesiredBuffering - sampleRateTransmitter / 100 /* 10ms */;
EXPECT_NEAR(ad.CurrentBuffering(), expectedBuffering, 512);
EXPECT_EQ(inToneVerifier.EstimatedFreq(), tone.mFrequency);
EXPECT_NEAR(inToneVerifier.EstimatedFreq(), tone.mFrequency, 1.0f);
EXPECT_EQ(inToneVerifier.PreSilenceSamples(), 0U);
EXPECT_EQ(inToneVerifier.CountDiscontinuities(), 0U);
EXPECT_EQ(outToneVerifier.EstimatedFreq(), tone.mFrequency);
EXPECT_NEAR(outToneVerifier.EstimatedFreq(), tone.mFrequency, 1.0f);
// The expected pre-silence is 50ms plus the resampling.
EXPECT_GE(outToneVerifier.PreSilenceSamples(), aTargetRate * 50 / 1000U);
EXPECT_EQ(outToneVerifier.CountDiscontinuities(), 0U);

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

@ -453,12 +453,12 @@ void TestCrossGraphPort(uint32_t aInputRate, uint32_t aOutputRate,
uint32_t partnerRate = partnerStream->InputSampleRate();
uint64_t preSilenceSamples;
uint32_t estimatedFreq;
float estimatedFreq;
uint32_t nrDiscontinuities;
Tie(preSilenceSamples, estimatedFreq, nrDiscontinuities) =
WaitFor(partnerStream->OutputVerificationEvent());
EXPECT_NEAR(estimatedFreq, inputFrequency, 10);
EXPECT_NEAR(estimatedFreq, inputFrequency / aDriftFactor, 5);
EXPECT_GE(preSilenceSamples, partnerRate / 100 /* 10ms */);
EXPECT_LE(nrDiscontinuities, 2U);
}