📄 monopred.c
字号:
fprintf(stderr,"\n\n ****** error in routine init_pred_stat ******\n"); fprintf(stderr,"\nwrong attenuation factor a: %e\n",a); fprintf(stderr,"range of allowed values: 0 ... 1\n\n"); CommonExit(1,""); } if(b<0 || b>1) { fprintf(stderr,"\n\n ****** error in routine init_pred_stat ******\n"); fprintf(stderr,"\nwrong attenuation factor b: %e\n",b); fprintf(stderr,"range of allowed values: 0 ... 1\n\n"); CommonExit(1,""); } /* Initialisation */ if (first_time) { ALPHA = alpha; A = a; B = b; make_inv_tables(); first_time = 0; } reset_pred_state(psp);}/******************************************************************************** *** FUNCTION: monopred() * *** * *** calculation of a predicted value from preceeding (quantised) samples * *** using a second order backward adaptive lattice predictor with full * *** LMS adaption algorithm for calculation of predictor coefficients * *** * *** parameters: input: if pred_flag predictionerror else quantized coef * *** output: if pred_flag predictionerror + predictedvalue * *** else preserved coef, * *** pointer to this quantised sample * *** predictedvalue: predicted value * *** psp: pointer to structure with predictor status * *** pred_flag: 1 if prediction is used * *** * ********************************************************************************/void monopred( float input, float *output, float *predictedvalue, PRED_STATUS *psp, TMP_PRED_STATUS *pst, int pred_flag){ float dr1; /* difference in the R-branch */ float e0,e1; /* "partial" prediction errors (E-branch) */ float r0,r1; /* content of delay elements */ float k1,k2; /* predictor coefficients */ float *R = pst->r; /* content of delay elements */ float *KOR = pst->kor; /* estimates of correlations */ float *VAR = pst->var; /* estimates of variances */ ulong tmp; int i, j;/* check that enc and dec track */#if (0){ static int i=0; static int frame=0; if (frame != bno) { frame=bno; i=0; } printf("P: %6d %6d: %1d %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f %8.2f\n", bno, i, pred_flag, input, R[0], R[1], KOR[0], KOR[1], VAR[0], VAR[1]); fflush(stdout); i++;} #endif r0=R[0]; r1=R[1]; /* Calculation of predictor coefficients to be used for the * calculation of the current predicted value based on previous * block's state */ /* the test, division and rounding is be pre-computed in the tables * equivalent calculation is: * k1 = (VAR[1-1]>MINVAR) ? KOR[1-1]/VAR[1-1]*B : 0.0F; * k2 = (VAR[2-1]>MINVAR) ? KOR[2-1]/VAR[2-1]*B : 0.0F; */ tmp = psp->var[1-1]; j = (tmp >> 7); i = tmp & 0x7f; k1 = KOR[1-1] * exp_table[j] * mnt_table[i]; tmp = psp->var[2-1]; j = (tmp >> 7); i = tmp & 0x7f; k2 = KOR[2-1] * exp_table[j] * mnt_table[i]; /* Predicted value */ *predictedvalue = k1*r0 + k2*r1; flt_round(predictedvalue); if (pred_flag) *output = input + *predictedvalue; else *output = input;/* printf("P1: %8.2f %8.2f\n", *predictedvalue, *output); */ /* Calculate state for use in next block */ /* E-Branch: * Calculate the partial prediction errors using the old predictor coefficients * and the old r-values in order to reconstruct the predictor status of the * previous step */ e0 = *output; e1 = e0-k1*r0; /* Difference in the R-Branch: * Calculate the difference in the R-Branch using the old predictor coefficients and * the old partial prediction errors as calculated above in order to reconstruct the * predictor status of the previous step */ dr1 = k1*e0; /* Adaption of variances and correlations for predictor coefficients: * These calculations are based on the predictor status of the previous step and give * the new estimates of variances and correlations used for the calculations of the * new predictor coefficients to be used for calculating the current predicted value */ VAR[1-1] = ALPHA*VAR[1-1]+(0.5F)*(r0*r0 + e0*e0); /* float const */ KOR[1-1] = ALPHA*KOR[1-1] + r0*e0; VAR[2-1] = ALPHA*VAR[2-1]+(0.5F)*(r1*r1 + e1*e1); /* float const */ KOR[2-1] = ALPHA*KOR[2-1] + r1*e1; /* Summation and delay in the R-Branch => new R-values */ r1 = A*(r0-dr1); r0 = A*e0; R[0]=r0; R[1]=r1;}/******************************************************************************** *** FUNCTION: predict() * *** * *** carry out prediction for all allowed spectral lines * *** * ********************************************************************************/void predict( Info* info, int* lpflag, PRED_STATUS* psp, Float* coef, HANDLE_CONCEALMENT hConcealment ){ int j, k, b, to, flag0; short *top; float predictedvalue; hConcealment = hConcealment; if (info->islong) { TMP_PRED_STATUS tmp_ps[MAX_PRED_BINS]; inv_quant_pred_state(tmp_ps, psp); b = 0; k = 0; top = info->sbk_sfb_top[b]; flag0 = *lpflag++; for (j = 0; j < pred_max_bands(); j++) { to = *top++; if (flag0 && *lpflag++) { for ( ; k < to; k++) { monopred(coef[k], &coef[k], &predictedvalue, &psp[k], &tmp_ps[k], 1); } } else { for ( ; k < to; k++) { monopred(coef[k], &coef[k], &predictedvalue, &psp[k], &tmp_ps[k], 0); } } } quant_pred_state(psp, tmp_ps); }}/******************************************************************************** *** FUNCTION: predict_reset() * *** * *** carry out cyclic predictor reset mechanism (long blocks) * *** resp. full reset (short blocks) * *** * ********************************************************************************/voidpredict_reset(Info* info, int *prstflag, PRED_STATUS **psp, int firstCh, int lastCh){ int j, prstflag0, prstgrp, ch; static int warn_flag = 1; prstgrp = 0; if (info->islong) { prstflag0 = *prstflag++; if (prstflag0) { /* for loop modified because of bit-reversed group number */ for (j=0; j<LEN_PRED_RSTGRP-1; j++) { prstgrp |= prstflag[j]; prstgrp <<= 1; } prstgrp |= prstflag[LEN_PRED_RSTGRP-1]; /* check if two consecutive reset group numbers are incremented by one (this is a poor check, but we don't have much alternatives) */ if ((warn_flag == 1) && (last_rstgrp_num > 0) && (last_rstgrp_num < 30)) { if ((prstgrp != last_rstgrp_num) && ((last_rstgrp_num + 1) != prstgrp)) { /* fprintf(stderr,"\nWARNING: suspicious Predictor Reset sequence !\n"); */ warn_flag = 0; } } last_rstgrp_num = prstgrp; if (debug['r']) { fprintf(stderr,"PRST: prstgrp: %d prstbits: ", prstgrp); for (j=0; j<LEN_PRED_RSTGRP; j++) fprintf(stderr,"%d ", prstflag[j]); fprintf(stderr,"FIRST: %d LAST %d\n", firstCh, lastCh); } if ( (prstgrp<1) || (prstgrp>30) ) { fprintf(stderr, "ERROR in prediction reset pattern\n"); return; } for (ch=firstCh; ch<=lastCh; ch++) { for (j=prstgrp-1; j<LN2; j+=30) { reset_pred_state(&psp[ch][j]); } } } /* end predictor reset */ } /* end islong */ else { /* short blocks */ /* complete prediction reset in all bins */ for (ch=firstCh; ch<=lastCh; ch++) { for (j=0; j<LN2; j++) reset_pred_state(&psp[ch][j]); } }}void MonoPredictor( float input, float *output, float *predictedvalue, PRED_STATUS *psp, int pred_flag){ TMP_PRED_STATUS tmp_psp; InverseQuantisationPredictorState(&tmp_psp, psp); monopred(input, output, predictedvalue, psp, &tmp_psp, pred_flag); QuantisationPredictorState(psp, &tmp_psp);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -