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

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

Issue 8283032: Low-latency AudioInputStream implementation based on WASAPI for Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fixes in AVRT wrapper based on review by tommi Created 9 years, 2 months 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 | Annotate | Revision Log
OLDNEW
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
11 #include <algorithm> 11 #include <algorithm>
12 12
13 #include "base/atomicops.h" 13 #include "base/atomicops.h"
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/shared_memory.h" 16 #include "base/shared_memory.h"
17 #if defined(OS_WIN)
18 #include "base/win/windows_version.h"
19 #endif
17 #include "media/audio/audio_util.h" 20 #include "media/audio/audio_util.h"
18 #if defined(OS_MACOSX) 21 #if defined(OS_MACOSX)
22 #include "media/audio/mac/audio_low_latency_input_mac.h"
19 #include "media/audio/mac/audio_low_latency_output_mac.h" 23 #include "media/audio/mac/audio_low_latency_output_mac.h"
20 #endif 24 #endif
25 #if defined(OS_WIN)
26 #include "media/audio/win/audio_low_latency_input_win.h"
27 #endif
21 28
22 using base::subtle::Atomic32; 29 using base::subtle::Atomic32;
23 30
24 const uint32 kUnknownDataSize = static_cast<uint32>(-1); 31 const uint32 kUnknownDataSize = static_cast<uint32>(-1);
25 32
26 namespace media { 33 namespace media {
27 34
28 // TODO(fbarchard): Convert to intrinsics for better efficiency. 35 // TODO(fbarchard): Convert to intrinsics for better efficiency.
29 template<class Fixed> 36 template<class Fixed>
30 static int ScaleChannel(int channel, int volume) { 37 static int ScaleChannel(int channel, int volume) {
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (sample < -32768.0) 230 if (sample < -32768.0)
224 sample = -32768.0; 231 sample = -32768.0;
225 else if (sample > 32767.0) 232 else if (sample > 32767.0)
226 sample = 32767.0; 233 sample = 32767.0;
227 234
228 destination[j * channels + i] = static_cast<int16>(sample); 235 destination[j * channels + i] = static_cast<int16>(sample);
229 } 236 }
230 } 237 }
231 } 238 }
232 239
233 double GetAudioHardwareSampleRate() 240 double GetAudioHardwareSampleRate() {
234 {
235 #if defined(OS_MACOSX) 241 #if defined(OS_MACOSX)
236 // Hardware sample-rate on the Mac can be configured, so we must query. 242 // Hardware sample-rate on the Mac can be configured, so we must query.
237 return AUAudioOutputStream::HardwareSampleRate(); 243 return AUAudioOutputStream::HardwareSampleRate();
238 #else 244 #else
239 // Hardware for Windows and Linux is nearly always 48KHz. 245 // Hardware for Windows and Linux is nearly always 48KHz.
240 // TODO(crogers) : return correct value in rare non-48KHz cases. 246 // TODO(crogers) : return correct value in rare non-48KHz cases.
241 return 48000.0; 247 return 48000.0;
242 #endif 248 #endif
243 } 249 }
244 250
251 double GetAudioInputHardwareSampleRate() {
252 #if defined(OS_MACOSX)
253 // Hardware sample-rate on the Mac can be configured, so we must query.
254 return AUAudioInputStream::HardwareSampleRate();
255 #elif defined(OS_WIN)
256 if (base::win::GetVersion() <= base::win::VERSION_XP) {
257 // Fall back to Windows Wave implementation on Windows XP or lower
258 // and use 48kHz as default input sample rate.
259 return 48000.0;
260 } else {
261 // Hardware sample-rate on Windows can be configured, so we must query.
262 // TODO(henrika): improve possibility to specify audio endpoint.
263 // Use the default device (same as for Wave) for now to be compatible.
264 return WASAPIAudioInputStream::HardwareSampleRate(eConsole);
265 }
266 #else
267 // Hardware for Linux is nearly always 48KHz.
268 // TODO(henrika) : return correct value in rare non-48KHz cases.
scherkus (not reviewing) 2011/10/18 21:12:30 nit: remove space between ) and :
henrika (OOO until Aug 14) 2011/10/19 15:42:43 Done.
269 return 48000.0;
270 #endif
271 }
272
245 size_t GetAudioHardwareBufferSize() { 273 size_t GetAudioHardwareBufferSize() {
246 // The sizes here were determined by experimentation and are roughly 274 // The sizes here were determined by experimentation and are roughly
247 // the lowest value (for low latency) that still allowed glitch-free 275 // the lowest value (for low latency) that still allowed glitch-free
248 // audio under high loads. 276 // audio under high loads.
249 // 277 //
250 // For Mac OS X the chromium audio backend uses a low-latency 278 // For Mac OS X the chromium audio backend uses a low-latency
251 // CoreAudio API, so a low buffer size is possible. For other OSes, 279 // CoreAudio API, so a low buffer size is possible. For other OSes,
252 // further tuning may be needed. 280 // further tuning may be needed.
253 #if defined(OS_MACOSX) 281 #if defined(OS_MACOSX)
254 return 128; 282 return 128;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size; 331 char* ptr = static_cast<char*>(shared_memory->memory()) + shared_memory_size;
304 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3); 332 DCHECK_EQ(0u, reinterpret_cast<size_t>(ptr) & 3);
305 333
306 // Actual data size stored at the end of the buffer. 334 // Actual data size stored at the end of the buffer.
307 uint32 actual_data_size = 335 uint32 actual_data_size =
308 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr)); 336 base::subtle::Acquire_Load(reinterpret_cast<volatile Atomic32*>(ptr));
309 return actual_data_size == kUnknownDataSize; 337 return actual_data_size == kUnknownDataSize;
310 } 338 }
311 339
312 } // namespace media 340 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698