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

📄 huffdec2.c

📁 语音压缩算法
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************* MPEG-2 NBC Audio Decoder ************************** *                                                                           *"This software module was originally developed by AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS and edited byYoshiaki Oikawa (Sony Corporation),Mitsuyuki Hatanaka (Sony Corporation),Ralph Sperschneider (Fraunhofer Gesellschaft IIS)Ali Nowbakht-Irani (Fraunhofer Gesellschaft IIS)in the course of development of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and 3. This software module is an implementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC  gives users of the MPEG-2 NBC/MPEG-4 Audio standards free license to this software module or modifications thereof for use in hardware or software products claiming conformance to the MPEG-2 NBC/MPEG-4Audio  standards. Those intending to use this software module in hardware or software products are advised that this use may infringe existing patents. The original developer of this software module and his/her company, the subsequent editors and their companies, and ISO/IEC have no liability for use of this software module or modifications thereof in an implementation. Copyright is not released for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original developerretains full right to use the code for his/her  own purpose, assign or donate the code to a third party and to inhibit third party from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products. This copyright notice mustbe included in all copies or derivative works." Copyright(c)1996. *                                                                           * ****************************************************************************/#include <math.h>#include <stdio.h>#include <string.h>#include "block.h"               /* handler, defines, enums */#include "buffersHandle.h"       /* handler, defines, enums */#include "concealmentHandle.h"   /* handler, defines, enums */#include "interface.h"           /* handler, defines, enums */#include "mod_bufHandle.h"       /* handler, defines, enums */#include "monopredHandle.h"      /* handler, defines, enums */#include "resilienceHandle.h"    /* handler, defines, enums */#include "reorderspecHandle.h"   /* handler, defines, enums */#include "tf_mainHandle.h"       /* handler, defines, enums */#include "all.h"                 /* structs */#include "bitstreamStruct.h"     /* structs */#include "monopredStruct.h"      /* structs */#include "nok_ltp_common.h"      /* structs */#include "nok_prediction.h"      /* structs */#include "tf_mainStruct.h"       /* structs */#include "tns.h"                 /* structs */#include "allVariables.h"        /* variables */#include "huffdec2.h"#include "huffdec3.h"#include "port.h"#include "sony_local.h" /* 971117 YT */#include "common_m4a.h"#include "bitfct.h"#include "buffers.h"#include "buffersHandle.h"#include "bitstream.h"#include "interface.h"#define MAX_NR_OF_SWB       120#define VCB11_ARRAY_SIZE    LN4 /* probably too large, but ... better than too small */  typedef struct {    unsigned short nrOfSwb;    unsigned short swbReal;  } ENTRY_POINT;static void PrintSpectralValues ( int *quant ){  unsigned short i;  for ( i = 0; i < LN2; i++ )    printf ( "bno %13li line %4i value %13i\n", bno, i, quant[i] );}void deinterleave ( void              *inptr,  /* formerly pointer to type int */                    void              *outptr, /* formerly pointer to type int */                    short             length,  /* sizeof base type of inptr and outptr in chars */                    short             ngroups,                    short             nsubgroups[],                     int               ncells[],                     short             cellsize[],                    int               islong,                    HANDLE_RESILIENCE hResilience ){  char *inptr1  = (char*)inptr;  char *outptr1 = (char*)outptr;    {/* just to avoid compiler messages like "warning: unused parameter" */      islong = islong;       hResilience = hResilience;    }    {      int i, j, k, l;      char *start_inptr, *start_subgroup_ptr, *subgroup_ptr;      short cell_inc, subgroup_inc;      start_subgroup_ptr = outptr1;      for (i = 0; i < ngroups; i++)        {          cell_inc = 0;          start_inptr = inptr1;          /* Compute the increment size for the subgroup pointer */          subgroup_inc = 0;          for (j = 0; j < ncells[i]; j++) {            subgroup_inc += cellsize[j];          }          /* Perform the deinterleaving across all subgroups in a group */          for (j = 0; j < ncells[i]; j++) {            subgroup_ptr = start_subgroup_ptr;            for (k = 0; k < nsubgroups[i]; k++) {              outptr1 = subgroup_ptr + length*cell_inc;              for (l = 0; l < cellsize[j]; l++) {                memcpy( outptr1, inptr1, length);                outptr1 += length;                inptr1  += length;              }              subgroup_ptr += length*subgroup_inc;            }            cell_inc += cellsize[j];          }          start_subgroup_ptr += (inptr1 - start_inptr);        }    }}static void calc_gsfb_table ( Info *info,                               byte *group ){  int group_offset;  int group_idx;  int offset;  short * group_offset_p;  int sfb,len;  /* first calc the group length*/  if (info->islong){    return;  } else {    group_offset = 0;    group_idx = 0;    do  {      info->group_len[group_idx] = group[group_idx] - group_offset;      group_offset=group[group_idx];      group_idx++;    } while (group_offset<8);    info->num_groups = group_idx;    group_offset_p = info->bk_sfb_top;    offset=0;    for ( group_idx = 0; group_idx < info->num_groups; group_idx++) {      len = info->group_len[group_idx];      for (sfb=0;sfb<info->sfb_per_sbk[group_idx];sfb++){        offset += info->sfb_width_short[sfb] * len;        *group_offset_p++ = offset;#if 0        printf("%d %d: %d\n",  group_idx, sfb, offset);#endif          }    }  }}void getgroup ( Info*             info,                 byte*             group,                 HANDLE_RESILIENCE hResilience,                HANDLE_BUFFER     hVm,                HANDLE_EP_INFO    hEpInfo ){  int i, j, first_short;  if( debug['g'] ) printf("Grouping: 0");  first_short = 1;  for (i = 0; i < info->nsbk; i++) {    if (info->bins_per_sbk[i] > SN2) {      /* non-short windows are always their own group */      *group++ = i+1;    }    else {      /* only short-window sequences are grouped! */      if (first_short) {        /* first short window is always a new group */        first_short=0;      }      else {        if((j = GetBits ( SCALE_FACTOR_GROUPING,                           1,                          hResilience,                          hVm,                           hEpInfo )) == 0) {          *group++ = i;        }        if( debug['g'] ) printf("%1d", j);      }    }  }  *group = i;  if( debug['g'] ) printf("\n");}/* * read a synthesis mask *  uses EXTENDED_MS_MASK *  and grouped mask  */int getmask ( Info*             info,               byte*             group,               byte              max_sfb,               byte*             mask,               HANDLE_RESILIENCE hResilience,              HANDLE_BUFFER     hVm,               HANDLE_EP_INFO    hEpInfo ){  int b, i, mp;  mp = GetBits ( MS_MASK_PRESENT,                  LEN_MASK_PRES,                 hResilience,                 hVm,                  hEpInfo );  if( debug['m'] )    printf("\nExt. Mask Present: %d\n",mp);  /* special EXTENDED_MS_MASK cases */  if(mp == 0) { /* no ms at all */    return 0;  }  if(mp == 2) {/* MS for whole spectrum on, mask bits set to 1 */    for(b = 0; b < info->nsbk; b = *group++)      for(i = 0; i < info->sfb_per_sbk[b]; i ++)        *mask++ = 1;    return 2;  }  /* otherwise get mask */  for(b = 0; b < info->nsbk; b = *group++){    if( debug['m'] ) printf(" gr%1i:",b);    for(i = 0; i < max_sfb; i ++) {      *mask = GetBits ( MS_USED,                         LEN_MASK,                        hResilience,                        hVm,                         hEpInfo );      if( debug['m'] )printf("%1i",*mask);      mask++;    }    for( ; i < info->sfb_per_sbk[b]; i++){      *mask = 0;      if( debug['m'] ) printf("%1i",*mask);      mask++;    }  }  if( debug['m'] ) printf("\n");  return 1;}void clr_tns( Info *info, TNS_frame_info *tns_frame_info ){  int s;  tns_frame_info->n_subblocks = info->nsbk;  for (s=0; s<tns_frame_info->n_subblocks; s++)    tns_frame_info->info[s].n_filt = 0;}static void get_tns ( Info*             info,                       TNS_frame_info*   tns_frame_info,                      HANDLE_RESILIENCE hResilience,                      HANDLE_BUFFER     hVm,                       HANDLE_EP_INFO    hEpInfo ){  int                       f, t, top, res, res2, compress;  int                       short_flag, s;  short                     *sp, tmp, s_mask, n_mask;  TNSfilt                   *tns_filt;  TNSinfo                   *tns_info;  static short              sgn_mask[] = {     0x2, 0x4, 0x8     };  static short              neg_mask[] = {     (short) 0xfffc, (short)0xfff8, (short)0xfff0     };  short_flag = (!info->islong);  tns_frame_info->n_subblocks = info->nsbk;  for (s=0; s<tns_frame_info->n_subblocks; s++) {    tns_info = &tns_frame_info->info[s];    if (!(tns_info->n_filt = GetBits ( N_FILT,                                        short_flag ? 1 : 2,                                       hResilience,                                       hVm,                                        hEpInfo )))      continue;                tns_info -> coef_res = res = GetBits ( COEF_RES,                                            1,                                           hResilience,                                           hVm,                                            hEpInfo ) + 3;    top = info->sfb_per_sbk[s];    tns_filt = &tns_info->filt[ 0 ];    for (f=tns_info->n_filt; f>0; f--)  {      tns_filt->stop_band = top;      top = tns_filt->start_band = top - GetBits ( TNS_LENGTH,                                                    short_flag ? 4 : 6,                                                   hResilience,                                                   hVm,                                                    hEpInfo );      tns_filt->order = GetBits ( ORDER,                                   short_flag ? 3 : 5,                                  hResilience,                                  hVm,                                   hEpInfo );      if (tns_filt->order)  {        tns_filt->direction = GetBits ( DIRECTION,                                         1,                                        hResilience,                                        hVm,                                         hEpInfo );        compress = GetBits ( COEF_COMPRESS,                              1,                             hResilience,                             hVm,                              hEpInfo );        res2 = res - compress;        s_mask = sgn_mask[ res2 - 2 ];        n_mask = neg_mask[ res2 - 2 ];        sp = tns_filt -> coef;        for (t=tns_filt->order; t>0; t--)  {          tmp = GetBits ( TNS_COEF,                           res2,                          hResilience,                          hVm,                           hEpInfo );          *sp++ = (tmp & s_mask) ? (tmp | n_mask) : tmp;        }      }      tns_filt++;    }  }   /* subblock loop */}/* * pulse noiseless coding */struct Pulse_Info{  int pulse_data_present;  int number_pulse;  int pulse_start_sfb;  int pulse_position[NUM_PULSE_LINES];  int pulse_offset[NUM_PULSE_LINES];  int pulse_amp[NUM_PULSE_LINES];};static struct Pulse_Info pulseInfo;static void GetPulseNc ( struct Pulse_Info* pulseInfo,                         HANDLE_RESILIENCE  hResilience,                         HANDLE_BUFFER      hVm,                         HANDLE_EP_INFO     hEpInfo ){  int i;  pulseInfo->number_pulse = GetBits ( NUMBER_PULSE,                                     LEN_PULSE_NPULSE,                                     hResilience,                                     hVm,                                      hEpInfo );  pulseInfo->pulse_start_sfb = GetBits ( PULSE_START_SFB,                                         LEN_PULSE_ST_SFB,                                        hResilience,                                        hVm,                                         hEpInfo );  for(i=0; i<pulseInfo->number_pulse + 1; i++) {    pulseInfo->pulse_offset[i] = GetBits ( PULSE_OFFSET,                                           LEN_PULSE_POFF,                                          hResilience,                                          hVm,                                           hEpInfo );    pulseInfo->pulse_amp[i] = GetBits ( PULSE_AMP,                                        LEN_PULSE_PAMP,                                       hResilience,                                       hVm,                                        hEpInfo );  }}static void pulse_nc ( int*               coef,                        struct Pulse_Info* pulse_info ){  int i, k;    if (pulse_info->pulse_start_sfb>0){    k = only_long_info.sbk_sfb_top[0][pulse_info->pulse_start_sfb-1];  }  else{    k = 0;  }  for(i=0; i<=pulse_info->number_pulse; i++) {    k += pulse_info->pulse_offset[i];    if ( k < LN2) {      if (coef[k]>0) {        coef[k] += pulse_info->pulse_amp[i];      }      else {        coef[k] -= pulse_info->pulse_amp[i];      }    }    else {        CommonExit( 2, "pulse_nc: pulse data cannot be processed on line %i (huffdec2.c)", k );    }   }}#ifdef SRSlong get_gcBuf ( byte              window_sequence,                  BsBitStream*      gc_streamCh,                 HANDLE_RESILIENCE hResilience ,                                  HANDLE_BUFFER     hVm,                 HANDLE_EP_INFO    hEpInfo ){  unsigned int bd;  int wd;  unsigned int ad;  unsigned long   max_band, natks, ltmp;  int loc;  loc = gc_streamCh->currentBit;  max_band = GetBits ( MAX_BAND,                        NBANDSBITS,                       hResilience,                       hVm,                        hEpInfo );  BsPutBit(gc_streamCh, max_band, NBANDSBITS);/*   0 < max_band <= 3 */  switch (window_sequence) {  case ONLY_LONG_SEQUENCE:    for (bd = 1; bd <= max_band; bd++) {      for (wd = 0; wd < 1; wd++) {        natks = GetBits ( ADJUST_NUM,                           NATKSBITS,                          hResilience,                          hVm,                           hEpInfo );        BsPutBit(gc_streamCh, natks, NATKSBITS);        for (ad = 0; ad < natks; ad++) {          ltmp = GetBits ( ALEVCODE,                            IDGAINBITS,                           hResilience,                           hVm,                            hEpInfo );          BsPutBit(gc_streamCh, ltmp, IDGAINBITS);          ltmp = GetBits ( ALOCCODE,                           ATKLOCBITS,                           hResilience,                           hVm, 

⌨️ 快捷键说明

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