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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 static_cast<int32*>(src), | 296 static_cast<int32*>(src), |
297 buflen / 4, | 297 buflen / 4, |
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 double 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.0; | 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 #else | 321 #else |
322 // Hardware for Linux is nearly always 48KHz. | 322 // Hardware for Linux is nearly always 48KHz. |
323 // TODO(crogers) : return correct value in rare non-48KHz cases. | 323 // TODO(crogers) : return correct value in rare non-48KHz cases. |
324 return 48000.0; | 324 return 48000; |
325 #endif | 325 #endif |
326 } | 326 } |
327 | 327 |
328 double GetAudioInputHardwareSampleRate(const std::string& device_id) { | 328 int GetAudioInputHardwareSampleRate(const std::string& device_id) { |
329 // TODO(henrika): add support for device selection on all platforms. | 329 // TODO(henrika): add support for device selection on all platforms. |
330 // Only exists on Windows today. | 330 // Only exists on Windows today. |
331 #if defined(OS_MACOSX) | 331 #if defined(OS_MACOSX) |
332 return AUAudioInputStream::HardwareSampleRate(); | 332 return AUAudioInputStream::HardwareSampleRate(); |
333 #elif defined(OS_WIN) | 333 #elif defined(OS_WIN) |
334 if (!IsWASAPISupported()) { | 334 if (!IsWASAPISupported()) { |
335 return 48000.0; | 335 return 48000; |
336 } | 336 } |
337 return WASAPIAudioInputStream::HardwareSampleRate(device_id); | 337 return WASAPIAudioInputStream::HardwareSampleRate(device_id); |
338 #else | 338 #else |
339 return 48000.0; | 339 return 48000; |
340 #endif | 340 #endif |
341 } | 341 } |
342 | 342 |
343 size_t GetAudioHardwareBufferSize() { | 343 size_t GetAudioHardwareBufferSize() { |
344 // The sizes here were determined by experimentation and are roughly | 344 // The sizes here were determined by experimentation and are roughly |
345 // the lowest value (for low latency) that still allowed glitch-free | 345 // the lowest value (for low latency) that still allowed glitch-free |
346 // audio under high loads. | 346 // audio under high loads. |
347 // | 347 // |
348 // For Mac OS X and Windows the chromium audio backend uses a low-latency | 348 // For Mac OS X and Windows the chromium audio backend uses a low-latency |
349 // Core Audio API, so a low buffer size is possible. For Linux, further | 349 // Core Audio API, so a low buffer size is possible. For Linux, further |
350 // tuning may be needed. | 350 // tuning may be needed. |
351 #if defined(OS_MACOSX) | 351 #if defined(OS_MACOSX) |
352 return 128; | 352 return 128; |
353 #elif defined(OS_WIN) | 353 #elif defined(OS_WIN) |
354 if (!IsWASAPISupported()) { | 354 if (!IsWASAPISupported()) { |
355 // Fall back to Windows Wave implementation on Windows XP or lower | 355 // Fall back to Windows Wave implementation on Windows XP or lower |
356 // and assume 48kHz as default sample rate. | 356 // and assume 48kHz as default sample rate. |
357 return 2048; | 357 return 2048; |
358 } | 358 } |
359 // This call must be done on a COM thread configured as MTA. | 359 // This call must be done on a COM thread configured as MTA. |
360 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. | 360 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. |
361 int mixing_sample_rate = | 361 int mixing_sample_rate = |
362 static_cast<int>(WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); | 362 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); |
363 if (mixing_sample_rate == 48000) | 363 if (mixing_sample_rate == 48000) |
364 return 480; | 364 return 480; |
365 else if (mixing_sample_rate == 44100) | 365 else if (mixing_sample_rate == 44100) |
366 return 448; | 366 return 448; |
367 else | 367 else |
368 return 960; | 368 return 960; |
369 #else | 369 #else |
370 return 2048; | 370 return 2048; |
371 #endif | 371 #endif |
372 } | 372 } |
373 | 373 |
374 uint32 GetAudioInputHardwareChannelCount(const std::string& device_id) { | 374 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { |
375 // TODO(henrika): add support for device selection on all platforms. | 375 // TODO(henrika): add support for device selection on all platforms. |
376 // Only exists on Windows today. | 376 // Only exists on Windows today. |
377 enum channel_layout { MONO = 1, STEREO = 2 }; | |
378 #if defined(OS_MACOSX) | 377 #if defined(OS_MACOSX) |
379 return MONO; | 378 return CHANNEL_LAYOUT_MONO; |
380 #elif defined(OS_WIN) | 379 #elif defined(OS_WIN) |
381 if (!IsWASAPISupported()) { | 380 if (!IsWASAPISupported()) { |
382 // Fall back to Windows Wave implementation on Windows XP or lower and | 381 // Fall back to Windows Wave implementation on Windows XP or lower and |
383 // use stereo by default. | 382 // use stereo by default. |
384 return STEREO; | 383 return CHANNEL_LAYOUT_STEREO; |
385 } | 384 } |
386 return WASAPIAudioInputStream::HardwareChannelCount(device_id); | 385 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ? |
| 386 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; |
387 #else | 387 #else |
388 return STEREO; | 388 return CHANNEL_LAYOUT_STEREO; |
389 #endif | 389 #endif |
390 } | 390 } |
391 | 391 |
392 // When transferring data in the shared memory, first word is size of data | 392 // When transferring data in the shared memory, first word is size of data |
393 // in bytes. Actual data starts immediately after it. | 393 // in bytes. Actual data starts immediately after it. |
394 | 394 |
395 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) { | 395 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) { |
396 // Need to reserve extra 4 bytes for size of data. | 396 // Need to reserve extra 4 bytes for size of data. |
397 return packet_size + sizeof(Atomic32); | 397 return packet_size + sizeof(Atomic32); |
398 } | 398 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 443 |
444 bool IsWASAPISupported() { | 444 bool IsWASAPISupported() { |
445 // Note: that function correctly returns that Windows Server 2003 does not | 445 // Note: that function correctly returns that Windows Server 2003 does not |
446 // support WASAPI. | 446 // support WASAPI. |
447 return base::win::GetVersion() >= base::win::VERSION_VISTA; | 447 return base::win::GetVersion() >= base::win::VERSION_VISTA; |
448 } | 448 } |
449 | 449 |
450 #endif | 450 #endif |
451 | 451 |
452 } // namespace media | 452 } // namespace media |
OLD | NEW |