Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 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 | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include "webrtc/modules/audio_processing/echo_detector/circular_buffer.h" | |
| 12 | |
| 13 #include <algorithm> | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 | |
| 19 CircularBuffer::CircularBuffer(size_t size) : buffer_(size) {} | |
| 20 CircularBuffer::CircularBuffer(CircularBuffer&& other) = default; | |
|
peah-webrtc
2016/10/19 14:45:25
I don't think you need this one. My guess is that
ivoc
2016/10/20 14:04:35
Done.
| |
| 21 CircularBuffer::~CircularBuffer() = default; | |
| 22 | |
| 23 void CircularBuffer::Push(float value) { | |
|
peah-webrtc
2016/10/19 14:45:25
For me it is very strange to have a circular buffe
ivoc
2016/10/20 14:04:35
This class behaves like a queue, except that it ha
peah-webrtc
2016/10/20 15:08:23
I see. Good point.
| |
| 24 buffer_[next_insertion_index_] = value; | |
| 25 ++next_insertion_index_; | |
| 26 next_insertion_index_ %= buffer_.size(); | |
| 27 RTC_DCHECK_LT(next_insertion_index_, buffer_.size()); | |
| 28 buffer_size_ = std::min(buffer_size_ + 1, buffer_.size()); | |
| 29 RTC_DCHECK_LE(buffer_size_, buffer_.size()); | |
| 30 } | |
| 31 | |
| 32 rtc::Optional<float> CircularBuffer::Pop() { | |
| 33 if (buffer_size_ == 0) { | |
| 34 return rtc::Optional<float>(); | |
| 35 } | |
| 36 const size_t index = | |
| 37 (buffer_.size() + next_insertion_index_ - buffer_size_) % buffer_.size(); | |
| 38 RTC_DCHECK_LT(index, buffer_.size()); | |
| 39 --buffer_size_; | |
| 40 return rtc::Optional<float>(buffer_[index]); | |
| 41 } | |
| 42 | |
| 43 void CircularBuffer::Clear() { | |
| 44 std::fill(buffer_.begin(), buffer_.end(), 0.f); | |
| 45 next_insertion_index_ = 0; | |
| 46 buffer_size_ = 0; | |
| 47 } | |
| 48 | |
| 49 } // namespace webrtc | |
| OLD | NEW |