pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "modules/audio_processing/vad/pitch_internal.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 12 | |
| 13 | #include <math.h> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 15 | #include "test/gtest.h" |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 16 | |
| 17 | TEST(PitchInternalTest, test) { |
| 18 | const int kSamplingRateHz = 8000; |
| 19 | const int kNumInputParameters = 4; |
| 20 | const int kNumOutputParameters = 3; |
| 21 | // Inputs |
| 22 | double log_old_gain = log(0.5); |
| 23 | double gains[] = {0.6, 0.2, 0.5, 0.4}; |
| 24 | |
| 25 | double old_lag = 70; |
| 26 | double lags[] = {90, 111, 122, 50}; |
| 27 | |
| 28 | // Expected outputs |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 29 | double expected_log_pitch_gain[] = {-0.541212549898316, -1.45672279045507, |
| 30 | -0.80471895621705}; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 31 | double expected_log_old_gain = log(gains[kNumInputParameters - 1]); |
| 32 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 33 | double expected_pitch_lag_hz[] = {92.3076923076923, 70.9010339734121, |
| 34 | 93.0232558139535}; |
pbos@webrtc.org | 788acd1 | 2014-12-15 09:41:24 +0000 | [diff] [blame] | 35 | double expected_old_lag = lags[kNumInputParameters - 1]; |
| 36 | |
| 37 | double log_pitch_gain[kNumOutputParameters]; |
| 38 | double pitch_lag_hz[kNumInputParameters]; |
| 39 | |
| 40 | GetSubframesPitchParameters(kSamplingRateHz, gains, lags, kNumInputParameters, |
| 41 | kNumOutputParameters, &log_old_gain, &old_lag, |
| 42 | log_pitch_gain, pitch_lag_hz); |
| 43 | |
| 44 | for (int n = 0; n < 3; n++) { |
| 45 | EXPECT_NEAR(pitch_lag_hz[n], expected_pitch_lag_hz[n], 1e-6); |
| 46 | EXPECT_NEAR(log_pitch_gain[n], expected_log_pitch_gain[n], 1e-8); |
| 47 | } |
| 48 | EXPECT_NEAR(old_lag, expected_old_lag, 1e-6); |
| 49 | EXPECT_NEAR(log_old_gain, expected_log_old_gain, 1e-8); |
| 50 | } |