OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 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 |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/modules/audio_processing/aec3/comfort_noise_generator.h" |
| 12 |
| 13 #include <algorithm> |
| 14 #include <numeric> |
| 15 |
| 16 #include "webrtc/test/gtest.h" |
| 17 |
| 18 namespace webrtc { |
| 19 namespace { |
| 20 |
| 21 float Power(const FftData& N) { |
| 22 std::array<float, kFftLengthBy2Plus1> N2; |
| 23 N.Spectrum(&N2); |
| 24 return std::accumulate(N2.begin(), N2.end(), 0.f) / N2.size(); |
| 25 } |
| 26 |
| 27 } // namespace |
| 28 |
| 29 #if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID) |
| 30 |
| 31 TEST(ComfortNoiseGenerator, NullLowerBandNoise) { |
| 32 std::array<float, kFftLengthBy2Plus1> N2; |
| 33 FftData noise; |
| 34 EXPECT_DEATH(ComfortNoiseGenerator().Compute(N2, nullptr, &noise), ""); |
| 35 } |
| 36 |
| 37 TEST(ComfortNoiseGenerator, NullUpperBandNoise) { |
| 38 std::array<float, kFftLengthBy2Plus1> N2; |
| 39 FftData noise; |
| 40 EXPECT_DEATH(ComfortNoiseGenerator().Compute(N2, &noise, nullptr), ""); |
| 41 } |
| 42 |
| 43 #endif |
| 44 |
| 45 TEST(ComfortNoiseGenerator, CorrectLevel) { |
| 46 ComfortNoiseGenerator cng; |
| 47 |
| 48 std::array<float, kFftLengthBy2Plus1> N2; |
| 49 N2.fill(1000.f * 1000.f); |
| 50 |
| 51 FftData n_lower; |
| 52 FftData n_upper; |
| 53 n_lower.re.fill(0.f); |
| 54 n_lower.im.fill(0.f); |
| 55 n_upper.re.fill(0.f); |
| 56 n_upper.im.fill(0.f); |
| 57 |
| 58 // Ensure instantaneous updata to nonzero noise. |
| 59 cng.Compute(N2, &n_lower, &n_upper); |
| 60 EXPECT_LT(0.f, Power(n_lower)); |
| 61 EXPECT_LT(0.f, Power(n_upper)); |
| 62 |
| 63 for (int k = 0; k < 10000; ++k) { |
| 64 cng.Compute(N2, &n_lower, &n_upper); |
| 65 } |
| 66 EXPECT_NEAR(N2[0], Power(n_lower), N2[0] / 10.f); |
| 67 EXPECT_NEAR(N2[0], Power(n_upper), N2[0] / 10.f); |
| 68 } |
| 69 |
| 70 } // namespace webrtc |
OLD | NEW |