📄 getext1k.c
字号:
if (rsq >= 1073741824 || rsq == 0){
/* If condition not met, don't iterate; use */
/* rough approximation. */
ans = shr(sv1,3);
ans = add(ans, shr(sv2,3));
ans = add(ans, shr(sub(ran0(seed0), 16384),2));
return (ans);
}
/*
* error in rsq doesn't seem to contribute to the final error in e_ran_g
*/
/*
* rsq scale down by two: input to fnLog must be scaled up by 2.
*/
rsq = L_shl(rsq, 1);
/* stemp1 = round32(L_negate(fnLog(rsq))); */
ltmp1 = L_negate(fnLog(rsq));
/*
* rsq must be greater than the log of lsq for the fractional
* divide to work. therfore normalize rsq.
*/
shft_fctr = norm_l(rsq);
rsq_s = round32(L_shl(rsq, shft_fctr));
stmp2 = (divide_s(round32(ltmp1), rsq_s));
/*
* stemp2 must be normalized before taking its square root.
* (increases precision).
*/
shft_fctr1 = norm_s(stmp2);
ltmp2 = L_deposit_h(shl(stmp2, shft_fctr1));
stemp1 = sqroot(ltmp2);
/*
* shifting involved before taking the square root:
* LEFT << shft_fctr. (LEFT because rsq is in the denominator
* of ltemp2 quotion).
* LEFT << 6. (multiply by 2 in original code and multiply by 32
* because output of fnLog scaled down by 32).
* RIGHT >> shft_fctr1. (normalization taken before sqroot).
*/
shft_fctr = shft_fctr + 6 - shft_fctr1;
/*
* PROPERTY: sqrt(2^n) = 2^(n/2)
* if shft_fctr is odd; multiply stemp1 by sqrt(2)/2 and
* increment number of shifts by 1. Can now use shft_fctr / 2.
*/
if (shft_fctr & 0x0001)
{
stemp1 = mult(stemp1, 23170);
shft_fctr++;
}
shft_fctr = shr(shft_fctr, 1);
/*
* normalize stemp1 for the following multiplication.
* adjust shft_fctr accordingly.
*/
shft_fctr1 = norm_s(stemp1);
stemp1 = shl(stemp1, shft_fctr1);
shft_fctr = shft_fctr - shft_fctr1;
gset = L_mult(sv1, stemp1);
/*
* final output is scaled down by 4, therefore shift up by
* shft_fctr - 2.
*/
gset = L_shl(gset, shft_fctr - 2);
iset = 1;
return round32(L_shl(L_mult(sv2, stemp1), shft_fctr - 2));
}
else
{
iset = 0;
return round32(gset);
}
}
void GetExc800bps(
/* 1 */ short *output,
/* 2 */ short *best,
/* 3 */ short scale,
/* 4 */ short *input,
/* 5 */ short length,
/* 6 */ short flag,
/* 7 */ short n)
{
short k, j;
short D;
long tmp;
long ltmp;
short stmp;
short *ptr;
long sum, lscale;
short ssum, sscale;
static short Seed = 1234;
static short Sum[NoOfSubFrames];
short shft_scale;
short shft_sum;
short stemp1;
if (!flag)
Seed = 1234;
/*
* sum is an integer value, not a fractional value.
*/
/* Get energy of next sub frame */
for (k = 0, sum = 0; k < length; k++)
{
sum = L_add(sum, L_deposit_l(abs_s(input[k])));
}
sum = L_shl(sum, 1); /* correct for scaling */
if (sum < SubFrameSize)
{
sum = fnLog10(L_deposit_h(scale));
sum = L_negate(L_add(L_shl(sum, 3), 484942745)); /* add (log8)/4 = 484842745 (VALUE ADJUSTED TO BETTER MATCH FLOAT MODEL) */
}
else
{
lscale = L_mult(SubFrameSize, scale);
shft_scale = norm_l(lscale);
sscale = round32(L_shl(lscale, shft_scale));
shft_sum = norm_l(sum) - 1;
ssum = round32(L_shl(sum, shft_sum));
/*
* The following divide/L_shl produced sum scaled down by 64.
* sum can have a max value of 40.xx in the sample data.
*/
/* sum = L_shl(L_divide(sum, lscale), (shft_scale + 7 - shft_sum)); */
sum = L_deposit_h(shl(divide_s(ssum, sscale), (shft_scale - shft_sum)));
/* sum = fnLog10(sum); */
sum = L_add(fnLog10(sum), 141412467); /* add log (2^7) scaled down by 32 */
sum = L_add(L_shl(sum, 3), 969485490); /* add (log8)/2 = 969685490 (VALUE ADJUSTED TO BETTER MATCH FLOAT MODEL) */
}
/*
* Sum scaled down by 4.
*/
Sum[n] = round32(sum);
/* Quantize if last frame */
if (n == NoOfSubFrames - 1)
{
/* Quantize to 8 bits */
for (k = 0, sum = 2147483647, ptr = Logqtbl; k < 256; k++)
{
for (j = 0, tmp = 0; j < 3; j++)
{
/*
* Sum and Logqtbl both scaled down by 4.
* Change Logqtbl to short if Lw not required.
*/
D = sub(Sum[j], (*ptr++));
tmp = L_mac(tmp, D, D);
}
if (tmp < sum)
{
ltmp = sum;
sum = tmp;
*best = k;
}
}
for (j = 0; j < 3; j++)
{
Sum[j] = Powqtbl[*best * 3 + j];
}
/* Get excitation */
j = FrameSize - ACBMemSize;
for (k = 0; k < FrameSize - 1; k++)
{
if (k >= j)
{
stmp = e_ran_g(&Seed);
stemp1 = k / (length - 1);
output[k - j] = round32(L_shr(L_mult(stmp, Sum[stemp1]), 5));
}
}
stmp = e_ran_g(&Seed);
output[k - j] = round32(L_shr(L_mult(stmp, Sum[2]), 5)); /* last excitation */
}
}
void GetExc800bps_dec(short *output, short length, short best, short flag, short n, short fer_flag)
{
short i, j;
short sum;
long Ltemp;
short temp;
static short Seed = 1234;
static short Sum[NoOfSubFrames];
static short PrevBest = 0;
#define P333 10923 /* (1/3) */
if (!flag && !n)
Seed = 1234;
if (n == 0)
{
/* De-quantize */
if (fer_flag == 0)
{
for (j = 0; j < 3; j++)
Sum[j] = Powqtbl[best * 3 + j];
PrevBest = best;
}
else
{
for (j = 0, Ltemp = 0; j < 3; j++)
Ltemp = L_mac(Ltemp, Powqtbl[PrevBest * 3 + j], P333);
for (j = 0; j < 3; j++)
Sum[j] = round32(Ltemp);
}
}
/* Convert to linear domain */
sum = Sum[n];
/* NOTE: Logqtbl[] and pow() function has been replaced with Powqtbl[] */
for (i = 0; i < length; i++)
{
temp = ran_g(&Seed);
Ltemp = L_mult(sum, temp);
Ltemp = L_shr(Ltemp, 5);
output[i] = round32(Ltemp);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -