blob: 19c2e1a2711d252aa55008d8f28583401d49d0e2 [file] [log] [blame]
pbos@webrtc.org788acd12014-12-15 09:41:24 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "modules/audio_processing/vad/pitch_internal.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000012
13#include <math.h>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "test/gtest.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000016
17TEST(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 Gerey665174f2018-06-19 15:03:05 +020029 double expected_log_pitch_gain[] = {-0.541212549898316, -1.45672279045507,
30 -0.80471895621705};
pbos@webrtc.org788acd12014-12-15 09:41:24 +000031 double expected_log_old_gain = log(gains[kNumInputParameters - 1]);
32
Yves Gerey665174f2018-06-19 15:03:05 +020033 double expected_pitch_lag_hz[] = {92.3076923076923, 70.9010339734121,
34 93.0232558139535};
pbos@webrtc.org788acd12014-12-15 09:41:24 +000035 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}