mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 16:47:50 +01:00

This reverts commit57e68ee1b9
. Reason for revert: bug in ancestor CL fixed Original change's description: > Revert "RNN VAD: pitch search optimizations (part 3)" > > This reverts commitea89f2a447
. > > Reason for revert: bug in ancestor CL https://webrtc-review.googlesource.com/c/src/+/191320 > > Original change's description: > > RNN VAD: pitch search optimizations (part 3) > > > > `ComputeSlidingFrameSquareEnergies()` which computes the energy of a > > sliding 20 ms frame in the pitch buffer has been switched from backward > > to forward. > > > > The benchmark has shown a slight improvement (about +6x). > > > > This change is not bit exact but all the tolerance tests still pass > > except for one single case in `RnnVadTest,PitchSearchWithinTolerance` > > for which the tolerance has been slightly increased. Note that the pitch > > estimation is still bit-exact. > > > > Benchmarked as follows: > > ``` > > out/release/modules_unittests \ > > --gtest_filter=*RnnVadTest.DISABLED_RnnVadPerformance* \ > > --gtest_also_run_disabled_tests --logs > > ``` > > > > Results: > > > > | baseline | this CL > > ------+----------------------+------------------------ > > run 1 | 22.8319 +/- 1.46554 | 22.087 +/- 0.552932 > > | 389.367x | 402.499x > > ------+----------------------+------------------------ > > run 2 | 22.4286 +/- 0.726449 | 22.216 +/- 0.916222 > > | 396.369x | 400.162x > > ------+----------------------+------------------------ > > run 2 | 22.5688 +/- 0.831341 | 22.4902 +/- 1.04881 > > | 393.906x | 395.283x > > > > Bug: webrtc:10480 > > Change-Id: I1fd54077a32e25e46196c8e18f003cd0ffd503e1 > > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/191703 > > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > > Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> > > Cr-Commit-Position: refs/heads/master@{#32572} > > TBR=alessiob@webrtc.org,kwiberg@webrtc.org > > Change-Id: I57a8f937ade0a35e1ccf0e229c391cc3a10e7c48 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: webrtc:10480 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192621 > Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> > Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> > Cr-Commit-Position: refs/heads/master@{#32578} TBR=alessiob@webrtc.org,kwiberg@webrtc.org # Not skipping CQ checks because this is a reland. Bug: webrtc:10480 Change-Id: I1d510697236255d8c0cca405e90781f5d8c6a3e6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/192783 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32587}
135 lines
4.3 KiB
C++
135 lines
4.3 KiB
C++
/*
|
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license
|
|
* that can be found in the LICENSE file in the root of the source
|
|
* tree. An additional intellectual property rights grant can be found
|
|
* in the file PATENTS. All contributing project authors may
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
*/
|
|
|
|
#include "modules/audio_processing/agc2/rnn_vad/test_utils.h"
|
|
|
|
#include <algorithm>
|
|
#include <memory>
|
|
|
|
#include "rtc_base/checks.h"
|
|
#include "rtc_base/numerics/safe_compare.h"
|
|
#include "rtc_base/system/arch.h"
|
|
#include "system_wrappers/include/cpu_features_wrapper.h"
|
|
#include "test/gtest.h"
|
|
#include "test/testsupport/file_utils.h"
|
|
|
|
namespace webrtc {
|
|
namespace rnn_vad {
|
|
namespace test {
|
|
namespace {
|
|
|
|
using ReaderPairType =
|
|
std::pair<std::unique_ptr<BinaryFileReader<float>>, const int>;
|
|
|
|
} // namespace
|
|
|
|
using webrtc::test::ResourcePath;
|
|
|
|
void ExpectEqualFloatArray(rtc::ArrayView<const float> expected,
|
|
rtc::ArrayView<const float> computed) {
|
|
ASSERT_EQ(expected.size(), computed.size());
|
|
for (int i = 0; rtc::SafeLt(i, expected.size()); ++i) {
|
|
SCOPED_TRACE(i);
|
|
EXPECT_FLOAT_EQ(expected[i], computed[i]);
|
|
}
|
|
}
|
|
|
|
void ExpectNearAbsolute(rtc::ArrayView<const float> expected,
|
|
rtc::ArrayView<const float> computed,
|
|
float tolerance) {
|
|
ASSERT_EQ(expected.size(), computed.size());
|
|
for (int i = 0; rtc::SafeLt(i, expected.size()); ++i) {
|
|
SCOPED_TRACE(i);
|
|
EXPECT_NEAR(expected[i], computed[i], tolerance);
|
|
}
|
|
}
|
|
|
|
std::pair<std::unique_ptr<BinaryFileReader<int16_t, float>>, const int>
|
|
CreatePcmSamplesReader(const int frame_length) {
|
|
auto ptr = std::make_unique<BinaryFileReader<int16_t, float>>(
|
|
test::ResourcePath("audio_processing/agc2/rnn_vad/samples", "pcm"),
|
|
frame_length);
|
|
// The last incomplete frame is ignored.
|
|
return {std::move(ptr), ptr->data_length() / frame_length};
|
|
}
|
|
|
|
ReaderPairType CreatePitchBuffer24kHzReader() {
|
|
constexpr int cols = 864;
|
|
auto ptr = std::make_unique<BinaryFileReader<float>>(
|
|
ResourcePath("audio_processing/agc2/rnn_vad/pitch_buf_24k", "dat"), cols);
|
|
return {std::move(ptr), rtc::CheckedDivExact(ptr->data_length(), cols)};
|
|
}
|
|
|
|
ReaderPairType CreateLpResidualAndPitchPeriodGainReader() {
|
|
constexpr int num_lp_residual_coeffs = 864;
|
|
auto ptr = std::make_unique<BinaryFileReader<float>>(
|
|
ResourcePath("audio_processing/agc2/rnn_vad/pitch_lp_res", "dat"),
|
|
num_lp_residual_coeffs);
|
|
return {std::move(ptr),
|
|
rtc::CheckedDivExact(ptr->data_length(), 2 + num_lp_residual_coeffs)};
|
|
}
|
|
|
|
ReaderPairType CreateVadProbsReader() {
|
|
auto ptr = std::make_unique<BinaryFileReader<float>>(
|
|
test::ResourcePath("audio_processing/agc2/rnn_vad/vad_prob", "dat"));
|
|
return {std::move(ptr), ptr->data_length()};
|
|
}
|
|
|
|
PitchTestData::PitchTestData() {
|
|
BinaryFileReader<float> test_data_reader(
|
|
ResourcePath("audio_processing/agc2/rnn_vad/pitch_search_int", "dat"),
|
|
1396);
|
|
test_data_reader.ReadChunk(test_data_);
|
|
// Reverse the order of the squared energy values.
|
|
// Required after the WebRTC CL 191703 which switched to forward computation.
|
|
std::reverse(test_data_.begin() + kBufSize24kHz,
|
|
test_data_.begin() + kBufSize24kHz + kNumPitchBufSquareEnergies);
|
|
}
|
|
|
|
PitchTestData::~PitchTestData() = default;
|
|
|
|
rtc::ArrayView<const float, kBufSize24kHz> PitchTestData::GetPitchBufView()
|
|
const {
|
|
return {test_data_.data(), kBufSize24kHz};
|
|
}
|
|
|
|
rtc::ArrayView<const float, kNumPitchBufSquareEnergies>
|
|
PitchTestData::GetPitchBufSquareEnergiesView() const {
|
|
return {test_data_.data() + kBufSize24kHz, kNumPitchBufSquareEnergies};
|
|
}
|
|
|
|
rtc::ArrayView<const float, kNumPitchBufAutoCorrCoeffs>
|
|
PitchTestData::GetPitchBufAutoCorrCoeffsView() const {
|
|
return {test_data_.data() + kBufSize24kHz + kNumPitchBufSquareEnergies,
|
|
kNumPitchBufAutoCorrCoeffs};
|
|
}
|
|
|
|
bool IsOptimizationAvailable(Optimization optimization) {
|
|
switch (optimization) {
|
|
case Optimization::kSse2:
|
|
#if defined(WEBRTC_ARCH_X86_FAMILY)
|
|
return GetCPUInfo(kSSE2) != 0;
|
|
#else
|
|
return false;
|
|
#endif
|
|
case Optimization::kNeon:
|
|
#if defined(WEBRTC_HAS_NEON)
|
|
return true;
|
|
#else
|
|
return false;
|
|
#endif
|
|
case Optimization::kNone:
|
|
return true;
|
|
}
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace rnn_vad
|
|
} // namespace webrtc
|