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

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

Powered by Google App Engine
This is Rietveld 408576698