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

Side by Side Diff: webrtc/modules/audio_coding/neteq/audio_vector.cc

Issue 2670643007: Make AudioVector::operator[] inline and modify index calculation (Closed)
Patch Set: Review comments Created 3 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
« no previous file with comments | « webrtc/modules/audio_coding/neteq/audio_vector.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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // Returns the number of elements in this AudioVector. 277 // Returns the number of elements in this AudioVector.
278 size_t AudioVector::Size() const { 278 size_t AudioVector::Size() const {
279 return (end_index_ + capacity_ - begin_index_) % capacity_; 279 return (end_index_ + capacity_ - begin_index_) % capacity_;
280 } 280 }
281 281
282 // Returns true if this AudioVector is empty. 282 // Returns true if this AudioVector is empty.
283 bool AudioVector::Empty() const { 283 bool AudioVector::Empty() const {
284 return begin_index_ == end_index_; 284 return begin_index_ == end_index_;
285 } 285 }
286 286
287 const int16_t& AudioVector::operator[](size_t index) const {
288 return array_[(begin_index_ + index) % capacity_];
289 }
290
291 int16_t& AudioVector::operator[](size_t index) {
292 return array_[(begin_index_ + index) % capacity_];
293 }
294
295 void AudioVector::Reserve(size_t n) { 287 void AudioVector::Reserve(size_t n) {
296 if (capacity_ > n) 288 if (capacity_ > n)
297 return; 289 return;
298 const size_t length = Size(); 290 const size_t length = Size();
299 // Reserve one more sample to remove the ambiguity between empty vector and 291 // Reserve one more sample to remove the ambiguity between empty vector and
300 // full vector. Therefore |begin_index_| == |end_index_| indicates empty 292 // full vector. Therefore |begin_index_| == |end_index_| indicates empty
301 // vector, and |begin_index_| == (|end_index_| + 1) % capacity indicates 293 // vector, and |begin_index_| == (|end_index_| + 1) % capacity indicates
302 // full vector. 294 // full vector.
303 std::unique_ptr<int16_t[]> temp_array(new int16_t[n + 1]); 295 std::unique_ptr<int16_t[]> temp_array(new int16_t[n + 1]);
304 CopyTo(length, 0, temp_array.get()); 296 CopyTo(length, 0, temp_array.get());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 if (remaining_zero_length > 0) 377 if (remaining_zero_length > 0)
386 memset(&array_[capacity_ - remaining_zero_length], 0, 378 memset(&array_[capacity_ - remaining_zero_length], 0,
387 remaining_zero_length * sizeof(int16_t)); 379 remaining_zero_length * sizeof(int16_t));
388 begin_index_ = (begin_index_ + capacity_ - length) % capacity_; 380 begin_index_ = (begin_index_ + capacity_ - length) % capacity_;
389 381
390 if (position > 0) 382 if (position > 0)
391 PushFront(temp_array.get(), position); 383 PushFront(temp_array.get(), position);
392 } 384 }
393 385
394 } // namespace webrtc 386 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/audio_vector.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698