blob: 70124f85acde225acccf0a81fb007fa1f69eaa3a [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
aluebsecf6b812015-06-25 12:28:48 -070011#include "webrtc/modules/audio_processing/vad/pitch_internal.h"
pbos@webrtc.org788acd12014-12-15 09:41:24 +000012
13#include <math.h>
14
kwiberg77eab702016-09-28 17:42:01 -070015#include "webrtc/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
aluebsecf6b812015-06-25 12:28:48 -070029 double expected_log_pitch_gain[] = {
30 -0.541212549898316, -1.45672279045507, -0.80471895621705};
pbos@webrtc.org788acd12014-12-15 09:41:24 +000031 double expected_log_old_gain = log(gains[kNumInputParameters - 1]);
32
aluebsecf6b812015-06-25 12:28:48 -070033 double expected_pitch_lag_hz[] = {
34 92.3076923076923, 70.9010339734121, 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}