summaryrefslogtreecommitdiffstats
path: root/media/audio/audio_util.cc
diff options
context:
space:
mode:
authorcrogers@google.com <crogers@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-15 00:18:39 +0000
committercrogers@google.com <crogers@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-15 00:18:39 +0000
commitec8962ca7de01eb5685b32a4361dd7be8f7e6293 (patch)
treef26945b2e47fb967427b831ec3d4b1b962be3964 /media/audio/audio_util.cc
parent521b248f7ce021f99932c9150461744b3edf3067 (diff)
downloadchromium_src-ec8962ca7de01eb5685b32a4361dd7be8f7e6293.zip
chromium_src-ec8962ca7de01eb5685b32a4361dd7be8f7e6293.tar.gz
chromium_src-ec8962ca7de01eb5685b32a4361dd7be8f7e6293.tar.bz2
Implement renderer AudioDevice API for low-latency audio output
BUG=none TEST=none (I tested locally for Mac OS X, but we'll need further testing for Windows and Linux as we add real-time threads, etc.) Review URL: http://codereview.chromium.org/6002005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71521 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_util.cc')
-rw-r--r--media/audio/audio_util.cc19
1 files changed, 19 insertions, 0 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index 6d80c87..ed84bc1 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -206,4 +206,23 @@ bool DeinterleaveAudioChannel(void* source,
return false;
}
+void InterleaveFloatToInt16(const std::vector<float*>& source,
+ int16* destination,
+ size_t number_of_frames) {
+ const float kScale = 32768.0f;
+ int channels = source.size();
+ for (int i = 0; i < channels; ++i) {
+ float* channel_data = source[i];
+ for (size_t j = 0; j < number_of_frames; ++j) {
+ float sample = kScale * channel_data[j];
+ if (sample < -32768.0)
+ sample = -32768.0;
+ else if (sample > 32767.0)
+ sample = 32767.0;
+
+ destination[j * channels + i] = static_cast<int16>(sample);
+ }
+ }
+}
+
} // namespace media