Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: media/base/audio_buffer.cc

Issue 600143002: Adding new function ReadFrames() that returns the audio frame in planar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« media/base/audio_buffer.h ('K') | « media/base/audio_buffer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/base/audio_buffer.h" 5 #include "media/base/audio_buffer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "media/base/audio_bus.h" 8 #include "media/base/audio_bus.h"
9 #include "media/base/buffers.h" 9 #include "media/base/buffers.h"
10 #include "media/base/limits.h" 10 #include "media/base/limits.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 DCHECK(sample_format_ == kSampleFormatU8 || 236 DCHECK(sample_format_ == kSampleFormatU8 ||
237 sample_format_ == kSampleFormatS16 || 237 sample_format_ == kSampleFormatS16 ||
238 sample_format_ == kSampleFormatS32); 238 sample_format_ == kSampleFormatS32);
239 int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format_); 239 int bytes_per_channel = SampleFormatToBytesPerChannel(sample_format_);
240 int frame_size = channel_count_ * bytes_per_channel; 240 int frame_size = channel_count_ * bytes_per_channel;
241 const uint8* source_data = data_.get() + source_frame_offset * frame_size; 241 const uint8* source_data = data_.get() + source_frame_offset * frame_size;
242 dest->FromInterleavedPartial( 242 dest->FromInterleavedPartial(
243 source_data, dest_frame_offset, frames_to_copy, bytes_per_channel); 243 source_data, dest_frame_offset, frames_to_copy, bytes_per_channel);
244 } 244 }
245 245
246 static const int32 kint24min = -0x7FFFFF - 1;
247 static const int32 kint24max = 0x7FFFFF;
248 static const int32 kUint8Bias = 128;
DaleCurtis 2014/09/24 22:30:17 remove capital U or capitalize int above.
249
250 static inline int32 ConvertS16ToS32(int16 value) {
251 return static_cast<int32>(value) << 8;
DaleCurtis 2014/09/24 22:30:17 These are mislabeled, you're actually converting t
252 }
253
254 static inline int32 ConvertU8ToS32(uint8 value) {
255 return (static_cast<int32>(value) - kUint8Bias) << 16;
256 }
257
258 static inline int32 ConvertF32ToS32(float value) {
259 return static_cast<int32>(value < 0 ? value * kint24min : value * kint24max);
260 }
261
262 std::vector<int32> AudioBuffer::ReadFrames() {
DaleCurtis 2014/09/24 22:30:17 All these conversion methods need to take trim_sta
263 int dest_data_offset = 0;
264 std::vector<int32> dest_data;
265 dest_data.reserve(channel_count_ * adjusted_frame_count_);
266
267 if (sample_format_ == kSampleFormatU8) {
DaleCurtis 2014/09/24 22:30:17 It may be worth finally adding in FFmpeg's super o
268 // Unsigned 8-bit w/ bias of 128.
269 const uint8* source_data =
270 reinterpret_cast<const uint8*>(channel_data_[0]);
271
272 for (int i = 0; i < adjusted_frame_count_ * channel_count_; ++i) {
273 dest_data[i] = ConvertU8ToS32(source_data[i]);
274 }
275 } else if (sample_format_ == kSampleFormatS16) {
276 // Format is interleaved signed16. Convert each value into int32 and insert
277 // into output channel data.
278 const int16* source_data =
279 reinterpret_cast<const int16*>(channel_data_[0]);
280
281 for (int i = 0; i < adjusted_frame_count_ * channel_count_; ++i) {
282 dest_data[i] = ConvertS16ToS32(source_data[i]);
283 }
284 } else if (sample_format_ == kSampleFormatS32) {
285 // Format is interleaved signed32; just copy the data.
286 const int32* source_data =
287 reinterpret_cast<const int32*>(channel_data_[0]);
288 dest_data.insert(dest_data.begin(),
289 source_data,
290 source_data + (adjusted_frame_count_ * channel_count_));
291 } else if (sample_format_ == kSampleFormatF32) {
292 // Format is interleaved float. Convert each value into int32 and insert
293 // into output channel data.
294 const float* source_data = reinterpret_cast<const float*>(channel_data_[0]);
295 for (int i = 0; i < adjusted_frame_count_ * channel_count_; ++i) {
296 dest_data[i] = ConvertF32ToS32(source_data[i]);
297 }
298 } else if (sample_format_ == kSampleFormatPlanarS16) {
299 // Format is planar signed16. Convert each value into int32 and insert into
300 // output channel data.
301 for (int ch = 0; ch < channel_count_; ++ch) {
302 const int16* source_data =
303 reinterpret_cast<const int16*>(channel_data_[ch]);
304
305 for (int i = 0; i < adjusted_frame_count_; ++i) {
306 dest_data[i + dest_data_offset] = ConvertS16ToS32(source_data[i]);
307 }
308 dest_data_offset += adjusted_frame_count_;
309 }
310 } else if (sample_format_ == kSampleFormatPlanarF32) {
311 // Format is planar float. Convert each value into int32 and insert into
312 // output channel data.
313 for (int ch = 0; ch < channel_count_; ++ch) {
314 const float* source_data =
315 reinterpret_cast<const float*>(channel_data_[ch]);
316
317 for (int i = 0; i < adjusted_frame_count_; ++i) {
318 dest_data[i + dest_data_offset] = ConvertF32ToS32(source_data[i]);
319 }
320 dest_data_offset += adjusted_frame_count_;
321 }
322 } else {
323 NOTREACHED();
324 }
325 return dest_data;
326 }
327
246 void AudioBuffer::TrimStart(int frames_to_trim) { 328 void AudioBuffer::TrimStart(int frames_to_trim) {
247 CHECK_GE(frames_to_trim, 0); 329 CHECK_GE(frames_to_trim, 0);
248 CHECK_LE(frames_to_trim, adjusted_frame_count_); 330 CHECK_LE(frames_to_trim, adjusted_frame_count_);
249 331
250 // Adjust the number of frames in this buffer and where the start really is. 332 // Adjust the number of frames in this buffer and where the start really is.
251 adjusted_frame_count_ -= frames_to_trim; 333 adjusted_frame_count_ -= frames_to_trim;
252 trim_start_ += frames_to_trim; 334 trim_start_ += frames_to_trim;
253 335
254 // Adjust timestamp_ and duration_ to reflect the smaller number of frames. 336 // Adjust timestamp_ and duration_ to reflect the smaller number of frames.
255 const base::TimeDelta old_duration = duration_; 337 const base::TimeDelta old_duration = duration_;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 } 385 }
304 } else { 386 } else {
305 CHECK_EQ(frames_to_copy, 0); 387 CHECK_EQ(frames_to_copy, 0);
306 } 388 }
307 389
308 // Trim the leftover data off the end of the buffer and update duration. 390 // Trim the leftover data off the end of the buffer and update duration.
309 TrimEnd(frames_to_trim); 391 TrimEnd(frames_to_trim);
310 } 392 }
311 393
312 } // namespace media 394 } // namespace media
OLDNEW
« media/base/audio_buffer.h ('K') | « media/base/audio_buffer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698