| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 destination[j * channels + i] = static_cast<int16>(sample); | 236 destination[j * channels + i] = static_cast<int16>(sample); |
| 237 } | 237 } |
| 238 } | 238 } |
| 239 } | 239 } |
| 240 | 240 |
| 241 double GetAudioHardwareSampleRate() { | 241 double GetAudioHardwareSampleRate() { |
| 242 #if defined(OS_MACOSX) | 242 #if defined(OS_MACOSX) |
| 243 // Hardware sample-rate on the Mac can be configured, so we must query. | 243 // Hardware sample-rate on the Mac can be configured, so we must query. |
| 244 return AUAudioOutputStream::HardwareSampleRate(); | 244 return AUAudioOutputStream::HardwareSampleRate(); |
| 245 #elif defined(OS_WIN) | 245 #elif defined(OS_WIN) |
| 246 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 246 if (!WindowsSupportWASAPI()) { |
| 247 // Fall back to Windows Wave implementation on Windows XP or lower | 247 // Fall back to Windows Wave implementation on Windows XP or lower |
| 248 // and use 48kHz as default input sample rate. | 248 // and use 48kHz as default input sample rate. |
| 249 return 48000.0; | 249 return 48000.0; |
| 250 } | 250 } |
| 251 | 251 |
| 252 // Hardware sample-rate on Windows can be configured, so we must query. | 252 // Hardware sample-rate on Windows can be configured, so we must query. |
| 253 // TODO(henrika): improve possibility to specify audio endpoint. | 253 // TODO(henrika): improve possibility to specify audio endpoint. |
| 254 // Use the default device (same as for Wave) for now to be compatible. | 254 // Use the default device (same as for Wave) for now to be compatible. |
| 255 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); | 255 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); |
| 256 #else | 256 #else |
| 257 // Hardware for Linux is nearly always 48KHz. | 257 // Hardware for Linux is nearly always 48KHz. |
| 258 // TODO(crogers) : return correct value in rare non-48KHz cases. | 258 // TODO(crogers) : return correct value in rare non-48KHz cases. |
| 259 return 48000.0; | 259 return 48000.0; |
| 260 #endif | 260 #endif |
| 261 } | 261 } |
| 262 | 262 |
| 263 double GetAudioInputHardwareSampleRate() { | 263 double GetAudioInputHardwareSampleRate() { |
| 264 #if defined(OS_MACOSX) | 264 #if defined(OS_MACOSX) |
| 265 // Hardware sample-rate on the Mac can be configured, so we must query. | 265 // Hardware sample-rate on the Mac can be configured, so we must query. |
| 266 return AUAudioInputStream::HardwareSampleRate(); | 266 return AUAudioInputStream::HardwareSampleRate(); |
| 267 #elif defined(OS_WIN) | 267 #elif defined(OS_WIN) |
| 268 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 268 if (!WindowsSupportWASAPI()) { |
| 269 // Fall back to Windows Wave implementation on Windows XP or lower | 269 // Fall back to Windows Wave implementation on Windows XP or lower |
| 270 // and use 48kHz as default input sample rate. | 270 // and use 48kHz as default input sample rate. |
| 271 return 48000.0; | 271 return 48000.0; |
| 272 } | 272 } |
| 273 | 273 |
| 274 // Hardware sample-rate on Windows can be configured, so we must query. | 274 // Hardware sample-rate on Windows can be configured, so we must query. |
| 275 // TODO(henrika): improve possibility to specify audio endpoint. | 275 // TODO(henrika): improve possibility to specify audio endpoint. |
| 276 // Use the default device (same as for Wave) for now to be compatible. | 276 // Use the default device (same as for Wave) for now to be compatible. |
| 277 return WASAPIAudioInputStream::HardwareSampleRate(eConsole); | 277 return WASAPIAudioInputStream::HardwareSampleRate(eConsole); |
| 278 #else | 278 #else |
| 279 // Hardware for Linux is nearly always 48KHz. | 279 // Hardware for Linux is nearly always 48KHz. |
| 280 // TODO(henrika): return correct value in rare non-48KHz cases. | 280 // TODO(henrika): return correct value in rare non-48KHz cases. |
| 281 return 48000.0; | 281 return 48000.0; |
| 282 #endif | 282 #endif |
| 283 } | 283 } |
| 284 | 284 |
| 285 size_t GetAudioHardwareBufferSize() { | 285 size_t GetAudioHardwareBufferSize() { |
| 286 // The sizes here were determined by experimentation and are roughly | 286 // The sizes here were determined by experimentation and are roughly |
| 287 // the lowest value (for low latency) that still allowed glitch-free | 287 // the lowest value (for low latency) that still allowed glitch-free |
| 288 // audio under high loads. | 288 // audio under high loads. |
| 289 // | 289 // |
| 290 // For Mac OS X and Windows the chromium audio backend uses a low-latency | 290 // For Mac OS X and Windows the chromium audio backend uses a low-latency |
| 291 // Core Audio API, so a low buffer size is possible. For Linux, further | 291 // Core Audio API, so a low buffer size is possible. For Linux, further |
| 292 // tuning may be needed. | 292 // tuning may be needed. |
| 293 #if defined(OS_MACOSX) | 293 #if defined(OS_MACOSX) |
| 294 return 128; | 294 return 128; |
| 295 #elif defined(OS_WIN) | 295 #elif defined(OS_WIN) |
| 296 if (base::win::GetVersion() <= base::win::VERSION_XP) { | 296 if (!WindowsSupportWASAPI()) { |
| 297 // Fall back to Windows Wave implementation on Windows XP or lower | 297 // Fall back to Windows Wave implementation on Windows XP or lower |
| 298 // and assume 48kHz as default sample rate. | 298 // and assume 48kHz as default sample rate. |
| 299 return 2048; | 299 return 2048; |
| 300 } | 300 } |
| 301 // This call must be done on a COM thread configured as MTA. | 301 // This call must be done on a COM thread configured as MTA. |
| 302 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. | 302 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. |
| 303 int mixing_sample_rate = | 303 int mixing_sample_rate = |
| 304 static_cast<int>(WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); | 304 static_cast<int>(WASAPIAudioOutputStream::HardwareSampleRate(eConsole)); |
| 305 if (mixing_sample_rate == 48000) | 305 if (mixing_sample_rate == 48000) |
| 306 return 480; | 306 return 480; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 uint32 shared_memory_size) { | 356 uint32 shared_memory_size) { |
| 357 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size; | 357 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size; |
| 358 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3); | 358 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3); |
| 359 | 359 |
| 360 // Actual data size stored at the end of the buffer. | 360 // Actual data size stored at the end of the buffer. |
| 361 uint32 actual_data_size = | 361 uint32 actual_data_size = |
| 362 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr)); | 362 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr)); |
| 363 return actual_data_size == kUnknownDataSize; | 363 return actual_data_size == kUnknownDataSize; |
| 364 } | 364 } |
| 365 | 365 |
| 366 #if defined(OS_WIN) |
| 367 |
| 368 bool WindowsSupportWASAPI() { |
| 369 // Note: that function correctly returns that Windows Server 2003 does not |
| 370 // support WASAPI. |
| 371 return base::win::GetVersion() >= base::win::VERSION_VISTA; |
| 372 } |
| 373 |
| 374 #endif |
| 375 |
| 366 } // namespace media | 376 } // namespace media |
| OLD | NEW |