void Lsp_Az( Word16 lsp[], /* (i) Q15 : line spectral frequencies */ Word16 a[] /* (o) Q12 : predictor coefficients (order = 10) */ ) { Word16 i, j; Word32 f1[6], f2[6]; Word32 t0; Get_lsp_pol(&lsp[0],f1); Get_lsp_pol(&lsp[1],f2); for (i = 5; i > 0; i--) { f1[i] = L_add(f1[i], f1[i-1]); /* f1[i] += f1[i-1]; */ f2[i] = L_sub(f2[i], f2[i-1]); /* f2[i] -= f2[i-1]; */ } a[0] = 4096; for (i = 1, j = 10; i <= 5; i++, j--) { t0 = L_add(f1[i], f2[i]); /* f1[i] + f2[i] */ a[i] = extract_l( L_shr_r(t0, 13) ); /* from Q24 to Q12 and * 0.5 */ t0 = L_sub(f1[i], f2[i]); /* f1[i] - f2[i] */ a[j] = extract_l( L_shr_r(t0, 13) ); /* from Q24 to Q12 and * 0.5 */ } return; }
/** * * function name: FreqToBandWithRounding * description: Retrieve index of nearest band border * returnt: index * */ static Word16 FreqToBandWithRounding(Word32 freq, /*!< frequency in Hertz */ Word32 fs, /*!< Sampling frequency in Hertz */ Word16 numOfBands, /*!< total number of bands */ const Word16 *bandStartOffset) /*!< table of band borders */ { Word32 lineNumber, band; Word32 temp, shift; /* assert(freq >= 0); */ shift = norm_l(fs); lineNumber = (extract_l(fixmul((bandStartOffset[numOfBands] << 2),Div_32(freq << shift,fs << shift))) + 1) >> 1; /* freq > fs/2 */ temp = lineNumber - bandStartOffset[numOfBands] ; if (temp >= 0) return numOfBands; /* find band the line number lies in */ for (band=0; band<numOfBands; band++) { temp = bandStartOffset[band + 1] - lineNumber; if (temp > 0) break; } temp = (lineNumber - bandStartOffset[band]); temp = (temp - (bandStartOffset[band + 1] - lineNumber)); if ( temp > 0 ) { band = band + 1; } return extract_l(band); }
void WebRtcG729fix_Lsp_Az( int16_t lsp[], /* (i) Q15 : line spectral frequencies */ int16_t a[] /* (o) Q12 : predictor coefficients (order = 10) */ ) { int16_t i; int32_t f1[6], f2[6]; int32_t ff1, ff2, fff1, fff2; Get_lsp_pol(&lsp[0],f1); Get_lsp_pol(&lsp[1],f2); a[0] = 4096; for (i = 1; i <= 5; i++) { ff1 = WebRtcSpl_AddSatW32(f1[i], f1[i-1]); /* f1[i] += f1[i-1]; */ ff2 = WebRtcSpl_SubSatW32(f2[i], f2[i-1]); /* f2[i] -= f2[i-1]; */ fff1 = WebRtcSpl_AddSatW32(ff1, ff2); /* f1[i] + f2[i] */ fff2 = WebRtcSpl_SubSatW32(ff1, ff2); /* f1[i] - f2[i] */ a[i] = extract_l(L_shr_r(fff1, 13)); /* from Q24 to Q12 and * 0.5 */ a[11-i] = extract_l(L_shr_r(fff2, 13)); /* from Q24 to Q12 and * 0.5 */ } }
void Cor_h_X( Word16 h[], /* (i) Q12 :Impulse response of filters */ Word16 X[], /* (i) :Target vector */ Word16 D[] /* (o) :Correlations between h[] and D[] */ /* Normalized to 13 bits */ ) { Word16 i, j; Word32 s, max, L_temp; Word32 y32[L_SUBFR]; /* first keep the result on 32 bits and find absolute maximum */ max = 0; for (i = 0; i < L_SUBFR; i++) { s = 0; for (j = i; j < L_SUBFR; j++) s = L_mac(s, X[j], h[j-i]); y32[i] = s; s = L_abs(s); L_temp =L_sub(s,max); if(L_temp>0L) { max = s; } } /* Find the number of right shifts to do on y32[] */ /* so that maximum is on 13 bits */ j = norm_l(max); if( sub(j,16) > 0) { j = 16; } j = sub(18, j); if(j>=0) { for(i=0; i<L_SUBFR; i++) { D[i] = extract_l( L_shr(y32[i], j) ); } } else { Word16 pj = abs_s(j); for(i=0; i<L_SUBFR; i++) { D[i] = extract_l( L_shr(y32[i], pj) ); } } return; }
void free_g(GUSANO *g) { POINT *p; int item; for(p=extract_l(g->cuerpo); p != NULL; p=extract_l(g->cuerpo)) { item = tablero[p->x/GORDO][p->y/GORDO]; delete_w(item); tablero[p->x/GORDO][p->y/GORDO] = 0; free(p); } }
/***************************************************************************** * * Function Name : Mpy_32_32_ss * * Purpose : * * Multiplies the 2 signed values L_var1 and L_var2 with saturation control * on 64-bit. The operation is performed in fractional mode : * - L_var1 and L_var2 are supposed to be in 1Q31 format. * - The result is produced in 1Q63 format : L_varout_h points to the * 32 MSBits while L_varout_l points to the 32 LSBits. * * Complexity weight : 4 * * Inputs : * * L_var1 32 bit long signed integer (Word32) whose value falls in the * range : 0x8000 0000 <= L_var1 <= 0x7fff ffff. * * L_var2 32 bit long signed integer (Word32) whose value falls in the * range : 0x8000 0000 <= L_var2 <= 0x7fff ffff. * * Outputs : * * *L_varout_h 32 bit long signed integer (Word32) whose value falls in * the range : 0x8000 0000 <= L_varout_h <= 0x7fff ffff. * * *L_varout_l 32 bit short unsigned integer (UWord32) whose value falls in * the range : 0x0000 0000 <= L_varout_l <= 0xffff ffff. * * * Return Value : * * none * *****************************************************************************/ void Mpy_32_32_ss( Word32 L_var1, Word32 L_var2, Word32 *L_varout_h, UWord32 *L_varout_l) { UWord16 uvar1_l, uvar2_l; Word16 var1_h, var2_h; Word40 L40_var1; if( (L_var1 == ( Word32)0x80000000) && (L_var2 == ( Word32)0x80000000)) { *L_varout_h = 0x7fffffff; *L_varout_l = ( UWord32)0xffffffff; } else { uvar1_l = extract_l( L_var1); var1_h = extract_h( L_var1); uvar2_l = extract_l( L_var2); var2_h = extract_h( L_var2); /* Below line can not overflow, so we can use << instead of L40_shl. */ L40_var1 = (( Word40) (( UWord32) uvar2_l * ( UWord32) uvar1_l)) << 1; *L_varout_l = 0x0000ffff & L_Extract40( L40_var1); L40_var1 = L40_shr( L40_var1, 16); L40_var1 = L40_add( L40_var1, (( Word40) (( Word32) var2_h * ( Word32) uvar1_l)) << 1); L40_var1 = L40_add( L40_var1, (( Word40) (( Word32) var1_h * ( Word32) uvar2_l)) << 1); *L_varout_l |= (L_Extract40( L40_var1)) << 16; L40_var1 = L40_shr( L40_var1, 16); L40_var1 = L40_mac( L40_var1, var1_h, var2_h); *L_varout_h = L_Extract40( L40_var1); #if (WMOPS) multiCounter[currCounter].extract_l-=2; multiCounter[currCounter].extract_h-=2; multiCounter[currCounter].L_Extract40-=3; multiCounter[currCounter].L40_shr-=2; multiCounter[currCounter].L40_add-=2; multiCounter[currCounter].L40_mac--; #endif /* if WMOPS */ } #if (WMOPS) multiCounter[currCounter].Mpy_32_32_ss++; #endif /* if WMOPS */ return; }
void WebRtcG729fix_Lsp_lsf2( int16_t lsp[], /* (i) Q15 : lsp[m] (range: -1<=val<1) */ int16_t lsf[], /* (o) Q13 : lsf[m] (range: 0.0<=val<PI) */ int16_t m /* (i) : LPC order */ ) { int16_t i, ind; int16_t offset; /* in Q15 */ int16_t freq; /* normalized frequency in Q16 */ int32_t L_tmp; ind = 63; /* begin at end of table2 -1 */ for(i= m-(int16_t)1; i >= 0; i--) { /* find value in table2 that is just greater than lsp[i] */ while( WebRtcSpl_SubSatW16(WebRtcG729fix_table2[ind], lsp[i]) < 0 ) { ind = WebRtcSpl_SubSatW16(ind,1); if ( ind <= 0 ) break; } offset = WebRtcSpl_SubSatW16(lsp[i], WebRtcG729fix_table2[ind]); /* acos(lsp[i])= ind*512 + (slope_acos[ind]*offset >> 11) */ L_tmp = L_mult( WebRtcG729fix_slope_acos[ind], offset ); /* L_tmp in Q28 */ freq = WebRtcSpl_AddSatW16(shl(ind, 9), extract_l(L_shr(L_tmp, 12))); lsf[i] = mult(freq, 25736); /* 25736: 2.0*PI in Q12 */ } }
void WebRtcG729fix_Lsf_lsp2( int16_t lsf[], /* (i) Q13 : lsf[m] (range: 0.0<=val<PI) */ int16_t lsp[], /* (o) Q15 : lsp[m] (range: -1<=val<1) */ int16_t m /* (i) : LPC order */ ) { int16_t i, ind; int16_t offset; /* in Q8 */ int16_t freq; /* normalized frequency in Q15 */ int32_t 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 & (int16_t)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(WebRtcG729fix_slope_cos[ind], offset); /* L_tmp in Q28 */ lsp[i] = WebRtcSpl_AddSatW16(WebRtcG729fix_table2[ind], extract_l(L_shr(L_tmp, 13))); } }
Word16 Test_Err(Word16 Lag1, Word16 Lag2,ENC_HANDLE *handle) { int i, i1, i2; Word16 zone1, zone2; Word32 Acc, Err_max; Word16 iTest; i2 = Lag2 + ClPitchOrd/2; zone2 = mult( (Word16) i2, (Word16) 1092); i1 = - SubFrLen + 1 + Lag1 - ClPitchOrd/2; if(i1 <= 0) i1 = 1; zone1 = mult( (Word16) i1, (Word16) 1092); Err_max = -1L; for(i=zone2; i>=zone1; i--) { Acc = L_sub(handle->CodStat.Err[i], Err_max); if(Acc > 0L) { Err_max = handle->CodStat.Err[i]; } } Acc = L_sub(Err_max, ThreshErr); if((Acc > 0L) || (handle->CodStat.SinDet < 0 ) ) { iTest = 0; } else { Acc = L_negate(Acc); Acc = L_shr(Acc, DEC); iTest = extract_l(Acc); } return(iTest); }
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); }
/*************************************************************************** * * 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; }
long interpolation_cos129( short freq ) { short sin_data,cos_data,count,temp ; long Ltemp,Lresult; /* cos(x)=cos(a)+(x-a)sin(a)-pow((a-x),2)*cos(a) */ count=shr(abs_s(freq ),7 ); temp=sub( extract_l(L_mult( count,64)) , freq ); /* (a-x)sin a */ /* Scale factor for (a-x): 3217=pi2/64 */ sin_data=sin129_table [ count]; cos_data=cos129_table [count]; Ltemp=L_mpy_ls(L_mult(3217,temp),sin_data); /* (a-x) sin(a) - [(a-x)*(a-x)*cos(a)] /2 */ /* Scale factor for (a-x)*(a-x): 20213=pi2*pi2/64 */ Ltemp=L_sub(Ltemp, L_mpy_ls(L_mult(mult_r(10106,temp),temp),cos_data)); /* Scaled up by 64/2 times */ Ltemp=L_shl( Ltemp ,6 ); Lresult= L_add(L_deposit_h(cos_data), (Ltemp)) ; return(Lresult); }
int32_t WebRtcG729fix_Inv_sqrt( /* (o) Q30 : output value (range: 0<=val<1) */ int32_t L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ ) { int16_t exp, i, a, tmp; int32_t L_y; if( L_x <= (int32_t)0) return ( (int32_t)0x3fffffffL); exp = WebRtcSpl_NormW32(L_x); L_x = L_shl(L_x, exp ); /* L_x is normalize */ exp = WebRtcSpl_SubSatW16(30, exp); if( (exp & 1) == 0 ) /* If exponent even -> shift right */ L_x = L_shr(L_x, 1); exp = shr(exp, 1); exp = WebRtcSpl_AddSatW16(exp, 1); L_x = L_shr(L_x, 9); i = extract_h(L_x); /* Extract b25-b31 */ L_x = L_shr(L_x, 1); a = extract_l(L_x); /* Extract b10-b24 */ a = a & (int16_t)0x7fff; i = WebRtcSpl_SubSatW16(i, 16); L_y = L_deposit_h(WebRtcG729fix_tabsqr[i]); /* tabsqr[i] << 16 */ tmp = WebRtcSpl_SubSatW16(WebRtcG729fix_tabsqr[i], WebRtcG729fix_tabsqr[i+1]); /* tabsqr[i] - tabsqr[i+1]) */ L_y = L_msu(L_y, tmp, a); /* L_y -= tmp*a*2 */ L_y = L_shr(L_y, exp); /* denormalization */ return(L_y); }
void dec3_10( Shortword index, /* (i) : indx of 3 pulses (10 bits) */ Shortword cod[], /* (o) Q12: algebraic (fixed) codebook excitation */ Shortword l_subfr /* (i) : lenght of subframe (53 or 54) */ ) { Shortword i, pos, gsign, sign; for (i = 0; i < l_subfr; i++) cod[i] = 0; if ((index & 0x0200) != 0) gsign = -1; else gsign = 1; for (i = 4; i >= 0; i -= 2) { pos = add(shr(extract_l(L_mult((index & 0x0007), STEP)), 1), i); if (i == 2) sign = negate(gsign); else sign = gsign; if (pos < l_subfr) cod[pos] = sign; index = shr(index, 3); } return; }
Word32 Inv_sqrt( /* (o) Q30 : output value (range: 0<=val<1) */ Word32 L_x /* (i) Q0 : input value (range: 0<=val<=7fffffff) */ ) { Word16 exp, i, a, tmp; Word32 L_y; if( L_x <= (Word32)0) return ( (Word32)0x3fffffffL); exp = norm_l(L_x); L_x = L_shl(L_x, exp ); /* L_x is normalize */ exp = sub(30, exp); if( (exp & 1) == 0 ) /* If exponent even -> shift right */ L_x = L_shr(L_x, 1); exp = shr(exp, 1); exp = add(exp, 1); L_x = L_shr(L_x, 9); i = extract_h(L_x); /* Extract b25-b31 */ L_x = L_shr(L_x, 1); a = extract_l(L_x); /* Extract b10-b24 */ a = a & (Word16)0x7fff; i = sub(i, 16); L_y = L_deposit_h(tabsqr[i]); /* tabsqr[i] << 16 */ tmp = sub(tabsqr[i], tabsqr[i+1]); /* tabsqr[i] - tabsqr[i+1]) */ L_y = L_msu(L_y, tmp, a); /* L_y -= tmp*a*2 */ L_y = L_shr(L_y, exp); /* denormalization */ return(L_y); }
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 ( sub(ind, 63)>0 ){ 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; }
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; }
int move_g(GUSANO *g) { POINT *p, *q; int item; if(!g->growth) { p = extract_l(g->cuerpo); item = tablero[p->x/GORDO][p->y/GORDO]; tablero[p->x/GORDO][p->y/GORDO] = 0; } else p = (POINT *)malloc(sizeof(POINT)); q = tail_l(g->cuerpo); p->x = q->x; p->y = q->y; switch(g->dir) { case 0: /* N */ p->y = q->y-GORDO; break; case 1: /* E */ p->x = q->x+GORDO; break; case 2: /* S */ p->y = q->y+GORDO; break; case 3: /* W */ p->x = q->x-GORDO; break; } if(p->x >= MAXX || p->x < 0 || p->y >= MAXY || p->y < 0 || (tablero[p->x/GORDO][p->y/GORDO] != 0 && (galleta.x != p->x || galleta.y != p->y))) { if(!g->growth) delete_w(item); free(p); return 0; } add_l(g->cuerpo, p); if(g->growth) { g->growth--; item = create_obj_w(p->x, p->y, GORDO, "oval", "red"); } else coords_w(item, p->x, p->y, GORDO); /* A comerse la galleta */ if(galleta.x == p->x && galleta.y == p->y) { g->growth += tablero[p->x/GORDO][p->y/GORDO]; tablero[p->x/GORDO][p->y/GORDO] = 0; cookie(MAXX, MAXY); } tablero[p->x/GORDO][p->y/GORDO] = item; return 1; }
void WebRtcG729fix_Log2( int32_t L_x, /* (i) Q0 : input value */ int16_t *exponent, /* (o) Q0 : Integer part of Log2. (range: 0<=val<=30) */ int16_t *fraction /* (o) Q15: Fractional part of Log2. (range: 0<=val<1) */ ) { int16_t exp, i, a, tmp; int32_t L_y; if( L_x <= (int32_t)0 ) { *exponent = 0; *fraction = 0; return; } exp = WebRtcSpl_NormW32(L_x); L_x = L_shl(L_x, exp ); /* L_x is normalized */ *exponent = WebRtcSpl_SubSatW16(30, exp); L_x = L_shr(L_x, 9); i = extract_h(L_x); /* Extract b25-b31 */ L_x = L_shr(L_x, 1); a = extract_l(L_x); /* Extract b10-b24 of fraction */ a = a & (int16_t)0x7fff; i = WebRtcSpl_SubSatW16(i, 32); L_y = L_deposit_h(WebRtcG729fix_tablog[i]); /* tablog[i] << 16 */ tmp = WebRtcSpl_SubSatW16(WebRtcG729fix_tablog[i], WebRtcG729fix_tablog[i+1]); /* tablog[i] - tablog[i+1] */ L_y = L_msu(L_y, tmp, a); /* L_y -= tmp*a*2 */ *fraction = extract_h( L_y); }
void Log2( Word32 x, /* (i) input */ Word16 *int_comp, /* Q0 integer part */ Word16 *frac_comp /* Q15 fractional part */ ) { Word16 exp, idx_man, sub_man, sub_tab; Word32 a0; if(x <= 0){ *int_comp = 0; *frac_comp = 0; } else{ exp = norm_l(x); // normalization a0 = L_shl(x, exp); // Q30 mantissa, i.e. 1.xxx Q30 /* use table look-up of man in [1.0, 2.0[ Q30 */ a0 = L_shr(L_sub(a0, (Word32)0x40000000), 8); // Q16 index into table - note zero'ing of leading 1 idx_man = extract_h(a0); // Q0 index into table sub_man = extract_l(L_shr((a0 & 0xFFFF), 1)); // Q15 fractional sub_man a0 = L_deposit_h(tablog[idx_man]); // Q31 sub_tab = sub(tablog[idx_man+1], tablog[idx_man]); // Q15 a0 = L_mac(a0, sub_man, sub_tab); // Q31 *frac_comp = intround(a0); // Q15 *int_comp = sub(30, exp); // Q0 } return; }
Word16 Random(Word16 *seed) { /* seed = seed*31821 + 13849; */ *seed = extract_l(L_add(L_shr(L_mult(*seed, 31821), 1), 13849L)); return(*seed); }
static Word16 Lag_max( /* output: lag found */ Word16 signal[], /* input : signal used to compute the open loop pitch */ Word16 L_frame, /* input : length of frame to compute pitch */ Word16 lag_max, /* input : maximum lag */ Word16 lag_min, /* input : minimum lag */ Word16 *cor_max) /* output: normalized correlation of selected lag */ { Word16 i, j; Word16 *p, *p1; Word32 max, t0, L_temp; Word16 max_h, max_l, ener_h, ener_l; Word16 p_max; max = MIN_32; /* initialization used only to suppress Microsoft Visual C++ warnings */ p_max = lag_max; for (i = lag_max; i >= lag_min; i--) { p = signal; p1 = &signal[-i]; t0 = 0; for (j=0; j<L_frame; j++, p++, p1++) t0 = L_mac(t0, *p, *p1); L_temp = L_sub(t0,max); if (L_temp >= 0L) { max = t0; p_max = i; } } /* compute energy */ t0 = 0; p = &signal[-p_max]; for(i=0; i<L_frame; i++, p++) t0 = L_mac(t0, *p, *p); /* 1/sqrt(energy), result in Q30 */ t0 = Inv_sqrt(t0); /* max = max/sqrt(energy) */ /* This result will always be on 16 bits !! */ L_Extract(max, &max_h, &max_l); L_Extract(t0, &ener_h, &ener_l); t0 = Mpy_32(max_h, max_l, ener_h, ener_l); *cor_max = extract_l(t0); return(p_max); }
/***************************************************************************** * * function name: count5_6_7_8_9_10_11 * description: counts tables 5-11 * returns: * input: quantized spectrum * output: bitCount for tables 5-11 * *****************************************************************************/ static void count5_6_7_8_9_10_11(const Word16 *values, const Word16 width, Word16 *bitCount) { Word32 t0,t1,i; Word32 bc5_6,bc7_8,bc9_10; Word16 bc11,sc; bc5_6=0; bc7_8=0; bc9_10=0; bc11=0; sc=0; for(i=0;i<width;i+=2){ t0 = values[i+0]; t1 = values[i+1]; bc5_6 = bc5_6 + EXPAND(huff_ltab5_6[t0+4][t1+4]); t0=ABS(t0); t1=ABS(t1); bc7_8 = bc7_8 + EXPAND(huff_ltab7_8[t0][t1]); bc9_10 = bc9_10 + EXPAND(huff_ltab9_10[t0][t1]); bc11 = bc11 + huff_ltab11[t0][t1]; sc = sc + (t0>0) + (t1>0); } bitCount[1]=INVALID_BITCOUNT; bitCount[2]=INVALID_BITCOUNT; bitCount[3]=INVALID_BITCOUNT; bitCount[4]=INVALID_BITCOUNT; bitCount[5]=extract_h(bc5_6); bitCount[6]=extract_l(bc5_6); bitCount[7]=extract_h(bc7_8) + sc; bitCount[8]=extract_l(bc7_8) + sc; bitCount[9]=extract_h(bc9_10) + sc; bitCount[10]=extract_l(bc9_10) + sc; bitCount[11]=bc11 + sc; }
short ran0(short *seed0) { long Ltemp; Ltemp = 0.0; Ltemp = L_mac(27698, 25173, *seed0); Ltemp = L_shr(Ltemp, 1); Ltemp = Ltemp & 0x0000ffffL; *seed0 = extract_l(Ltemp); return (extract_h(L_shl(Ltemp,15))); }
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; }
void free_g(GUSANO *g) { POINT *p; /* int item; */ if (g == NULL) return; for(p=extract_l(g->cuerpo); p != NULL; p=extract_l(g->cuerpo)) { /* item = tablero[p->x/GORDO][p->y/GORDO]; delete_w(item); tablero[p->x/GORDO][p->y/GORDO] = 0; */ free(p); } free(g->cuerpo); free(g); }
/**************************************************************************************** Function: categorize Syntax: void categorize(Word16 number_of_available_bits, Word16 number_of_regions, Word16 num_categorization_control_possibilities, Word16 rms_index, Word16 power_categories, Word16 category_balances) inputs: number_of_regions num_categorization_control_possibilities number_of_available_bits rms_index[MAX_NUMBER_OF_REGIONS] outputs: power_categories[MAX_NUMBER_OF_REGIONS] category_balances[MAX_NUM_CATEGORIZATION_CONTROL_POSSIBILITIES-1] Description: Computes a series of categorizations WMOPS: 7kHz | 24kbit | 32kbit -------|--------------|---------------- AVG | 0.14 | 0.14 -------|--------------|---------------- MAX | 0.15 | 0.15 -------|--------------|---------------- 14kHz | 24kbit | 32kbit | 48kbit -------|--------------|----------------|---------------- AVG | 0.42 | 0.45 | 0.48 -------|--------------|----------------|---------------- MAX | 0.47 | 0.52 | 0.52 -------|--------------|----------------|---------------- ****************************************************************************************/ void categorize(Word16 number_of_available_bits, Word16 number_of_regions, Word16 num_categorization_control_possibilities, Word16 *rms_index, Word16 *power_categories, Word16 *category_balances) { Word16 offset; Word16 temp; Word16 frame_size; /* At higher bit rates, there is an increase for most categories in average bit consumption per region. We compensate for this by pretending we have fewer available bits. */ test(); if (number_of_regions == NUMBER_OF_REGIONS) { frame_size = DCT_LENGTH; } else { frame_size = MAX_DCT_LENGTH; } temp = sub(number_of_available_bits,frame_size); test(); if (temp > 0) { number_of_available_bits = sub(number_of_available_bits,frame_size); number_of_available_bits = extract_l(L_mult0(number_of_available_bits,5)); number_of_available_bits = shr(number_of_available_bits,3); number_of_available_bits = add(number_of_available_bits,frame_size); } /* calculate the offset using the original category assignments */ offset = calc_offset(rms_index,number_of_regions,number_of_available_bits); /* compute the power categories based on the uniform offset */ compute_raw_pow_categories(power_categories,rms_index,number_of_regions,offset); /* adjust the category assignments */ /* compute the new power categories and category balances */ comp_powercat_and_catbalance(power_categories,category_balances,rms_index,number_of_available_bits,number_of_regions,num_categorization_control_possibilities,offset); }
static Word16 findMinMergeBits(const Word16 *bc1, const Word16 *bc2) { Word32 minBits, j, sum; minBits = INVALID_BITCOUNT; for (j=0; j<=CODE_BOOK_ESC_NDX; j++) { sum = bc1[j] + bc2[j]; if (sum < minBits) { minBits = sum; } } return extract_l(minBits); }
/*************************************************************************** Function: adjust_abs_region_power_index Syntax: adjust_abs_region_power_index(Word16 *absolute_region_power_index, Word16 *mlt_coefs, Word16 number_of_regions) inputs: *mlt_coefs *absolute_region_power_index number_of_regions outputs: *absolute_region_power_index Description: Adjusts the absolute power index WMOPS: 7kHz | 24kbit | 32kbit -------|--------------|---------------- AVG | 0.03 | 0.03 -------|--------------|---------------- MAX | 0.12 | 0.12 -------|--------------|---------------- 14kHz | 24kbit | 32kbit | 48kbit -------|--------------|----------------|---------------- AVG | 0.03 | 0.03 | 0.03 -------|--------------|----------------|---------------- MAX | 0.14 | 0.14 | 0.14 -------|--------------|----------------|---------------- ***************************************************************************/ void adjust_abs_region_power_index(Word16 *absolute_region_power_index,Word16 *mlt_coefs,Word16 number_of_regions) { Word16 n,i; Word16 region; Word16 *raw_mlt_ptr; Word32 acca; Word16 temp; for (region=0; region<number_of_regions; region++) { n = sub(absolute_region_power_index[region],39); n = shr_nocheck(n,1); test(); if (n > 0) { temp = extract_l(L_mult0(region,REGION_SIZE)); raw_mlt_ptr = &mlt_coefs[temp]; for (i=0; i<REGION_SIZE; i++) { acca = L_shl_nocheck(*raw_mlt_ptr,16); acca = L_add(acca,32768L); acca = L_shr_nocheck(acca,n); acca = L_shr_nocheck(acca,16); *raw_mlt_ptr++ = extract_l(acca); } temp = shl_nocheck(n,1); temp = sub(absolute_region_power_index[region],temp); absolute_region_power_index[region] = temp; move16(); } } }
/***************************************************************************** * * function name: findBestBook * description: essential helper functions * *****************************************************************************/ static Word16 findBestBook(const Word16 *bc, Word16 *book) { Word32 minBits, j; minBits = INVALID_BITCOUNT; for (j=0; j<=CODE_BOOK_ESC_NDX; j++) { if (bc[j] < minBits) { minBits = bc[j]; *book = j; } } return extract_l(minBits); }