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

Side by Side Diff: webrtc/modules/audio_processing/intelligibility/intelligibility_enhancer_unittest.cc

Issue 1693823004: Use VAD to get a better speech power estimation in the IntelligibilityEnhancer (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@pow
Patch Set: Make gain change limit relative Created 4 years, 10 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
11 //
12 // Unit tests for intelligibility enhancer.
13 //
14
15 #include <math.h> 11 #include <math.h>
16 #include <stdlib.h> 12 #include <stdlib.h>
17 #include <algorithm> 13 #include <algorithm>
18 #include <vector> 14 #include <vector>
19 15
20 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
21 #include "webrtc/base/arraysize.h" 17 #include "webrtc/base/arraysize.h"
22 #include "webrtc/base/scoped_ptr.h" 18 #include "webrtc/base/scoped_ptr.h"
23 #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"
24 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc er.h" 20 #include "webrtc/modules/audio_processing/intelligibility/intelligibility_enhanc er.h"
25 21
26 namespace webrtc { 22 namespace webrtc {
27 23
28 namespace { 24 namespace {
29 25
30 // Target output for ERB create test. Generated with matlab. 26 // Target output for ERB create test. Generated with matlab.
31 const float kTestCenterFreqs[] = { 27 const float kTestCenterFreqs[] = {
32 13.169f, 26.965f, 41.423f, 56.577f, 72.461f, 89.113f, 106.57f, 124.88f, 28 14.5213f, 29.735f, 45.6781f, 62.3884f, 79.9058f, 98.2691f, 117.521f,
33 144.08f, 164.21f, 185.34f, 207.5f, 230.75f, 255.16f, 280.77f, 307.66f, 29 137.708f, 158.879f, 181.084f, 204.378f, 228.816f, 254.459f, 281.371f,
34 335.9f, 365.56f, 396.71f, 429.44f, 463.84f, 500.f}; 30 309.618f, 339.273f, 370.411f, 403.115f, 437.469f, 473.564f, 511.497f,
35 const float kTestFilterBank[][2] = {{0.055556f, 0.f}, 31 551.371f, 593.293f, 637.386f, 683.77f, 732.581f, 783.96f, 838.06f,
36 {0.055556f, 0.f}, 32 895.046f, 955.09f, 1018.38f, 1085.13f, 1155.54f, 1229.85f, 1308.32f,
37 {0.055556f, 0.f}, 33 1391.22f, 1478.83f, 1571.5f, 1669.55f, 1773.37f, 1883.37f, 2000.f};
38 {0.055556f, 0.f}, 34 const float kTestFilterBank[][33] = {
39 {0.055556f, 0.f}, 35 {0.2f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
40 {0.055556f, 0.f}, 36 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
41 {0.055556f, 0.f}, 37 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
42 {0.055556f, 0.f}, 38 {0.2f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
43 {0.055556f, 0.f}, 39 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
44 {0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f, 0.f, 0.f, 0.f},
107 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
108 0.f, 0.285714f, 0.315789f, 0.222222f, 0.111111f, 0.f, 0.f, 0.f, 0.f,
109 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
110 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
111 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
112 0.f, 0.f, 0.315789f, 0.333333f, 0.222222f, 0.111111f, 0.f, 0.f, 0.f,
113 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
114 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
115 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
116 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f, 0.111111f, 0.f, 0.f,
117 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
118 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
119 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
120 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f, 0.111111f, 0.f,
121 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
122 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
123 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
124 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f, 0.111111f,
125 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
126 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
127 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
128 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f, 0.222222f,
129 0.108108f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
130 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
131 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
132 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.333333f,
133 0.243243f, 0.153846f, 0.0833333f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
134 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
135 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
136 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.333333f,
137 0.324324f, 0.230769f, 0.166667f, 0.0909091f, 0.f, 0.f, 0.f, 0.f, 0.f,
138 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
139 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
140 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
141 0.324324f, 0.307692f, 0.25f, 0.181818f, 0.0833333f, 0.f, 0.f, 0.f, 0.f,
142 0.f, 0.f, 0.f, 0.f, 0.f, 0.f},
143 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
144 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
145 0.f, 0.f, 0.f, 0.f, 0.f, 0.307692f, 0.333333f,
146 0.363636f, 0.25f, 0.151515f, 0.0793651f, 0.f, 0.f, 0.f,
147 0.f, 0.f, 0.f, 0.f, 0.f},
148 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
149 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
150 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
151 0.f, 0.f, 0.166667f, 0.363636f, 0.333333f, 0.242424f,
152 0.190476f, 0.133333f, 0.0689655f, 0.f, 0.f, 0.f,
153 0.f, 0.f, 0.f},
154 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
155 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
156 0.f, 0.f, 0.f, 0.f, 0.333333f, 0.30303f, 0.253968f, 0.2f, 0.137931f,
157 0.0714286f, 0.f, 0.f, 0.f, 0.f, 0.f},
158 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
159 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
160 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
161 0.f, 0.f, 0.30303f, 0.31746f, 0.333333f, 0.275862f, 0.214286f,
162 0.125f, 0.0655738f, 0.f, 0.f, 0.f},
163 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
164 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
165 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
166 0.f, 0.f, 0.f, 0.15873f, 0.333333f, 0.344828f, 0.357143f,
167 0.25f, 0.196721f, 0.137931f, 0.0816327f, 0.f},
168 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
169 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
170 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
171 0.f, 0.f, 0.f, 0.f, 0.f, 0.172414f, 0.357143f,
172 0.3125f, 0.245902f, 0.172414f, 0.102041f, 0.f},
173 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
174 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
175 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
176 0.f, 0.3125f, 0.327869f, 0.344828f, 0.204082f, 0.f},
177 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
178 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
179 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.163934f, 0.344828f, 0.408163f, 0.5f},
180 {0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
181 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
182 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.204082f, 0.5f}};
57 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestFilterBank), 183 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestFilterBank),
58 "Test filterbank badly initialized."); 184 "Test filterbank badly initialized.");
59 185
60 // Target output for gain solving test. Generated with matlab. 186 // Target output for gain solving test. Generated with matlab.
61 const size_t kTestStartFreq = 12; // Lowest integral frequency for ERBs. 187 const size_t kTestStartFreq = 12; // Lowest integral frequency for ERBs.
62 const float kTestZeroVar[] = {1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 188 const float kTestZeroVar[] = {
63 1.f, 1.f, 1.f, 0.f, 0.f, 0.f, 0.f, 0.f, 189 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f,
64 0.f, 0.f, 0.f, 0.f, 0.f, 0.f}; 190 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
191 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0};
65 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestZeroVar), 192 static_assert(arraysize(kTestCenterFreqs) == arraysize(kTestZeroVar),
66 "Variance test data badly initialized."); 193 "Power test data badly initialized.");
67 const float kTestNonZeroVarLambdaTop[] = { 194 const float kTestNonZeroVarLambdaTop[] = {
68 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 195 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 1.f, 0.f, 0.f, 0.f,
69 1.f, 1.f, 1.f, 0.f, 0.f, 0.0351f, 0.0636f, 0.0863f, 196 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f,
70 0.1037f, 0.1162f, 0.1236f, 0.1251f, 0.1189f, 0.0993f}; 197 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0.f, 0};
71 static_assert(arraysize(kTestCenterFreqs) == 198 static_assert(arraysize(kTestCenterFreqs) ==
72 arraysize(kTestNonZeroVarLambdaTop), 199 arraysize(kTestNonZeroVarLambdaTop),
73 "Variance test data badly initialized."); 200 "Power test data badly initialized.");
74 const float kMaxTestError = 0.005f; 201 const float kMaxTestError = 0.005f;
75 202
76 // Enhancer initialization parameters. 203 // Enhancer initialization parameters.
77 const int kSamples = 2000; 204 const int kSamples = 1000;
78 const int kSampleRate = 1000; 205 const int kSampleRate = 4000;
79 const int kNumChannels = 1; 206 const int kNumChannels = 1;
80 const int kFragmentSize = kSampleRate / 100; 207 const int kFragmentSize = kSampleRate / 100;
81 208
82 } // namespace 209 } // namespace
83 210
84 using std::vector;
85 using intelligibility::VarianceArray;
86
87 class IntelligibilityEnhancerTest : public ::testing::Test { 211 class IntelligibilityEnhancerTest : public ::testing::Test {
88 protected: 212 protected:
89 IntelligibilityEnhancerTest() 213 IntelligibilityEnhancerTest()
90 : clear_data_(kSamples), noise_data_(kSamples), orig_data_(kSamples) { 214 : clear_data_(kSamples), noise_data_(kSamples), orig_data_(kSamples) {
91 config_.sample_rate_hz = kSampleRate; 215 enh_.reset(new IntelligibilityEnhancer(kSampleRate, kNumChannels));
92 enh_.reset(new IntelligibilityEnhancer(config_));
93 } 216 }
94 217
95 bool CheckUpdate(VarianceArray::StepType step_type) { 218 bool CheckUpdate() {
96 config_.sample_rate_hz = kSampleRate; 219 enh_.reset(new IntelligibilityEnhancer(kSampleRate, kNumChannels));
97 config_.var_type = step_type;
98 enh_.reset(new IntelligibilityEnhancer(config_));
99 float* clear_cursor = &clear_data_[0]; 220 float* clear_cursor = &clear_data_[0];
100 float* noise_cursor = &noise_data_[0]; 221 float* noise_cursor = &noise_data_[0];
101 for (int i = 0; i < kSamples; i += kFragmentSize) { 222 for (int i = 0; i < kSamples; i += kFragmentSize) {
102 enh_->ProcessRenderAudio(&clear_cursor, kSampleRate, kNumChannels); 223 enh_->ProcessRenderAudio(&clear_cursor, kSampleRate, kNumChannels);
103 clear_cursor += kFragmentSize; 224 clear_cursor += kFragmentSize;
104 noise_cursor += kFragmentSize; 225 noise_cursor += kFragmentSize;
105 } 226 }
106 for (int i = 0; i < kSamples; i++) { 227 for (int i = 0; i < kSamples; i++) {
107 if (std::fabs(clear_data_[i] - orig_data_[i]) > kMaxTestError) { 228 if (std::fabs(clear_data_[i] - orig_data_[i]) > kMaxTestError) {
108 return true; 229 return true;
109 } 230 }
110 } 231 }
111 return false; 232 return false;
112 } 233 }
113 234
114 IntelligibilityEnhancer::Config config_;
115 rtc::scoped_ptr<IntelligibilityEnhancer> enh_; 235 rtc::scoped_ptr<IntelligibilityEnhancer> enh_;
116 vector<float> clear_data_; 236 std::vector<float> clear_data_;
117 vector<float> noise_data_; 237 std::vector<float> noise_data_;
118 vector<float> orig_data_; 238 std::vector<float> orig_data_;
119 }; 239 };
120 240
121 // For each class of generated data, tests that render stream is 241 // For each class of generated data, tests that render stream is updated when
122 // updated when it should be for each variance update method. 242 // it should be.
123 TEST_F(IntelligibilityEnhancerTest, TestRenderUpdate) { 243 TEST_F(IntelligibilityEnhancerTest, TestRenderUpdate) {
124 vector<VarianceArray::StepType> step_types; 244 std::fill(noise_data_.begin(), noise_data_.end(), 0.f);
125 step_types.push_back(VarianceArray::kStepInfinite); 245 std::fill(orig_data_.begin(), orig_data_.end(), 0.f);
126 step_types.push_back(VarianceArray::kStepDecaying); 246 std::fill(clear_data_.begin(), clear_data_.end(), 0.f);
127 step_types.push_back(VarianceArray::kStepWindowed); 247 EXPECT_FALSE(CheckUpdate());
128 step_types.push_back(VarianceArray::kStepBlocked);
129 step_types.push_back(VarianceArray::kStepBlockBasedMovingAverage);
130 std::fill(noise_data_.begin(), noise_data_.end(), 0.0f);
131 std::fill(orig_data_.begin(), orig_data_.end(), 0.0f);
132 for (auto step_type : step_types) {
133 std::fill(clear_data_.begin(), clear_data_.end(), 0.0f);
134 EXPECT_FALSE(CheckUpdate(step_type));
135 }
136 std::srand(1); 248 std::srand(1);
137 auto float_rand = []() { return std::rand() * 2.f / RAND_MAX - 1; }; 249 auto float_rand = []() { return std::rand() * 2.f / RAND_MAX - 1; };
138 std::generate(noise_data_.begin(), noise_data_.end(), float_rand); 250 std::generate(noise_data_.begin(), noise_data_.end(), float_rand);
139 for (auto step_type : step_types) { 251 EXPECT_FALSE(CheckUpdate());
140 EXPECT_FALSE(CheckUpdate(step_type)); 252 std::generate(clear_data_.begin(), clear_data_.end(), float_rand);
141 } 253 orig_data_ = clear_data_;
142 for (auto step_type : step_types) { 254 EXPECT_TRUE(CheckUpdate());
143 std::generate(clear_data_.begin(), clear_data_.end(), float_rand);
144 orig_data_ = clear_data_;
145 EXPECT_TRUE(CheckUpdate(step_type));
146 }
147 } 255 }
148 256
149 // Tests ERB bank creation, comparing against matlab output. 257 // Tests ERB bank creation, comparing against matlab output.
150 TEST_F(IntelligibilityEnhancerTest, TestErbCreation) { 258 TEST_F(IntelligibilityEnhancerTest, TestErbCreation) {
151 ASSERT_EQ(arraysize(kTestCenterFreqs), enh_->bank_size_); 259 ASSERT_EQ(arraysize(kTestCenterFreqs), enh_->bank_size_);
152 for (size_t i = 0; i < enh_->bank_size_; ++i) { 260 for (size_t i = 0; i < enh_->bank_size_; ++i) {
153 EXPECT_NEAR(kTestCenterFreqs[i], enh_->center_freqs_[i], kMaxTestError); 261 EXPECT_NEAR(kTestCenterFreqs[i], enh_->center_freqs_[i], kMaxTestError);
154 ASSERT_EQ(arraysize(kTestFilterBank[0]), enh_->freqs_); 262 ASSERT_EQ(arraysize(kTestFilterBank[0]), enh_->freqs_);
155 for (size_t j = 0; j < enh_->freqs_; ++j) { 263 for (size_t j = 0; j < enh_->freqs_; ++j) {
156 EXPECT_NEAR(kTestFilterBank[i][j], enh_->render_filter_bank_[i][j], 264 EXPECT_NEAR(kTestFilterBank[i][j], enh_->render_filter_bank_[i][j],
157 kMaxTestError); 265 kMaxTestError);
158 } 266 }
159 } 267 }
160 } 268 }
161 269
162 // Tests analytic solution for optimal gains, comparing 270 // Tests analytic solution for optimal gains, comparing
163 // against matlab output. 271 // against matlab output.
164 TEST_F(IntelligibilityEnhancerTest, TestSolveForGains) { 272 TEST_F(IntelligibilityEnhancerTest, TestSolveForGains) {
165 ASSERT_EQ(kTestStartFreq, enh_->start_freq_); 273 ASSERT_EQ(kTestStartFreq, enh_->start_freq_);
166 vector<float> sols(enh_->bank_size_); 274 std::vector<float> sols(enh_->bank_size_);
167 float lambda = -0.001f; 275 float lambda = -0.001f;
168 for (size_t i = 0; i < enh_->bank_size_; i++) { 276 for (size_t i = 0; i < enh_->bank_size_; i++) {
169 enh_->filtered_clear_var_[i] = 0.0f; 277 enh_->filtered_clear_pow_[i] = 0.f;
170 enh_->filtered_noise_var_[i] = 0.0f; 278 enh_->filtered_noise_pow_[i] = 0.f;
171 enh_->rho_[i] = 0.02f;
172 } 279 }
173 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, &sols[0]); 280 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, &sols[0]);
174 for (size_t i = 0; i < enh_->bank_size_; i++) { 281 for (size_t i = 0; i < enh_->bank_size_; i++) {
175 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError); 282 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError);
176 } 283 }
177 for (size_t i = 0; i < enh_->bank_size_; i++) { 284 for (size_t i = 0; i < enh_->bank_size_; i++) {
178 enh_->filtered_clear_var_[i] = static_cast<float>(i + 1); 285 enh_->filtered_clear_pow_[i] = static_cast<float>(i + 1);
179 enh_->filtered_noise_var_[i] = static_cast<float>(enh_->bank_size_ - i); 286 enh_->filtered_noise_pow_[i] = static_cast<float>(enh_->bank_size_ - i);
180 } 287 }
181 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, &sols[0]); 288 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, &sols[0]);
182 for (size_t i = 0; i < enh_->bank_size_; i++) { 289 for (size_t i = 0; i < enh_->bank_size_; i++) {
183 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); 290 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError);
184 } 291 }
185 lambda = -1.0; 292 lambda = -1.f;
186 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, &sols[0]); 293 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, &sols[0]);
187 for (size_t i = 0; i < enh_->bank_size_; i++) { 294 for (size_t i = 0; i < enh_->bank_size_; i++) {
188 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError); 295 EXPECT_NEAR(kTestZeroVar[i], sols[i], kMaxTestError);
189 } 296 }
190 } 297 }
191 298
192 } // namespace webrtc 299 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698