95    {
   96 
   99 
  101 
  102 
  103 
  104 
  105 
  107       int n, k, meml_gotten, Nfor, Nback, i, pos;
  112       unsigned char *pbytes;
  113       int diff, start_pos, state_first;
  114       float en1, en2;
  115       int index, ulp, firstpart;
  116       int subcount, subframe;
  121 
  122       
  123
  124 
  126                   data, (*iLBCenc_inst).hpimem);
  127 
  128       
  129 
  130       
  131 
  132       
  133 
  134       LPCencode(syntdenum, weightdenum, lsf_i, data, iLBCenc_inst);
 
  135 
  136 
  137       
  138 
  139       for (n=0; n<iLBCenc_inst->
nsub; n++) {
 
  142       }
  143 
  144       
  145 
  147 
  148       
  149
  150 
  152       en1 = 0;
  153       index = (start-1)*
SUBL;
 
  154 
  155 
  156 
  157 
  158 
  160           en1 += residual[index+i]*residual[index+i];
  161       }
  162       en2 = 0;
  163       index = (start-1)*
SUBL+diff;
 
  165           en2 += residual[index+i]*residual[index+i];
  166       }
  167 
  168 
  169       if (en1 > en2) {
  170           state_first = 1;
  171           start_pos = (start-1)*
SUBL;
 
  172       } else {
  173           state_first = 0;
  174           start_pos = (start-1)*
SUBL + diff;
 
  175       }
  176 
  177       
  178 
  183 
  187 
  188       
  189 
  190       if (state_first) { 
  191 
  192           
  193 
  194           memset(mem, 0,
  197               decresidual+start_pos,
  200 
  201           
  202 
  203           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
 
  207 
  208 
  209 
  210 
  211 
  213               weightState, 0);
  214 
  215           
  216 
  219               extra_cb_index, extra_gain_index,
  222 
  223       }
  224       else { 
  225 
  226           
  227 
  228           for (k=0; k<diff; k++) {
  229               reverseResidual[k] = residual[(start+1)*
SUBL-1
 
  231           }
  232 
  233           
  234 
  236           for (k=0; k<meml_gotten; k++) {
  237               mem[
CB_MEML-1-k] = decresidual[start_pos + k];
 
  238           }
  239           memset(mem, 0, (
CB_MEML-k)*
sizeof(
float));
 
  241 
  242           
  243 
  244           iCBSearch(iLBCenc_inst, extra_cb_index, extra_gain_index,
 
  248               weightState, 0);
  249 
  250           
  251 
  255 
  256           
  257 
  258           for (k=0; k<diff; k++) {
  259               decresidual[start_pos-1-k] = reverseDecresidual[k];
  260 
  261 
  262 
  263 
  264 
  265           }
  266       }
  267 
  268       
  269 
  270       subcount=0;
  271 
  272       
  273 
  274       Nfor = iLBCenc_inst->
nsub-start-1;
 
  275 
  276 
  277       if ( Nfor > 0 ) {
  278 
  279           
  280 
  285 
  286           
  287 
  288           for (subframe=0; subframe<Nfor; subframe++) {
  289 
  290               
  291 
  294                   &residual[(start+1+subframe)*
SUBL],
 
  297                   &weightdenum[(start+1+subframe)*
  299                   weightState, subcount+1);
  300 
  301               
  302 
  308 
  309               
  310 
  313 
  314 
  315 
  316 
  317 
  318                   &decresidual[(start+1+subframe)*
SUBL],
 
  321 
  322               subcount++;
  323           }
  324       }
  325 
  326 
  327       
  328 
  329       Nback = start-1;
  330 
  331 
  332       if ( Nback > 0 ) {
  333 
  334           
  335 
  336           for (n=0; n<Nback; n++) {
  337               for (k=0; k<
SUBL; k++) {
 
  338                   reverseResidual[n*
SUBL+k] =
 
  339                       residual[(start-1)*
SUBL-1-n*
SUBL-k];
 
  340                   reverseDecresidual[n*
SUBL+k] =
 
  341                       decresidual[(start-1)*
SUBL-1-n*
SUBL-k];
 
  342               }
  343           }
  344 
  345           
  346 
  347           meml_gotten = 
SUBL*(iLBCenc_inst->
nsub+1-start);
 
  348 
  349 
  352           }
  353           for (k=0; k<meml_gotten; k++) {
  354               mem[
CB_MEML-1-k] = decresidual[(start-1)*
SUBL + k];
 
  355           }
  356           memset(mem, 0, (
CB_MEML-k)*
sizeof(
float));
 
  358 
  359           
  360 
  361           for (subframe=0; subframe<Nback; subframe++) {
  362 
  363               
  364 
  366 
  367 
  368 
  369 
  370 
  372                   &reverseResidual[subframe*
SUBL],
 
  375                   &weightdenum[(start-2-subframe)*
  377                   weightState, subcount+1);
  378 
  379               
  380 
  386 
  387               
  388 
  391                   &reverseDecresidual[subframe*
SUBL],
 
  394 
  395               subcount++;
  396 
  397           }
  398 
  399           
  400 
  401           for (i=0; i<
SUBL*Nback; i++) {
 
  402               decresidual[
SUBL*Nback - i - 1] =
 
  403                   reverseDecresidual[i];
  404           }
  405       }
  406       
  407 
  408       
  410 
  411       
  412 
  413       pbytes=bytes;
  414       pos=0;
  415 
  416       
  417 
  418       for (ulp=0; ulp<3; ulp++) {
  419 
  420 
  421 
  422 
  423 
  424 
  425           
  427               packsplit(&lsf_i[k], &firstpart, &lsf_i[k],
 
  432               dopack( &pbytes, firstpart,
 
  434           }
  435 
  436           
  437 
  443           dopack( &pbytes, firstpart,
 
  445 
  446           packsplit(&state_first, &firstpart, &state_first,
 
  451           dopack( &pbytes, firstpart,
 
  453 
  454           packsplit(&idxForMax, &firstpart, &idxForMax,
 
  459           dopack( &pbytes, firstpart,
 
  461 
  463               packsplit(idxVec+k, &firstpart, idxVec+k,
 
  468               dopack( &pbytes, firstpart,
 
  470           }
  471 
  472 
  473 
  474 
  475 
  476 
  477           
  478 
  481                   extra_cb_index+k,
  486               dopack( &pbytes, firstpart,
 
  488                   &pos);
  489           }
  490 
  492               packsplit(extra_gain_index+k, &firstpart,
 
  493                   extra_gain_index+k,
  498               dopack( &pbytes, firstpart,
 
  500                   &pos);
  501           }
  502 
  503           
  504 
  505           for (i=0; i<iLBCenc_inst->
nasub; i++) {
 
  513                   dopack( &pbytes, firstpart,
 
  515                       &pos);
  516               }
  517           }
  518 
  519           for (i=0; i<iLBCenc_inst->
nasub; i++) {
 
  525 
  526 
  527 
  528 
  529 
  532                   dopack( &pbytes, firstpart,
 
  534                       &pos);
  535               }
  536           }
  537       }
  538 
  539       
  540
  541       dopack( &pbytes, 0, 1, &pos);
 
  542   }
int FrameClassify(iLBC_Enc_Inst_t *iLBCenc_inst, float *residual)
void LPCencode(float *syntdenum, float *weightdenum, int *lsf_index, float *data, iLBC_Enc_Inst_t *iLBCenc_inst)
void StateConstructW(int idxForMax, int *idxVec, float *syntDenum, float *out, int len)
void StateSearchW(iLBC_Enc_Inst_t *iLBCenc_inst, float *residual, float *syntDenum, float *weightDenum, int *idxForMax, int *idxVec, int len, int state_first)
void anaFilter(float *In, float *a, int len, float *Out, float *mem)
void iCBConstruct(float *decvector, int *index, int *gain_index, float *mem, int lMem, int veclen, int nStages)
void index_conv_enc(int *index)
void iCBSearch(iLBC_Enc_Inst_t *iLBCenc_inst, int *index, int *gain_index, float *intarget, float *mem, int lMem, int lTarget, int nStages, float *weightDenum, float *weightState, int block)
void dopack(unsigned char **bitstream, int index, int bitno, int *pos)
void packsplit(int *index, int *firstpart, int *rest, int bitno_firstpart, int bitno_total)
const iLBC_ULP_Inst_t * ULP_inst
float anaMem[LPC_FILTERORDER]
int scale_bits[ULP_CLASSES+2]
int extra_cb_index[CB_NSTAGES][ULP_CLASSES+2]
int lsf_bits[6][ULP_CLASSES+2]
int startfirst_bits[ULP_CLASSES+2]
int cb_index[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]
int cb_gain[NSUB_MAX][CB_NSTAGES][ULP_CLASSES+2]
int extra_cb_gain[CB_NSTAGES][ULP_CLASSES+2]
int start_bits[ULP_CLASSES+2]
int state_bits[ULP_CLASSES+2]