Functions to estimate the inverse filter via LPC and compute the LP residual applying the inverse filter. This CL also includes test utilities, in particular BinaryFileReader, used to read chunks of data and optionally cast them on the fly, and Create*Reader() functions to read resource files available at test time. Bug: webrtc:9076 Change-Id: Ia4793b8ad6a63cb3089ed11ddad89d1aa0b840f6 Reviewed-on: https://webrtc-review.googlesource.com/70244 Commit-Queue: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Jesus de Vicente Pena <devicentepena@webrtc.org> Reviewed-by: Alex Loiko <aleloi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#22946}
56 lines
1.8 KiB
C++
56 lines
1.8 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 "rtc_base/checks.h"
|
|
#include "rtc_base/ptr_util.h"
|
|
#include "test/gtest.h"
|
|
#include "test/testsupport/fileutils.h"
|
|
|
|
namespace webrtc {
|
|
namespace test {
|
|
namespace {
|
|
|
|
using ReaderPairType =
|
|
std::pair<std::unique_ptr<BinaryFileReader<float>>, const size_t>;
|
|
|
|
} // namespace
|
|
|
|
void ExpectNearAbsolute(rtc::ArrayView<const float> expected,
|
|
rtc::ArrayView<const float> computed,
|
|
const float tolerance) {
|
|
ASSERT_EQ(expected.size(), computed.size());
|
|
for (size_t i = 0; i < expected.size(); ++i) {
|
|
SCOPED_TRACE(i);
|
|
EXPECT_NEAR(expected[i], computed[i], tolerance);
|
|
}
|
|
}
|
|
|
|
ReaderPairType CreatePitchBuffer24kHzReader() {
|
|
auto ptr = rtc::MakeUnique<BinaryFileReader<float>>(
|
|
test::ResourcePath("audio_processing/agc2/rnn_vad/pitch_buf_24k", "dat"),
|
|
864);
|
|
return {std::move(ptr),
|
|
rtc::CheckedDivExact(ptr->data_length(), static_cast<size_t>(864))};
|
|
}
|
|
|
|
ReaderPairType CreateLpResidualAndPitchPeriodGainReader() {
|
|
constexpr size_t num_lp_residual_coeffs = 864;
|
|
auto ptr = rtc::MakeUnique<BinaryFileReader<float>>(
|
|
test::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)};
|
|
}
|
|
|
|
} // namespace test
|
|
} // namespace webrtc
|