summaryrefslogtreecommitdiffstats
path: root/media/audio
diff options
context:
space:
mode:
authorkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-16 20:44:09 +0000
committerkbr@google.com <kbr@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-16 20:44:09 +0000
commit949b9944f46a631b50887462ab74e37d9fe2b31a (patch)
tree0714f906d828f66fcb6aec52b3e3bb62e32e61cd /media/audio
parent90f9a2962b73b2db4192129961648b449f74f651 (diff)
downloadchromium_src-949b9944f46a631b50887462ab74e37d9fe2b31a.zip
chromium_src-949b9944f46a631b50887462ab74e37d9fe2b31a.tar.gz
chromium_src-949b9944f46a631b50887462ab74e37d9fe2b31a.tar.bz2
(Committing on behalf of Chris Rogers -- original CL http://codereview.chromium.org/5550006/ )
Implement WebKitClientImpl::loadAudioResource() to decode in-memory audio file data for use by WebKit. Most of the interesting low-level code is being added in the media directory. BUG=NONE TEST=NONE (tested locally with web audio API loading files of format .wav .aif .mp3 .m4a 16bit 24bit In the longer term, WebKit layout tests will comprehensively exercise this code) Review URL: http://codereview.chromium.org/5880002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69458 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio')
-rw-r--r--media/audio/audio_util.cc46
-rw-r--r--media/audio/audio_util.h15
2 files changed, 60 insertions, 1 deletions
diff --git a/media/audio/audio_util.cc b/media/audio/audio_util.cc
index e3e94cd..4c8be79 100644
--- a/media/audio/audio_util.cc
+++ b/media/audio/audio_util.cc
@@ -158,4 +158,50 @@ bool FoldChannels(void* buf,
return false;
}
+bool DeinterleaveAudioChannel(void* source,
+ float* destination,
+ int channels,
+ int channel_index,
+ int bytes_per_sample,
+ size_t number_of_frames) {
+ switch (bytes_per_sample) {
+ case 1:
+ {
+ uint8* source8 = static_cast<uint8*>(source) + channel_index;
+ const float kScale = 1.0f / 128.0f;
+ for (unsigned i = 0; i < number_of_frames; ++i) {
+ destination[i] = kScale * static_cast<int>(*source8 + 128);
+ source8 += channels;
+ }
+ return true;
+ }
+
+ case 2:
+ {
+ int16* source16 = static_cast<int16*>(source) + channel_index;
+ const float kScale = 1.0f / 32768.0f;
+ for (unsigned i = 0; i < number_of_frames; ++i) {
+ destination[i] = kScale * *source16;
+ source16 += channels;
+ }
+ return true;
+ }
+
+ case 4:
+ {
+ int32* source32 = static_cast<int32*>(source) + channel_index;
+ const float kScale = 1.0f / (1L << 31);
+ for (unsigned i = 0; i < number_of_frames; ++i) {
+ destination[i] = kScale * *source32;
+ source32 += channels;
+ }
+ return true;
+ }
+
+ default:
+ break;
+ }
+ return false;
+}
+
} // namespace media
diff --git a/media/audio/audio_util.h b/media/audio/audio_util.h
index edfe7ab..669b4fa 100644
--- a/media/audio/audio_util.h
+++ b/media/audio/audio_util.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -49,6 +49,19 @@ bool FoldChannels(void* buf,
int bytes_per_sample,
float volume);
+// DeinterleaveAudioChannel() takes interleaved audio buffer |source|
+// of the given |sample_fmt| and |number_of_channels| and extracts
+// |number_of_frames| data for the given |channel_index| and
+// puts it in the floating point |destination|.
+// It returns |true| on success, or |false| if the |sample_fmt| is
+// not recognized.
+bool DeinterleaveAudioChannel(void* source,
+ float* destination,
+ int channels,
+ int channel_index,
+ int bytes_per_sample,
+ size_t number_of_frames);
+
} // namespace media
#endif // MEDIA_AUDIO_AUDIO_UTIL_H_