#define _ISOC9X_SOURCE 1 #define _ISOC99_SOURCE 1 #define __USE_ISOC9X 1 #define __USE_ISOC99 1 #include #define BUFF_LENGTH 8192 #define BUFF_MIX 2048 //somewhat regular audio chunk size? volatile float src_buff[BUFF_LENGTH]; //src float buffer volatile float dst_buff[BUFF_LENGTH]; //dst float buffer void resample() { int todo=BUFF_MIX; float advance_f=0.3; float volume_f=0.2; // 1/5 of max volume volatile float *src_ptr=src_buff; volatile float *dst_ptr=dst_buff; float res,res_next; float counter=0.0f; int pos; while (todo--) { pos=lrintf(counter); //pos=todo>>2; res=src_ptr[pos]; res_next=src_ptr[pos+1]; counter+=advance_f; //this line works perfect, since res and res_next contain 16 bits values res+= (res_next-res) * (counter-(float)pos); res*=volume_f; //thanks to the volume, now the value goes into the higher 16 bits *dst_ptr++ +=res; } } #define TEST_REPEAT 100000 int main() { //fill it with some data int i; for (i=0;i