24 lines
567 B
C++
24 lines
567 B
C++
#include "ringbuf.h"
|
|
|
|
void ringbuf_init(ringbuf_t *rb) {
|
|
rb->head = 0;
|
|
for (int i = 0; i < RINGBUF_SIZE; i++) {
|
|
rb->values[i].ts_ms = 0;
|
|
rb->values[i].value = 0;
|
|
}
|
|
}
|
|
|
|
void ringbuf_push(ringbuf_t *rb, uint32_t ts_ms, int v) {
|
|
rb->values[rb->head].ts_ms = ts_ms;
|
|
rb->values[rb->head].value = v;
|
|
rb->head = (rb->head + 1) % RINGBUF_SIZE;
|
|
}
|
|
|
|
void ringbuf_copy(const ringbuf_t *rb, sample_t *out) {
|
|
int idx = rb->head;
|
|
|
|
for (int i = 0; i < RINGBUF_SIZE; i++) {
|
|
out[i] = rb->values[(idx + i) % RINGBUF_SIZE];
|
|
}
|
|
}
|