Index: media/base/audio_buffer.cc |
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc |
index 33d4ecbb1abbd4b3bdc709bdd3a817f530d872a9..fcc35044f376400d978fe4aa46437159908fd1e1 100644 |
--- a/media/base/audio_buffer.cc |
+++ b/media/base/audio_buffer.cc |
@@ -243,6 +243,89 @@ void AudioBuffer::ReadFrames(int frames_to_copy, |
source_data, dest_frame_offset, frames_to_copy, bytes_per_channel); |
} |
+static const int32 kUint8Bias = 128; |
+ |
+static inline int32 ConvertU8ToS32(uint8 value) { |
+ return (static_cast<int32>(value) - kUint8Bias) << 24; |
+} |
+ |
+static inline int32 ConvertS16ToS32(int16 value) { |
+ return static_cast<int32>(value) << 16; |
+} |
+ |
+static inline int32 ConvertF32ToS32(float value) { |
+ return static_cast<int32>(value < 0 |
+ ? value * ~std::numeric_limits<int32>::min() |
DaleCurtis
2014/09/25 22:30:44
I don't think this does what you want; e.g., ~(-5)
|
+ : value * std::numeric_limits<int32>::max()); |
+} |
+ |
+void AudioBuffer::ReadFramesInterleavedS32(int frames_to_copy, |
+ int32* dest_data) { |
+ DCHECK_EQ(frames_to_copy, channel_count_ * adjusted_frame_count_); |
+ |
+ if (sample_format_ == kSampleFormatU8) { |
+ // Unsigned 8-bit w/ bias of 128. |
+ const uint8* source_data = |
+ reinterpret_cast<const uint8*>(channel_data_[0]) + trim_start_; |
+ |
+ 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]) + trim_start_; |
+ |
+ 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]) + trim_start_; |
+ memcpy(dest_data, |
+ source_data, |
+ adjusted_frame_count_ * channel_count_ * sizeof(int32)); |
+ } 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]) + trim_start_; |
+ 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 signed 16 bit. Convert each value into int32 and insert |
+ // into output channel data. |
+ int dest_data_frame_size = channel_count_; |
+ for (int ch = 0; ch < channel_count_; ++ch) { |
+ const int16* source_data = |
+ reinterpret_cast<const int16*>(channel_data_[ch]) + trim_start_; |
+ |
+ for (int i = 0; i < adjusted_frame_count_; ++i) { |
+ dest_data[ch + (i * dest_data_frame_size)] = |
DaleCurtis
2014/09/25 22:30:44
A paired incrementing offset is more efficient tha
|
+ ConvertS16ToS32(source_data[i]); |
+ } |
+ } |
+ } else if (sample_format_ == kSampleFormatPlanarF32) { |
+ // Format is planar float. Convert each value into int32 and insert into |
+ // output channel data. |
+ int dest_data_frame_size = channel_count_; |
+ for (int ch = 0; ch < channel_count_; ++ch) { |
+ const float* source_data = |
+ reinterpret_cast<const float*>(channel_data_[ch]) + trim_start_; |
+ |
+ for (int i = 0; i < adjusted_frame_count_; ++i) { |
+ dest_data[ch + (i * dest_data_frame_size)] = |
DaleCurtis
2014/09/25 22:30:44
Ditto.
|
+ ConvertF32ToS32(source_data[i]); |
+ } |
+ } |
+ } else { |
+ NOTREACHED(); |
DaleCurtis
2014/09/25 22:30:44
If you prefer you could use case statement since i
|
+ } |
+} |
+ |
void AudioBuffer::TrimStart(int frames_to_trim) { |
CHECK_GE(frames_to_trim, 0); |
CHECK_LE(frames_to_trim, adjusted_frame_count_); |