From 19cb5c172bc3472f1c8b1b3281006c9e2a0fcf37 Mon Sep 17 00:00:00 2001 From: Ismael Gomez Date: Mon, 3 Jun 2019 21:19:06 +0200 Subject: [PATCH] Added read-and-convert function to ringbuffer --- lib/include/srslte/phy/utils/ringbuffer.h | 2 ++ lib/src/phy/utils/ringbuffer.c | 33 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/include/srslte/phy/utils/ringbuffer.h b/lib/include/srslte/phy/utils/ringbuffer.h index 6329b542a..5a9cdc39d 100644 --- a/lib/include/srslte/phy/utils/ringbuffer.h +++ b/lib/include/srslte/phy/utils/ringbuffer.h @@ -58,6 +58,8 @@ SRSLTE_API int srslte_ringbuffer_read(srslte_ringbuffer_t* q, void* ptr, int nof SRSLTE_API int srslte_ringbuffer_read_timed(srslte_ringbuffer_t* q, void* p, int nof_bytes, uint32_t timeout_ms); +SRSLTE_API int srslte_ringbuffer_read_convert_conj(srslte_ringbuffer_t* q, cf_t* dst_ptr, float norm, int nof_samples); + SRSLTE_API void srslte_ringbuffer_stop(srslte_ringbuffer_t *q); #ifdef __cplusplus diff --git a/lib/src/phy/utils/ringbuffer.c b/lib/src/phy/utils/ringbuffer.c index 91104a394..d37e12e9f 100644 --- a/lib/src/phy/utils/ringbuffer.c +++ b/lib/src/phy/utils/ringbuffer.c @@ -188,3 +188,36 @@ void srslte_ringbuffer_stop(srslte_ringbuffer_t *q) { pthread_mutex_unlock(&q->mutex); } +// Converts SC16 to cf_t +int srslte_ringbuffer_read_convert_conj(srslte_ringbuffer_t* q, cf_t* dst_ptr, float norm, int nof_samples) +{ + uint32_t nof_bytes = nof_samples * 4; + + pthread_mutex_lock(&q->mutex); + while (q->count < nof_bytes && q->active) { + pthread_cond_wait(&q->cvar, &q->mutex); + } + if (!q->active) { + pthread_mutex_unlock(&q->mutex); + return 0; + } + + int16_t* src = (int16_t*)&q->buffer[q->rpm]; + float* dst = (float*)dst_ptr; + + if (nof_bytes + q->rpm > q->capacity) { + int x = (q->capacity - q->rpm); + srslte_vec_convert_if(src, norm, dst, x / 2); + srslte_vec_convert_if((int16_t*)q->buffer, norm, &dst[x], 2 * nof_samples - x / 2); + } else { + srslte_vec_convert_if(src, norm, dst, 2 * nof_samples); + } + srslte_vec_conj_cc(dst_ptr, dst_ptr, nof_samples); + q->rpm += nof_bytes; + if (q->rpm >= q->capacity) { + q->rpm -= q->capacity; + } + q->count -= nof_bytes; + pthread_mutex_unlock(&q->mutex); + return nof_samples; +}