OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "base/basictypes.h" | 6 #include "base/basictypes.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "media/audio/audio_manager.h" | 9 #include "media/audio/audio_manager.h" |
10 #include "media/audio/fake_audio_output_stream.h" | 10 #include "media/audio/fake_audio_output_stream.h" |
11 #include "media/audio/simple_sources.h" | 11 #include "media/audio/simple_sources.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 static void GenerateRandomData(char* buffer, uint32 len) { | 14 static void GenerateRandomData(char* buffer, uint32 len) { |
15 static bool called = false; | 15 static bool called = false; |
16 if (!called) { | 16 if (!called) { |
17 called = true; | 17 called = true; |
18 int seed = static_cast<int>(base::Time::Now().ToInternalValue()); | 18 int seed = static_cast<int>(base::Time::Now().ToInternalValue()); |
19 srand(seed); | 19 srand(seed); |
20 VLOG(1) << "Random seed: " << seed; | 20 VLOG(1) << "Random seed: " << seed; |
21 } | 21 } |
22 | 22 |
23 for (uint32 i = 0; i < len; i++) | 23 for (uint32 i = 0; i < len; i++) |
24 buffer[i] = static_cast<char>(rand()); | 24 buffer[i] = static_cast<char>(rand()); // NOLINT |
25 } | 25 } |
26 | 26 |
27 // To test write size smaller than read size. | 27 // To test write size smaller than read size. |
28 TEST(SimpleSourcesTest, PushSourceSmallerWrite) { | 28 TEST(SimpleSourcesTest, PushSourceSmallerWrite) { |
29 const uint32 kDataSize = 40960; | 29 const uint32 kDataSize = 40960; |
30 scoped_array<char> data(new char[kDataSize]); | 30 scoped_array<char> data(new char[kDataSize]); |
31 GenerateRandomData(data.get(), kDataSize); | 31 GenerateRandomData(data.get(), kDataSize); |
32 | 32 |
33 // Choose two prime numbers for read and write sizes. | 33 // Choose two prime numbers for read and write sizes. |
34 const uint32 kWriteSize = 283; | 34 const uint32 kWriteSize = 283; |
(...skipping 26 matching lines...) Expand all Loading... |
61 // do not affect the result. We also test that AudioManager::GetLastMockBuffer | 61 // do not affect the result. We also test that AudioManager::GetLastMockBuffer |
62 // works. | 62 // works. |
63 TEST(SimpleSources, SineWaveAudio16MonoTest) { | 63 TEST(SimpleSources, SineWaveAudio16MonoTest) { |
64 const uint32 samples = 1024; | 64 const uint32 samples = 1024; |
65 const uint32 bytes_per_sample = 2; | 65 const uint32 bytes_per_sample = 2; |
66 const int freq = 200; | 66 const int freq = 200; |
67 | 67 |
68 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, | 68 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, |
69 freq, AudioParameters::kTelephoneSampleRate); | 69 freq, AudioParameters::kTelephoneSampleRate); |
70 | 70 |
71 AudioManager* audio_man = AudioManager::GetAudioManager(); | 71 scoped_refptr<AudioManager> audio_man(AudioManager::Create()); |
72 ASSERT_TRUE(NULL != audio_man); | |
73 AudioParameters params( | 72 AudioParameters params( |
74 AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_MONO, | 73 AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_MONO, |
75 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 2, samples); | 74 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 2, samples); |
76 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params); | 75 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params); |
77 ASSERT_TRUE(NULL != oas); | 76 ASSERT_TRUE(NULL != oas); |
78 EXPECT_TRUE(oas->Open()); | 77 EXPECT_TRUE(oas->Open()); |
79 | 78 |
80 oas->Start(&source); | 79 oas->Start(&source); |
81 oas->Stop(); | 80 oas->Stop(); |
82 oas->Close(); | 81 oas->Close(); |
(...skipping 10 matching lines...) Expand all Loading... |
93 EXPECT_EQ(0, last_buffer[0]); | 92 EXPECT_EQ(0, last_buffer[0]); |
94 EXPECT_EQ(5126, last_buffer[1]); | 93 EXPECT_EQ(5126, last_buffer[1]); |
95 EXPECT_TRUE(last_buffer[1] < last_buffer[2]); | 94 EXPECT_TRUE(last_buffer[1] < last_buffer[2]); |
96 EXPECT_TRUE(last_buffer[2] < last_buffer[3]); | 95 EXPECT_TRUE(last_buffer[2] < last_buffer[3]); |
97 // Spot test negative incursion of sine wave. | 96 // Spot test negative incursion of sine wave. |
98 EXPECT_EQ(0, last_buffer[half_period]); | 97 EXPECT_EQ(0, last_buffer[half_period]); |
99 EXPECT_EQ(-5126, last_buffer[half_period + 1]); | 98 EXPECT_EQ(-5126, last_buffer[half_period + 1]); |
100 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]); | 99 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]); |
101 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]); | 100 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]); |
102 } | 101 } |
OLD | NEW |