1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/audio_processing/agc2/rnn_vad/pitch_search.h" 12 13 #include <algorithm> 14 #include <vector> 15 16 #include "modules/audio_processing/agc2/rnn_vad/pitch_info.h" 17 #include "modules/audio_processing/agc2/rnn_vad/pitch_search_internal.h" 18 #include "modules/audio_processing/agc2/rnn_vad/test_utils.h" 19 // TODO(bugs.webrtc.org/8948): Add when the issue is fixed. 20 // #include "test/fpe_observer.h" 21 #include "test/gtest.h" 22 23 namespace webrtc { 24 namespace rnn_vad { 25 namespace test { 26 27 // Checks that the computed pitch period is bit-exact and that the computed 28 // pitch gain is within tolerance given test input data. TEST(RnnVadTest,PitchSearchWithinTolerance)29TEST(RnnVadTest, PitchSearchWithinTolerance) { 30 auto lp_residual_reader = CreateLpResidualAndPitchPeriodGainReader(); 31 const size_t num_frames = std::min(lp_residual_reader.second, 32 static_cast<size_t>(300)); // Max 3 s. 33 std::vector<float> lp_residual(kBufSize24kHz); 34 float expected_pitch_period, expected_pitch_gain; 35 PitchEstimator pitch_estimator; 36 { 37 // TODO(bugs.webrtc.org/8948): Add when the issue is fixed. 38 // FloatingPointExceptionObserver fpe_observer; 39 for (size_t i = 0; i < num_frames; ++i) { 40 SCOPED_TRACE(i); 41 lp_residual_reader.first->ReadChunk(lp_residual); 42 lp_residual_reader.first->ReadValue(&expected_pitch_period); 43 lp_residual_reader.first->ReadValue(&expected_pitch_gain); 44 PitchInfo pitch_info = 45 pitch_estimator.Estimate({lp_residual.data(), kBufSize24kHz}); 46 EXPECT_EQ(static_cast<int>(expected_pitch_period), pitch_info.period); 47 EXPECT_NEAR(expected_pitch_gain, pitch_info.gain, 1e-5f); 48 } 49 } 50 } 51 52 } // namespace test 53 } // namespace rnn_vad 54 } // namespace webrtc 55