Chromium Code Reviews| 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 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 | 25 |
| 26 #if defined(OS_MACOSX) | 26 #if defined(OS_MACOSX) |
| 27 #include "media/audio/mac/audio_low_latency_input_mac.h" | 27 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 28 #include "media/audio/mac/audio_low_latency_output_mac.h" | 28 #include "media/audio/mac/audio_low_latency_output_mac.h" |
| 29 #elif defined(OS_WIN) | 29 #elif defined(OS_WIN) |
| 30 #include "base/command_line.h" | 30 #include "base/command_line.h" |
| 31 #include "base/win/windows_version.h" | 31 #include "base/win/windows_version.h" |
| 32 #include "media/audio/audio_manager_base.h" | 32 #include "media/audio/audio_manager_base.h" |
| 33 #include "media/audio/win/audio_low_latency_input_win.h" | 33 #include "media/audio/win/audio_low_latency_input_win.h" |
| 34 #include "media/audio/win/audio_low_latency_output_win.h" | 34 #include "media/audio/win/audio_low_latency_output_win.h" |
| 35 #include "media/base/limits.h" | |
| 35 #include "media/base/media_switches.h" | 36 #include "media/base/media_switches.h" |
| 36 #endif | 37 #endif |
| 37 | 38 |
| 38 namespace media { | 39 namespace media { |
| 39 | 40 |
| 40 // TODO(fbarchard): Convert to intrinsics for better efficiency. | 41 // TODO(fbarchard): Convert to intrinsics for better efficiency. |
| 41 template<class Fixed> | 42 template<class Fixed> |
| 42 static int ScaleChannel(int channel, int volume) { | 43 static int ScaleChannel(int channel, int volume) { |
| 43 return static_cast<int>((static_cast<Fixed>(channel) * volume) >> 16); | 44 return static_cast<int>((static_cast<Fixed>(channel) * volume) >> 16); |
| 44 } | 45 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // The sizes here were determined by experimentation and are roughly | 299 // The sizes here were determined by experimentation and are roughly |
| 299 // the lowest value (for low latency) that still allowed glitch-free | 300 // the lowest value (for low latency) that still allowed glitch-free |
| 300 // audio under high loads. | 301 // audio under high loads. |
| 301 // | 302 // |
| 302 // For Mac OS X and Windows the chromium audio backend uses a low-latency | 303 // For Mac OS X and Windows the chromium audio backend uses a low-latency |
| 303 // Core Audio API, so a low buffer size is possible. For Linux, further | 304 // Core Audio API, so a low buffer size is possible. For Linux, further |
| 304 // tuning may be needed. | 305 // tuning may be needed. |
| 305 #if defined(OS_MACOSX) | 306 #if defined(OS_MACOSX) |
| 306 return 128; | 307 return 128; |
| 307 #elif defined(OS_WIN) | 308 #elif defined(OS_WIN) |
| 309 // Buffer size to use when a proper size can't be determined from the system. | |
| 310 static const int kFallbackBufferSize = 2048; | |
| 311 | |
| 308 if (!IsWASAPISupported()) { | 312 if (!IsWASAPISupported()) { |
| 309 // Fall back to Windows Wave implementation on Windows XP or lower | 313 // Fall back to Windows Wave implementation on Windows XP or lower |
| 310 // and assume 48kHz as default sample rate. | 314 // and assume 48kHz as default sample rate. |
| 311 return 2048; | 315 return kFallbackBufferSize; |
| 312 } | 316 } |
| 313 | 317 |
| 314 // TODO(crogers): tune this size to best possible WebAudio performance. | 318 // TODO(crogers): tune this size to best possible WebAudio performance. |
| 315 // WebRTC always uses 10ms for Windows and does not call this method. | 319 // WebRTC always uses 10ms for Windows and does not call this method. |
| 316 // Note that exclusive mode is experimental. | 320 // Note that exclusive mode is experimental. |
| 317 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 321 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 318 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { | 322 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { |
| 319 return 256; | 323 return 256; |
| 320 } | 324 } |
| 321 | 325 |
| 322 // This call must be done on a COM thread configured as MTA. | 326 // This call must be done on a COM thread configured as MTA. |
| 323 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. | 327 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. |
| 324 int mixing_sample_rate = | 328 int mixing_sample_rate = |
| 325 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | 329 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); |
| 326 | 330 |
| 331 // Windows will return a sample rate of 0 when no audio output is available, | |
| 332 // but we should never return a buffer size of zero. | |
| 333 if (mixing_sample_rate == 0) | |
| 334 return kFallbackBufferSize; | |
| 335 | |
| 327 // Use different buffer sizes depening on the sample rate . The existing | 336 // Use different buffer sizes depening on the sample rate . The existing |
| 328 // WASAPI implementation is tuned to provide the most stable callback | 337 // WASAPI implementation is tuned to provide the most stable callback |
| 329 // sequence using these combinations. | 338 // sequence using these combinations. |
| 330 if (mixing_sample_rate % 11025 == 0) | 339 if (mixing_sample_rate % 11025 == 0) |
| 331 // Use buffer size of ~10.15873 ms. | 340 // Use buffer size of ~10.15873 ms. |
| 332 return (112 * (mixing_sample_rate / 11025)); | 341 return (112 * (mixing_sample_rate / 11025)); |
| 333 | 342 |
| 334 if (mixing_sample_rate % 8000 == 0) | 343 if (mixing_sample_rate % 8000 == 0) |
| 335 // Use buffer size of 10ms. | 344 // Use buffer size of 10ms. |
| 336 return (80 * (mixing_sample_rate / 8000)); | 345 return (80 * (mixing_sample_rate / 8000)); |
| 337 | 346 |
| 347 // Ensure we always return a buffer size which is somewhat appropriate. | |
| 338 LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected."; | 348 LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected."; |
| 339 return (mixing_sample_rate / 100); | 349 if (mixing_sample_rate > limits::kMinSampleRate) |
| 350 return (mixing_sample_rate / 100); | |
| 351 return kFallbackBufferSize; | |
|
Ami GONE FROM CHROMIUM
2012/09/25 18:25:46
any reason you're going to 2048 here from the 960
DaleCurtis
2012/09/25 18:39:30
Most cases are now handled by the mixing_sample_ra
| |
| 340 #else | 352 #else |
| 341 return 2048; | 353 return 2048; |
|
Ami GONE FROM CHROMIUM
2012/09/25 18:25:46
constify
DaleCurtis
2012/09/25 18:39:30
I intentionally skipped this because it's not in t
| |
| 342 #endif | 354 #endif |
| 343 } | 355 } |
| 344 | 356 |
| 345 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { | 357 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { |
| 346 // TODO(henrika): add support for device selection on all platforms. | 358 // TODO(henrika): add support for device selection on all platforms. |
| 347 // Only exists on Windows today. | 359 // Only exists on Windows today. |
| 348 #if defined(OS_MACOSX) | 360 #if defined(OS_MACOSX) |
| 349 return CHANNEL_LAYOUT_MONO; | 361 return CHANNEL_LAYOUT_MONO; |
| 350 #elif defined(OS_WIN) | 362 #elif defined(OS_WIN) |
| 351 if (!IsWASAPISupported()) { | 363 if (!IsWASAPISupported()) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 406 // out performance was degraded compared to XP. | 418 // out performance was degraded compared to XP. |
| 407 // - The regression was fixed in Windows 7 and most configurations will work | 419 // - The regression was fixed in Windows 7 and most configurations will work |
| 408 // with 2, but some (e.g., some Sound Blasters) still need 3. | 420 // with 2, but some (e.g., some Sound Blasters) still need 3. |
| 409 // - Some XP configurations (even multi-processor ones) also need 3. | 421 // - Some XP configurations (even multi-processor ones) also need 3. |
| 410 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; | 422 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; |
| 411 } | 423 } |
| 412 | 424 |
| 413 #endif | 425 #endif |
| 414 | 426 |
| 415 } // namespace media | 427 } // namespace media |
| OLD | NEW |