http://www.vttoth.com/CMS/index.php/technical-notes/68
8bit
一:
Z=2*(A+B)−(A*B)128−256.
二:
static double f = 1.0f;
static int MAX = 127, MIN = -127;
double STEPSIZE;
double temp = 0;
temp = sample1 + sample2;
if (temp == 0) return 0;
temp = temp * f;
if (temp > MAX) {
double f0 = 127.0f / temp;
f = f0;
temp = MAX;
}
else if (temp < MIN) {
double f0 = -127.0f / temp;
f = f0;
temp = (byte)MIN;
}
if (f < 1) {
STEPSIZE = ((1.0f - f) / 16);
f += STEPSIZE;
}
return(byte)temp;