summaryrefslogtreecommitdiffstats
path: root/media/audio/simple_sources_unittest.cc
diff options
context:
space:
mode:
authorhclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 00:06:17 +0000
committerhclam@google.com <hclam@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 00:06:17 +0000
commitdff80f15dca03378e052f725a6dbff46f4649249 (patch)
tree8b87e546774f6ff053bf590fe440e653314adce7 /media/audio/simple_sources_unittest.cc
parentee01535e43949832b8fb57a74d892390e01d36dd (diff)
downloadchromium_src-dff80f15dca03378e052f725a6dbff46f4649249.zip
chromium_src-dff80f15dca03378e052f725a6dbff46f4649249.tar.gz
chromium_src-dff80f15dca03378e052f725a6dbff46f4649249.tar.bz2
Refactoring to share MockAudioOutputStream implementations across 3 platforms
Re-trying the previous CL. The last change got reverted because of valgrind failure. TBR=scherkus Original CL: http://codereview.chromium.org/155471 Review URL: http://codereview.chromium.org/159167 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21242 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/simple_sources_unittest.cc')
-rw-r--r--media/audio/simple_sources_unittest.cc46
1 files changed, 46 insertions, 0 deletions
diff --git a/media/audio/simple_sources_unittest.cc b/media/audio/simple_sources_unittest.cc
index 32176b7..ef6a5a7 100644
--- a/media/audio/simple_sources_unittest.cc
+++ b/media/audio/simple_sources_unittest.cc
@@ -6,6 +6,7 @@
#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "base/time.h"
+#include "media/audio/fake_audio_output_stream.h"
#include "media/audio/simple_sources.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -60,3 +61,48 @@ TEST(SimpleSourcesTest, PushSourceSmallerWrite) {
push_source.OnClose(NULL);
}
+
+// Validate that the SineWaveAudioSource writes the expected values for
+// the FORMAT_16BIT_MONO. The values are carefully selected so rounding issues
+// do not affect the result. We also test that AudioManager::GetLastMockBuffer
+// works.
+TEST(SimpleSources, SineWaveAudio16MonoTest) {
+ const size_t samples = 1024;
+ const size_t bytes_per_sample = 2;
+ const int freq = 200;
+
+ SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1,
+ freq, AudioManager::kTelephoneSampleRate);
+
+ AudioManager* audio_man = AudioManager::GetAudioManager();
+ ASSERT_TRUE(NULL != audio_man);
+ AudioOutputStream* oas =
+ audio_man->MakeAudioStream(AudioManager::AUDIO_MOCK, 1,
+ AudioManager::kTelephoneSampleRate,
+ bytes_per_sample * 2);
+ ASSERT_TRUE(NULL != oas);
+ EXPECT_TRUE(oas->Open(samples * bytes_per_sample));
+
+ oas->Start(&source);
+ oas->Stop();
+ oas->Close();
+
+ ASSERT_TRUE(FakeAudioOutputStream::GetLastFakeStream());
+ const int16* last_buffer =
+ reinterpret_cast<int16*>(
+ FakeAudioOutputStream::GetLastFakeStream()->buffer());
+ ASSERT_TRUE(NULL != last_buffer);
+
+ size_t half_period = AudioManager::kTelephoneSampleRate / (freq * 2);
+
+ // Spot test positive incursion of sine wave.
+ EXPECT_EQ(0, last_buffer[0]);
+ EXPECT_EQ(5126, last_buffer[1]);
+ EXPECT_TRUE(last_buffer[1] < last_buffer[2]);
+ EXPECT_TRUE(last_buffer[2] < last_buffer[3]);
+ // Spot test negative incursion of sine wave.
+ EXPECT_EQ(0, last_buffer[half_period]);
+ EXPECT_EQ(-5126, last_buffer[half_period + 1]);
+ EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]);
+ EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]);
+}