AnsweredAssumed Answered

Efficient circular buffer for use with CMSIS-DSP lib K64

Question asked by jparrish88 on Aug 6, 2015
Latest reply on Aug 6, 2015 by xiangjun.rong

Hello all,


I'm trying to figure out an efficient method to pass my (our any version of circular buffer) to the CMSIS-DSPs functions. Specifically, I'm targeting the arm_cfft_f32 function. The issue here is that it requires a source pointer to a contiguous memory space. Yet, the design of a ring or circular buffer makes that difficult.


I'm using a K64, using 32 bit floats, with 32 point input buffer.



My current buffer code is:

#define BUFF_SIZE 32

typedef struct filbuffer{
    float buff[BUFF_SIZE];
    int writeIndex;

void initBuffer(filbuffer* buffer){
  int i;
  buffer->writeIndex = 0;

/* Write to the buffer */
void write(filbuffer* buffer, float value){
    buffer->buff[(buffer->writeIndex++) & BUFF_SIZE_MASK] = value;
/* Read from the buffer -- probably not needed */
float readn(filbuffer* buffer, int Xn){
    return buffer->buff[(buffer->writeIndex + (~Xn)) & BUFF_SIZE_MASK];