int a = *(src+0); a |= (a << 8); int b = *(src+1); b |= (b << 8); int c = *(src+2); c |= (c << 8);
int a = *(src+0); a = (a|(a << 8))-32768; int b = *(src+1); b = (a|(b << 8))-32768; int c = *(src+2); c = (a|(c << 8))-32768;
static	sint16 *resample_new(uint8 *src,						size_t sourcelen, size_t &size,						int rate, int wanted_rate){	int fp_pos = 0;	int fp_speed = (1 << 16) * rate / wanted_rate;	size = sourcelen;	// adjust the magnitudes of size and rate to prevent division error	while (size & 0xFFFF0000)		size >>= 1, rate = (rate >> 1) + 1;		// Compute the output size (times 4 since it is 16 stereo)	size = (size * wanted_rate / rate) << 2;	sint16 *stereo_data = new sint16 [size];	sint16 *data = stereo_data;	uint8 *src_end = src + sourcelen;	int result;		// Compute the initial data feed for the interpolator. We don't simply	// shift by 8, but rather duplicate the byte, this way we cover the full	// range. Probably doesn't make a big difference, listening wise :-)	int a = *(src+0); a |= (a << 8);	int b = *(src+1); b |= (b << 8);	int c = *(src+2); c |= (c << 8);		// We divide the data by 2, to prevent overshots. Imagine this sample pattern:	// 0, 65535, 65535, 0. Now you want to compute a value between the two 65535.	// Obviously, it will be *bigger* than 65535 (it can get to about 80,000).	// It is possibly to clamp it, but that leads to a distored wave form. Compare	// this to turning up the volume of your stereo to much, it will start to sound	// bad at a certain level (depending on the power of your stereo, your speakers 	// etc, this can be quite loud, though ;-). Hence we reduce the original range.	// A factor of roughly 1/1.2 = 0.8333 is sufficient. Since we want to avoid 	// floating point, we approximate that by 27/32	#define RANGE_REDUX(x)	(((x) * 27) >> 5)//	#define RANGE_REDUX(x)	((x) >> 1)//	#define RANGE_REDUX(x)	((x) / 1.2)	CubicInterpolator	interp(RANGE_REDUX(a), RANGE_REDUX(b), RANGE_REDUX(c));		do {		do {			// Convert to signed data			result = interp.interpolate(fp_pos) - 32768;			// Enforce range in case of an "overshot". Shouldn't happen since we			// scale down already, but safe is safe.			if (result < -32768)				result = -32768;			else if (result > 32767)				result = 32767;				*data++ = result;			*data++ = result;				fp_pos += fp_speed;		} while (!(fp_pos & 0xFFFF0000));		src++;		fp_pos &= 0x0000FFFF;				if (src+2 < src_end) {			c = *(src+2);			c |= (c << 8);			interp.feedData(RANGE_REDUX(c));		} else			interp.feedData();	} while (src < src_end);		return stereo_data;}