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

Side by Side Diff: webrtc/modules/audio_processing/test/audio_processing_unittest.cc

Issue 1227213002: Update audio code to use size_t more correctly, webrtc/modules/audio_processing/ (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
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
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 117 }
118 } 118 }
119 119
120 void VerifyChannelsAreEqual(int16_t* stereo, int samples_per_channel) { 120 void VerifyChannelsAreEqual(int16_t* stereo, int samples_per_channel) {
121 for (int i = 0; i < samples_per_channel; i++) { 121 for (int i = 0; i < samples_per_channel; i++) {
122 EXPECT_EQ(stereo[i * 2 + 1], stereo[i * 2]); 122 EXPECT_EQ(stereo[i * 2 + 1], stereo[i * 2]);
123 } 123 }
124 } 124 }
125 125
126 void SetFrameTo(AudioFrame* frame, int16_t value) { 126 void SetFrameTo(AudioFrame* frame, int16_t value) {
127 for (int i = 0; i < frame->samples_per_channel_ * frame->num_channels_; ++i) { 127 for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_;
128 ++i) {
128 frame->data_[i] = value; 129 frame->data_[i] = value;
129 } 130 }
130 } 131 }
131 132
132 void SetFrameTo(AudioFrame* frame, int16_t left, int16_t right) { 133 void SetFrameTo(AudioFrame* frame, int16_t left, int16_t right) {
133 ASSERT_EQ(2, frame->num_channels_); 134 ASSERT_EQ(2, frame->num_channels_);
134 for (int i = 0; i < frame->samples_per_channel_ * 2; i += 2) { 135 for (size_t i = 0; i < frame->samples_per_channel_ * 2; i += 2) {
135 frame->data_[i] = left; 136 frame->data_[i] = left;
136 frame->data_[i + 1] = right; 137 frame->data_[i + 1] = right;
137 } 138 }
138 } 139 }
139 140
140 void ScaleFrame(AudioFrame* frame, float scale) { 141 void ScaleFrame(AudioFrame* frame, float scale) {
141 for (int i = 0; i < frame->samples_per_channel_ * frame->num_channels_; ++i) { 142 for (size_t i = 0; i < frame->samples_per_channel_ * frame->num_channels_;
143 ++i) {
142 frame->data_[i] = FloatS16ToS16(frame->data_[i] * scale); 144 frame->data_[i] = FloatS16ToS16(frame->data_[i] * scale);
143 } 145 }
144 } 146 }
145 147
146 bool FrameDataAreEqual(const AudioFrame& frame1, const AudioFrame& frame2) { 148 bool FrameDataAreEqual(const AudioFrame& frame1, const AudioFrame& frame2) {
147 if (frame1.samples_per_channel_ != frame2.samples_per_channel_) { 149 if (frame1.samples_per_channel_ != frame2.samples_per_channel_) {
148 return false; 150 return false;
149 } 151 }
150 if (frame1.num_channels_ != frame2.num_channels_) { 152 if (frame1.num_channels_ != frame2.num_channels_) {
151 return false; 153 return false;
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 } 656 }
655 657
656 rewind(near_file_); 658 rewind(near_file_);
657 while (!frame_queue.empty()) { 659 while (!frame_queue.empty()) {
658 AudioFrame* frame = frame_queue.front(); 660 AudioFrame* frame = frame_queue.front();
659 frame_queue.pop(); 661 frame_queue.pop();
660 delete frame; 662 delete frame;
661 } 663 }
662 // Calculate expected delay estimate and acceptable regions. Further, 664 // Calculate expected delay estimate and acceptable regions. Further,
663 // limit them w.r.t. AEC delay estimation support. 665 // limit them w.r.t. AEC delay estimation support.
664 const int samples_per_ms = std::min(16, frame_->samples_per_channel_ / 10); 666 const size_t samples_per_ms =
667 std::min(static_cast<size_t>(16), frame_->samples_per_channel_ / 10);
665 int expected_median = std::min(std::max(delay_ms - system_delay_ms, 668 int expected_median = std::min(std::max(delay_ms - system_delay_ms,
666 delay_min), delay_max); 669 delay_min), delay_max);
667 int expected_median_high = std::min(std::max( 670 int expected_median_high = std::min(
668 expected_median + 96 / samples_per_ms, delay_min), delay_max); 671 std::max(expected_median + static_cast<int>(96 / samples_per_ms),
669 int expected_median_low = std::min(std::max( 672 delay_min),
670 expected_median - 96 / samples_per_ms, delay_min), delay_max); 673 delay_max);
674 int expected_median_low = std::min(
675 std::max(expected_median - static_cast<int>(96 / samples_per_ms),
676 delay_min),
677 delay_max);
671 // Verify delay metrics. 678 // Verify delay metrics.
672 int median; 679 int median;
673 int std; 680 int std;
674 float poor_fraction; 681 float poor_fraction;
675 EXPECT_EQ(apm_->kNoError, 682 EXPECT_EQ(apm_->kNoError,
676 apm_->echo_cancellation()->GetDelayMetrics(&median, &std, 683 apm_->echo_cancellation()->GetDelayMetrics(&median, &std,
677 &poor_fraction)); 684 &poor_fraction));
678 EXPECT_GE(expected_median_high, median); 685 EXPECT_GE(expected_median_high, median);
679 EXPECT_LE(expected_median_low, median); 686 EXPECT_LE(expected_median_low, median);
680 } 687 }
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 // sampling frequency dependent. 980 // sampling frequency dependent.
974 for (size_t i = 0; i < kProcessSampleRatesSize; i++) { 981 for (size_t i = 0; i < kProcessSampleRatesSize; i++) {
975 Init(kProcessSampleRates[i], 982 Init(kProcessSampleRates[i],
976 kProcessSampleRates[i], 983 kProcessSampleRates[i],
977 kProcessSampleRates[i], 984 kProcessSampleRates[i],
978 2, 985 2,
979 2, 986 2,
980 2, 987 2,
981 false); 988 false);
982 // Sampling frequency dependent variables. 989 // Sampling frequency dependent variables.
983 const int num_ms_per_block = std::max(4, 990 const int num_ms_per_block =
984 640 / frame_->samples_per_channel_); 991 std::max(4, static_cast<int>(640 / frame_->samples_per_channel_));
985 const int delay_min_ms = -kLookaheadBlocks * num_ms_per_block; 992 const int delay_min_ms = -kLookaheadBlocks * num_ms_per_block;
986 const int delay_max_ms = (kMaxDelayBlocks - 1) * num_ms_per_block; 993 const int delay_max_ms = (kMaxDelayBlocks - 1) * num_ms_per_block;
987 994
988 // 1) Verify correct delay estimate at lookahead boundary. 995 // 1) Verify correct delay estimate at lookahead boundary.
989 int delay_ms = TruncateToMultipleOf10(kSystemDelayMs + delay_min_ms); 996 int delay_ms = TruncateToMultipleOf10(kSystemDelayMs + delay_min_ms);
990 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms, 997 ProcessDelayVerificationTest(delay_ms, kSystemDelayMs, delay_min_ms,
991 delay_max_ms); 998 delay_max_ms);
992 // 2) A delay less than maximum lookahead should give an delay estimate at 999 // 2) A delay less than maximum lookahead should give an delay estimate at
993 // the boundary (= -kLookaheadBlocks * num_ms_per_block). 1000 // the boundary (= -kLookaheadBlocks * num_ms_per_block).
994 delay_ms -= 20; 1001 delay_ms -= 20;
(...skipping 1679 matching lines...) Expand 10 before | Expand all | Expand 10 after
2674 std::tr1::make_tuple(16000, 16000, 32000, 40), 2681 std::tr1::make_tuple(16000, 16000, 32000, 40),
2675 std::tr1::make_tuple(16000, 16000, 16000, 0))); 2682 std::tr1::make_tuple(16000, 16000, 16000, 0)));
2676 #endif 2683 #endif
2677 2684
2678 // TODO(henrike): re-implement functionality lost when removing the old main 2685 // TODO(henrike): re-implement functionality lost when removing the old main
2679 // function. See 2686 // function. See
2680 // https://code.google.com/p/webrtc/issues/detail?id=1981 2687 // https://code.google.com/p/webrtc/issues/detail?id=1981
2681 2688
2682 } // namespace 2689 } // namespace
2683 } // namespace webrtc 2690 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/splitting_filter_unittest.cc ('k') | webrtc/modules/audio_processing/three_band_filter_bank.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698