Added read-and-convert function to ringbuffer
This commit is contained in:
parent
e47010130f
commit
19cb5c172b
2 changed files with 35 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue