All pastes #273521 Raw Edit

Anonymous

public c v1 · immutable
·published 2006-12-09 23:38 UTC
rendered paste body
short afccoef[16][2] ={{0,0},{0x0800,0},{0,0x0800},{0x0400,0x0400},{0x1000,0xf800},{0x0e00,0xfa00},{0x0c00,0xfc00},{0x1200,0xf600},{0x1068,0xf738},{0x12c0,0xf704},{0x1400,0xf400},{0x0800,0xf800},{0x0400,0xfc00},{0xfc00,0x0400},{0xfc00,0},{0xf800,0}};// AFC decoder (guesswork and bullshit by hcs)int AFCdecodebuffer(    u8			*input, // location of encoded source samples    s16         *out,   // location of destination buffer (16 bits / sample)    short		coef[16],   // location of adpcm info	short * histp,	short * hist2p){int sample;short nibbles[16];int i,j;char *src,*dst;short idx;short delta;short hist=*histp;short hist2=*hist2p;	dst = (char*)out;	src=input;    delta = 1<<(((*src)>>4)&0xf);	idx = (*src)&0xf;	src++;        for(i = 0; i < 16; i = i + 2) {		j = ( *src & 255) >> 4;		nibbles[i] = j;		j = *src & 255 & 15;		nibbles[i+1] = j;		src++;	}     for(i = 0; i < 16; i = i + 1) {		if(nibbles[i] >= 8) 			nibbles[i] = nibbles[i] - 16;     }     	 for(i = 0; i<16 ; i = i + 1) {		sample = (delta * nibbles[i])<<11;		sample += ((long)hist * afccoef[idx][0]) + ((long)hist2 * afccoef[idx][1]);		sample = sample >> 11;		if(sample > 32767) {			sample = 32767;		}		if(sample < -32768) {			sample = -32768;		}        *(short*)dst = (short)sample;        dst = dst + 2;		hist2 = hist;        hist = (short)sample;            }	*histp=hist;	*hist2p=hist2;    return((int)src);}