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 21 matching lines...) Expand all Loading... |
32 return data; | 32 return data; |
33 } | 33 } |
34 | 34 |
35 // Tests PowerEstimator, for all power step types. | 35 // Tests PowerEstimator, for all power step types. |
36 TEST(IntelligibilityUtilsTest, TestPowerEstimator) { | 36 TEST(IntelligibilityUtilsTest, TestPowerEstimator) { |
37 const size_t kFreqs = 10; | 37 const size_t kFreqs = 10; |
38 const size_t kSamples = 100; | 38 const size_t kSamples = 100; |
39 const float kDecay = 0.5f; | 39 const float kDecay = 0.5f; |
40 const std::vector<std::vector<std::complex<float>>> test_data( | 40 const std::vector<std::vector<std::complex<float>>> test_data( |
41 GenerateTestData(kFreqs, kSamples)); | 41 GenerateTestData(kFreqs, kSamples)); |
42 PowerEstimator power_estimator(kFreqs, kDecay); | 42 PowerEstimator<std::complex<float>> power_estimator(kFreqs, kDecay); |
43 EXPECT_EQ(0, power_estimator.Power()[0]); | 43 EXPECT_EQ(0, power_estimator.power()[0]); |
44 | 44 |
45 // Makes sure Step is doing something. | 45 // Makes sure Step is doing something. |
46 power_estimator.Step(&test_data[0][0]); | 46 power_estimator.Step(&test_data[0][0]); |
47 for (size_t i = 1; i < kSamples; ++i) { | 47 for (size_t i = 1; i < kSamples; ++i) { |
48 power_estimator.Step(&test_data[i][0]); | 48 power_estimator.Step(&test_data[i][0]); |
49 for (size_t j = 0; j < kFreqs; ++j) { | 49 for (size_t j = 0; j < kFreqs; ++j) { |
50 const float* power = power_estimator.Power(); | 50 EXPECT_GE(power_estimator.power()[j], 0.f); |
51 EXPECT_GE(power[j], 0.f); | 51 EXPECT_LE(power_estimator.power()[j], 1.f); |
52 EXPECT_LE(power[j], 1.f); | |
53 } | 52 } |
54 } | 53 } |
55 } | 54 } |
56 | 55 |
57 // Tests gain applier. | 56 // Tests gain applier. |
58 TEST(IntelligibilityUtilsTest, TestGainApplier) { | 57 TEST(IntelligibilityUtilsTest, TestGainApplier) { |
59 const size_t kFreqs = 10; | 58 const size_t kFreqs = 10; |
60 const size_t kSamples = 100; | 59 const size_t kSamples = 100; |
61 const float kChangeLimit = 0.1f; | 60 const float kChangeLimit = 0.1f; |
62 GainApplier gain_applier(kFreqs, kChangeLimit); | 61 GainApplier gain_applier(kFreqs, kChangeLimit); |
63 const std::vector<std::vector<std::complex<float>>> in_data( | 62 const std::vector<std::vector<std::complex<float>>> in_data( |
64 GenerateTestData(kFreqs, kSamples)); | 63 GenerateTestData(kFreqs, kSamples)); |
65 std::vector<std::vector<std::complex<float>>> out_data(GenerateTestData( | 64 std::vector<std::vector<std::complex<float>>> out_data( |
66 kFreqs, kSamples)); | 65 GenerateTestData(kFreqs, kSamples)); |
67 for (size_t i = 0; i < kSamples; ++i) { | 66 for (size_t i = 0; i < kSamples; ++i) { |
68 gain_applier.Apply(&in_data[i][0], &out_data[i][0]); | 67 gain_applier.Apply(&in_data[i][0], &out_data[i][0]); |
69 for (size_t j = 0; j < kFreqs; ++j) { | 68 for (size_t j = 0; j < kFreqs; ++j) { |
70 EXPECT_GT(out_data[i][j].real(), 0.f); | 69 EXPECT_GT(out_data[i][j].real(), 0.f); |
71 EXPECT_LT(out_data[i][j].real(), 1.f); | 70 EXPECT_LT(out_data[i][j].real(), 1.f); |
72 EXPECT_GT(out_data[i][j].imag(), 0.f); | 71 EXPECT_GT(out_data[i][j].imag(), 0.f); |
73 EXPECT_LT(out_data[i][j].imag(), 1.f); | 72 EXPECT_LT(out_data[i][j].imag(), 1.f); |
74 } | 73 } |
75 } | 74 } |
76 } | 75 } |
77 | 76 |
78 } // namespace intelligibility | 77 } // namespace intelligibility |
79 | 78 |
80 } // namespace webrtc | 79 } // namespace webrtc |
OLD | NEW |