kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 5642058716eb37a920c182d3278bd3722df351da
parent f37072d53d8f1846518a36955e98ecc72f2df9ad
Author: [email protected] <[email protected]>
Date:   Thu, 11 Aug 2016 08:21:48 +0300

univector.hpp: read/write vectors to ring buffer

Diffstat:
Minclude/kfr/base/univector.hpp | 45++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)

diff --git a/include/kfr/base/univector.hpp b/include/kfr/base/univector.hpp @@ -109,20 +109,59 @@ struct univector_base : input_expression, output_expression } ringbuf_step(cursor, srcsize); } - + template <size_t N> + void ringbuf_write(size_t& cursor, const vec<T, N>& x) + { + ringbuf_write(cursor, x.data(), N); + } void ringbuf_write(size_t& cursor, const T value) { T* data = get_data(); data[cursor] = value; - ringbuf_step(cursor, 1); } - void ringbuf_step(size_t& cursor, size_t step) + void ringbuf_step(size_t& cursor, size_t step) const { const size_t size = get_size(); cursor = cursor + step; cursor = cursor >= size ? cursor - size : cursor; } + void ringbuf_read(size_t& cursor, T& value) + { + T* data = get_data(); + value = data[cursor]; + ringbuf_step(cursor, 1); + } + template <size_t N> + void ringbuf_read(size_t& cursor, vec<T, N>& x) + { + ringbuf_read(cursor, x.data(), N); + } + void ringbuf_read(size_t& cursor, T* dest, size_t destsize) const + { + if (destsize == 0) + return; + // skip redundant data + const size_t size = get_size(); + const T* data = get_data(); + if (destsize > size) + { + dest = dest + destsize / size; + destsize = destsize % size; + } + const size_t fsize = size - cursor; + // one fragment + if (destsize <= fsize) + { + std::copy_n(data + cursor, destsize, dest); + } + else // two fragments + { + std::copy_n(data + cursor, fsize, dest); + std::copy_n(data, destsize - fsize, dest + fsize); + } + ringbuf_step(cursor, destsize); + } protected: template <typename Input>