Index: media/base/audio_buffer.cc |
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc |
index 33d4ecbb1abbd4b3bdc709bdd3a817f530d872a9..0b1d26718359777fc2491f08170dedf23af17327 100644 |
--- a/media/base/audio_buffer.cc |
+++ b/media/base/audio_buffer.cc |
@@ -243,6 +243,88 @@ void AudioBuffer::ReadFrames(int frames_to_copy, |
source_data, dest_frame_offset, frames_to_copy, bytes_per_channel); |
} |
+static const int32 kint24min = -0x7FFFFF - 1; |
+static const int32 kint24max = 0x7FFFFF; |
+static const int32 kUint8Bias = 128; |
DaleCurtis
2014/09/24 22:30:17
remove capital U or capitalize int above.
|
+ |
+static inline int32 ConvertS16ToS32(int16 value) { |
+ return static_cast<int32>(value) << 8; |
DaleCurtis
2014/09/24 22:30:17
These are mislabeled, you're actually converting t
|
+} |
+ |
+static inline int32 ConvertU8ToS32(uint8 value) { |
+ return (static_cast<int32>(value) - kUint8Bias) << 16; |
+} |
+ |
+static inline int32 ConvertF32ToS32(float value) { |
+ return static_cast<int32>(value < 0 ? value * kint24min : value * kint24max); |
+} |
+ |
+std::vector<int32> AudioBuffer::ReadFrames() { |
DaleCurtis
2014/09/24 22:30:17
All these conversion methods need to take trim_sta
|
+ int dest_data_offset = 0; |
+ std::vector<int32> dest_data; |
+ dest_data.reserve(channel_count_ * adjusted_frame_count_); |
+ |
+ if (sample_format_ == kSampleFormatU8) { |
DaleCurtis
2014/09/24 22:30:17
It may be worth finally adding in FFmpeg's super o
|
+ // Unsigned 8-bit w/ bias of 128. |
+ const uint8* source_data = |
+ reinterpret_cast<const uint8*>(channel_data_[0]); |
+ |
+ for (int i = 0; i < adjusted_frame_count_ * channel_count_; ++i) { |
+ dest_data[i] = ConvertU8ToS32(source_data[i]); |
+ } |
+ } else if (sample_format_ == kSampleFormatS16) { |
+ // Format is interleaved signed16. Convert each value into int32 and insert |
+ // into output channel data. |
+ const int16* source_data = |
+ reinterpret_cast<const int16*>(channel_data_[0]); |
+ |
+ for (int i = 0; i < adjusted_frame_count_ * channel_count_; ++i) { |
+ dest_data[i] = ConvertS16ToS32(source_data[i]); |
+ } |
+ } else if (sample_format_ == kSampleFormatS32) { |
+ // Format is interleaved signed32; just copy the data. |
+ const int32* source_data = |
+ reinterpret_cast<const int32*>(channel_data_[0]); |
+ dest_data.insert(dest_data.begin(), |
+ source_data, |
+ source_data + (adjusted_frame_count_ * channel_count_)); |
+ } else if (sample_format_ == kSampleFormatF32) { |
+ // Format is interleaved float. Convert each value into int32 and insert |
+ // into output channel data. |
+ const float* source_data = reinterpret_cast<const float*>(channel_data_[0]); |
+ for (int i = 0; i < adjusted_frame_count_ * channel_count_; ++i) { |
+ dest_data[i] = ConvertF32ToS32(source_data[i]); |
+ } |
+ } else if (sample_format_ == kSampleFormatPlanarS16) { |
+ // Format is planar signed16. Convert each value into int32 and insert into |
+ // output channel data. |
+ for (int ch = 0; ch < channel_count_; ++ch) { |
+ const int16* source_data = |
+ reinterpret_cast<const int16*>(channel_data_[ch]); |
+ |
+ for (int i = 0; i < adjusted_frame_count_; ++i) { |
+ dest_data[i + dest_data_offset] = ConvertS16ToS32(source_data[i]); |
+ } |
+ dest_data_offset += adjusted_frame_count_; |
+ } |
+ } else if (sample_format_ == kSampleFormatPlanarF32) { |
+ // Format is planar float. Convert each value into int32 and insert into |
+ // output channel data. |
+ for (int ch = 0; ch < channel_count_; ++ch) { |
+ const float* source_data = |
+ reinterpret_cast<const float*>(channel_data_[ch]); |
+ |
+ for (int i = 0; i < adjusted_frame_count_; ++i) { |
+ dest_data[i + dest_data_offset] = ConvertF32ToS32(source_data[i]); |
+ } |
+ dest_data_offset += adjusted_frame_count_; |
+ } |
+ } else { |
+ NOTREACHED(); |
+ } |
+ return dest_data; |
+} |
+ |
void AudioBuffer::TrimStart(int frames_to_trim) { |
CHECK_GE(frames_to_trim, 0); |
CHECK_LE(frames_to_trim, adjusted_frame_count_); |