Index: media/base/audio_buffer.cc |
diff --git a/media/base/audio_buffer.cc b/media/base/audio_buffer.cc |
index 33d4ecbb1abbd4b3bdc709bdd3a817f530d872a9..2ceccf1d5226b2356b65eedacb6e76a2e0a94df5 100644 |
--- a/media/base/audio_buffer.cc |
+++ b/media/base/audio_buffer.cc |
@@ -243,6 +243,82 @@ void AudioBuffer::ReadFrames(int frames_to_copy, |
source_data, dest_frame_offset, frames_to_copy, bytes_per_channel); |
} |
+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() |
+ : value * std::numeric_limits<int32>::max()); |
+} |
+ |
+void AudioBuffer::ReadFramesInterleavedS32(int frames_to_copy, |
+ int32* dest_data) { |
+ DCHECK_LE(frames_to_copy, channel_count_ * adjusted_frame_count_); |
DaleCurtis
2014/09/26 23:02:41
frames_to_copy must be per channel.
pwestin(chromium)
2014/09/29 22:54:47
Done.
|
+ DCHECK_EQ(frames_to_copy % channel_count_, 0); |
+ |
DaleCurtis
2014/09/26 23:02:41
You'll need to update your frames to copy in the i
pwestin(chromium)
2014/09/29 22:54:47
Done.
|
+ switch (sample_format_) { |
+ case kSampleFormatU8: |
+ NOTIMPLEMENTED(); |
+ break; |
+ case 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 < frames_to_copy; ++i) { |
DaleCurtis
2014/09/26 23:02:41
Typically drop {} for one line for loops. Ditto f
pwestin(chromium)
2014/09/29 22:54:47
Done.
|
+ dest_data[i] = ConvertS16ToS32(source_data[i]); |
+ } |
+ } break; |
DaleCurtis
2014/09/26 23:02:41
break; should be inside {}. What does clang-format
pwestin(chromium)
2014/09/29 22:54:47
Done.
|
+ case 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, frames_to_copy * sizeof(int32)); |
+ } break; |
+ case 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 < frames_to_copy; ++i) { |
+ dest_data[i] = ConvertF32ToS32(source_data[i]); |
+ } |
+ } break; |
+ case kSampleFormatPlanarS16: { |
+ // Format is planar signed 16 bit. 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]) + trim_start_; |
+ |
+ for (int i = 0, offset = ch; i < frames_to_copy / channel_count_; |
+ ++i, offset += channel_count_) { |
+ dest_data[offset] = ConvertS16ToS32(source_data[i]); |
+ } |
+ } |
+ } break; |
+ case 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]) + trim_start_; |
+ |
+ for (int i = 0, offset = ch; i < frames_to_copy / channel_count_; |
+ ++i, offset += channel_count_) { |
+ dest_data[offset] = ConvertF32ToS32(source_data[i]); |
+ } |
+ } |
+ } break; |
+ case kUnknownSampleFormat: |
+ NOTREACHED(); |
+ break; |
+ } |
+} |
+ |
void AudioBuffer::TrimStart(int frames_to_trim) { |
CHECK_GE(frames_to_trim, 0); |
CHECK_LE(frames_to_trim, adjusted_frame_count_); |