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 #ifndef MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_ 12 #define MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_ 13 14 #include <stddef.h> 15 16 #include <vector> 17 18 #include "absl/types/optional.h" 19 20 namespace webrtc { 21 22 // Ring buffer containing floating point values. 23 struct CircularBuffer { 24 public: 25 explicit CircularBuffer(size_t size); 26 ~CircularBuffer(); 27 28 void Push(float value); 29 absl::optional<float> Pop(); SizeCircularBuffer30 size_t Size() const { return nr_elements_in_buffer_; } 31 // This function fills the buffer with zeros, but does not change its size. 32 void Clear(); 33 34 private: 35 std::vector<float> buffer_; 36 size_t next_insertion_index_ = 0; 37 // This is the number of elements that have been pushed into the circular 38 // buffer, not the allocated buffer size. 39 size_t nr_elements_in_buffer_ = 0; 40 }; 41 42 } // namespace webrtc 43 44 #endif // MODULES_AUDIO_PROCESSING_ECHO_DETECTOR_CIRCULAR_BUFFER_H_ 45