Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: webrtc/common_audio/vad/vad_sp_unittest.cc

Issue 1227203003: Update audio code to use size_t more correctly, webrtc/common_audio/ portion. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/common_audio/vad/vad_sp.c ('k') | webrtc/common_audio/vad/vad_unittest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdlib.h> 11 #include <stdlib.h>
12 12
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/common_audio/vad/vad_unittest.h" 14 #include "webrtc/common_audio/vad/vad_unittest.h"
15 #include "webrtc/typedefs.h" 15 #include "webrtc/typedefs.h"
16 16
17 extern "C" { 17 extern "C" {
18 #include "webrtc/common_audio/vad/vad_core.h" 18 #include "webrtc/common_audio/vad/vad_core.h"
19 #include "webrtc/common_audio/vad/vad_sp.h" 19 #include "webrtc/common_audio/vad/vad_sp.h"
20 } 20 }
21 21
22 namespace { 22 namespace {
23 23
24 TEST_F(VadTest, vad_sp) { 24 TEST_F(VadTest, vad_sp) {
25 VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT))); 25 VadInstT* self = reinterpret_cast<VadInstT*>(malloc(sizeof(VadInstT)));
26 const int kMaxFrameLenSp = 960; // Maximum frame length in this unittest. 26 const size_t kMaxFrameLenSp = 960; // Maximum frame length in this unittest.
27 int16_t zeros[kMaxFrameLenSp] = { 0 }; 27 int16_t zeros[kMaxFrameLenSp] = { 0 };
28 int32_t state[2] = { 0 }; 28 int32_t state[2] = { 0 };
29 int16_t data_in[kMaxFrameLenSp]; 29 int16_t data_in[kMaxFrameLenSp];
30 int16_t data_out[kMaxFrameLenSp]; 30 int16_t data_out[kMaxFrameLenSp];
31 31
32 // We expect the first value to be 1600 as long as |frame_counter| is zero, 32 // We expect the first value to be 1600 as long as |frame_counter| is zero,
33 // which is true for the first iteration. 33 // which is true for the first iteration.
34 static const int16_t kReferenceMin[32] = { 34 static const int16_t kReferenceMin[32] = {
35 1600, 720, 509, 512, 532, 552, 570, 588, 35 1600, 720, 509, 512, 532, 552, 570, 588,
36 606, 624, 642, 659, 675, 691, 707, 723, 36 606, 624, 642, 659, 675, 691, 707, 723,
37 1600, 544, 502, 522, 542, 561, 579, 597, 37 1600, 544, 502, 522, 542, 561, 579, 597,
38 615, 633, 651, 667, 683, 699, 715, 731 38 615, 633, 651, 667, 683, 699, 715, 731
39 }; 39 };
40 40
41 // Construct a speech signal that will trigger the VAD in all modes. It is 41 // Construct a speech signal that will trigger the VAD in all modes. It is
42 // known that (i * i) will wrap around, but that doesn't matter in this case. 42 // known that (i * i) will wrap around, but that doesn't matter in this case.
43 for (int16_t i = 0; i < kMaxFrameLenSp; ++i) { 43 for (size_t i = 0; i < kMaxFrameLenSp; ++i) {
44 data_in[i] = static_cast<int16_t>(i * i); 44 data_in[i] = static_cast<int16_t>(i * i);
45 } 45 }
46 // Input values all zeros, expect all zeros out. 46 // Input values all zeros, expect all zeros out.
47 WebRtcVad_Downsampling(zeros, data_out, state, kMaxFrameLenSp); 47 WebRtcVad_Downsampling(zeros, data_out, state, kMaxFrameLenSp);
48 EXPECT_EQ(0, state[0]); 48 EXPECT_EQ(0, state[0]);
49 EXPECT_EQ(0, state[1]); 49 EXPECT_EQ(0, state[1]);
50 for (int16_t i = 0; i < kMaxFrameLenSp / 2; ++i) { 50 for (size_t i = 0; i < kMaxFrameLenSp / 2; ++i) {
51 EXPECT_EQ(0, data_out[i]); 51 EXPECT_EQ(0, data_out[i]);
52 } 52 }
53 // Make a simple non-zero data test. 53 // Make a simple non-zero data test.
54 WebRtcVad_Downsampling(data_in, data_out, state, kMaxFrameLenSp); 54 WebRtcVad_Downsampling(data_in, data_out, state, kMaxFrameLenSp);
55 EXPECT_EQ(207, state[0]); 55 EXPECT_EQ(207, state[0]);
56 EXPECT_EQ(2270, state[1]); 56 EXPECT_EQ(2270, state[1]);
57 57
58 ASSERT_EQ(0, WebRtcVad_InitCore(self)); 58 ASSERT_EQ(0, WebRtcVad_InitCore(self));
59 // TODO(bjornv): Replace this part of the test with taking values from an 59 // TODO(bjornv): Replace this part of the test with taking values from an
60 // array and calculate the reference value here. Make sure the values are not 60 // array and calculate the reference value here. Make sure the values are not
61 // ordered. 61 // ordered.
62 for (int16_t i = 0; i < 16; ++i) { 62 for (int16_t i = 0; i < 16; ++i) {
63 int16_t value = 500 * (i + 1); 63 int16_t value = 500 * (i + 1);
64 for (int j = 0; j < kNumChannels; ++j) { 64 for (int j = 0; j < kNumChannels; ++j) {
65 // Use values both above and below initialized value. 65 // Use values both above and below initialized value.
66 EXPECT_EQ(kReferenceMin[i], WebRtcVad_FindMinimum(self, value, j)); 66 EXPECT_EQ(kReferenceMin[i], WebRtcVad_FindMinimum(self, value, j));
67 EXPECT_EQ(kReferenceMin[i + 16], WebRtcVad_FindMinimum(self, 12000, j)); 67 EXPECT_EQ(kReferenceMin[i + 16], WebRtcVad_FindMinimum(self, 12000, j));
68 } 68 }
69 self->frame_counter++; 69 self->frame_counter++;
70 } 70 }
71 71
72 free(self); 72 free(self);
73 } 73 }
74 } // namespace 74 } // namespace
OLDNEW
« no previous file with comments | « webrtc/common_audio/vad/vad_sp.c ('k') | webrtc/common_audio/vad/vad_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698