⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 huffdec2.c

📁 语音压缩算法
💻 C
📖 第 1 页 / 共 3 页
字号:
                           HANDLE_CONCEALMENT hConcealment){  int            quant[LN2];   unsigned short lengthOfLongestCodeword;    intclr  ( quant, LN2);      lengthOfLongestCodeword = HuffSpecDecDefault ( info,                                                    sect,                                                    nsect,                                                    quant,                                                    hVm,                                                   hResilience,                                                    hHcrInfo,                                                   hEpInfo,                                                   hConcealment );  hHcrSpecData = hHcrSpecData; /* to aviod compiler warning */  /* pulse noisless coding reconstruction */  if ( (info->islong) && (pulseInfo.pulse_data_present) )    pulse_nc(quant, &pulseInfo             );  if (!info->islong) {    int tmp_spec[LN2];    deinterleave ( quant,                   tmp_spec,                   sizeof(int),                   info->num_groups,                      info->group_len,                   info->sfb_per_sbk,                   info->sfb_width_short,                   info->islong,                   hResilience );    memcpy(quant,tmp_spec,sizeof(tmp_spec));  }  if ( debug['Q'] ) {    PrintSpectralValues ( quant );  }  /* inverse quantization */  {    unsigned short i;    for (i=0; i<info->bins_per_bk; i++) {      coef[i] = esc_iquant(quant[i]);    }  }  /* rescaling */  {    unsigned short i;    unsigned short k;    int sbk, nsbk, sfb, nsfb, fac, top;    Float *fp, scale;    i = 0;    fp = coef;    nsbk = info->nsbk;    for (sbk=0; sbk<nsbk; sbk++) {      nsfb = info->sfb_per_sbk[sbk];      k=0;      for (sfb=0; sfb<nsfb; sfb++) {        top = info->sbk_sfb_top[sbk][sfb];        fac = factors[i++]-SF_OFFSET;        if (fac >= 0 && fac < TEXP) {          scale = exptable[fac];        }        else {          if (fac == -SF_OFFSET) {            scale = 0;          }          else {            scale = pow( 2.0,  0.25*fac );          }        }        for ( ; k<top; k++) {          *fp++ *= scale;        }      }    }  }  return 1;}int getics ( Info*                    info,              int                      common_window,              WINDOW_SEQUENCE*         win,              WINDOW_SHAPE*            wshape,              byte*                    group,              byte*                    max_sfb,              PRED_TYPE                pred_type,              int*                     lpflag,              int*                     prstflag,              byte*                    cb_map,              Float*                   coef,              short*                   global_gain,              short*                   factors,             NOK_LT_PRED_STATUS*      nok_ltp,              TNS_frame_info*          tns,             BsBitStream*             gc_streamCh,              enum AAC_BIT_STREAM_TYPE bitStreamType,             HANDLE_RESILIENCE        hResilience,             HANDLE_BUFFER            hVm,             HANDLE_BUFFER            hHcrSpecData,             HANDLE_HCR               hHcrInfo,             HANDLE_EP_INFO           hEpInfo,             HANDLE_CONCEALMENT       hConcealment,             QC_MOD_SELECT qc_select){  int            nsect;  int            i;  int            cb;  int            top;  int            bot;  int            tot_sfb;  byte           sect[ 2*(MAXBANDS+1) ];  unsigned long  tmp;  /*   * global gain   */  *global_gain = 0;  tmp = GetBits ( GLOBAL_GAIN_MSB_1_5,                  5,                  hResilience,                  hVm,                   hEpInfo );  *global_gain |= (tmp<<3);  tmp = GetBits ( GLOBAL_GAIN_MSB_6_7,                  2,                   hResilience,                  hVm,                   hEpInfo);  *global_gain |= (tmp<<1);  tmp = GetBits ( GLOBAL_GAIN_MSB_8,                   1,                   hResilience,                  hVm,                   hEpInfo);  *global_gain |= tmp;  if (debug['f'])    printf("global gain: %3d\n", *global_gain);  if ( bitStreamType != SCALABLE ){    memcpy(info, winmap[*win], sizeof(Info));  }  if (( !common_window ) && ( bitStreamType != SCALABLE )) {    get_ics_info ( win,                    wshape,                    group,                    max_sfb,                    pred_type,                    lpflag,                    prstflag,                    bitStreamType,                   hResilience,                   hVm,                   hEpInfo,                   nok_ltp,		   NULL,		   common_window,                   qc_select);    memcpy(info, winmap[*win], sizeof(Info));  } else {    if( info->nsbk == 1 ) {      group[0] = 1;    } else {      int sum = 0;      for( i=0; i<info->num_groups; i++ ) {        sum  += info->group_len[i];        group[i]  = sum;      }    }  }  /* calculate total number of sfb for this grouping */  if (*max_sfb == 0) {    tot_sfb = 0;  }  else {    i=0;    tot_sfb = info->sfb_per_sbk[0];    if (debug['f'])printf("tot sfb %d %d\n", i, tot_sfb);    while (group[i++] < info->nsbk) {      tot_sfb += info->sfb_per_sbk[0];      if (debug['f'])printf("tot sfb %d %d\n", i, tot_sfb);    }  }  /* calculate band offsets   * (because of grouping and interleaving this cannot be   * a constant: store it in info.bk_sfb_top)   */  calc_gsfb_table(info, group);  /*    * section data   */  nsect = huffcb ( sect,                    *info,                   info->sectbits,                    tot_sfb,                    info->sfb_per_sbk[0],                    *max_sfb,                   info->num_groups,                   hHcrInfo,                   hResilience,                   hVm,                    hEpInfo,                   hConcealment);  if( ( nsect == 0 ) && ( *max_sfb > 0 ) ) {      CommonExit ( 2, "getics: nsect = 0 but maxSfb = %hu", *max_sfb);  }  /* generate "linear" description from section info   * stored as codebook for each scalefactor band and group   */  if (nsect) {    bot = 0;    for (i=0; i<nsect; i++) {      cb = sect[2*i];      top = sect[2*i + 1];      for (; bot<top; bot++)        *cb_map++ = cb;      bot = top;    }  }    else {    for (i=0; i<MAXBANDS; i++)      cb_map[i] = 0;  }    /*   * scale factor data   */    /* normal AAC Mode */    if(!hufffac( info,                  group,                  nsect,                  sect,                  *global_gain,                  factors,                 hVm,                 hResilience,                  hEpInfo ) ) {      return 0;    }  if ( bitStreamType  !=  SCALABLE ){      /*     * pulse noiseless coding     */    if ((pulseInfo.pulse_data_present = GetBits ( PULSE_DATA_PRESENT,                                                  LEN_PULSE_PRES,                                                 hResilience,                                                 hVm,                                                  hEpInfo ))) {      if (info->islong) {        GetPulseNc ( &pulseInfo,                     hResilience,                     hVm,                      hEpInfo );      }      else {          CommonExit ( 2, "getics: pulse data not allowed for short blocks");      }    }    /*     * tns data     */    if (GetBits ( TNS_DATA_PRESENT,                   LEN_TNS_PRES,                  hResilience,                  hVm,                   hEpInfo )) {      get_tns ( info,                 tns,                 hResilience,                hVm,                 hEpInfo );    }    else {      clr_tns ( info, tns );    }        /*     * Sony gain control     */    if (GetBits ( GAIN_CONTROL_DATA_PRESENT,                   LEN_GAIN_PRES,                  hResilience,                  hVm,                   hEpInfo )) {#ifdef  SRS      get_gcBuf( *win,                 gc_streamCh,                 hResilience,                 hVm,                  hEpInfo);#else      CommonExit(1, "Gain control not implemented");#endif    }  }  return HuffSpecFrame ( info,                          nsect,                          sect,                          factors,                         coef,                         hResilience,                         hVm,                         hHcrSpecData,                         hHcrInfo, hEpInfo,                         hConcealment );}/*  * get scale factors */int hufffac ( Info*              info,               byte*              group,               int                nsect,               byte*              sect,              short              global_gain,               short*             factors,              HANDLE_BUFFER      hVm,              HANDLE_RESILIENCE  hResilience,              HANDLE_EP_INFO     hEpInfo ) {  Hcb*     hcb;  Huffman* hcw;  int      i;  int      b;  int      bb;  int      t;  int      n;  int      sfb;  int      top;  int      fac;  int      is_pos;  int      factor_transmitted[MAXBANDS];  int*     fac_trans;  int      noise_pcm_flag = 1;  int      noise_nrg;  /* clear array for the case of max_sfb == 0 */  intclr(factor_transmitted, MAXBANDS);  shortclr(factors, MAXBANDS);  sfb = 0;  fac_trans = factor_transmitted;  for ( i = 0; i < nsect; i++ ) {    t   = sect[0];              /* codebook for this section */    top = sect[1];              /* top of section in sfb */    sect += 2;    for ( ; sfb < top; sfb++ ) {      fac_trans[sfb] = t;    }  }  /* scale factors are dpcm relative to global gain   * intensity positions are dpcm relative to zero   */  fac = global_gain;  is_pos = 0;  noise_nrg = global_gain - NOISE_OFFSET;  /* get scale factors */  hcb = &book[BOOKSCL];  hcw = hcb->hcw;  bb = 0;  if (debug['f'])    printf("scale factors\n");  for(b = 0; b < info->nsbk; ){    n = info->sfb_per_sbk[b];    b = *group++;    for(i = 0; i < n; i++){      switch (fac_trans[i]) {      case ZERO_HCB:        /* zero book */        break;      default:              /* spectral books */        /* decode scale factor */        t = decode_huff_cw ( hcw,                             hResilience,                             hVm,                              0,                              hEpInfo );        fac += t - MIDFAC;    /* 1.5 dB */        if (debug['f'])          printf("%3d:%3d", i, fac);        if( ( fac >= ( 2 * TEXP ) ) ) {            CommonExit(2, "hufffac: Scale factor too large: %d", fac);        }        if( fac < 0 ) {            CommonExit( 2, "hufffac: scale factor too small: %d", fac);        }        factors[i] = fac;        break;      case BOOKSCL:         /* invalid books */          CommonExit ( 2, "hufffac: book %d: invalid book", BOOKSCL );        break;      case INTENSITY_HCB:           /* intensity books */      case INTENSITY_HCB2:        /* decode intensity position */        t = decode_huff_cw ( hcw,                             hResilience,                             hVm,                              0,                              hEpInfo );        is_pos += t - MIDFAC;        factors[i] = is_pos;        break;      case NOISE_HCB:       /* noise books */        /* decode noise energy */        if (noise_pcm_flag) {          noise_pcm_flag = 0;          t = GetBits ( DPCM_NOISE_NRG,                         NOISE_PCM_BITS,                        hResilience,                        hVm,                         hEpInfo ) - NOISE_PCM_OFFSET;        }        else          t = decode_huff_cw ( hcw,                               hResilience,                               hVm,                                0,                                hEpInfo ) - MIDFAC;        noise_nrg += t;        if (debug['f'])          printf("\n%3d %3d (noise, code %d)", i, noise_nrg, t);        factors[i] = noise_nrg;        break;      }      if (debug['f'])        printf("%3d: %3d %3d\n", i, fac_trans[i], factors[i]);    }    if (debug['f'])      printf("\n");    /* expand short block grouping */    if (!(info->islong)) {      for(bb++; bb < b; bb++) {        for (i=0; i<n; i++) {          factors[i+n] = factors[i];        }        factors += n;      }    }    fac_trans += n;    factors += n;  }  return 1;}/* rm2 inverse quantization * escape books need ftn call * other books done via macro */#define iquant( q ) ( q >= 0 ) ? \(Float)iq_exp_tbl[ q ] : (Float)(-iq_exp_tbl[ - q ])

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -