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

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

Issue 11309015: Increase Windows XP hardware buffer size to 4096. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix includes. Created 8 years, 1 month 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
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
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 "media/audio/audio_util.h" 15 #include "media/audio/audio_util.h"
16 16
17 #include <algorithm> 17 #include <algorithm>
18 #include <limits> 18 #include <limits>
19 19
20 #include "base/basictypes.h" 20 #include "base/basictypes.h"
21 #include "base/command_line.h"
21 #include "base/logging.h" 22 #include "base/logging.h"
23 #include "base/string_number_conversions.h"
22 #include "base/time.h" 24 #include "base/time.h"
23 #include "media/audio/audio_parameters.h" 25 #include "media/audio/audio_parameters.h"
24 #include "media/base/audio_bus.h" 26 #include "media/base/audio_bus.h"
27 #include "media/base/media_switches.h"
25 28
26 #if defined(OS_MACOSX) 29 #if defined(OS_MACOSX)
27 #include "media/audio/mac/audio_low_latency_input_mac.h" 30 #include "media/audio/mac/audio_low_latency_input_mac.h"
28 #include "media/audio/mac/audio_low_latency_output_mac.h" 31 #include "media/audio/mac/audio_low_latency_output_mac.h"
29 #elif defined(OS_WIN) 32 #elif defined(OS_WIN)
30 #include "base/command_line.h"
31 #include "base/win/windows_version.h" 33 #include "base/win/windows_version.h"
32 #include "media/audio/audio_manager_base.h" 34 #include "media/audio/audio_manager_base.h"
33 #include "media/audio/win/audio_low_latency_input_win.h" 35 #include "media/audio/win/audio_low_latency_input_win.h"
34 #include "media/audio/win/audio_low_latency_output_win.h" 36 #include "media/audio/win/audio_low_latency_output_win.h"
35 #include "media/audio/win/core_audio_util_win.h" 37 #include "media/audio/win/core_audio_util_win.h"
36 #include "media/base/limits.h" 38 #include "media/base/limits.h"
37 #include "media/base/media_switches.h"
38 #endif 39 #endif
39 40
40 namespace media { 41 namespace media {
41 42
43 // Returns user buffer size as specified on the command line or 0 if no buffer
44 // size has been specified.
45 static int GetUserBufferSize() {
46 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
47 int buffer_size = 0;
48 std::string buffer_size_str(cmd_line->GetSwitchValueASCII(
49 switches::kAudioBufferSize));
50 if (base::StringToInt(buffer_size_str, &buffer_size) && buffer_size > 0) {
51 return buffer_size;
52 }
53
54 return 0;
55 }
56
42 // TODO(fbarchard): Convert to intrinsics for better efficiency. 57 // TODO(fbarchard): Convert to intrinsics for better efficiency.
43 template<class Fixed> 58 template<class Fixed>
44 static int ScaleChannel(int channel, int volume) { 59 static int ScaleChannel(int channel, int volume) {
45 return static_cast<int>((static_cast<Fixed>(channel) * volume) >> 16); 60 return static_cast<int>((static_cast<Fixed>(channel) * volume) >> 16);
46 } 61 }
47 62
48 template<class Format, class Fixed, int bias> 63 template<class Format, class Fixed, int bias>
49 static void AdjustVolume(Format* buf_out, 64 static void AdjustVolume(Format* buf_out,
50 int sample_count, 65 int sample_count,
51 int fixed_volume) { 66 int fixed_volume) {
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 } 233 }
219 return WASAPIAudioInputStream::HardwareSampleRate(device_id); 234 return WASAPIAudioInputStream::HardwareSampleRate(device_id);
220 #elif defined(OS_ANDROID) 235 #elif defined(OS_ANDROID)
221 return 16000; 236 return 16000;
222 #else 237 #else
223 return 48000; 238 return 48000;
224 #endif 239 #endif
225 } 240 }
226 241
227 size_t GetAudioHardwareBufferSize() { 242 size_t GetAudioHardwareBufferSize() {
243 int user_buffer_size = GetUserBufferSize();
244 if (user_buffer_size)
245 return user_buffer_size;
246
228 // The sizes here were determined by experimentation and are roughly 247 // The sizes here were determined by experimentation and are roughly
229 // the lowest value (for low latency) that still allowed glitch-free 248 // the lowest value (for low latency) that still allowed glitch-free
230 // audio under high loads. 249 // audio under high loads.
231 // 250 //
232 // For Mac OS X and Windows the chromium audio backend uses a low-latency 251 // For Mac OS X and Windows the chromium audio backend uses a low-latency
233 // Core Audio API, so a low buffer size is possible. For Linux, further 252 // Core Audio API, so a low buffer size is possible. For Linux, further
234 // tuning may be needed. 253 // tuning may be needed.
235 #if defined(OS_MACOSX) 254 #if defined(OS_MACOSX)
236 return 128; 255 return 128;
237 #elif defined(OS_WIN) 256 #elif defined(OS_WIN)
238 // Buffer size to use when a proper size can't be determined from the system. 257 // Buffer size to use when a proper size can't be determined from the system.
239 static const int kFallbackBufferSize = 2048; 258 static const int kFallbackBufferSize = 4096;
240 259
241 if (!CoreAudioUtil::IsSupported()) { 260 if (!CoreAudioUtil::IsSupported()) {
242 // Fall back to Windows Wave implementation on Windows XP or lower 261 // Fall back to Windows Wave implementation on Windows XP or lower
243 // and assume 48kHz as default sample rate. 262 // and assume 48kHz as default sample rate.
244 return kFallbackBufferSize; 263 return kFallbackBufferSize;
245 } 264 }
246 265
247 // TODO(crogers): tune this size to best possible WebAudio performance. 266 // TODO(crogers): tune this size to best possible WebAudio performance.
248 // WebRTC always uses 10ms for Windows and does not call this method. 267 // WebRTC always uses 10ms for Windows and does not call this method.
249 // Note that exclusive mode is experimental. 268 // Note that exclusive mode is experimental.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ? 326 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ?
308 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; 327 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO;
309 #else 328 #else
310 return CHANNEL_LAYOUT_STEREO; 329 return CHANNEL_LAYOUT_STEREO;
311 #endif 330 #endif
312 } 331 }
313 332
314 // Computes a buffer size based on the given |sample_rate|. Must be used in 333 // Computes a buffer size based on the given |sample_rate|. Must be used in
315 // conjunction with AUDIO_PCM_LINEAR. 334 // conjunction with AUDIO_PCM_LINEAR.
316 size_t GetHighLatencyOutputBufferSize(int sample_rate) { 335 size_t GetHighLatencyOutputBufferSize(int sample_rate) {
336 int user_buffer_size = GetUserBufferSize();
337 if (user_buffer_size)
338 return user_buffer_size;
339
317 // TODO(vrk/crogers): The buffer sizes that this function computes is probably 340 // TODO(vrk/crogers): The buffer sizes that this function computes is probably
318 // overly conservative. However, reducing the buffer size to 2048-8192 bytes 341 // overly conservative. However, reducing the buffer size to 2048-8192 bytes
319 // caused crbug.com/108396. This computation should be revisited while making 342 // caused crbug.com/108396. This computation should be revisited while making
320 // sure crbug.com/108396 doesn't happen again. 343 // sure crbug.com/108396 doesn't happen again.
321 344
322 // The minimum number of samples in a hardware packet. 345 // The minimum number of samples in a hardware packet.
323 // This value is selected so that we can handle down to 5khz sample rate. 346 // This value is selected so that we can handle down to 5khz sample rate.
324 static const size_t kMinSamplesPerHardwarePacket = 1024; 347 static const size_t kMinSamplesPerHardwarePacket = 1024;
325 348
326 // The maximum number of samples in a hardware packet. 349 // The maximum number of samples in a hardware packet.
(...skipping 24 matching lines...) Expand all
351 // out performance was degraded compared to XP. 374 // out performance was degraded compared to XP.
352 // - The regression was fixed in Windows 7 and most configurations will work 375 // - The regression was fixed in Windows 7 and most configurations will work
353 // with 2, but some (e.g., some Sound Blasters) still need 3. 376 // with 2, but some (e.g., some Sound Blasters) still need 3.
354 // - Some XP configurations (even multi-processor ones) also need 3. 377 // - Some XP configurations (even multi-processor ones) also need 3.
355 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 378 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
356 } 379 }
357 380
358 #endif 381 #endif
359 382
360 } // namespace media 383 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698