| 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 <windows.h> | 5 #include <windows.h> |
| 6 #include <mmsystem.h> | 6 #include <mmsystem.h> |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/base_paths.h" | 9 #include "base/base_paths.h" |
| 10 #include "base/memory/aligned_memory.h" | 10 #include "base/memory/aligned_memory.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 using ::testing::_; | 23 using ::testing::_; |
| 24 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| 25 using ::testing::DoAll; | 25 using ::testing::DoAll; |
| 26 using ::testing::Field; | 26 using ::testing::Field; |
| 27 using ::testing::Invoke; | 27 using ::testing::Invoke; |
| 28 using ::testing::InSequence; | 28 using ::testing::InSequence; |
| 29 using ::testing::NiceMock; | 29 using ::testing::NiceMock; |
| 30 using ::testing::NotNull; | 30 using ::testing::NotNull; |
| 31 using ::testing::Return; | 31 using ::testing::Return; |
| 32 | 32 |
| 33 using base::win::ScopedCOMInitializer; | |
| 34 | |
| 35 namespace media { | 33 namespace media { |
| 36 | 34 |
| 37 static const wchar_t kAudioFile1_16b_m_16K[] | 35 static const wchar_t kAudioFile1_16b_m_16K[] |
| 38 = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; | 36 = L"media\\test\\data\\sweep02_16b_mono_16KHz.raw"; |
| 39 | 37 |
| 40 static int ClearData(AudioBus* audio_bus, uint32 total_bytes_delay) { | 38 static int ClearData(AudioBus* audio_bus, uint32 total_bytes_delay) { |
| 41 audio_bus->Zero(); | 39 audio_bus->Zero(); |
| 42 return audio_bus->frames(); | 40 return audio_bus->frames(); |
| 43 } | 41 } |
| 44 | 42 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 oas->Close(); | 413 oas->Close(); |
| 416 } | 414 } |
| 417 | 415 |
| 418 // With the low latency mode, WASAPI is utilized by default for Vista and | 416 // With the low latency mode, WASAPI is utilized by default for Vista and |
| 419 // higher and Wave is used for XP and lower. It is possible to utilize a | 417 // higher and Wave is used for XP and lower. It is possible to utilize a |
| 420 // smaller buffer size for WASAPI than for Wave. | 418 // smaller buffer size for WASAPI than for Wave. |
| 421 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { | 419 TEST(WinAudioTest, PCMWaveStreamPlay200HzToneLowLatency) { |
| 422 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); | 420 scoped_ptr<AudioManager> audio_man(AudioManager::CreateForTesting()); |
| 423 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); | 421 ABORT_AUDIO_TEST_IF_NOT(audio_man->HasAudioOutputDevices()); |
| 424 | 422 |
| 425 // The WASAPI API requires a correct COM environment. | |
| 426 ScopedCOMInitializer com_init(ScopedCOMInitializer::kMTA); | |
| 427 | |
| 428 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. | 423 // Use 10 ms buffer size for WASAPI and 50 ms buffer size for Wave. |
| 429 // Take the existing native sample rate into account. | 424 // Take the existing native sample rate into account. |
| 430 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); | 425 const AudioParameters params = audio_man->GetDefaultOutputStreamParameters(); |
| 431 int sample_rate = params.sample_rate(); | 426 int sample_rate = params.sample_rate(); |
| 432 uint32 samples_10_ms = sample_rate / 100; | 427 uint32 samples_10_ms = sample_rate / 100; |
| 433 int n = 1; | 428 int n = 1; |
| 434 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; | 429 (base::win::GetVersion() <= base::win::VERSION_XP) ? n = 5 : n = 1; |
| 435 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( | 430 AudioOutputStream* oas = audio_man->MakeAudioOutputStream( |
| 436 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 431 AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, |
| 437 CHANNEL_LAYOUT_MONO, sample_rate, | 432 CHANNEL_LAYOUT_MONO, sample_rate, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 oas->Start(&source); | 620 oas->Start(&source); |
| 626 | 621 |
| 627 ::WaitForSingleObject(thread, INFINITE); | 622 ::WaitForSingleObject(thread, INFINITE); |
| 628 ::CloseHandle(thread); | 623 ::CloseHandle(thread); |
| 629 | 624 |
| 630 oas->Stop(); | 625 oas->Stop(); |
| 631 oas->Close(); | 626 oas->Close(); |
| 632 } | 627 } |
| 633 | 628 |
| 634 } // namespace media | 629 } // namespace media |
| OLD | NEW |