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/cpu_features.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 26 // Checks that the computed pitch period is bit-exact and that the computed 27 // pitch gain is within tolerance given test input data. TEST(RnnVadTest,PitchSearchWithinTolerance)28TEST(RnnVadTest, PitchSearchWithinTolerance) { 29 ChunksFileReader reader = CreateLpResidualAndPitchInfoReader(); 30 const int num_frames = std::min(reader.num_chunks, 300); // Max 3 s. 31 std::vector<float> lp_residual(kBufSize24kHz); 32 float expected_pitch_period, expected_pitch_strength; 33 const AvailableCpuFeatures cpu_features = GetAvailableCpuFeatures(); 34 PitchEstimator pitch_estimator(cpu_features); 35 { 36 // TODO(bugs.webrtc.org/8948): Add when the issue is fixed. 37 // FloatingPointExceptionObserver fpe_observer; 38 for (int i = 0; i < num_frames; ++i) { 39 SCOPED_TRACE(i); 40 ASSERT_TRUE(reader.reader->ReadChunk(lp_residual)); 41 ASSERT_TRUE(reader.reader->ReadValue(expected_pitch_period)); 42 ASSERT_TRUE(reader.reader->ReadValue(expected_pitch_strength)); 43 int pitch_period = 44 pitch_estimator.Estimate({lp_residual.data(), kBufSize24kHz}); 45 EXPECT_EQ(expected_pitch_period, pitch_period); 46 EXPECT_NEAR(expected_pitch_strength, 47 pitch_estimator.GetLastPitchStrengthForTesting(), 15e-6f); 48 } 49 } 50 } 51 52 } // namespace rnn_vad 53 } // namespace webrtc 54