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
#define BUFF_SIZE_MASK (BUFF_SIZE-1)


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

void initBuffer(filbuffer* buffer){
  int i;
  buffer->writeIndex = 0;
  for(i=0;i<BUFF_SIZE;i++){
  buffer->buff[i]=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];
}

Outcomes