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

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

Issue 10993013: Return fixed hardware buffer size for odd sample rates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments Created 8 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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
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
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 // (i.e. via RemoteDesktop with remote audio disabled), but we should never
333 // return a buffer size of zero.
334 if (mixing_sample_rate == 0)
335 return kFallbackBufferSize;
336
327 // Use different buffer sizes depening on the sample rate . The existing 337 // Use different buffer sizes depening on the sample rate . The existing
328 // WASAPI implementation is tuned to provide the most stable callback 338 // WASAPI implementation is tuned to provide the most stable callback
329 // sequence using these combinations. 339 // sequence using these combinations.
330 if (mixing_sample_rate % 11025 == 0) 340 if (mixing_sample_rate % 11025 == 0)
331 // Use buffer size of ~10.15873 ms. 341 // Use buffer size of ~10.15873 ms.
332 return (112 * (mixing_sample_rate / 11025)); 342 return (112 * (mixing_sample_rate / 11025));
333 343
334 if (mixing_sample_rate % 8000 == 0) 344 if (mixing_sample_rate % 8000 == 0)
335 // Use buffer size of 10ms. 345 // Use buffer size of 10ms.
336 return (80 * (mixing_sample_rate / 8000)); 346 return (80 * (mixing_sample_rate / 8000));
337 347
348 // Ensure we always return a buffer size which is somewhat appropriate.
338 LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected."; 349 LOG(ERROR) << "Unknown sample rate " << mixing_sample_rate << " detected.";
339 return (mixing_sample_rate / 100); 350 if (mixing_sample_rate > limits::kMinSampleRate)
351 return (mixing_sample_rate / 100);
352 return kFallbackBufferSize;
340 #else 353 #else
341 return 2048; 354 return 2048;
342 #endif 355 #endif
343 } 356 }
344 357
345 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { 358 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) {
346 // TODO(henrika): add support for device selection on all platforms. 359 // TODO(henrika): add support for device selection on all platforms.
347 // Only exists on Windows today. 360 // Only exists on Windows today.
348 #if defined(OS_MACOSX) 361 #if defined(OS_MACOSX)
349 return CHANNEL_LAYOUT_MONO; 362 return CHANNEL_LAYOUT_MONO;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 // out performance was degraded compared to XP. 419 // out performance was degraded compared to XP.
407 // - The regression was fixed in Windows 7 and most configurations will work 420 // - 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. 421 // with 2, but some (e.g., some Sound Blasters) still need 3.
409 // - Some XP configurations (even multi-processor ones) also need 3. 422 // - Some XP configurations (even multi-processor ones) also need 3.
410 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 423 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
411 } 424 }
412 425
413 #endif 426 #endif
414 427
415 } // namespace media 428 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698