[RingBugffer]\n- added operators\n- Remove get() and put()
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
#include <cstdint>
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include "../../dsp_types.hpp"
|
||||
|
||||
namespace dsp {
|
||||
@@ -37,8 +38,8 @@ namespace dsp {
|
||||
template <typename T>
|
||||
class RingBuffer
|
||||
{
|
||||
uint32_t m_index;
|
||||
uint32_t m_mask;
|
||||
uint m_index;
|
||||
uint m_mask;
|
||||
size_t m_capacity;
|
||||
vector<T> m_buffer;
|
||||
|
||||
@@ -55,6 +56,12 @@ class RingBuffer
|
||||
{
|
||||
return m_buffer.capacity();
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
void resize(int capacity, T value=T())
|
||||
{
|
||||
m_capacity = 1;
|
||||
@@ -68,17 +75,40 @@ class RingBuffer
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
void put(T sample)
|
||||
T & operator[](int offset)
|
||||
{
|
||||
m_index = (m_index + 1) & m_mask;
|
||||
m_buffer[m_index] = sample;
|
||||
return m_buffer[(m_index + (uint)offset) & m_mask];
|
||||
}
|
||||
|
||||
T get(uint32_t delay = 0)
|
||||
const T & operator[](int offset) const
|
||||
{
|
||||
uint32_t i = (m_index - delay) & m_mask;
|
||||
return m_buffer[i];
|
||||
return m_buffer[(m_index + (uint)offset) & m_mask];
|
||||
}
|
||||
|
||||
RingBuffer & operator ++()
|
||||
{
|
||||
++m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RingBuffer & operator +=(int i)
|
||||
{
|
||||
m_index += (uint)i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RingBuffer & operator --()
|
||||
{
|
||||
--m_index;
|
||||
return *this;
|
||||
}
|
||||
|
||||
RingBuffer & operator -=(int i)
|
||||
{
|
||||
m_index -= (uint)i;
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user