summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
authorrtoy@google.com <rtoy@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 05:29:18 +0000
committerrtoy@google.com <rtoy@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-15 05:29:18 +0000
commit441ec4dc183c1c6c4f303855aaeea75cb60074fe (patch)
tree712e21b89b7b15c0c9a8cd31b5fb962179c06c66 /media/audio
parent5fa278c10430a00706d0e296216b4c9543bacbc7 (diff)
downloadchromium_src-441ec4dc183c1c6c4f303855aaeea75cb60074fe.zip
chromium_src-441ec4dc183c1c6c4f303855aaeea75cb60074fe.tar.gz
chromium_src-441ec4dc183c1c6c4f303855aaeea75cb60074fe.tar.bz2
Add API to query for the audio buffer size.
This is essentially identical to the GetAudioHardwareSampleRate API, except we get the "optimal" hardware buffer size to be used. BUG=None TEST=None Review URL: http://codereview.chromium.org/7837030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101249 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/audio_util.cc17
-rw-r--r--media/audio/audio_util.h5
2 files changed, 22 insertions, 0 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index 2b790d8..120e2ed 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -242,6 +242,23 @@ double GetAudioHardwareSampleRate()
#endif
}
+size_t GetAudioHardwareBufferSize() {
+ // The sizes here were determined by experimentation and are roughly
+ // the lowest value (for low latency) that still allowed glitch-free
+ // audio under high loads.
+ //
+ // For Mac OS X the chromium audio backend uses a low-latency
+ // CoreAudio API, so a low buffer size is possible. For other OSes,
+ // further tuning may be needed.
+#if defined(OS_MACOSX)
+ return 128;
+#elif defined(OS_LINUX)
+ return 2048;
+#else
+ return 2048;
+#endif
+}
+
// When transferring data in the shared memory, first word is size of data
// in bytes. Actual data starts immediately after it.
diff --git a/media/audio/audio_util.h b/media/audio/audio_util.h
index e9452b2..6ea697b 100644
--- a/media/audio/audio_util.h
+++ b/media/audio/audio_util.h
@@ -82,6 +82,11 @@ MEDIA_EXPORT void InterleaveFloatToInt16(const std::vector<float*>& source,
// Returns the default audio hardware sample-rate.
MEDIA_EXPORT double GetAudioHardwareSampleRate();
+// Returns the optimal low-latency buffer size for the audio hardware.
+// This is the smallest buffer size the system can comfortably render
+// at without glitches. The buffer size is in sample-frames.
+MEDIA_EXPORT size_t GetAudioHardwareBufferSize();
+
// Functions that handle data buffer passed between processes in the shared
// memory. Called on both IPC sides.