Word16 ACELP_CodebookD( /* (o) :index of pulses positions */ Word16 x[], /* (i) :Target vector */ Word16 h[], /* (i) Q12 :Impulse response of filters */ Word16 T0, /* (i) :Pitch lag */ Word16 pitch_sharp, /* (i) Q14 :Last quantized pitch gain */ Word16 i_subfr, /* (i) :Indicator of 1st subframe, */ Word16 code[], /* (o) Q13 :Innovative codebook */ Word16 y[], /* (o) Q12 :Filtered innovative codebook */ Word16 *sign /* (o) :Signs of 4 pulses */ ) { Word16 i, index, sharp; Word16 Dn[L_SUBFR]; Word16 rr[DIM_RR]; /*-----------------------------------------------------------------* * Include fixed-gain pitch contribution into impulse resp. h[] * * Find correlations of h[] needed for the codebook search. * *-----------------------------------------------------------------*/ sharp = shl(pitch_sharp, 1); /* From Q14 to Q15 */ if (sub(T0, L_SUBFR)<0) for (i = T0; i < L_SUBFR; i++) { /* h[i] += pitch_sharp*h[i-T0] */ h[i] = add(h[i], mult(h[i-T0], sharp)); } Cor_h_D(h, rr); /*-----------------------------------------------------------------* * Compute correlation of target vector with impulse response. * *-----------------------------------------------------------------*/ Cor_h_X(h, x, Dn); /*-----------------------------------------------------------------* * Find innovative codebook. * *-----------------------------------------------------------------*/ if (sub(CODEC_MODE, 2) == 0) index = D4i40_17(Dn, rr, h, code, y, sign, i_subfr); else if (sub(CODEC_MODE, 1) == 0) index = D2i40_11(Dn, rr, h, code, y, sign, i_subfr); else { fprintf(stderr, "CODEC mode invalid\n"); exit(-1); } /*-----------------------------------------------------------------* * Compute innovation vector gain. * * Include fixed-gain pitch contribution into code[]. * *-----------------------------------------------------------------*/ if(sub(T0 ,L_SUBFR) <0) for (i = T0; i < L_SUBFR; i++) { /* code[i] += pitch_sharp*code[i-T0] */ code[i] = add(code[i], mult(code[i-T0], sharp)); } return index; }
Word16 ACELP_Code_A( /* (o) :index of pulses positions */ Word16 x[], /* (i) :Target vector */ Word16 h[], /* (i) Q12 :Inpulse response of filters */ Word16 T0, /* (i) :Pitch lag */ Word16 pitch_sharp, /* (i) Q14 :Last quantized pitch gain */ Word16 code[], /* (o) Q13 :Innovative codebook */ Word16 y[], /* (o) Q12 :Filtered innovative codebook */ Word16 *sign /* (o) :Signs of 4 pulses */ ) { Word16 i, index, sharp; Word16 Dn[L_SUBFR]; Word16 rr [DIM_RR]; /*-----------------------------------------------------------------* * Include fixed-gain pitch contribution into impulse resp. h[] * * Find correlations of h[] needed for the codebook search. * *-----------------------------------------------------------------*/ sharp = shl(pitch_sharp, 1); /* From Q14 to Q15 */ if (T0 < L_SUBFR) for (i = T0; i < L_SUBFR; i++) /* h[i] += pitch_sharp*h[i-T0] */ h[i] = add(h[i], mult(h[i-T0], sharp)); #ifdef RALINK_VOIP_CVERSION Cor_h(h, rr); #else Cor_hs(h, rr); #endif /*-----------------------------------------------------------------* * Compute correlation of target vector with impulse response. * *-----------------------------------------------------------------*/ Cor_h_X(h, x, Dn); /*-----------------------------------------------------------------* * Find innovative codebook. * *-----------------------------------------------------------------*/ #ifdef RALINK_VOIP_CVERSION index = D4i40_17_fast(Dn, rr, h, code, y, sign); #else index = D4i40_17_fasts(Dn, rr, h, code, y, sign); #endif /*-----------------------------------------------------------------* * Compute innovation vector gain. * * Include fixed-gain pitch contribution into code[]. * *-----------------------------------------------------------------*/ if(T0 < L_SUBFR) for (i = T0; i < L_SUBFR; i++) /* code[i] += pitch_sharp*code[i-T0] */ code[i] = add(code[i], mult(code[i-T0], sharp)); return index; }
Word16 Pitch_fr3_fast(/* (o) : pitch period. */ Word16 exc[], /* (i) : excitation buffer */ Word16 xn[], /* (i) : target vector */ Word16 h[], /* (i) Q12 : impulse response of filters. */ Word16 L_subfr, /* (i) : Length of subframe */ Word16 t0_min, /* (i) : minimum value in the searched range. */ Word16 t0_max, /* (i) : maximum value in the searched range. */ Word16 i_subfr, /* (i) : indicator for first subframe. */ Word16 *pit_frac /* (o) : chosen fraction. */ ) { Word16 t, t0; Word16 Dn[L_SUBFR]; Word16 exc_tmp[L_SUBFR]; Word32 max, corr, L_temp; /*-----------------------------------------------------------------* * Compute correlation of target vector with impulse response. * *-----------------------------------------------------------------*/ Cor_h_X(h, xn, Dn); /*-----------------------------------------------------------------* * Find maximum integer delay. * *-----------------------------------------------------------------*/ max = MIN_32; t0 = t0_min; /* Only to remove warning from some compilers */ for(t=t0_min; t<=t0_max; t++) { corr = Dot_Product(Dn, &exc[-t], L_subfr); L_temp = L_sub(corr, max); if(L_temp > 0) {max = corr; t0 = t; } } /*-----------------------------------------------------------------* * Test fractions. * *-----------------------------------------------------------------*/ /* Fraction 0 */ Pred_lt_3(exc, t0, 0, L_subfr); max = Dot_Product(Dn, exc, L_subfr); *pit_frac = 0; /* If first subframe and lag > 84 do not search fractional pitch */ if( (i_subfr == 0) && (sub(t0, 84) > 0) ) return t0; Copy(exc, exc_tmp, L_subfr); /* Fraction -1/3 */ Pred_lt_3(exc, t0, -1, L_subfr); corr = Dot_Product(Dn, exc, L_subfr); L_temp = L_sub(corr, max); if(L_temp > 0) { max = corr; *pit_frac = -1; Copy(exc, exc_tmp, L_subfr); } /* Fraction +1/3 */ Pred_lt_3(exc, t0, 1, L_subfr); corr = Dot_Product(Dn, exc, L_subfr); L_temp = L_sub(corr, max); if(L_temp > 0) { max = corr; *pit_frac = 1; } else Copy(exc_tmp, exc, L_subfr); return t0; }