int16_t WebRtcG729fix_Random(int16_t *seed) { /* seed = seed*31821 + 13849; */ *seed = extract_l(WebRtcSpl_AddSatW32(L_shr(L_mult(*seed, 31821), 1), 13849L)); return(*seed); }
void Lsp_lsf( Word16 lsp[], /* (i) Q15 : lsp[m] (range: -1<=val<1) */ Word16 lsf[], /* (o) Q15 : lsf[m] normalized (range: 0.0<=val<=0.5) */ Word16 m /* (i) : LPC order */ ) { Word16 i, ind, tmp; Word32 L_tmp; ind = 63; /* begin at end of table -1 */ for(i= m-(Word16)1; i >= 0; i--) { /* find value in table that is just greater than lsp[i] */ while(table[ind] < lsp[i]) { ind = sub(ind,1); } /* acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) * slope[ind] )/4096 */ L_tmp = L_mult( sub(lsp[i], table[ind]) , slope[ind] ); tmp = round(L_shl(L_tmp, 3)); /*(lsp[i]-table[ind])*slope[ind])>>12*/ lsf[i] = add(tmp, shl(ind, 8)); } return; }
/* extract elementary LSP from composed LSP with previous LSP */ void Lsp_prev_extract( Word16 lsp[M], /* (i) Q13 : unquantized LSP parameters */ Word16 lsp_ele[M], /* (o) Q13 : target vector */ Word16 fg[MA_NP][M], /* (i) Q15 : MA prediction coef. */ Word16 freq_prev[MA_NP][M], /* (i) Q13 : previous LSP vector */ Word16 fg_sum_inv[M] /* (i) Q12 : inverse previous LSP vector */ ) { Word16 j, k; Word32 L_temp; /* Q19 */ Word16 temp; /* Q13 */ for ( j = 0 ; j < M ; j++ ) { L_temp = L_deposit_h(lsp[j]); for ( k = 0 ; k < MA_NP ; k++ ) L_temp = L_msu( L_temp, freq_prev[k][j], fg[k][j] ); temp = extract_h(L_temp); L_temp = L_mult( temp, fg_sum_inv[j] ); lsp_ele[j] = extract_h( L_shl( L_temp, 3 ) ); } return; }
/*---------------------------------------------------------------------------- * filt_plt - ltp postfilter *---------------------------------------------------------------------------- */ static void filt_plt( Word16 *s_in, /* input : input signal with past*/ Word16 *s_ltp, /* input : filtered signal with gain 1 */ Word16 *s_out, /* output: output signal */ Word16 gain_plt /* input : filter gain */ ) { /* Local variables */ int n; Word32 L_acc; Word16 gain_plt_1; gain_plt_1 = sub(32767, gain_plt); gain_plt_1 = add(gain_plt_1, 1); /* 2**15 (1 - g) */ for(n=0; n<L_SUBFR; n++) { /* s_out(n) = gain_plt x s_in(n) + gain_plt_1 x s_ltp(n) */ L_acc = L_mult(gain_plt, s_in[n]); L_acc = L_mac(L_acc, gain_plt_1, s_ltp[n]); /* no overflow */ s_out[n] = round(L_acc); } return; }
void Lsf_lsp2( Word16 lsf[], /* (i) Q13 : lsf[m] (range: 0.0<=val<PI) */ Word16 lsp[], /* (o) Q15 : lsp[m] (range: -1<=val<1) */ Word16 m /* (i) : LPC order */ ) { Word16 i, ind; Word16 offset; /* in Q8 */ Word16 freq; /* normalized frequency in Q15 */ Word32 L_tmp; for(i=0; i<m; i++) { /* freq = abs_s(freq);*/ freq = mult(lsf[i], 20861); /* 20861: 1.0/(2.0*PI) in Q17 */ ind = shr(freq, 8); /* ind = b8-b15 of freq */ offset = freq & (Word16)0x00ff; /* offset = b0-b7 of freq */ if (ind > 63){ ind = 63; /* 0 <= ind <= 63 */ } /* lsp[i] = table2[ind]+ (slope_cos[ind]*offset >> 12) */ L_tmp = L_mult(slope_cos[ind], offset); /* L_tmp in Q28 */ lsp[i] = add(table2[ind], extract_l(L_shr(L_tmp, 13))); } return; }
static void Get_lsp_pol(Word16 *lsp, Word32 *f) { Word16 i,j, hi, lo; Word32 t0; /* All computation in Q24 */ *f = L_mult(4096, 2048); /* f[0] = 1.0; in Q24 */ f++; *f = L_msu((Word32)0, *lsp, 512); /* f[1] = -2.0 * lsp[0]; in Q24 */ f++; lsp += 2; /* Advance lsp pointer */ for(i=2; i<=5; i++) { *f = f[-2]; for(j=1; j<i; j++, f--) { L_Extract(f[-1] ,&hi, &lo); t0 = Mpy_32_16(hi, lo, *lsp); /* t0 = f[-1] * lsp */ t0 = L_shl(t0, 1); *f = L_add(*f, f[-2]); /* *f += f[-2] */ *f = L_sub(*f, t0); /* *f -= t0 */ } *f = L_msu(*f, *lsp, 512); /* *f -= lsp<<9 */ f += i; /* Advance f pointer */ lsp += 2; /* Advance lsp pointer */ } return; }
void Lsp_lsf2( Word16 lsp[], /* (i) Q15 : lsp[m] (range: -1<=val<1) */ Word16 lsf[], /* (o) Q13 : lsf[m] (range: 0.0<=val<PI) */ Word16 m /* (i) : LPC order */ ) { Word16 i, ind; Word16 offset; /* in Q15 */ Word16 freq; /* normalized frequency in Q16 */ Word32 L_tmp; ind = 63; /* begin at end of table2 -1 */ for(i= m-(Word16)1; i >= 0; i--) { /* find value in table2 that is just greater than lsp[i] */ while( sub(table2[ind], lsp[i]) < 0 ) { ind = sub(ind,1); if ( ind <= 0 ) break; } offset = sub(lsp[i], table2[ind]); /* acos(lsp[i])= ind*512 + (slope_acos[ind]*offset >> 11) */ L_tmp = L_mult( slope_acos[ind], offset ); /* L_tmp in Q28 */ freq = add(shl(ind, 9), extract_l(L_shr(L_tmp, 12))); lsf[i] = mult(freq, 25736); /* 25736: 2.0*PI in Q12 */ } return; }
/*************************************************************************** * * Function : build_CN_code * ***************************************************************************/ void build_CN_code ( Word32 *seed, /* i/o : Old CN generator shift register state */ Word16 cod[] /* o : Generated CN fixed codebook vector */ ) { Word16 i, j, k; for (i = 0; i < L_SUBFR; i++) { cod[i] = 0; } for (k = 0; k < NB_PULSE10; k++) { i = pseudonoise (seed, 2); /* generate pulse position */ i = shr (extract_l (L_mult (i, 10)), 1); i = i + k; j = pseudonoise (seed, 1); /* generate sign */ if (j > 0) { cod[i] = 4096; } else { cod[i] = -4096; } } return; }
Word16 Random(Word16 *seed) { /* seed = seed*31821 + 13849; */ *seed = extract_l(L_add(L_shr(L_mult(*seed, 31821), 1), 13849L)); return(*seed); }
Word32 Mpy_32_16(Word16 hi, Word16 lo, Word16 n) { Word32 L_32; L_32 = L_mult(hi, n); L_32 = L_mac(L_32, mult(lo, n) , 1); return( L_32 ); }
/*-------------------------------------------------------------------* * Function set_sign() * * ~~~~~~~~~~~~~~~~~~~~ * * Set the sign of each pulse position. * *-------------------------------------------------------------------*/ static void set_sign( Word16 fac_cn, /* (i) Q15: residual weight for sign determination */ Word16 cn[], /* (i) Q0 : residual after long term prediction */ Word16 dn[], /* (i) Q0 : correlation between target and h[] */ Word16 sign[], /* (o) Q15: sign vector (sign of each position) */ Word16 inv_sign[], /* (o) Q15: inverse of sign[] */ Word16 pos_max[], /* (o) : pos of max of correlation */ Word32 corr[] /* (o) : correlation of each track */ ) { Word16 i, k, pos, k_cn, k_dn, val; Word32 s, max; /* calculate energy for normalization of cn[] and dn[] */ s = 0; for (i=0; i<L_SUBFR; i++) s = L_mac(s, cn[i], cn[i]); if (s < 512) s = 512; s = Inv_sqrt(s); k_cn = extract_h(L_shl(s, 5)); /* k_cn = 11..23170 */ k_cn = mult(k_cn, fac_cn); s = 0; for (i=0; i<L_SUBFR; i++) s = L_mac(s, dn[i], dn[i]); if (s < 512) s = 512; s = Inv_sqrt(s); k_dn = extract_h(L_shl(s, 5)); /* k_dn = 11..23170 */ /* set sign according to en[] = k_cn*cn[] + k_dn*dn[] */ /* find position of maximum of correlation in each track */ for (k=0; k<NB_TRACK; k++) { max = -1; for (i=k; i<L_SUBFR; i+=STEP) { val = dn[i]; s = L_mac(L_mult(k_cn, cn[i]), k_dn, val); if (s >= 0) { sign[i] = 32767L; /* sign = +1 (Q15) */ inv_sign[i] = -32768L; } else { sign[i] = -32768L; /* sign = -1 (Q15) */ inv_sign[i] = 32767L; val = negate(val); } dn[i] = val; /* modify dn[] according to the fixed sign */ s = L_abs(s); if (s > max) { max = s; pos = i; } } pos_max[k] = pos; corr[k] = max; } return; }
void Weight_Az( Word16 a[], /* (i) Q12 : a[m+1] LPC coefficients */ Word16 gamma, /* (i) Q15 : Spectral expansion factor. */ Word16 m, /* (i) : LPC order. */ Word16 ap[] /* (o) Q12 : Spectral expanded LPC coefficients */ ) { Word16 i, fac; ap[0] = a[0]; fac = gamma; for(i=1; i<m; i++) { ap[i] = round( L_mult(a[i], fac) ); fac = round( L_mult(fac, gamma) ); } ap[m] = round( L_mult(a[m], fac) ); }
void WebRtcG729fix_Weight_Az( int16_t a[], /* (i) Q12 : a[m+1] LPC coefficients */ int16_t gamma, /* (i) Q15 : Spectral expansion factor. */ int16_t m, /* (i) : LPC order. */ int16_t ap[] /* (o) Q12 : Spectral expanded LPC coefficients */ ) { int16_t i, fac; ap[0] = a[0]; fac = gamma; for(i=1; i<m; i++) { ap[i] = L_round( L_mult(a[i], fac) ); fac = L_round( L_mult(fac, gamma) ); } ap[m] = L_round( L_mult(a[m], fac) ); }
static Word16 compress10 ( Word16 pos_indxA, /* i : signs of 4 pulses (signs only) */ Word16 pos_indxB, /* i : position index of 8 pulses (pos only) */ Word16 pos_indxC) /* i : position and sign of 8 pulses (compressed) */ { Word16 indx, ia,ib,ic; ia = shr(pos_indxA, 1); ib = extract_l(L_shr(L_mult(shr(pos_indxB, 1), 5), 1)); ic = extract_l(L_shr(L_mult(shr(pos_indxC, 1), 25), 1)); indx = shl(add(ia, add(ib, ic)), 3); ia = pos_indxA & 1; logic16 (); ib = shl((pos_indxB & 1), 1); logic16 (); ic = shl((pos_indxC & 1), 2); logic16 (); indx = add(indx , add(ia, add(ib, ic))); return indx; }
Word32 Mpy_32(Word16 hi1, Word16 lo1, Word16 hi2, Word16 lo2) { Word32 L_32; L_32 = L_mult(hi1, hi2); L_32 = L_mac(L_32, mult(hi1, lo2) , 1); L_32 = L_mac(L_32, mult(lo1, hi2) , 1); return( L_32 ); }
static Word16 Vq_subvec (/* o : quantization index, Q0 */ Word16 *lsf_r1, /* i : 1st LSF residual vector, Q15 */ Word16 *lsf_r2, /* i : 2nd LSF residual vector, Q15 */ const Word16 *dico, /* i : quantization codebook, Q15 */ Word16 *wf1, /* i : 1st LSF weighting factors Q13 */ Word16 *wf2, /* i : 2nd LSF weighting factors Q13 */ Word16 dico_size /* i : size of quantization codebook, Q0 */ ) { Word16 index = 0; /* initialization only needed to keep gcc silent */ Word16 i, temp; const Word16 *p_dico; Word32 dist_min, dist; dist_min = MAX_32; move32 (); p_dico = dico; move16 (); for (i = 0; i < dico_size; i++) { temp = sub (lsf_r1[0], *p_dico++); temp = mult (wf1[0], temp); dist = L_mult (temp, temp); temp = sub (lsf_r1[1], *p_dico++); temp = mult (wf1[1], temp); dist = L_mac (dist, temp, temp); temp = sub (lsf_r2[0], *p_dico++); temp = mult (wf2[0], temp); dist = L_mac (dist, temp, temp); temp = sub (lsf_r2[1], *p_dico++); temp = mult (wf2[1], temp); dist = L_mac (dist, temp, temp); test (); if (L_sub (dist, dist_min) < (Word32) 0) { dist_min = dist; move32 (); index = i; move16 (); } } /* Reading the selected vector */ p_dico = &dico[shl (index, 2)]; move16 (); lsf_r1[0] = *p_dico++; move16 (); lsf_r1[1] = *p_dico++; move16 (); lsf_r2[0] = *p_dico++; move16 (); lsf_r2[1] = *p_dico++; move16 (); return index; }
Word32 fnLog2(Word32 L_Input) { static Word16 swC0 = -0x2b2a, swC1 = 0x7fc5, swC2 = -0x54d0; Word16 siShiftCnt, swInSqrd, swIn; Word32 LwIn; /*_________________________________________________________________________ | | | Executable Code | |_________________________________________________________________________| */ /* normalize input and store shifts required */ /* ----------------------------------------- */ siShiftCnt = norm_l(L_Input); LwIn = L_shl(L_Input, siShiftCnt); siShiftCnt = add(siShiftCnt, 1); siShiftCnt = negate(siShiftCnt); /* calculate x*x*c0 */ /* ---------------- */ swIn = extract_h(LwIn); swInSqrd = mult_r(swIn, swIn); LwIn = L_mult(swInSqrd, swC0); /* add x*c1 */ /* --------- */ LwIn = L_mac(LwIn, swIn, swC1); /* add c2 */ /* ------ */ LwIn = L_add(LwIn, L_deposit_h(swC2)); /* apply *(4/32) */ /* ------------- */ LwIn = L_shr(LwIn, 3); LwIn = LwIn & 0x03ffffff; siShiftCnt = shl(siShiftCnt, 10); LwIn = L_add(LwIn, L_deposit_h(siShiftCnt)); /* return log2 */ /* ----------- */ return (LwIn); }
Word16 FNevChebP( Word16 x, /* (i) Q15: value */ Word16 *t_man, /* (i) Q7: mantissa of coefficients */ Word16 *t_exp, /* (i): exponent fo cofficients */ Word16 nd2) /* (i): order */ { Word16 i; Word16 x2; Word16 b_man[NAB], b_exp[NAB]; Word16 y; Word32 a0; x2 = x; // 2x in Q14 b_man[0] = t_man[nd2]; b_exp[0] = t_exp[nd2]; // b[0] in Q(7+t_exp) a0 = L_mult(x2, b_man[0]); a0 = L_shr(a0, sub(b_exp[0], 1)); // t*b[0] in Q23 a0 = L_add(a0, L_shr(L_deposit_h(t_man[nd2-1]), t_exp[nd2-1])); // c[nd2-1] + t*b[0] in Q23 b_exp[1] = norm_l(a0); b_man[1] = intround(L_shl(a0, b_exp[1])); // b[1] = c[nd2-1] + t * b[0] for (i=2;i<nd2;i++){ a0 = L_mult(x2, b_man[i-1]); a0 = L_shr(a0, sub(b_exp[i-1], 1)); // t*b[i-1] in Q23 a0 = L_add(a0, L_shr(L_deposit_h(t_man[nd2-i]), t_exp[nd2-i]));// c[nd2-i] + t*b[i-1] in Q23 a0 = L_sub(a0, L_shr(L_deposit_h(b_man[i-2]), b_exp[i-2])); // c[nd2-i] + t*b[i-1] - b[i-2] in Q23 b_exp[i] = norm_l(a0); b_man[i] = intround(L_shl(a0, b_exp[i])); // b[i] = c[nd2-i] - b[i-2] + t * b[i-1] } a0 = L_mult(x, b_man[nd2-1]); a0 = L_shr(a0, b_exp[nd2-1]); // x*b[nd2-1] in Q23 a0 = L_add(a0, L_shr(L_deposit_h(t_man[0]), t_exp[0])); // c[0] + x*b[nd2-1] in Q23 a0 = L_sub(a0, L_shr(L_deposit_h(b_man[nd2-2]), b_exp[nd2-2])); // c[0] + x*b[nd2-1] - b[nd2-2] in Q23 y = intround(L_shl(a0, 6)); // Q13 return y; // Q13 }
/* ******************************************************************************** * PRIVATE PROGRAM CODE ******************************************************************************** */ void MR475_quant_store_results( gc_predState *pred_st, /* i/o: gain predictor state struct */ const Word16 *p, /* i : pointer to selected quantizer table entry */ Word16 gcode0, /* i : predicted CB gain, Q(14 - exp_gcode0) */ Word16 exp_gcode0, /* i : exponent of predicted CB gain, Q0 */ Word16 *gain_pit, /* o : Pitch gain, Q14 */ Word16 *gain_cod /* o : Code gain, Q1 */ ) { Word16 g_code, exp, frac, tmp; Word32 L_tmp; Word16 qua_ener_MR122; /* o : quantized energy error, MR122 version Q10 */ Word16 qua_ener; /* o : quantized energy error, Q10 */ /* Read the quantized gains */ *gain_pit = *p++; g_code = *p++; /*------------------------------------------------------------------* * calculate final fixed codebook gain: * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * * * gc = gc0 * g * *------------------------------------------------------------------*/ L_tmp = L_mult(g_code, gcode0); L_tmp = L_shr(L_tmp, sub(10, exp_gcode0)); *gain_cod = extract_h(L_tmp); /*------------------------------------------------------------------* * calculate predictor update values and update gain predictor: * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * * * qua_ener = log2(g) * * qua_ener_MR122 = 20*log10(g) * *------------------------------------------------------------------*/ Log2 (L_deposit_l (g_code), &exp, &frac); /* Log2(x Q12) = log2(x) + 12 */ exp = sub(exp, 12); tmp = shr_r (frac, 5); qua_ener_MR122 = add (tmp, shl (exp, 10)); L_tmp = Mpy_32_16(exp, frac, 24660); /* 24660 Q12 ~= 6.0206 = 20*log10(2) */ qua_ener = round (L_shl (L_tmp, 13)); /* Q12 * Q0 = Q13 -> Q10 */ gc_pred_update(pred_st, qua_ener_MR122, qua_ener); }
void Syn_filte( Word16 m, /* (i) : LPC order */ Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients (m=10) */ Word16 x[], /* (i) : input signal */ Word16 y[], /* (o) : output signal */ Word16 lg, /* (i) : size of filtering */ Word16 mem[], /* (i/o) : memory associated with this filtering. */ Word16 update /* (i) : 0=no update, 1=update of memory. */ ) { Word16 i, j; Word32 s; Word16 tmp[80]; /* This is usually done by memory allocation (lg+M) */ Word16 *yy; /* Copy mem[] to yy[] */ yy = tmp; for(i=0; i<m; i++) { *yy++ = mem[i]; } /* Do the filtering. */ for (i = 0; i < lg; i++) { s = L_mult(x[i], a[0]); for (j = 1; j <= m; j++) s = L_msu(s, a[j], yy[-j]); s = L_shl(s, 3); *yy++ = round(s); } for(i=0; i<lg; i++) { y[i] = tmp[i+m]; } /* Update of memory if update==1 */ if(update != 0) for (i = 0; i < m; i++) { mem[i] = y[lg-m+i]; } return; }
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] = round(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] = round(Ltemp); } }
/*-------------------------------------------------------------------* * Function search_ixiy() * * ~~~~~~~~~~~~~~~~~~~~~~~ * * Find the best positions of 2 pulses in a subframe. * *-------------------------------------------------------------------*/ static void search_ixiy( Word16 track_x, /* (i) track of pulse 1 */ Word16 track_y, /* (i) track of pulse 2 */ Word16 *ps, /* (i/o) correlation of all fixed pulses */ Word16 *alp, /* (i/o) energy of all fixed pulses */ Word16 *ix, /* (o) position of pulse 1 */ Word16 *iy, /* (o) position of pulse 2 */ Word16 dn[], /* (i) corr. between target and h[] */ Word16 cor_x[], /* (i) corr. of pulse 1 with fixed pulses */ Word16 cor_y[], /* (i) corr. of pulse 2 with fixed pulses */ Word16 rrixiy[][MSIZE] /* (i) corr. of pulse 1 with pulse 2 */ ) { Word16 x, y, pos; Word16 ps1, ps2, sq, sqk; Word16 alp1, alp2, alpk; Word16 *p0, *p1, *p2; Word32 s; p0 = cor_x; p1 = cor_y; p2 = rrixiy[track_x]; sqk = -1; alpk = 1; for (x=track_x; x<L_SUBFR; x+=STEP) { ps1 = add(*ps, dn[x]); alp1 = add(*alp, *p0++); pos = -1; for (y=track_y; y<L_SUBFR; y+=STEP) { ps2 = add(ps1, dn[y]); alp2 = add(alp1, add(*p1++, *p2++)); sq = mult(ps2, ps2); s = L_msu(L_mult(alpk,sq),sqk,alp2); if (s > 0) { sqk = sq; alpk = alp2; pos = y; } } p1 -= NB_POS; if (pos >= 0) { *ix = x; *iy = pos; } } *ps = add(*ps, add(dn[*ix], dn[*iy])); *alp = alpk; return; }
/*---------------------------------------------------------------------------- * filt_mu - tilt filtering with : (1 + mu z-1) * (1/1-|mu|) * computes y[n] = (1/1-|mu|) (x[n]+mu*x[n-1]) *---------------------------------------------------------------------------- */ static void filt_mu( Word16 *sig_in, /* input : input signal (beginning at sample -1) */ Word16 *sig_out, /* output: output signal */ Word16 parcor0 /* input : parcor0 (mu = parcor0 * gamma3) */ ) { int n; Word16 mu, mu2, ga, temp; Word32 L_acc, L_temp, L_fact; Word16 fact, sh_fact1; Word16 *ptrs; if(parcor0 > 0) { mu = mult_r(parcor0, GAMMA3_PLUS); /* GAMMA3_PLUS < 0.5 */ sh_fact1 = 15; /* sh_fact + 1 */ fact = (Word16)0x4000; /* 2**sh_fact */ L_fact = (Word32)0x00004000L; } else { mu = mult_r(parcor0, GAMMA3_MINUS); /* GAMMA3_MINUS < 0.9375 */ sh_fact1 = 12; /* sh_fact + 1 */ fact = (Word16)0x0800; /* 2**sh_fact */ L_fact = (Word32)0x00000800L; } temp = sub(1, abs_s(mu)); mu2 = add(32767, temp); /* 2**15 (1 - |mu|) */ ga = div_s(fact, mu2); /* 2**sh_fact / (1 - |mu|) */ ptrs = sig_in; /* points on sig_in(-1) */ mu = shr(mu, 1); /* to avoid overflows */ for(n=0; n<L_SUBFR; n++) { temp = *ptrs++; L_temp = L_deposit_l(*ptrs); L_acc = L_shl(L_temp, 15); /* sig_in(n) * 2**15 */ L_temp = L_mac(L_acc, mu, temp); L_temp = L_add(L_temp, 0x00004000L); temp = extract_l(L_shr(L_temp,15)); /* ga x temp x 2 with rounding */ L_temp = L_add(L_mult(temp, ga),L_fact); L_temp = L_shr(L_temp, sh_fact1); /* mult. temp x ga */ sig_out[n] = sature(L_temp); } return; }
/* ******************************************************************************** * PUBLIC PROGRAM CODE ******************************************************************************** */ void Weight_Ai ( Word16 a[], /* (i) : a[M+1] LPC coefficients (M=10) */ const Word16 fac[], /* (i) : Spectral expansion factors. */ Word16 a_exp[] /* (o) : Spectral expanded LPC coefficients */ ) { Word16 i; a_exp[0] = a[0]; for (i = 1; i <= M; i++) { a_exp[i] = round (L_mult (a[i], fac[i - 1])); } return; }
/*---------------------------------------------------------------------------* * Function Init_lsfq_noise * * ~~~~~~~~~~~~~~~~~~~~~~~~~ * * * * -> Initialization of variables for the lsf quantization in the SID * * * *---------------------------------------------------------------------------*/ void Init_lsfq_noise(void) { Word16 i, j; Word32 acc0; /* initialize the noise_fg */ for (i=0; i<4; i++) Copy(fg[0][i], noise_fg[0][i], M); for (i=0; i<4; i++) for (j=0; j<M; j++){ acc0 = L_mult(fg[0][i][j], 19660); acc0 = L_mac(acc0, fg[1][i][j], 13107); noise_fg[1][i][j] = extract_h(acc0); } }
void energy_computation ( Word16 r_h[], Word16 scal_acf, Word16 rvad[], Word16 scal_rvad, Pfloat * acf0, Pfloat * pvad ) { Word16 i, temp, norm_prod; Word32 L_temp; /* r[0] is always greater than zero (no need to test for r[0] == 0) */ /* Computation of acf0 (exponent and mantissa) */ acf0->e = sub (32, scal_acf); acf0->m = r_h[0] & 0x7ff8; /* Computation of pvad (exponent and mantissa) */ pvad->e = add (acf0->e, 14); pvad->e = sub (pvad->e, scal_rvad); L_temp = 0L; for (i = 1; i <= 8; i++) { temp = shr (r_h[i], 3); L_temp = L_mac (L_temp, temp, rvad[i]); } temp = shr (r_h[0], 3); L_temp = L_add (L_temp, L_shr (L_mult (temp, rvad[0]), 1)); if (L_temp <= 0L) { L_temp = 1L; } norm_prod = norm_l (L_temp); pvad->e = sub (pvad->e, norm_prod); if(norm_prod<=0) pvad->m = extract_h (L_shr (L_temp, -norm_prod)); else pvad->m = extract_h (L_shl (L_temp, norm_prod)); return; }
static Word16 Sqrt( Word32 Num ) { Word16 i ; Word16 Rez = (Word16) 0 ; Word16 Exp = (Word16) 0x4000 ; Word32 Acc, L_temp; for ( i = 0 ; i < 14 ; i ++ ) { Acc = L_mult(add(Rez, Exp), add(Rez, Exp) ); L_temp = L_sub(Num, Acc); if(L_temp >= 0L) Rez = add( Rez, Exp); Exp = shr( Exp, (Word16) 1 ) ; } return Rez ; }
/************************************************************************* * * FUNCTION: compress_code() * * PURPOSE: compression of the linear codewords to 4+three indeces * one bit from each pulse is made robust to errors by * minimizing the phase shift of a bit error. * 4 signs (one for each track) * i0,i4,i1 => one index (7+3) bits, 3 LSBs more robust * i2,i6,i5 => one index (7+3) bits, 3 LSBs more robust * i3,i7 => one index (5+2) bits, 2-3 LSbs more robust * *************************************************************************/ void compress_code ( Word16 sign_indx[], /* i : signs of 4 pulses (signs only) */ Word16 pos_indx[], /* i : position index of 8 pulses (position only) */ Word16 indx[]) /* o : position and sign of 8 pulses (compressed) */ { Word16 i, ia, ib, ic; for (i = 0; i < NB_TRACK_MR102; i++) { indx[i] = sign_indx[i]; } /* First index indx[NB_TRACK] = (ia/2+(ib/2)*5 +(ic/2)*25)*8 + ia%2 + (ib%2)*2 + (ic%2)*4; */ indx[NB_TRACK_MR102] = compress10(pos_indx[0],pos_indx[4],pos_indx[1]); /* Second index indx[NB_TRACK+1] = (ia/2+(ib/2)*5 +(ic/2)*25)*8 + ia%2 + (ib%2)*2 + (ic%2)*4; */ indx[NB_TRACK_MR102+1]= compress10(pos_indx[2],pos_indx[6],pos_indx[5]); /* Third index if ((ib/2)%2 == 1) indx[NB_TRACK+2] = ((((4-ia/2) + (ib/2)*5)*32+12)/25)*4 + ia%2 + (ib%2)*2; else indx[NB_TRACK+2] = ((((ia/2) + (ib/2)*5)*32+12)/25)*4 + ia%2 + (ib%2)*2; */ ib = shr(pos_indx[7], 1) & 1; if (sub(ib, 1) == 0) ia = sub(4, shr(pos_indx[3], 1)); else ia = shr(pos_indx[3], 1); ib = extract_l(L_shr(L_mult(shr(pos_indx[7], 1), 5), 1)); ib = add(shl(add(ia, ib), 5), 12); ic = shl(mult(ib, 1311), 2); ia = pos_indx[3] & 1; ib = shl((pos_indx[7] & 1), 1); indx[NB_TRACK_MR102+2] = add(ia, add(ib, ic)); }
/************************************************************************* * * FUNCTION NAME: build_CN_param * *************************************************************************/ void build_CN_param ( Word16 *seed, /* i/o : Old CN generator shift register state */ const Word16 n_param, /* i : number of params */ const Word16 param_size_table[],/* i : size of params */ Word16 parm[] /* o : CN Generated params */ ) { Word16 i; const Word16 *p; *seed = extract_l(L_add(L_shr(L_mult(*seed, 31821), 1), 13849L)); p = &window_200_40[*seed & 0x7F]; for(i=0; i< n_param;i++){ parm[i] = *p++ & ~(0xFFFF<<param_size_table[i]); } }
static int16_t Sqrt(int32_t Num) { int16_t i; int16_t Rez = (int16_t)0; int16_t Exp = (int16_t)0x4000; int32_t Acc, L_temp; for (i = 0; i < 14 ; i++) { Acc = L_mult(WebRtcSpl_AddSatW16(Rez, Exp), WebRtcSpl_AddSatW16(Rez, Exp)); L_temp = WebRtcSpl_SubSatW32(Num, Acc); if (L_temp >= 0L) Rez = WebRtcSpl_AddSatW16(Rez, Exp); Exp = shr(Exp, (int16_t)1); } return Rez; }