OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/common_audio/vad/vad_unittest.h" | 11 #include "webrtc/common_audio/vad/vad_unittest.h" |
12 | 12 |
13 #include <stdlib.h> | 13 #include <stdlib.h> |
14 | 14 |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 #include "webrtc/base/arraysize.h" | 17 #include "webrtc/base/arraysize.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" | 19 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar
y.h" |
20 #include "webrtc/common_audio/vad/include/webrtc_vad.h" | 20 #include "webrtc/common_audio/vad/include/webrtc_vad.h" |
21 #include "webrtc/typedefs.h" | 21 #include "webrtc/typedefs.h" |
22 | 22 |
23 VadTest::VadTest() {} | 23 VadTest::VadTest() {} |
24 | 24 |
25 void VadTest::SetUp() {} | 25 void VadTest::SetUp() {} |
26 | 26 |
27 void VadTest::TearDown() {} | 27 void VadTest::TearDown() {} |
28 | 28 |
29 // Returns true if the rate and frame length combination is valid. | 29 // Returns true if the rate and frame length combination is valid. |
30 bool VadTest::ValidRatesAndFrameLengths(int rate, int frame_length) { | 30 bool VadTest::ValidRatesAndFrameLengths(int rate, size_t frame_length) { |
31 if (rate == 8000) { | 31 if (rate == 8000) { |
32 if (frame_length == 80 || frame_length == 160 || frame_length == 240) { | 32 if (frame_length == 80 || frame_length == 160 || frame_length == 240) { |
33 return true; | 33 return true; |
34 } | 34 } |
35 return false; | 35 return false; |
36 } else if (rate == 16000) { | 36 } else if (rate == 16000) { |
37 if (frame_length == 160 || frame_length == 320 || frame_length == 480) { | 37 if (frame_length == 160 || frame_length == 320 || frame_length == 480) { |
38 return true; | 38 return true; |
39 } | 39 } |
40 return false; | 40 return false; |
(...skipping 17 matching lines...) Expand all Loading... |
58 TEST_F(VadTest, ApiTest) { | 58 TEST_F(VadTest, ApiTest) { |
59 // This API test runs through the APIs for all possible valid and invalid | 59 // This API test runs through the APIs for all possible valid and invalid |
60 // combinations. | 60 // combinations. |
61 | 61 |
62 VadInst* handle = WebRtcVad_Create(); | 62 VadInst* handle = WebRtcVad_Create(); |
63 int16_t zeros[kMaxFrameLength] = { 0 }; | 63 int16_t zeros[kMaxFrameLength] = { 0 }; |
64 | 64 |
65 // Construct a speech signal that will trigger the VAD in all modes. It is | 65 // Construct a speech signal that will trigger the VAD in all modes. It is |
66 // known that (i * i) will wrap around, but that doesn't matter in this case. | 66 // known that (i * i) will wrap around, but that doesn't matter in this case. |
67 int16_t speech[kMaxFrameLength]; | 67 int16_t speech[kMaxFrameLength]; |
68 for (int16_t i = 0; i < kMaxFrameLength; i++) { | 68 for (size_t i = 0; i < kMaxFrameLength; i++) { |
69 speech[i] = static_cast<int16_t>(i * i); | 69 speech[i] = static_cast<int16_t>(i * i); |
70 } | 70 } |
71 | 71 |
72 // nullptr instance tests | 72 // nullptr instance tests |
73 EXPECT_EQ(-1, WebRtcVad_Init(nullptr)); | 73 EXPECT_EQ(-1, WebRtcVad_Init(nullptr)); |
74 EXPECT_EQ(-1, WebRtcVad_set_mode(nullptr, kModes[0])); | 74 EXPECT_EQ(-1, WebRtcVad_set_mode(nullptr, kModes[0])); |
75 EXPECT_EQ(-1, | 75 EXPECT_EQ(-1, |
76 WebRtcVad_Process(nullptr, kRates[0], speech, kFrameLengths[0])); | 76 WebRtcVad_Process(nullptr, kRates[0], speech, kFrameLengths[0])); |
77 | 77 |
78 // WebRtcVad_Create() | 78 // WebRtcVad_Create() |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 127 } |
128 | 128 |
129 TEST_F(VadTest, ValidRatesFrameLengths) { | 129 TEST_F(VadTest, ValidRatesFrameLengths) { |
130 // This test verifies valid and invalid rate/frame_length combinations. We | 130 // This test verifies valid and invalid rate/frame_length combinations. We |
131 // loop through some sampling rates and frame lengths from negative values to | 131 // loop through some sampling rates and frame lengths from negative values to |
132 // values larger than possible. | 132 // values larger than possible. |
133 const int kRates[] = { | 133 const int kRates[] = { |
134 -8000, -4000, 0, 4000, 8000, 8001, 15999, 16000, 32000, 48000, 48001, 96000 | 134 -8000, -4000, 0, 4000, 8000, 8001, 15999, 16000, 32000, 48000, 48001, 96000 |
135 }; | 135 }; |
136 | 136 |
137 const int kFrameLengths[] = { | 137 const size_t kFrameLengths[] = { |
138 -10, 0, 80, 81, 159, 160, 240, 320, 480, 640, 960, 1440, 2000 | 138 0, 80, 81, 159, 160, 240, 320, 480, 640, 960, 1440, 2000 |
139 }; | 139 }; |
140 | 140 |
141 for (size_t i = 0; i < arraysize(kRates); i++) { | 141 for (size_t i = 0; i < arraysize(kRates); i++) { |
142 for (size_t j = 0; j < arraysize(kFrameLengths); j++) { | 142 for (size_t j = 0; j < arraysize(kFrameLengths); j++) { |
143 if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) { | 143 if (ValidRatesAndFrameLengths(kRates[i], kFrameLengths[j])) { |
144 EXPECT_EQ(0, WebRtcVad_ValidRateAndFrameLength(kRates[i], | 144 EXPECT_EQ(0, WebRtcVad_ValidRateAndFrameLength(kRates[i], |
145 kFrameLengths[j])); | 145 kFrameLengths[j])); |
146 } else { | 146 } else { |
147 EXPECT_EQ(-1, WebRtcVad_ValidRateAndFrameLength(kRates[i], | 147 EXPECT_EQ(-1, WebRtcVad_ValidRateAndFrameLength(kRates[i], |
148 kFrameLengths[j])); | 148 kFrameLengths[j])); |
149 } | 149 } |
150 } | 150 } |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 // TODO(bjornv): Add a process test, run on file. | 154 // TODO(bjornv): Add a process test, run on file. |
155 | 155 |
156 } // namespace | 156 } // namespace |
OLD | NEW |