From a3eaaf8b2d1a2c0ad8c03cc8658b2ff43cd36b03 Mon Sep 17 00:00:00 2001 From: Tomasz Lauda Date: Thu, 7 Feb 2019 10:07:44 +0100 Subject: [PATCH] buffer: add helper function for processing wrapped buffer Adds helper function for easier processing of wrapped buffer. Processing modules should switch to this function instead of directly using read and write pointers of buffer. Signed-off-by: Tomasz Lauda --- src/include/sof/audio/buffer.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/include/sof/audio/buffer.h b/src/include/sof/audio/buffer.h index 4909f847c..9a29bb673 100644 --- a/src/include/sof/audio/buffer.h +++ b/src/include/sof/audio/buffer.h @@ -96,6 +96,24 @@ struct comp_buffer { buffer->sink = comp; \ } while (0) \ +#define buffer_read_frag(buffer, idx, size) \ + buffer_get_frag(buffer, buffer->r_ptr, idx, size) + +#define buffer_read_frag_s16(buffer, idx) \ + buffer_get_frag(buffer, buffer->r_ptr, idx, sizeof(int16_t)) + +#define buffer_read_frag_s32(buffer, idx) \ + buffer_get_frag(buffer, buffer->r_ptr, idx, sizeof(int32_t)) + +#define buffer_write_frag(buffer, idx, size) \ + buffer_get_frag(buffer, buffer->w_ptr, idx, size) + +#define buffer_write_frag_s16(buffer, idx) \ + buffer_get_frag(buffer, buffer->w_ptr, idx, sizeof(int16_t)) + +#define buffer_write_frag_s32(buffer, idx) \ + buffer_get_frag(buffer, buffer->w_ptr, idx, sizeof(int32_t)) + typedef void (*cache_buff_op)(struct comp_buffer *); /* pipeline buffer creation and destruction */ @@ -197,4 +215,16 @@ static inline int buffer_set_size(struct comp_buffer *buffer, uint32_t size) return 0; } +static inline void *buffer_get_frag(struct comp_buffer *buffer, void *ptr, + uint32_t idx, uint32_t size) +{ + void *current = ptr + (idx * size); + + /* check for pointer wrap */ + if (current >= buffer->end_addr) + current = buffer->addr + (current - buffer->end_addr); + + return current; +} + #endif