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

Side by Side Diff: webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer_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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 {0.055556f, 0.f}, 50 {0.055556f, 0.f},
51 {0.055556f, 0.2f}, 51 {0.055556f, 0.2f},
52 {0, 0.2f}, 52 {0, 0.2f},
53 {0, 0.2f}, 53 {0, 0.2f},
54 {0, 0.2f}, 54 {0, 0.2f},
55 {0, 0.2f}}; 55 {0, 0.2f}};
56 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestFilterBank), 56 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestFilterBank),
57 "Test filterbank badly initialized."); 57 "Test filterbank badly initialized.");
58 58
59 // Target output for gain solving test. Generated with matlab. 59 // Target output for gain solving test. Generated with matlab.
60 const int kTestStartFreq = 12; // Lowest integral frequency for ERBs. 60 const size_t kTestStartFreq = 12; // Lowest integral frequency for ERBs.
61 const float kTestZeroVar[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 61 const float kTestZeroVar[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f,
62 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f, 62 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f,
63 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; 63 0.f, 0.f, 0.f, 0.f, 0.f, 0.f};
64 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestZeroVar), 64 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestZeroVar),
65 "Variance test data badly initialized."); 65 "Variance test data badly initialized.");
66 const float kTestNonZeroVarLambdaTop[] = { 66 const float kTestNonZeroVarLambdaTop[] = {
67 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 67 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f,
68 1.f, 1.f, 1.f, 0.f, 0.f, 0.0351f, 0.0636f, 0.0863f, 68 1.f, 1.f, 1.f, 0.f, 0.f, 0.0351f, 0.0636f, 0.0863f,
69 0.1037f, 0.1162f, 0.1236f, 0.1251f, 0.1189f, 0.0993f}; 69 0.1037f, 0.1162f, 0.1236f, 0.1251f, 0.1189f, 0.0993f};
70 static_assert(arraysize(kTestCenterFreqs) == 70 static_assert(arraysize(kTestCenterFreqs) ==
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 154 }
155 for (auto step_type : step_types) { 155 for (auto step_type : step_types) {
156 std::generate(clear_data_.begin(), clear_data_.end(), float_rand); 156 std::generate(clear_data_.begin(), clear_data_.end(), float_rand);
157 orig_data_ = clear_data_; 157 orig_data_ = clear_data_;
158 EXPECT_TRUE(CheckUpdate(step_type)); 158 EXPECT_TRUE(CheckUpdate(step_type));
159 } 159 }
160 } 160 }
161 161
162 // Tests ERB bank creation, comparing against matlab output. 162 // Tests ERB bank creation, comparing against matlab output.
163 TEST_F(IntelligibilityEnhancerTest, TestErbCreation) { 163 TEST_F(IntelligibilityEnhancerTest, TestErbCreation) {
164 ASSERT_EQ(static_cast<int>(arraysize(kTestCenterFreqs)), enh_.bank_size_); 164 ASSERT_EQ(arraysize(kTestCenterFreqs), enh_.bank_size_);
165 for (int i = 0; i < enh_.bank_size_; ++i) { 165 for (size_t i = 0; i < enh_.bank_size_; ++i) {
166 EXPECT_NEAR(kTestCenterFreqs[i], enh_.center_freqs_[i], kMaxTestError); 166 EXPECT_NEAR(kTestCenterFreqs[i], enh_.center_freqs_[i], kMaxTestError);
167 ASSERT_EQ(static_cast<int>(arraysize(kTestFilterBank[0])), enh_.freqs_); 167 ASSERT_EQ(arraysize(kTestFilterBank[0]), enh_.freqs_);
168 for (int j = 0; j < enh_.freqs_; ++j) { 168 for (size_t j = 0; j < enh_.freqs_; ++j) {
169 EXPECT_NEAR(kTestFilterBank[i][j], enh_.filter_bank_[i][j], 169 EXPECT_NEAR(kTestFilterBank[i][j], enh_.filter_bank_[i][j],
170 kMaxTestError); 170 kMaxTestError);
171 } 171 }
172 } 172 }
173 } 173 }
174 174
175 // Tests analytic solution for optimal gains, comparing 175 // Tests analytic solution for optimal gains, comparing
176 // against matlab output. 176 // against matlab output.
177 TEST_F(IntelligibilityEnhancerTest, TestSolveForGains) { 177 TEST_F(IntelligibilityEnhancerTest, TestSolveForGains) {
178 ASSERT_EQ(kTestStartFreq, enh_.start_freq_); 178 ASSERT_EQ(kTestStartFreq, enh_.start_freq_);
179 vector<float> sols(enh_.bank_size_); 179 vector<float> sols(enh_.bank_size_);
180 float lambda = -0.001f; 180 float lambda = -0.001f;
181 for (int i = 0; i < enh_.bank_size_; i++) { 181 for (size_t i = 0; i < enh_.bank_size_; i++) {
182 enh_.filtered_clear_var_[i] = 0.0f; 182 enh_.filtered_clear_var_[i] = 0.0f;
183 enh_.filtered_noise_var_[i] = 0.0f; 183 enh_.filtered_noise_var_[i] = 0.0f;
184 enh_.rho_[i] = 0.02f; 184 enh_.rho_[i] = 0.02f;
185 } 185 }
186 enh_.SolveForGainsGivenLambda(lambda, enh_.start_freq_, &sols[0]); 186 enh_.SolveForGainsGivenLambda(lambda, enh_.start_freq_, &sols[0]);
187 for (int i = 0; i < enh_.bank_size_; i++) { 187 for (size_t i = 0; i < enh_.bank_size_; i++) {
188 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError); 188 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError);
189 } 189 }
190 for (int i = 0; i < enh_.bank_size_; i++) { 190 for (size_t i = 0; i < enh_.bank_size_; i++) {
191 enh_.filtered_clear_var_[i] = static_cast<float>(i + 1); 191 enh_.filtered_clear_var_[i] = static_cast<float>(i + 1);
192 enh_.filtered_noise_var_[i] = static_cast<float>(enh_.bank_size_ - i); 192 enh_.filtered_noise_var_[i] = static_cast<float>(enh_.bank_size_ - i);
193 } 193 }
194 enh_.SolveForGainsGivenLambda(lambda, enh_.start_freq_, &sols[0]); 194 enh_.SolveForGainsGivenLambda(lambda, enh_.start_freq_, &sols[0]);
195 for (int i = 0; i < enh_.bank_size_; i++) { 195 for (size_t i = 0; i < enh_.bank_size_; i++) {
196 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); 196 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError);
197 } 197 }
198 lambda = -1.0; 198 lambda = -1.0;
199 enh_.SolveForGainsGivenLambda(lambda, enh_.start_freq_, &sols[0]); 199 enh_.SolveForGainsGivenLambda(lambda, enh_.start_freq_, &sols[0]);
200 for (int i = 0; i < enh_.bank_size_; i++) { 200 for (size_t i = 0; i < enh_.bank_size_; i++) {
201 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError); 201 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError);
202 } 202 }
203 } 203 }
204 204
205 } // namespace webrtc 205 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698