OLD | NEW |
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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 230 |
231 intelligibility_enhancer->ProcessRenderAudio( | 231 intelligibility_enhancer->ProcessRenderAudio( |
232 render_audio_buffer->split_channels_f(kBand0To8kHz), | 232 render_audio_buffer->split_channels_f(kBand0To8kHz), |
233 IntelligibilityEnhancerSampleRate(sample_rate_hz), | 233 IntelligibilityEnhancerSampleRate(sample_rate_hz), |
234 render_audio_buffer->num_channels()); | 234 render_audio_buffer->num_channels()); |
235 | 235 |
236 noise_suppressor->AnalyzeCaptureAudio(capture_audio_buffer); | 236 noise_suppressor->AnalyzeCaptureAudio(capture_audio_buffer); |
237 noise_suppressor->ProcessCaptureAudio(capture_audio_buffer); | 237 noise_suppressor->ProcessCaptureAudio(capture_audio_buffer); |
238 | 238 |
239 intelligibility_enhancer->SetCaptureNoiseEstimate( | 239 intelligibility_enhancer->SetCaptureNoiseEstimate( |
240 noise_suppressor->NoiseEstimate()); | 240 noise_suppressor->NoiseEstimate(), 0); |
241 | 241 |
242 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { | 242 if (sample_rate_hz > AudioProcessing::kSampleRate16kHz) { |
243 render_audio_buffer->MergeFrequencyBands(); | 243 render_audio_buffer->MergeFrequencyBands(); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 // Processes a specified amount of frames, verifies the results and reports | 247 // Processes a specified amount of frames, verifies the results and reports |
248 // any errors. | 248 // any errors. |
249 void RunBitexactnessTest(int sample_rate_hz, | 249 void RunBitexactnessTest(int sample_rate_hz, |
250 size_t num_channels, | 250 size_t num_channels, |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // Compare the output with the reference. Only the first values of the output | 304 // Compare the output with the reference. Only the first values of the output |
305 // from last frame processed are compared in order not having to specify all | 305 // from last frame processed are compared in order not having to specify all |
306 // preceeding frames as testvectors. As the algorithm being tested has a | 306 // preceeding frames as testvectors. As the algorithm being tested has a |
307 // memory, testing only the last frame implicitly also tests the preceeding | 307 // memory, testing only the last frame implicitly also tests the preceeding |
308 // frames. | 308 // frames. |
309 EXPECT_TRUE(test::VerifyDeinterleavedArray( | 309 EXPECT_TRUE(test::VerifyDeinterleavedArray( |
310 render_buffer.num_frames(), render_config.num_channels(), | 310 render_buffer.num_frames(), render_config.num_channels(), |
311 output_reference, render_output, kElementErrorBound)); | 311 output_reference, render_output, kElementErrorBound)); |
312 } | 312 } |
313 | 313 |
| 314 float float_rand() { |
| 315 return std::rand() * 2.f / RAND_MAX - 1; |
| 316 } |
| 317 |
314 } // namespace | 318 } // namespace |
315 | 319 |
316 class IntelligibilityEnhancerTest : public ::testing::Test { | 320 class IntelligibilityEnhancerTest : public ::testing::Test { |
317 protected: | 321 protected: |
318 IntelligibilityEnhancerTest() | 322 IntelligibilityEnhancerTest() |
319 : clear_data_(kSamples), noise_data_(kSamples), orig_data_(kSamples) { | 323 : clear_data_(kSamples), noise_data_(kSamples), orig_data_(kSamples) { |
| 324 std::srand(1); |
320 enh_.reset( | 325 enh_.reset( |
321 new IntelligibilityEnhancer(kSampleRate, kNumChannels, kNumNoiseBins)); | 326 new IntelligibilityEnhancer(kSampleRate, kNumChannels, kNumNoiseBins)); |
322 } | 327 } |
323 | 328 |
324 bool CheckUpdate() { | 329 bool CheckUpdate() { |
325 enh_.reset( | 330 enh_.reset( |
326 new IntelligibilityEnhancer(kSampleRate, kNumChannels, kNumNoiseBins)); | 331 new IntelligibilityEnhancer(kSampleRate, kNumChannels, kNumNoiseBins)); |
327 float* clear_cursor = clear_data_.data(); | 332 float* clear_cursor = clear_data_.data(); |
328 float* noise_cursor = noise_data_.data(); | 333 float* noise_cursor = noise_data_.data(); |
329 for (int i = 0; i < kSamples; i += kFragmentSize) { | 334 for (int i = 0; i < kSamples; i += kFragmentSize) { |
(...skipping 15 matching lines...) Expand all Loading... |
345 std::vector<float> orig_data_; | 350 std::vector<float> orig_data_; |
346 }; | 351 }; |
347 | 352 |
348 // For each class of generated data, tests that render stream is updated when | 353 // For each class of generated data, tests that render stream is updated when |
349 // it should be. | 354 // it should be. |
350 TEST_F(IntelligibilityEnhancerTest, TestRenderUpdate) { | 355 TEST_F(IntelligibilityEnhancerTest, TestRenderUpdate) { |
351 std::fill(noise_data_.begin(), noise_data_.end(), 0.f); | 356 std::fill(noise_data_.begin(), noise_data_.end(), 0.f); |
352 std::fill(orig_data_.begin(), orig_data_.end(), 0.f); | 357 std::fill(orig_data_.begin(), orig_data_.end(), 0.f); |
353 std::fill(clear_data_.begin(), clear_data_.end(), 0.f); | 358 std::fill(clear_data_.begin(), clear_data_.end(), 0.f); |
354 EXPECT_FALSE(CheckUpdate()); | 359 EXPECT_FALSE(CheckUpdate()); |
355 std::srand(1); | |
356 auto float_rand = []() { return std::rand() * 2.f / RAND_MAX - 1; }; | |
357 std::generate(noise_data_.begin(), noise_data_.end(), float_rand); | 360 std::generate(noise_data_.begin(), noise_data_.end(), float_rand); |
358 EXPECT_FALSE(CheckUpdate()); | 361 EXPECT_FALSE(CheckUpdate()); |
359 std::generate(clear_data_.begin(), clear_data_.end(), float_rand); | 362 std::generate(clear_data_.begin(), clear_data_.end(), float_rand); |
360 orig_data_ = clear_data_; | 363 orig_data_ = clear_data_; |
361 EXPECT_TRUE(CheckUpdate()); | 364 EXPECT_TRUE(CheckUpdate()); |
362 } | 365 } |
363 | 366 |
364 // Tests ERB bank creation, comparing against matlab output. | 367 // Tests ERB bank creation, comparing against matlab output. |
365 TEST_F(IntelligibilityEnhancerTest, TestErbCreation) { | 368 TEST_F(IntelligibilityEnhancerTest, TestErbCreation) { |
366 ASSERT_EQ(arraysize(kTestCenterFreqs), enh_->bank_size_); | 369 ASSERT_EQ(arraysize(kTestCenterFreqs), enh_->bank_size_); |
(...skipping 29 matching lines...) Expand all Loading... |
396 for (size_t i = 0; i < enh_->bank_size_; i++) { | 399 for (size_t i = 0; i < enh_->bank_size_; i++) { |
397 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); | 400 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); |
398 } | 401 } |
399 lambda = -1.f; | 402 lambda = -1.f; |
400 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, sols.data()); | 403 enh_->SolveForGainsGivenLambda(lambda, enh_->start_freq_, sols.data()); |
401 for (size_t i = 0; i < enh_->bank_size_; i++) { | 404 for (size_t i = 0; i < enh_->bank_size_; i++) { |
402 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); | 405 EXPECT_NEAR(kTestNonZeroVarLambdaTop[i], sols[i], kMaxTestError); |
403 } | 406 } |
404 } | 407 } |
405 | 408 |
| 409 TEST_F(IntelligibilityEnhancerTest, TestNoiseGainHasExpectedResult) { |
| 410 const int kGainDB = 6; |
| 411 const float kGainFactor = std::pow(10.f, kGainDB / 20.f); |
| 412 const float kTolerance = 0.003f; |
| 413 std::vector<float> noise(kNumNoiseBins); |
| 414 std::vector<float> noise_psd(kNumNoiseBins); |
| 415 std::generate(noise.begin(), noise.end(), float_rand); |
| 416 for (size_t i = 0; i < kNumNoiseBins; ++i) { |
| 417 noise_psd[i] = kGainFactor * kGainFactor * noise[i] * noise[i]; |
| 418 } |
| 419 float* clear_cursor = clear_data_.data(); |
| 420 for (size_t i = 0; i < kNumFramesToProcess; ++i) { |
| 421 enh_->SetCaptureNoiseEstimate(noise, kGainDB); |
| 422 enh_->ProcessRenderAudio(&clear_cursor, kSampleRate, kNumChannels); |
| 423 } |
| 424 const std::vector<float>& estimated_psd = |
| 425 enh_->noise_power_estimator_.power(); |
| 426 for (size_t i = 0; i < kNumNoiseBins; ++i) { |
| 427 EXPECT_LT(std::abs(estimated_psd[i] - noise_psd[i]) / noise_psd[i], |
| 428 kTolerance); |
| 429 } |
| 430 } |
| 431 |
406 TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono8kHz) { | 432 TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono8kHz) { |
407 const float kOutputReference[] = {-0.001892f, -0.003296f, -0.001953f}; | 433 const float kOutputReference[] = {-0.001892f, -0.003296f, -0.001953f}; |
408 | 434 |
409 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference); | 435 RunBitexactnessTest(AudioProcessing::kSampleRate8kHz, 1, kOutputReference); |
410 } | 436 } |
411 | 437 |
412 TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono16kHz) { | 438 TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Mono16kHz) { |
413 const float kOutputReference[] = {-0.000977f, -0.003296f, -0.002441f}; | 439 const float kOutputReference[] = {-0.000977f, -0.003296f, -0.002441f}; |
414 | 440 |
415 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference); | 441 RunBitexactnessTest(AudioProcessing::kSampleRate16kHz, 1, kOutputReference); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 } | 475 } |
450 | 476 |
451 TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Stereo48kHz) { | 477 TEST(IntelligibilityEnhancerBitExactnessTest, DISABLED_Stereo48kHz) { |
452 const float kOutputReference[] = {-0.009276f, -0.001601f, -0.008255f, | 478 const float kOutputReference[] = {-0.009276f, -0.001601f, -0.008255f, |
453 -0.012975f, -0.015940f, -0.017820f}; | 479 -0.012975f, -0.015940f, -0.017820f}; |
454 | 480 |
455 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference); | 481 RunBitexactnessTest(AudioProcessing::kSampleRate48kHz, 2, kOutputReference); |
456 } | 482 } |
457 | 483 |
458 } // namespace webrtc | 484 } // namespace webrtc |
OLD | NEW |