| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 205 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 206 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { | 206 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { |
| 207 // This sample rate will be combined with a buffer size of 256 samples | 207 // This sample rate will be combined with a buffer size of 256 samples |
| 208 // (see GetAudioHardwareBufferSize()), which corresponds to an output | 208 // (see GetAudioHardwareBufferSize()), which corresponds to an output |
| 209 // delay of ~5.33ms. | 209 // delay of ~5.33ms. |
| 210 return 48000; | 210 return 48000; |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Hardware sample-rate on Windows can be configured, so we must query. | 213 // Hardware sample-rate on Windows can be configured, so we must query. |
| 214 // TODO(henrika): improve possibility to specify an audio endpoint. | 214 // TODO(henrika): improve possibility to specify an audio endpoint. |
| 215 // Use the default device (same as for Wave) for now to be compatible | 215 // Use the default device (same as for Wave) for now to be compatible. |
| 216 // or possibly remove the ERole argument completely until it is in use. | 216 return WASAPIAudioOutputStream::HardwareSampleRate(); |
| 217 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | |
| 218 #elif defined(OS_ANDROID) | 217 #elif defined(OS_ANDROID) |
| 219 return 16000; | 218 return 16000; |
| 220 #else | 219 #else |
| 221 // Hardware for Linux is nearly always 48KHz. | 220 // Hardware for Linux is nearly always 48KHz. |
| 222 // TODO(crogers) : return correct value in rare non-48KHz cases. | 221 // TODO(crogers) : return correct value in rare non-48KHz cases. |
| 223 return 48000; | 222 return 48000; |
| 224 #endif | 223 #endif |
| 225 } | 224 } |
| 226 | 225 |
| 227 int GetAudioInputHardwareSampleRate(const std::string& device_id) { | 226 int GetAudioInputHardwareSampleRate(const std::string& device_id) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 249 // The sizes here were determined by experimentation and are roughly | 248 // The sizes here were determined by experimentation and are roughly |
| 250 // the lowest value (for low latency) that still allowed glitch-free | 249 // the lowest value (for low latency) that still allowed glitch-free |
| 251 // audio under high loads. | 250 // audio under high loads. |
| 252 // | 251 // |
| 253 // For Mac OS X and Windows the chromium audio backend uses a low-latency | 252 // For Mac OS X and Windows the chromium audio backend uses a low-latency |
| 254 // Core Audio API, so a low buffer size is possible. For Linux, further | 253 // Core Audio API, so a low buffer size is possible. For Linux, further |
| 255 // tuning may be needed. | 254 // tuning may be needed. |
| 256 #if defined(OS_MACOSX) | 255 #if defined(OS_MACOSX) |
| 257 return 128; | 256 return 128; |
| 258 #elif defined(OS_WIN) | 257 #elif defined(OS_WIN) |
| 258 // TODO(henrika): resolve conflict with GetUserBufferSize(). |
| 259 // If the user tries to set a buffer size using GetUserBufferSize() it will |
| 260 // most likely fail since only the native/perfect buffer size is allowed. |
| 261 |
| 259 // Buffer size to use when a proper size can't be determined from the system. | 262 // Buffer size to use when a proper size can't be determined from the system. |
| 260 static const int kFallbackBufferSize = 4096; | 263 static const int kFallbackBufferSize = 4096; |
| 261 | 264 |
| 262 if (!CoreAudioUtil::IsSupported()) { | 265 if (!CoreAudioUtil::IsSupported()) { |
| 263 // Fall back to Windows Wave implementation on Windows XP or lower | 266 // Fall back to Windows Wave implementation on Windows XP or lower |
| 264 // and assume 48kHz as default sample rate. | 267 // and assume 48kHz as default sample rate. |
| 265 return kFallbackBufferSize; | 268 return kFallbackBufferSize; |
| 266 } | 269 } |
| 267 | 270 |
| 268 // TODO(crogers): tune this size to best possible WebAudio performance. | 271 // TODO(crogers): tune this size to best possible WebAudio performance. |
| 269 // WebRTC always uses 10ms for Windows and does not call this method. | 272 // WebRTC always uses 10ms for Windows and does not call this method. |
| 270 // Note that exclusive mode is experimental. | 273 // Note that exclusive mode is experimental. |
| 271 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); | 274 const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); |
| 272 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { | 275 if (cmd_line->HasSwitch(switches::kEnableExclusiveAudio)) { |
| 273 return 256; | 276 return 256; |
| 274 } | 277 } |
| 275 | 278 |
| 276 // TODO(henrika): remove when the --enable-webaudio-input flag is no longer | 279 AudioParameters params; |
| 277 // utilized. | 280 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole, |
| 278 if (cmd_line->HasSwitch(switches::kEnableWebAudioInput)) { | 281 ¶ms); |
| 279 AudioParameters params; | 282 return FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer(); |
| 280 HRESULT hr = CoreAudioUtil::GetPreferredAudioParameters(eRender, eConsole, | |
| 281 ¶ms); | |
| 282 return FAILED(hr) ? kFallbackBufferSize : params.frames_per_buffer(); | |
| 283 } | |
| 284 | |
| 285 // This call must be done on a COM thread configured as MTA. | |
| 286 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. | |
| 287 int mixing_sample_rate = | |
| 288 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | |
| 289 | |
| 290 // Windows will return a sample rate of 0 when no audio output is available | |
| 291 // (i.e. via RemoteDesktop with remote audio disabled), but we should never | |
| 292 // return a buffer size of zero. | |
| 293 if (mixing_sample_rate == 0) | |
| 294 return kFallbackBufferSize; | |
| 295 | |
| 296 // Use different buffer sizes depening on the sample rate . The existing | |
| 297 // WASAPI implementation is tuned to provide the most stable callback | |
| 298 // sequence using these combinations. | |
| 299 if (mixing_sample_rate % 11025 == 0) | |
| 300 // Use buffer size of ~10.15873 ms. | |
| 301 return (112 * (mixing_sample_rate / 11025)); | |
| 302 | |
| 303 if (mixing_sample_rate % 8000 == 0) | |
| 304 // Use buffer size of 10ms. | |
| 305 return (80 * (mixing_sample_rate / 8000)); | |
| 306 | |
| 307 // Ensure we always return a buffer size which is somewhat appropriate. | |
| 308 LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected."; | |
| 309 if (mixing_sample_rate > limits::kMinSampleRate) | |
| 310 return (mixing_sample_rate / 100); | |
| 311 return kFallbackBufferSize; | |
| 312 #else | 283 #else |
| 313 return 2048; | 284 return 2048; |
| 314 #endif | 285 #endif |
| 315 } | 286 } |
| 316 | 287 |
| 317 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { | 288 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { |
| 318 // TODO(henrika): add support for device selection on all platforms. | 289 // TODO(henrika): add support for device selection on all platforms. |
| 319 // Only exists on Windows today. | 290 // Only exists on Windows today. |
| 320 #if defined(OS_MACOSX) | 291 #if defined(OS_MACOSX) |
| 321 return CHANNEL_LAYOUT_MONO; | 292 return CHANNEL_LAYOUT_MONO; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // out performance was degraded compared to XP. | 347 // out performance was degraded compared to XP. |
| 377 // - The regression was fixed in Windows 7 and most configurations will work | 348 // - The regression was fixed in Windows 7 and most configurations will work |
| 378 // with 2, but some (e.g., some Sound Blasters) still need 3. | 349 // with 2, but some (e.g., some Sound Blasters) still need 3. |
| 379 // - Some XP configurations (even multi-processor ones) also need 3. | 350 // - Some XP configurations (even multi-processor ones) also need 3. |
| 380 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; | 351 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; |
| 381 } | 352 } |
| 382 | 353 |
| 383 #endif | 354 #endif |
| 384 | 355 |
| 385 } // namespace media | 356 } // namespace media |
| OLD | NEW |