You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
718 B
43 lines
718 B
9 years ago
|
#include "RingBuffer.h"
|
||
|
|
||
|
RingBuffer::RingBuffer()
|
||
|
: size(0), writeIndex(0)
|
||
|
{}
|
||
|
|
||
|
void RingBuffer::resize(int sz)
|
||
|
{
|
||
|
size = sz;
|
||
|
buffer.resize(size + interpolatorMargin);
|
||
|
}
|
||
|
|
||
|
void RingBuffer::write(float sample)
|
||
|
{
|
||
|
buffer[writeIndex] = sample;
|
||
|
writeIndex++;
|
||
|
if(writeIndex == size){
|
||
|
writeIndex = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void RingBuffer::write_margined(float sample)
|
||
|
{
|
||
|
buffer[writeIndex] = sample;
|
||
|
|
||
|
if( writeIndex < interpolatorMargin )
|
||
|
{
|
||
|
buffer[size + writeIndex] = sample;
|
||
|
}
|
||
|
|
||
|
writeIndex++;
|
||
|
if(writeIndex == size){
|
||
|
writeIndex = 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
float RingBuffer::readWithDelay(int delay){
|
||
|
int readIndex = writeIndex - delay;
|
||
|
if (readIndex < 0){
|
||
|
readIndex += size;
|
||
|
}
|
||
|
return buffer[readIndex];
|
||
|
}
|