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

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

Issue 9691001: Audio software mixer. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 8 years, 9 months 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
OLDNEW
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 <algorithm>
6
5 #include "base/logging.h" 7 #include "base/logging.h"
6 #include "base/basictypes.h" 8 #include "base/basictypes.h"
7 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
8 #include "base/time.h" 10 #include "base/time.h"
9 #include "media/audio/audio_manager.h" 11 #include "media/audio/audio_manager.h"
10 #include "media/audio/fake_audio_output_stream.h" 12 #include "media/audio/fake_audio_output_stream.h"
11 #include "media/audio/simple_sources.h" 13 #include "media/audio/simple_sources.h"
12 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
13 15
14 static void GenerateRandomData(char* buffer, uint32 len) { 16 static void GenerateRandomData(char* buffer, uint32 len) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 TEST(SimpleSources, SineWaveAudio16MonoTest) { 65 TEST(SimpleSources, SineWaveAudio16MonoTest) {
64 const uint32 samples = 1024; 66 const uint32 samples = 1024;
65 const uint32 bytes_per_sample = 2; 67 const uint32 bytes_per_sample = 2;
66 const int freq = 200; 68 const int freq = 200;
67 69
68 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, 70 SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1,
69 freq, AudioParameters::kTelephoneSampleRate); 71 freq, AudioParameters::kTelephoneSampleRate);
70 72
71 scoped_ptr<AudioManager> audio_man(AudioManager::Create()); 73 scoped_ptr<AudioManager> audio_man(AudioManager::Create());
72 AudioParameters params( 74 AudioParameters params(
73 AudioParameters::AUDIO_MOCK, CHANNEL_LAYOUT_MONO, 75 AudioParameters::AUDIO_MOCK, false, CHANNEL_LAYOUT_MONO,
74 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 8, samples); 76 AudioParameters::kTelephoneSampleRate, bytes_per_sample * 8, samples);
75 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params); 77 AudioOutputStream* oas = audio_man->MakeAudioOutputStream(params);
76 ASSERT_TRUE(NULL != oas); 78 ASSERT_TRUE(NULL != oas);
77 EXPECT_TRUE(oas->Open()); 79 EXPECT_TRUE(oas->Open());
78 80
79 oas->Start(&source); 81 oas->Start(&source);
80 oas->Stop(); 82 oas->Stop();
81 83
82 ASSERT_TRUE(FakeAudioOutputStream::GetCurrentFakeStream()); 84 ASSERT_TRUE(FakeAudioOutputStream::GetCurrentFakeStream());
83 const int16* last_buffer = 85 const int16* last_buffer =
84 reinterpret_cast<int16*>( 86 reinterpret_cast<int16*>(
85 FakeAudioOutputStream::GetCurrentFakeStream()->buffer()); 87 FakeAudioOutputStream::GetCurrentFakeStream()->buffer());
86 ASSERT_TRUE(NULL != last_buffer); 88 ASSERT_TRUE(NULL != last_buffer);
87 89
88 uint32 half_period = AudioParameters::kTelephoneSampleRate / (freq * 2); 90 uint32 half_period = AudioParameters::kTelephoneSampleRate / (freq * 2);
89 91
90 // Spot test positive incursion of sine wave. 92 // Spot test positive incursion of sine wave.
91 EXPECT_EQ(0, last_buffer[0]); 93 EXPECT_EQ(0, last_buffer[0]);
92 EXPECT_EQ(5126, last_buffer[1]); 94 EXPECT_EQ(5126, last_buffer[1]);
93 EXPECT_TRUE(last_buffer[1] < last_buffer[2]); 95 EXPECT_TRUE(last_buffer[1] < last_buffer[2]);
94 EXPECT_TRUE(last_buffer[2] < last_buffer[3]); 96 EXPECT_TRUE(last_buffer[2] < last_buffer[3]);
95 // Spot test negative incursion of sine wave. 97 // Spot test negative incursion of sine wave.
96 EXPECT_EQ(0, last_buffer[half_period]); 98 EXPECT_EQ(0, last_buffer[half_period]);
97 EXPECT_EQ(-5126, last_buffer[half_period + 1]); 99 EXPECT_EQ(-5126, last_buffer[half_period + 1]);
98 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]); 100 EXPECT_TRUE(last_buffer[half_period + 1] > last_buffer[half_period + 2]);
99 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]); 101 EXPECT_TRUE(last_buffer[half_period + 2] > last_buffer[half_period + 3]);
100 oas->Close(); 102 oas->Close();
101 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698