| 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 if (sample < -32768.0) | 234 if (sample < -32768.0) |
| 235 sample = -32768.0; | 235 sample = -32768.0; |
| 236 else if (sample > 32767.0) | 236 else if (sample > 32767.0) |
| 237 sample = 32767.0; | 237 sample = 32767.0; |
| 238 | 238 |
| 239 destination[j * channels + i] = static_cast<int16>(sample); | 239 destination[j * channels + i] = static_cast<int16>(sample); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 double GetAudioHardwareSampleRate() { | 244 int GetAudioHardwareSampleRate() { |
| 245 #if defined(OS_MACOSX) | 245 #if defined(OS_MACOSX) |
| 246 // Hardware sample-rate on the Mac can be configured, so we must query. | 246 // Hardware sample-rate on the Mac can be configured, so we must query. |
| 247 return AUAudioOutputStream::HardwareSampleRate(); | 247 return AUAudioOutputStream::HardwareSampleRate(); |
| 248 #elif defined(OS_WIN) | 248 #elif defined(OS_WIN) |
| 249 if (!IsWASAPISupported()) { | 249 if (!IsWASAPISupported()) { |
| 250 // Fall back to Windows Wave implementation on Windows XP or lower | 250 // Fall back to Windows Wave implementation on Windows XP or lower |
| 251 // and use 48kHz as default input sample rate. | 251 // and use 48kHz as default input sample rate. |
| 252 return 48000.0; | 252 return 48000; |
| 253 } | 253 } |
| 254 | 254 |
| 255 // Hardware sample-rate on Windows can be configured, so we must query. | 255 // Hardware sample-rate on Windows can be configured, so we must query. |
| 256 // TODO(henrika): improve possibility to specify audio endpoint. | 256 // TODO(henrika): improve possibility to specify audio endpoint. |
| 257 // Use the default device (same as for Wave) for now to be compatible. | 257 // Use the default device (same as for Wave) for now to be compatible. |
| 258 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | 258 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); |
| 259 #else | 259 #else |
| 260 // Hardware for Linux is nearly always 48KHz. | 260 // Hardware for Linux is nearly always 48KHz. |
| 261 // TODO(crogers) : return correct value in rare non-48KHz cases. | 261 // TODO(crogers) : return correct value in rare non-48KHz cases. |
| 262 return 48000.0; | 262 return 48000; |
| 263 #endif | 263 #endif |
| 264 } | 264 } |
| 265 | 265 |
| 266 double GetAudioInputHardwareSampleRate(const std::string& device_id) { | 266 int GetAudioInputHardwareSampleRate(const std::string& device_id) { |
| 267 // TODO(henrika): add support for device selection on all platforms. | 267 // TODO(henrika): add support for device selection on all platforms. |
| 268 // Only exists on Windows today. | 268 // Only exists on Windows today. |
| 269 #if defined(OS_MACOSX) | 269 #if defined(OS_MACOSX) |
| 270 return AUAudioInputStream::HardwareSampleRate(); | 270 return AUAudioInputStream::HardwareSampleRate(); |
| 271 #elif defined(OS_WIN) | 271 #elif defined(OS_WIN) |
| 272 if (!IsWASAPISupported()) { | 272 if (!IsWASAPISupported()) { |
| 273 return 48000.0; | 273 return 48000; |
| 274 } | 274 } |
| 275 return WASAPIAudioInputStream::HardwareSampleRate(device_id); | 275 return WASAPIAudioInputStream::HardwareSampleRate(device_id); |
| 276 #else | 276 #else |
| 277 return 48000.0; | 277 return 48000; |
| 278 #endif | 278 #endif |
| 279 } | 279 } |
| 280 | 280 |
| 281 size_t GetAudioHardwareBufferSize() { | 281 size_t GetAudioHardwareBufferSize() { |
| 282 // The sizes here were determined by experimentation and are roughly | 282 // The sizes here were determined by experimentation and are roughly |
| 283 // the lowest value (for low latency) that still allowed glitch-free | 283 // the lowest value (for low latency) that still allowed glitch-free |
| 284 // audio under high loads. | 284 // audio under high loads. |
| 285 // | 285 // |
| 286 // For Mac OS X and Windows the chromium audio backend uses a low-latency | 286 // For Mac OS X and Windows the chromium audio backend uses a low-latency |
| 287 // Core Audio API, so a low buffer size is possible. For Linux, further | 287 // Core Audio API, so a low buffer size is possible. For Linux, further |
| 288 // tuning may be needed. | 288 // tuning may be needed. |
| 289 #if defined(OS_MACOSX) | 289 #if defined(OS_MACOSX) |
| 290 return 128; | 290 return 128; |
| 291 #elif defined(OS_WIN) | 291 #elif defined(OS_WIN) |
| 292 if (!IsWASAPISupported()) { | 292 if (!IsWASAPISupported()) { |
| 293 // Fall back to Windows Wave implementation on Windows XP or lower | 293 // Fall back to Windows Wave implementation on Windows XP or lower |
| 294 // and assume 48kHz as default sample rate. | 294 // and assume 48kHz as default sample rate. |
| 295 return 2048; | 295 return 2048; |
| 296 } | 296 } |
| 297 // This call must be done on a COM thread configured as MTA. | 297 // This call must be done on a COM thread configured as MTA. |
| 298 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. | 298 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. |
| 299 int mixing_sample_rate = | 299 int mixing_sample_rate = |
| 300 static_cast<int>(WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); | 300 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); |
| 301 if (mixing_sample_rate == 48000) | 301 if (mixing_sample_rate == 48000) |
| 302 return 480; | 302 return 480; |
| 303 else if (mixing_sample_rate == 44100) | 303 else if (mixing_sample_rate == 44100) |
| 304 return 448; | 304 return 448; |
| 305 else | 305 else |
| 306 return 960; | 306 return 960; |
| 307 #else | 307 #else |
| 308 return 2048; | 308 return 2048; |
| 309 #endif | 309 #endif |
| 310 } | 310 } |
| 311 | 311 |
| 312 uint32 GetAudioInputHardwareChannelCount(const std::string& device_id) { | 312 ChannelLayout GetAudioInputHardwareChannelLayout(const std::string& device_id) { |
| 313 // TODO(henrika): add support for device selection on all platforms. | 313 // TODO(henrika): add support for device selection on all platforms. |
| 314 // Only exists on Windows today. | 314 // Only exists on Windows today. |
| 315 enum channel_layout { MONO = 1, STEREO = 2 }; | |
| 316 #if defined(OS_MACOSX) | 315 #if defined(OS_MACOSX) |
| 317 return MONO; | 316 return CHANNEL_LAYOUT_MONO; |
| 318 #elif defined(OS_WIN) | 317 #elif defined(OS_WIN) |
| 319 if (!IsWASAPISupported()) { | 318 if (!IsWASAPISupported()) { |
| 320 // Fall back to Windows Wave implementation on Windows XP or lower and | 319 // Fall back to Windows Wave implementation on Windows XP or lower and |
| 321 // use stereo by default. | 320 // use stereo by default. |
| 322 return STEREO; | 321 return CHANNEL_LAYOUT_STEREO; |
| 323 } | 322 } |
| 324 return WASAPIAudioInputStream::HardwareChannelCount(device_id); | 323 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ? |
| 324 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; |
| 325 #else | 325 #else |
| 326 return STEREO; | 326 return CHANNEL_LAYOUT_STEREO; |
| 327 #endif | 327 #endif |
| 328 } | 328 } |
| 329 | 329 |
| 330 // When transferring data in the shared memory, first word is size of data | 330 // When transferring data in the shared memory, first word is size of data |
| 331 // in bytes. Actual data starts immediately after it. | 331 // in bytes. Actual data starts immediately after it. |
| 332 | 332 |
| 333 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) { | 333 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) { |
| 334 // Need to reserve extra 4 bytes for size of data. | 334 // Need to reserve extra 4 bytes for size of data. |
| 335 return packet_size + sizeof(Atomic32); | 335 return packet_size + sizeof(Atomic32); |
| 336 } | 336 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 381 |
| 382 bool IsWASAPISupported() { | 382 bool IsWASAPISupported() { |
| 383 // Note: that function correctly returns that Windows Server 2003 does not | 383 // Note: that function correctly returns that Windows Server 2003 does not |
| 384 // support WASAPI. | 384 // support WASAPI. |
| 385 return base::win::GetVersion() >= base::win::VERSION_VISTA; | 385 return base::win::GetVersion() >= base::win::VERSION_VISTA; |
| 386 } | 386 } |
| 387 | 387 |
| 388 #endif | 388 #endif |
| 389 | 389 |
| 390 } // namespace media | 390 } // namespace media |
| OLD | NEW |