OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/basictypes.h" | |
10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
11 #include "media/audio/audio_parameters.h" | 10 #include "media/audio/audio_parameters.h" |
12 #include "media/audio/simple_sources.h" | 11 #include "media/audio/simple_sources.h" |
13 #include "media/audio/sounds/test_data.h" | 12 #include "media/audio/sounds/test_data.h" |
14 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
16 | 15 |
17 namespace media { | 16 namespace media { |
18 | 17 |
19 // Validate that the SineWaveAudioSource writes the expected values. | 18 // Validate that the SineWaveAudioSource writes the expected values. |
20 TEST(SimpleSources, SineWaveAudioSource) { | 19 TEST(SimpleSources, SineWaveAudioSource) { |
21 static const uint32 samples = 1024; | 20 static const uint32_t samples = 1024; |
22 static const uint32 bytes_per_sample = 2; | 21 static const uint32_t bytes_per_sample = 2; |
23 static const int freq = 200; | 22 static const int freq = 200; |
24 | 23 |
25 AudioParameters params( | 24 AudioParameters params( |
26 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, | 25 AudioParameters::AUDIO_PCM_LINEAR, CHANNEL_LAYOUT_MONO, |
27 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 8, samples); | 26 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 8, samples); |
28 | 27 |
29 SineWaveAudioSource source(1, freq, params.sample_rate()); | 28 SineWaveAudioSource source(1, freq, params.sample_rate()); |
30 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(params); | 29 scoped_ptr<AudioBus> audio_bus = AudioBus::Create(params); |
31 source.OnMoreData(audio_bus.get(), 0, 0); | 30 source.OnMoreData(audio_bus.get(), 0, 0); |
32 EXPECT_EQ(1, source.callbacks()); | 31 EXPECT_EQ(1, source.callbacks()); |
33 EXPECT_EQ(0, source.errors()); | 32 EXPECT_EQ(0, source.errors()); |
34 | 33 |
35 uint32 half_period = AudioParameters::kTelephoneSampleRate / (freq * 2); | 34 uint32_t half_period = AudioParameters::kTelephoneSampleRate / (freq * 2); |
36 | 35 |
37 // Spot test positive incursion of sine wave. | 36 // Spot test positive incursion of sine wave. |
38 EXPECT_NEAR(0, audio_bus->channel(0)[0], | 37 EXPECT_NEAR(0, audio_bus->channel(0)[0], |
39 std::numeric_limits<float>::epsilon()); | 38 std::numeric_limits<float>::epsilon()); |
40 EXPECT_FLOAT_EQ(0.15643446f, audio_bus->channel(0)[1]); | 39 EXPECT_FLOAT_EQ(0.15643446f, audio_bus->channel(0)[1]); |
41 EXPECT_LT(audio_bus->channel(0)[1], audio_bus->channel(0)[2]); | 40 EXPECT_LT(audio_bus->channel(0)[1], audio_bus->channel(0)[2]); |
42 EXPECT_LT(audio_bus->channel(0)[2], audio_bus->channel(0)[3]); | 41 EXPECT_LT(audio_bus->channel(0)[2], audio_bus->channel(0)[3]); |
43 // Spot test negative incursion of sine wave. | 42 // Spot test negative incursion of sine wave. |
44 EXPECT_NEAR(0, audio_bus->channel(0)[half_period], | 43 EXPECT_NEAR(0, audio_bus->channel(0)[half_period], |
45 std::numeric_limits<float>::epsilon()); | 44 std::numeric_limits<float>::epsilon()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 168 |
170 // Confirm all frames are zero-padded. | 169 // Confirm all frames are zero-padded. |
171 for (int channel = 0; channel < audio_bus->channels(); ++channel) { | 170 for (int channel = 0; channel < audio_bus->channels(); ++channel) { |
172 for (int frame = 0; frame < audio_bus->frames(); ++frame) { | 171 for (int frame = 0; frame < audio_bus->frames(); ++frame) { |
173 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]); | 172 EXPECT_FLOAT_EQ(0.0, audio_bus->channel(channel)[frame]); |
174 } | 173 } |
175 } | 174 } |
176 } | 175 } |
177 | 176 |
178 } // namespace media | 177 } // namespace media |
OLD | NEW |