Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: media/audio/simple_sources_unittest.cc

Issue 4661001: Simplified AudioOutputStream interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « media/audio/simple_sources.cc ('k') | media/audio/test_audio_input_controller_factory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/scoped_ptr.h" 7 #include "base/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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 EXPECT_EQ(kDataSize, push_source.UnProcessedBytes()); 51 EXPECT_EQ(kDataSize, push_source.UnProcessedBytes());
52 52
53 // Read everything from the push source. 53 // Read everything from the push source.
54 for (uint32 i = 0; i < kDataSize; i += kReadSize) { 54 for (uint32 i = 0; i < kDataSize; i += kReadSize) {
55 uint32 size = std::min(kDataSize - i , kReadSize); 55 uint32 size = std::min(kDataSize - i , kReadSize);
56 EXPECT_EQ(size, push_source.OnMoreData(NULL, read_data.get(), size, 56 EXPECT_EQ(size, push_source.OnMoreData(NULL, read_data.get(), size,
57 AudioBuffersState())); 57 AudioBuffersState()));
58 EXPECT_EQ(0, memcmp(data.get() + i, read_data.get(), size)); 58 EXPECT_EQ(0, memcmp(data.get() + i, read_data.get(), size));
59 } 59 }
60 EXPECT_EQ(0u, push_source.UnProcessedBytes()); 60 EXPECT_EQ(0u, push_source.UnProcessedBytes());
61
62 push_source.OnClose(NULL);
63 } 61 }
64 62
65 // Validate that the SineWaveAudioSource writes the expected values for 63 // Validate that the SineWaveAudioSource writes the expected values for
66 // the FORMAT_16BIT_MONO. The values are carefully selected so rounding issues 64 // the FORMAT_16BIT_MONO. The values are carefully selected so rounding issues
67 // do not affect the result. We also test that AudioManager::GetLastMockBuffer 65 // do not affect the result. We also test that AudioManager::GetLastMockBuffer
68 // works. 66 // works.
69 TEST(SimpleSources, SineWaveAudio16MonoTest) { 67 TEST(SimpleSources, SineWaveAudio16MonoTest) {
70 const uint32 samples = 1024; 68 const uint32 samples = 1024;
71 const uint32 bytes_per_sample = 2; 69 const uint32 bytes_per_sample = 2;
72 const int freq = 200; 70 const int freq = 200;
73 71
74 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, 72 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1,
75 freq, AudioParameters::kTelephoneSampleRate); 73 freq, AudioParameters::kTelephoneSampleRate);
76 74
77 AudioManager* audio_man = AudioManager::GetAudioManager(); 75 AudioManager* audio_man = AudioManager::GetAudioManager();
78 ASSERT_TRUE(NULL != audio_man); 76 ASSERT_TRUE(NULL != audio_man);
79 AudioParameters params( 77 AudioParameters params(
80 AudioParameters::AUDIO_MOCK, 1, AudioParameters::kTelephoneSampleRate, 78 AudioParameters::AUDIO_MOCK, 1, AudioParameters::kTelephoneSampleRate,
81 bytes_per_sample * 2); 79 bytes_per_sample * 2, samples);
82 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params); 80 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params);
83 ASSERT_TRUE(NULL != oas); 81 ASSERT_TRUE(NULL != oas);
84 EXPECT_TRUE(oas->Open(samples * bytes_per_sample)); 82 EXPECT_TRUE(oas->Open());
85 83
86 oas->Start(&source); 84 oas->Start(&source);
87 oas->Stop(); 85 oas->Stop();
88 oas->Close(); 86 oas->Close();
89 87
90 ASSERT_TRUE(FakeAudioOutputStream::GetLastFakeStream()); 88 ASSERT_TRUE(FakeAudioOutputStream::GetLastFakeStream());
91 const int16* last_buffer = 89 const int16* last_buffer =
92 reinterpret_cast<int16*>( 90 reinterpret_cast<int16*>(
93 FakeAudioOutputStream::GetLastFakeStream()->buffer()); 91 FakeAudioOutputStream::GetLastFakeStream()->buffer());
94 ASSERT_TRUE(NULL != last_buffer); 92 ASSERT_TRUE(NULL != last_buffer);
95 93
96 uint32 half_period = AudioParameters::kTelephoneSampleRate / (freq * 2); 94 uint32 half_period = AudioParameters::kTelephoneSampleRate / (freq * 2);
97 95
98 // Spot test positive incursion of sine wave. 96 // Spot test positive incursion of sine wave.
99 EXPECT_EQ(0, last_buffer[0]); 97 EXPECT_EQ(0, last_buffer[0]);
100 EXPECT_EQ(5126, last_buffer[1]); 98 EXPECT_EQ(5126, last_buffer[1]);
101 EXPECT_TRUE(last_buffer[1] < last_buffer[2]); 99 EXPECT_TRUE(last_buffer[1] < last_buffer[2]);
102 EXPECT_TRUE(last_buffer[2] < last_buffer[3]); 100 EXPECT_TRUE(last_buffer[2] < last_buffer[3]);
103 // Spot test negative incursion of sine wave. 101 // Spot test negative incursion of sine wave.
104 EXPECT_EQ(0, last_buffer[half_period]); 102 EXPECT_EQ(0, last_buffer[half_period]);
105 EXPECT_EQ(-5126, last_buffer[half_period + 1]); 103 EXPECT_EQ(-5126, last_buffer[half_period + 1]);
106 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]); 104 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]);
107 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]); 105 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]);
108 } 106 }
OLDNEW
« no previous file with comments | « media/audio/simple_sources.cc ('k') | media/audio/test_audio_input_controller_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698