diff 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
line wrap: on
line diff
--- a/src/CircularBuffer.h	Sat Jun 18 10:50:06 2016 +0100
+++ b/src/CircularBuffer.h	Fri Aug 18 20:07:33 2023 +0200
@@ -1,6 +1,6 @@
 //=======================================================================
 /** @file CircularBuffer.h
- *  @brief A class for calculating onset detection functions
+ *  @brief A circular buffer
  *  @author Adam Stark
  *  @copyright Copyright (C) 2008-2014  Queen Mary University of London
  *
@@ -27,7 +27,8 @@
 //=======================================================================
 /** A circular buffer that allows you to add new samples to the end
  * whilst removing them from the beginning. This is implemented in an
- * efficient way which doesn't involve any memory allocation
+ * efficient way which doesn't involve any memory allocation as samples
+ * are added to the end of the buffer
  */
 class CircularBuffer
 {
@@ -58,9 +59,16 @@
     void resize (int size)
     {
         buffer.resize (size);
+        std::fill (buffer.begin(), buffer.end(), 0.0);
         writeIndex = 0;
     }
     
+    /** Returns the size of the buffer */
+    int size()
+    {
+        return static_cast<int> (buffer.size());
+    }
+    
 private:
     
     std::vector<double> buffer;