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

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

Issue 156783003: Enhance AudioSplicer to crossfade marked splice frames. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tests. Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | media/base/audio_splicer.h » ('j') | media/base/audio_splicer.h » ('J')
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 <cmath>
8
7 #include "base/logging.h" 9 #include "base/logging.h"
8 #include "media/base/audio_bus.h" 10 #include "media/base/audio_bus.h"
9 #include "media/base/buffers.h" 11 #include "media/base/buffers.h"
10 #include "media/base/limits.h" 12 #include "media/base/limits.h"
11 13
12 namespace media { 14 namespace media {
13 15
14 AudioBuffer::AudioBuffer(SampleFormat sample_format, 16 AudioBuffer::AudioBuffer(SampleFormat sample_format,
15 int channel_count, 17 int channel_count,
16 int frame_count, 18 int frame_count,
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 const uint8* source_data = data_.get() + source_frame_offset * frame_size; 215 const uint8* source_data = data_.get() + source_frame_offset * frame_size;
214 dest->FromInterleavedPartial( 216 dest->FromInterleavedPartial(
215 source_data, dest_frame_offset, frames_to_copy, bytes_per_channel); 217 source_data, dest_frame_offset, frames_to_copy, bytes_per_channel);
216 } 218 }
217 219
218 void AudioBuffer::TrimStart(int frames_to_trim) { 220 void AudioBuffer::TrimStart(int frames_to_trim) {
219 CHECK_GE(frames_to_trim, 0); 221 CHECK_GE(frames_to_trim, 0);
220 CHECK_LE(frames_to_trim, adjusted_frame_count_); 222 CHECK_LE(frames_to_trim, adjusted_frame_count_);
221 223
222 // Adjust timestamp_ and duration_ to reflect the smaller number of frames. 224 // Adjust timestamp_ and duration_ to reflect the smaller number of frames.
223 double offset = static_cast<double>(duration_.InMicroseconds()) * 225 const base::TimeDelta offset_as_time = base::TimeDelta::FromMicroseconds(
224 frames_to_trim / adjusted_frame_count_; 226 floor(static_cast<double>(duration_.InMicroseconds()) * frames_to_trim /
acolwell GONE FROM CHROMIUM 2014/02/24 21:46:11 nit: Why can't you use (duration_ * frames_to_trim
DaleCurtis 2014/02/26 02:38:45 Removed in favor of using the AudioTimestampHelper
225 base::TimeDelta offset_as_time = 227 adjusted_frame_count_));
226 base::TimeDelta::FromMicroseconds(static_cast<int64>(offset));
227 timestamp_ += offset_as_time; 228 timestamp_ += offset_as_time;
228 duration_ -= offset_as_time; 229 duration_ -= offset_as_time;
229 230
230 // Finally adjust the number of frames in this buffer and where the start 231 // Finally adjust the number of frames in this buffer and where the start
231 // really is. 232 // really is.
232 adjusted_frame_count_ -= frames_to_trim; 233 adjusted_frame_count_ -= frames_to_trim;
233 trim_start_ += frames_to_trim; 234 trim_start_ += frames_to_trim;
234 } 235 }
235 236
236 void AudioBuffer::TrimEnd(int frames_to_trim) { 237 void AudioBuffer::TrimEnd(int frames_to_trim) {
237 CHECK_GE(frames_to_trim, 0); 238 CHECK_GE(frames_to_trim, 0);
238 CHECK_LE(frames_to_trim, adjusted_frame_count_); 239 CHECK_LE(frames_to_trim, adjusted_frame_count_);
239 240
240 // Adjust duration_ only to reflect the smaller number of frames. 241 // Adjust duration_ only to reflect the smaller number of frames.
241 double offset = static_cast<double>(duration_.InMicroseconds()) * 242 duration_ -= base::TimeDelta::FromMicroseconds(
acolwell GONE FROM CHROMIUM 2014/02/24 21:46:11 Why does this computation differ from the one abov
DaleCurtis 2014/02/26 02:38:45 Ditto.
242 frames_to_trim / adjusted_frame_count_; 243 ceil(static_cast<double>(duration_.InMicroseconds()) * frames_to_trim /
243 base::TimeDelta offset_as_time = 244 adjusted_frame_count_));
244 base::TimeDelta::FromMicroseconds(static_cast<int64>(offset));
245 duration_ -= offset_as_time;
246 245
247 // Finally adjust the number of frames in this buffer. 246 // Finally adjust the number of frames in this buffer.
248 adjusted_frame_count_ -= frames_to_trim; 247 adjusted_frame_count_ -= frames_to_trim;
249 } 248 }
250 249
251 } // namespace media 250 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | media/base/audio_splicer.h » ('j') | media/base/audio_splicer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698