pitch_internal_unittest.cc (1859B)
1 /* 2 * Copyright (c) 2012 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/vad/pitch_internal.h" 12 13 #include <cmath> 14 15 #include "test/gtest.h" 16 17 namespace webrtc { 18 19 TEST(PitchInternalTest, test) { 20 const int kSamplingRateHz = 8000; 21 const int kNumInputParameters = 4; 22 const int kNumOutputParameters = 3; 23 // Inputs 24 double log_old_gain = log(0.5); 25 double gains[] = {0.6, 0.2, 0.5, 0.4}; 26 27 double old_lag = 70; 28 double lags[] = {90, 111, 122, 50}; 29 30 // Expected outputs 31 double expected_log_pitch_gain[] = {-0.541212549898316, -1.45672279045507, 32 -0.80471895621705}; 33 double expected_log_old_gain = log(gains[kNumInputParameters - 1]); 34 35 double expected_pitch_lag_hz[] = {92.3076923076923, 70.9010339734121, 36 93.0232558139535}; 37 double expected_old_lag = lags[kNumInputParameters - 1]; 38 39 double log_pitch_gain[kNumOutputParameters]; 40 double pitch_lag_hz[kNumInputParameters]; 41 42 GetSubframesPitchParameters(kSamplingRateHz, gains, lags, kNumInputParameters, 43 kNumOutputParameters, &log_old_gain, &old_lag, 44 log_pitch_gain, pitch_lag_hz); 45 46 for (int n = 0; n < 3; n++) { 47 EXPECT_NEAR(pitch_lag_hz[n], expected_pitch_lag_hz[n], 1e-6); 48 EXPECT_NEAR(log_pitch_gain[n], expected_log_pitch_gain[n], 1e-8); 49 } 50 EXPECT_NEAR(old_lag, expected_old_lag, 1e-6); 51 EXPECT_NEAR(log_old_gain, expected_log_old_gain, 1e-8); 52 } 53 54 } // namespace webrtc