Everything is a buffer

This commit is contained in:
2025-11-04 20:17:46 +01:00
parent 87598b5d65
commit 0adfa715d4
7 changed files with 403 additions and 69 deletions
+70 -7
View File
@@ -31,19 +31,30 @@
namespace dsp {
template <typename T>
class BufferMulti : public Buffer<T>
class BufferMulti
{
Buffer<T> m_buffer;
size_t m_numChannels;
size_t m_capacity;
public:
BufferMulti(size_t numChannels, size_t capacity)
: Buffer<T>(capacity*numChannels)
: m_buffer(capacity*numChannels)
, m_numChannels(numChannels)
, m_capacity(capacity)
{
}
Buffer<T> & buffer()
{
return m_buffer;
}
void reset()
{
m_buffer.reset();
}
size_t capacity()
{
return m_capacity;
@@ -54,18 +65,70 @@ class BufferMulti : public Buffer<T>
return m_numChannels;
}
using Buffer<T>::at;
T & at(uint channel, int offset)
Buffer<T> operator[](uint channel)
{
return at(int(m_capacity*channel + offset));
return at(channel);
}
const T & at(uint channel, int offset) const
const Buffer<T> operator [](uint channel) const
{
return at(channel, offset);
return at(channel);
}
BufferMulti & operator ++()
{
++m_buffer;
return *this;
}
BufferMulti & operator +=(int i)
{
m_buffer += i;
return *this;
}
BufferMulti & operator --()
{
--m_buffer;
return *this;
}
BufferMulti & operator -=(int i)
{
m_buffer -= i;
return *this;
}
BufferMulti & operator =(T value)
{
for (uint c=0; c < m_numChannels; c++)
{
this->at(c)[0] = value;
}
return *this;
}
dsp::Buffer<T> quer(int offset=0)
{
return Buffer<T>(m_buffer, offset, m_capacity);
}
const dsp::Buffer<T> quer(int offset=0) const
{
return Buffer<T>(m_buffer, offset, m_capacity);
}
protected:
Buffer<T> at(uint channel)
{
return Buffer<T>(m_buffer, channel*m_capacity);
}
const Buffer<T> at(uint channel) const
{
return Buffer<T>(m_buffer, channel*m_capacity);
}
};
}