OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 52 matching lines...) Loading... |
63 AudioMultiVector signal(channels); | 63 AudioMultiVector signal(channels); |
64 AudioMultiVector ref_signal(channels); | 64 AudioMultiVector ref_signal(channels); |
65 | 65 |
66 const int event_vec[] = {0, 4, 9, 13}; // Test a few events. | 66 const int event_vec[] = {0, 4, 9, 13}; // Test a few events. |
67 for (int e = 0; e < 4; ++e) { | 67 for (int e = 0; e < 4; ++e) { |
68 int event = event_vec[e]; | 68 int event = event_vec[e]; |
69 // Create full-scale reference. | 69 // Create full-scale reference. |
70 ASSERT_EQ(0, tone_gen_.Init(fs_hz, event, 0)); // 0 attenuation. | 70 ASSERT_EQ(0, tone_gen_.Init(fs_hz, event, 0)); // 0 attenuation. |
71 EXPECT_EQ(kNumSamples, tone_gen_.Generate(kNumSamples, &ref_signal)); | 71 EXPECT_EQ(kNumSamples, tone_gen_.Generate(kNumSamples, &ref_signal)); |
72 // Test every 5 steps (to save time). | 72 // Test every 5 steps (to save time). |
73 for (int attenuation = 1; attenuation <= 36; attenuation += 5) { | 73 for (int attenuation = 1; attenuation <= 63; attenuation += 5) { |
74 std::ostringstream ss; | 74 std::ostringstream ss; |
75 ss << "Checking event " << event << " at sample rate " << fs_hz; | 75 ss << "Checking event " << event << " at sample rate " << fs_hz; |
76 ss << "; attenuation " << attenuation; | 76 ss << "; attenuation " << attenuation; |
77 SCOPED_TRACE(ss.str()); | 77 SCOPED_TRACE(ss.str()); |
78 ASSERT_EQ(0, tone_gen_.Init(fs_hz, event, attenuation)); | 78 ASSERT_EQ(0, tone_gen_.Init(fs_hz, event, attenuation)); |
79 EXPECT_EQ(kNumSamples, tone_gen_.Generate(kNumSamples, &signal)); | 79 EXPECT_EQ(kNumSamples, tone_gen_.Generate(kNumSamples, &signal)); |
80 for (int n = 0; n < kNumSamples; ++n) { | 80 for (int n = 0; n < kNumSamples; ++n) { |
81 double attenuation_factor = | 81 double attenuation_factor = |
82 pow(10, -static_cast<double>(attenuation) / 20); | 82 pow(10, -static_cast<double>(attenuation) / 20); |
83 // Verify that the attenuation is correct. | 83 // Verify that the attenuation is correct. |
(...skipping 73 matching lines...) Loading... |
157 const int event = 7; // Valid event. | 157 const int event = 7; // Valid event. |
158 const int attenuation = 0; // Valid attenuation. | 158 const int attenuation = 0; // Valid attenuation. |
159 // Initialize with invalid event -1. | 159 // Initialize with invalid event -1. |
160 EXPECT_EQ(DtmfToneGenerator::kParameterError, | 160 EXPECT_EQ(DtmfToneGenerator::kParameterError, |
161 tone_gen.Init(fs, -1, attenuation)); | 161 tone_gen.Init(fs, -1, attenuation)); |
162 // Initialize with invalid event 16. | 162 // Initialize with invalid event 16. |
163 EXPECT_EQ(DtmfToneGenerator::kParameterError, | 163 EXPECT_EQ(DtmfToneGenerator::kParameterError, |
164 tone_gen.Init(fs, 16, attenuation)); | 164 tone_gen.Init(fs, 16, attenuation)); |
165 // Initialize with invalid attenuation -1. | 165 // Initialize with invalid attenuation -1. |
166 EXPECT_EQ(DtmfToneGenerator::kParameterError, tone_gen.Init(fs, event, -1)); | 166 EXPECT_EQ(DtmfToneGenerator::kParameterError, tone_gen.Init(fs, event, -1)); |
167 // Initialize with invalid attenuation 37. | 167 // Initialize with invalid attenuation 64. |
168 EXPECT_EQ(DtmfToneGenerator::kParameterError, tone_gen.Init(fs, event, 37)); | 168 EXPECT_EQ(DtmfToneGenerator::kParameterError, tone_gen.Init(fs, event, 64)); |
169 EXPECT_FALSE(tone_gen.initialized()); // Should still be uninitialized. | 169 EXPECT_FALSE(tone_gen.initialized()); // Should still be uninitialized. |
170 | 170 |
171 // Initialize with valid parameters. | 171 // Initialize with valid parameters. |
172 ASSERT_EQ(0, tone_gen.Init(fs, event, attenuation)); | 172 ASSERT_EQ(0, tone_gen.Init(fs, event, attenuation)); |
173 EXPECT_TRUE(tone_gen.initialized()); | 173 EXPECT_TRUE(tone_gen.initialized()); |
174 // NULL pointer to destination. | 174 // NULL pointer to destination. |
175 EXPECT_EQ(DtmfToneGenerator::kParameterError, | 175 EXPECT_EQ(DtmfToneGenerator::kParameterError, |
176 tone_gen.Generate(kNumSamples, NULL)); | 176 tone_gen.Generate(kNumSamples, NULL)); |
177 } | 177 } |
178 | 178 |
179 } // namespace webrtc | 179 } // namespace webrtc |
OLD | NEW |