17 : mBufferSize{ blockSize }, mBlockSize{ blockSize }
19 assert(blockSize > 0);
24 unsigned nChannels,
size_t blockSize,
size_t nBlocks,
27 Reinit(nChannels, blockSize, nBlocks, padding);
31 unsigned nChannels,
size_t blockSize,
size_t nBlocks,
size_t padding)
33 assert(blockSize > 0);
35 mBuffers.resize(nChannels);
36 mPositions.resize(nChannels);
37 const auto bufferSize = blockSize * nBlocks;
38 for (
auto &buffer : mBuffers)
40 buffer.resize(bufferSize + padding, 0.0f);
41 mBufferSize = bufferSize;
42 mBlockSize = blockSize;
52 assert(drop + keep <= Remaining());
60 auto iterP = mPositions.begin();
61 auto iterB = mBuffers.begin();
62 auto position = *iterP;
63 auto data = iterB->data();
64 auto end = data + iterB->size();
69 drop = std::min<size_t>(
end - position, drop);
71 const size_t size = ((
end - position) - drop) *
sizeof(float);
72 memmove(position, position + drop,
size);
75 for (
const auto endB = mBuffers.end(); ++iterB != endB;) {
77 memmove(position, position + drop,
size);
82 for (
auto position : mPositions)
83 memmove(position, position + drop, keep *
sizeof(
float));
86 assert(oldRemaining == Remaining());
95 assert(count <= Remaining());
103 auto iterP = mPositions.begin();
104 auto iterB = mBuffers.begin();
105 auto &position = *iterP;
106 auto data = iterB->data();
107 auto end = data + iterB->size();
109 assert(data <= position && position <=
end);
110 count = std::min<size_t>(
end - position, count);
112 assert(data <= position && position <=
end);
115 for (
const auto endB = mBuffers.end(); ++iterB != endB;) {
116 auto &position = *++iterP;
118 assert(iterB->data() <= position);
119 assert(position <= iterB->data() + iterB->size());
123 assert(iterB->data() <= position);
124 assert(position <= iterB->data() + iterB->size());
129 for (
auto &position : mPositions)
133 assert(Remaining() == oldRemaining - count);
138 auto iterP = mPositions.begin();
139 for (
auto &buffer : mBuffers)
140 *iterP++ = buffer.data();
146 auto oldRemaining = Remaining();
150 Discard(
free, oldRemaining);
158 auto buffer = mBuffers[
iChannel].data();
165 return mBuffers[
iChannel].data()[ Position() ];
173 auto end = buffer.data() + buffer.size();
175 n = std::min<size_t>(
end - p, n);
176 std::fill(p, p + n, 0);
Buffers(size_t blockSize=512)
float & GetWritePosition(unsigned iChannel)
Get writable position for one channel.
void Advance(size_t count)
Move the positions.
void Rewind()
Reset positions to starts of buffers.
void Reinit(unsigned nChannels, size_t blockSize, size_t nBlocks, size_t padding=0)
size_t Rotate()
Shift all data at and after the old position to position 0.
void ClearBuffer(unsigned iChannel, size_t n)
void Discard(size_t drop, size_t keep)
Discard some data at the (unchanging) positions.
constSamplePtr GetReadPosition(unsigned iChannel) const
Get accumulated data for one channel.
Positions or offsets within audio files need a wide type.
const char * end(const char *str) noexcept