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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 volume); | 298 volume); |
299 break; | 299 break; |
300 default: | 300 default: |
301 NOTREACHED() << "Illegal bytes per sample"; | 301 NOTREACHED() << "Illegal bytes per sample"; |
302 break; | 302 break; |
303 } | 303 } |
304 } | 304 } |
305 | 305 |
306 int GetAudioHardwareSampleRate() { | 306 int GetAudioHardwareSampleRate() { |
307 #if defined(OS_MACOSX) | 307 #if defined(OS_MACOSX) |
308 // Hardware sample-rate on the Mac can be configured, so we must query. | 308 // Hardware sample-rate on the Mac can be configured, so we must query. |
309 return AUAudioOutputStream::HardwareSampleRate(); | 309 return AUAudioOutputStream::HardwareSampleRate(); |
310 #elif defined(OS_WIN) | 310 #elif defined(OS_WIN) |
311 if (!IsWASAPISupported()) { | 311 if (!IsWASAPISupported()) { |
312 // Fall back to Windows Wave implementation on Windows XP or lower | 312 // Fall back to Windows Wave implementation on Windows XP or lower |
313 // and use 48kHz as default input sample rate. | 313 // and use 48kHz as default input sample rate. |
314 return 48000; | 314 return 48000; |
315 } | 315 } |
316 | 316 |
317 // Hardware sample-rate on Windows can be configured, so we must query. | 317 // Hardware sample-rate on Windows can be configured, so we must query. |
318 // TODO(henrika): improve possibility to specify audio endpoint. | 318 // TODO(henrika): improve possibility to specify audio endpoint. |
319 // Use the default device (same as for Wave) for now to be compatible. | 319 // Use the default device (same as for Wave) for now to be compatible. |
320 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | 320 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); |
| 321 #elif defined(OS_ANDROID) |
| 322 return 16000; |
321 #else | 323 #else |
322 // Hardware for Linux is nearly always 48KHz. | 324 // Hardware for Linux is nearly always 48KHz. |
323 // TODO(crogers) : return correct value in rare non-48KHz cases. | 325 // TODO(crogers) : return correct value in rare non-48KHz cases. |
324 return 48000; | 326 return 48000; |
325 #endif | 327 #endif |
326 } | 328 } |
327 | 329 |
328 int GetAudioInputHardwareSampleRate(const std::string& device_id) { | 330 int GetAudioInputHardwareSampleRate(const std::string& device_id) { |
329 // TODO(henrika): add support for device selection on all platforms. | 331 // TODO(henrika): add support for device selection on all platforms. |
330 // Only exists on Windows today. | 332 // Only exists on Windows today. |
331 #if defined(OS_MACOSX) | 333 #if defined(OS_MACOSX) |
332 return AUAudioInputStream::HardwareSampleRate(); | 334 return AUAudioInputStream::HardwareSampleRate(); |
333 #elif defined(OS_WIN) | 335 #elif defined(OS_WIN) |
334 if (!IsWASAPISupported()) { | 336 if (!IsWASAPISupported()) { |
335 return 48000; | 337 return 48000; |
336 } | 338 } |
337 return WASAPIAudioInputStream::HardwareSampleRate(device_id); | 339 return WASAPIAudioInputStream::HardwareSampleRate(device_id); |
| 340 #elif defined(OS_ANDROID) |
| 341 return 16000; |
338 #else | 342 #else |
339 return 48000; | 343 return 48000; |
340 #endif | 344 #endif |
341 } | 345 } |
342 | 346 |
343 size_t GetAudioHardwareBufferSize() { | 347 size_t GetAudioHardwareBufferSize() { |
344 // The sizes here were determined by experimentation and are roughly | 348 // The sizes here were determined by experimentation and are roughly |
345 // the lowest value (for low latency) that still allowed glitch-free | 349 // the lowest value (for low latency) that still allowed glitch-free |
346 // audio under high loads. | 350 // audio under high loads. |
347 // | 351 // |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 447 |
444 bool IsWASAPISupported() { | 448 bool IsWASAPISupported() { |
445 // Note: that function correctly returns that Windows Server 2003 does not | 449 // Note: that function correctly returns that Windows Server 2003 does not |
446 // support WASAPI. | 450 // support WASAPI. |
447 return base::win::GetVersion() >= base::win::VERSION_VISTA; | 451 return base::win::GetVersion() >= base::win::VERSION_VISTA; |
448 } | 452 } |
449 | 453 |
450 #endif | 454 #endif |
451 | 455 |
452 } // namespace media | 456 } // namespace media |
OLD | NEW |