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 // Software adjust volume of samples, allows each audio stream its own | 5 // Software adjust volume of samples, allows each audio stream its own |
6 // volume without impacting master volume for chrome and other applications. | 6 // volume without impacting master volume for chrome and other applications. |
7 | 7 |
8 // Implemented as templates to allow 8, 16 and 32 bit implementations. | 8 // Implemented as templates to allow 8, 16 and 32 bit implementations. |
9 // 8 bit is unsigned and biased by 128. | 9 // 8 bit is unsigned and biased by 128. |
10 | 10 |
11 // TODO(vrk): This file has been running pretty wild and free, and it's likely | 11 // TODO(vrk): This file has been running pretty wild and free, and it's likely |
12 // that a lot of the functions can be simplified and made more elegant. Revisit | 12 // that a lot of the functions can be simplified and made more elegant. Revisit |
13 // after other audio cleanup is done. (crbug.com/120319) | 13 // after other audio cleanup is done. (crbug.com/120319) |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 #include <limits> | 16 #include <limits> |
17 | 17 |
18 #include "base/atomicops.h" | 18 #include "base/atomicops.h" |
19 #include "base/basictypes.h" | 19 #include "base/basictypes.h" |
20 #if defined(OS_WIN) | |
scherkus (not reviewing)
2012/06/27 04:20:30
this kind of splitting up + alpha order is a recip
henrika (OOO until Aug 14)
2012/06/27 11:26:07
Agree. Will fix.
| |
21 #include "base/command_line.h" | |
22 #endif | |
20 #include "base/logging.h" | 23 #include "base/logging.h" |
21 #include "base/shared_memory.h" | 24 #include "base/shared_memory.h" |
22 #include "base/time.h" | 25 #include "base/time.h" |
23 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
24 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
25 #include "base/win/windows_version.h" | 28 #include "base/win/windows_version.h" |
26 #include "media/audio/audio_manager_base.h" | 29 #include "media/audio/audio_manager_base.h" |
27 #endif | 30 #endif |
28 #include "media/audio/audio_parameters.h" | 31 #include "media/audio/audio_parameters.h" |
29 #include "media/audio/audio_util.h" | 32 #include "media/audio/audio_util.h" |
30 #if defined(OS_MACOSX) | 33 #if defined(OS_MACOSX) |
31 #include "media/audio/mac/audio_low_latency_input_mac.h" | 34 #include "media/audio/mac/audio_low_latency_input_mac.h" |
32 #include "media/audio/mac/audio_low_latency_output_mac.h" | 35 #include "media/audio/mac/audio_low_latency_output_mac.h" |
33 #endif | 36 #endif |
34 #if defined(OS_WIN) | 37 #if defined(OS_WIN) |
35 #include "media/audio/win/audio_low_latency_input_win.h" | 38 #include "media/audio/win/audio_low_latency_input_win.h" |
36 #include "media/audio/win/audio_low_latency_output_win.h" | 39 #include "media/audio/win/audio_low_latency_output_win.h" |
40 #include "media/base/media_switches.h" | |
37 #endif | 41 #endif |
38 | 42 |
39 using base::subtle::Atomic32; | 43 using base::subtle::Atomic32; |
40 | 44 |
41 const uint32 kUnknownDataSize = static_cast<uint32>(-1); | 45 const uint32 kUnknownDataSize = static_cast<uint32>(-1); |
42 | 46 |
43 namespace media { | 47 namespace media { |
44 | 48 |
45 // TODO(fbarchard): Convert to intrinsics for better efficiency. | 49 // TODO(fbarchard): Convert to intrinsics for better efficiency. |
46 template<class Fixed> | 50 template<class Fixed> |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 #if defined(OS_MACOSX) | 348 #if defined(OS_MACOSX) |
345 // Hardware sample-rate on the Mac can be configured, so we must query. | 349 // Hardware sample-rate on the Mac can be configured, so we must query. |
346 return AUAudioOutputStream::HardwareSampleRate(); | 350 return AUAudioOutputStream::HardwareSampleRate(); |
347 #elif defined(OS_WIN) | 351 #elif defined(OS_WIN) |
348 if (!IsWASAPISupported()) { | 352 if (!IsWASAPISupported()) { |
349 // Fall back to Windows Wave implementation on Windows XP or lower | 353 // Fall back to Windows Wave implementation on Windows XP or lower |
350 // and use 48kHz as default input sample rate. | 354 // and use 48kHz as default input sample rate. |
351 return 48000; | 355 return 48000; |
352 } | 356 } |
353 | 357 |
354 // Hardware sample-rate on Windows can be configured, so we must query. | 358 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
355 // TODO(henrika): improve possibility to specify audio endpoint. | 359 if (!cmd_line->HasSwitch(switches::kEnableExclusiveMode)) { |
356 // Use the default device (same as for Wave) for now to be compatible. | 360 // Hardware sample-rate on Windows can be configured, so we must query. |
357 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | 361 // TODO(henrika): improve possibility to specify audio endpoint. |
362 // Use the default device (same as for Wave) for now to be compatible. | |
363 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | |
364 } else { | |
365 return 44100; | |
366 } | |
358 #elif defined(OS_ANDROID) | 367 #elif defined(OS_ANDROID) |
359 return 16000; | 368 return 16000; |
360 #else | 369 #else |
361 // Hardware for Linux is nearly always 48KHz. | 370 // Hardware for Linux is nearly always 48KHz. |
362 // TODO(crogers) : return correct value in rare non-48KHz cases. | 371 // TODO(crogers) : return correct value in rare non-48KHz cases. |
363 return 48000; | 372 return 48000; |
364 #endif | 373 #endif |
365 } | 374 } |
366 | 375 |
367 int GetAudioInputHardwareSampleRate(const std::string& device_id) { | 376 int GetAudioInputHardwareSampleRate(const std::string& device_id) { |
(...skipping 22 matching lines...) Expand all Loading... | |
390 // Core Audio API, so a low buffer size is possible. For Linux, further | 399 // Core Audio API, so a low buffer size is possible. For Linux, further |
391 // tuning may be needed. | 400 // tuning may be needed. |
392 #if defined(OS_MACOSX) | 401 #if defined(OS_MACOSX) |
393 return 128; | 402 return 128; |
394 #elif defined(OS_WIN) | 403 #elif defined(OS_WIN) |
395 if (!IsWASAPISupported()) { | 404 if (!IsWASAPISupported()) { |
396 // Fall back to Windows Wave implementation on Windows XP or lower | 405 // Fall back to Windows Wave implementation on Windows XP or lower |
397 // and assume 48kHz as default sample rate. | 406 // and assume 48kHz as default sample rate. |
398 return 2048; | 407 return 2048; |
399 } | 408 } |
409 | |
410 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | |
411 if (cmd_line->HasSwitch(switches::kEnableExclusiveMode)) { | |
412 return 256; | |
413 } | |
414 | |
400 // This call must be done on a COM thread configured as MTA. | 415 // This call must be done on a COM thread configured as MTA. |
401 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. | 416 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. |
402 int mixing_sample_rate = | 417 int mixing_sample_rate = |
403 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | 418 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); |
404 if (mixing_sample_rate == 48000) | 419 if (mixing_sample_rate == 48000) |
405 return 480; | 420 return 480; |
406 else if (mixing_sample_rate == 44100) | 421 else if (mixing_sample_rate == 44100) |
407 return 448; | 422 return 448; |
408 else | 423 else |
409 return 960; | 424 return 960; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 if ((base::SysInfo::NumberOfProcessors() < 2) || | 545 if ((base::SysInfo::NumberOfProcessors() < 2) || |
531 (base::win::GetVersion() == base::win::VERSION_VISTA)) { | 546 (base::win::GetVersion() == base::win::VERSION_VISTA)) { |
532 return 3; | 547 return 3; |
533 } | 548 } |
534 return 2; | 549 return 2; |
535 } | 550 } |
536 | 551 |
537 #endif | 552 #endif |
538 | 553 |
539 } // namespace media | 554 } // namespace media |
OLD | NEW |