comparison src/CircularBuffer.h @ 117:ca2d83d29814 tip master

Merge branch 'release/1.0.5'
author Adam Stark <adamstark.uk@gmail.com>
date Fri, 18 Aug 2023 20:07:33 +0200
parents 8fb1610c9192
children
comparison
equal deleted inserted replaced
96:c58f01834337 117:ca2d83d29814
1 //======================================================================= 1 //=======================================================================
2 /** @file CircularBuffer.h 2 /** @file CircularBuffer.h
3 * @brief A class for calculating onset detection functions 3 * @brief A circular buffer
4 * @author Adam Stark 4 * @author Adam Stark
5 * @copyright Copyright (C) 2008-2014 Queen Mary University of London 5 * @copyright Copyright (C) 2008-2014 Queen Mary University of London
6 * 6 *
7 * This program is free software: you can redistribute it and/or modify 7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
25 #include <vector> 25 #include <vector>
26 26
27 //======================================================================= 27 //=======================================================================
28 /** A circular buffer that allows you to add new samples to the end 28 /** A circular buffer that allows you to add new samples to the end
29 * whilst removing them from the beginning. This is implemented in an 29 * whilst removing them from the beginning. This is implemented in an
30 * efficient way which doesn't involve any memory allocation 30 * efficient way which doesn't involve any memory allocation as samples
31 * are added to the end of the buffer
31 */ 32 */
32 class CircularBuffer 33 class CircularBuffer
33 { 34 {
34 public: 35 public:
35 36
56 57
57 /** Resize the buffer */ 58 /** Resize the buffer */
58 void resize (int size) 59 void resize (int size)
59 { 60 {
60 buffer.resize (size); 61 buffer.resize (size);
62 std::fill (buffer.begin(), buffer.end(), 0.0);
61 writeIndex = 0; 63 writeIndex = 0;
64 }
65
66 /** Returns the size of the buffer */
67 int size()
68 {
69 return static_cast<int> (buffer.size());
62 } 70 }
63 71
64 private: 72 private:
65 73
66 std::vector<double> buffer; 74 std::vector<double> buffer;