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

📄 scal_enc_frame.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    CalcFssControl( coreSpectrum[MONO_CHAN], p_spectrum[MONO_CHAN], diffSpectrum[MONO_CHAN], blockType[MONO_CHAN],                    FssControl[MONO_CHAN], blockSizeSamples, sfb_width_table[MONO_CHAN], samplRate ,diffContrSimu);  } else {    for( ch=0; ch<omi.ch_no_max; ch++ ) {      for( i=0; i<blockSizeSamples; i++ ) {        diffSpectrum[ch][i] = p_spectrum[ch][i];      }    }  }  /* first T/F layer */  if (blockType[MONO_CHAN] == EIGHT_SHORT_SEQUENCE) {    num_window_groups=4;    window_group_length[0] = 1;    window_group_length[1] = 2;    window_group_length[2] = 3;    window_group_length[3] = 2;  } else {    num_window_groups = 1;    window_group_length[0] = 1;  }  aacEncodeScalHeader( fixedStream, NULL, blockType[MONO_CHAN],                       blockType[MONO_CHAN]==EIGHT_SHORT_SEQUENCE ? nr_of_sfb[MONO_CHAN]*num_window_groups : nr_of_sfb[MONO_CHAN] /*max_sfb*/,                       omi.ch_no_tf[0], omi.ch_no_max, omi.ch_no_core,                       samplRate, FssControl, ms_mask, num_window_groups, window_group_length, tnsInfo ? tnsInfo[MONO_CHAN]:NULL ,frameData, qc_select, NULL);  rem_bits = frameBits - BsCurrentBit(fixedStream) - (7/numGranules+1); /* reserve bits for byte allignment */  {    int _nr_of_sfb[MAX_TIME_CHANNELS];    memcpy( _nr_of_sfb, nr_of_sfb, sizeof(int)*MAX_TIME_CHANNELS );    rem_bits -= tf_encode_spectrum_aac( diffSpectrum,                                         energy,                                         allowed_dist,                                         blockType,                                        sfb_width_table,                                         _nr_of_sfb,                                         (rem_bits/omi.tf_layers),                                        0,                                         padding_limit,                                         dynpartStream,                                         var_stream,                                         NULL,                                        omi.ch_no_tf[0],                                        p_reconstructed_spectrum,                                         useShortWindows,                                        windowShape,                                         aacAllowScalefacs,                                         samplRate,                                        qc_select,                                         pred_type,                                        NULL,                                         nok_bwp_status,                                         blockSizeSamples,                                         num_window_groups,                                         window_group_length,                                        NULL,                                        15000/* bandwidth in Hz */                                      );  }  /* other T/F layers */  for( lay=1; lay<omi.tf_layers; lay++ ) {    for( ch=0; ch<omi.ch_no_tf[lay-1]; ch++ ) {      for( i=0; i<blockSizeSamples; i++ ) {  /* for now just always the difference signal */        diffSpectrum[ch][i] -= p_reconstructed_spectrum[ch][i];      }      for( i=0; i<8; i++ ) {        msFssControl[ch][i] = DC_DIFF;      }    }   {    int hbits = -BsCurrentBit( fixedStream );    aacEncodeLayerHeader( fixedStream, blockType[MONO_CHAN], nr_of_sfb[MONO_CHAN] /* max_sfb */, nr_of_sfb[MONO_CHAN]                          /* max_sfb_prev_layer */, msFssControl, ms_mask, (omi.ch_no_tf[lay]>omi.ch_no_tf[lay-1]) , omi.ch_no_tf[lay],frameData );    hbits += BsCurrentBit( fixedStream );    rem_bits -= hbits;   }   {	/* HP 971120 */    int _nr_of_sfb[MAX_TIME_CHANNELS];    memcpy( _nr_of_sfb, nr_of_sfb, sizeof(int)*MAX_TIME_CHANNELS );    rem_bits -= tf_encode_spectrum_aac( diffSpectrum, energy, allowed_dist, blockType,                                        sfb_width_table, _nr_of_sfb, (rem_bits/(omi.tf_layers-lay)),                                        0, padding_limit, dynpartStream, var_stream, NULL,                                        omi.ch_no_tf[lay],                                        p_reconstructed_spectrum, useShortWindows,                                        windowShape, aacAllowScalefacs, samplRate,                                        qc_select, pred_type,                                        NULL, nok_bwp_status, blockSizeSamples, num_window_groups, window_group_length,                                        NULL,                                        15000 /* bandwidth in Hz */                                      );   }  }   dynpartBits = BsCurrentBit( dynpartStream );  codedFixedBits +=BsCurrentBit( fixedStream );     /* new clean up and write superframe that consists out of 3 granules(=normal frames) */   if( granule == 2 ) {     int fillBits;    int alignBits;    /* bytaalign bits for fixed stream */    alignBits = 8 - codedFixedBits%8;    alignBits = (alignBits == 8) ? 0 : alignBits;    BsPutBit( fixedStream, 0, alignBits );     codedFixedBits += alignBits;    /* fillBits for the dynamic part*/    fillBits = (numGranules*frameBits) - codedFixedBits - dynpartBits;    if( fillBits < 0 )      CommonExit(-1,"\n negativ amount of fillbits");    for( i=0; i<fillBits; i++ ) {      BsPutBit( dynpartStream, 1, 1 );     }    dynpartStream->currentBit = 0; /* rewind buffer */    dynpartStream->write = 0;/* and make it readable */    for( i=0; i<numGranules; i++ ) {      BsPutBuffer( mainStream, fixedPartBuf[i] );      dynpartBits= frameBits *(i+1) - BsCurrentBit(mainStream);      BsGetBuffer( dynpartStream, tmpBitBuf, dynpartBits );      BsPutBuffer( mainStream, tmpBitBuf );    }  }     (granule>=2) ? granule=0 : granule++;  return( BsCurrentBit(mainStream) );}void printOpModeInfo(FILE *fp) {  int x,y;  fprintf(fp,"\n-mode <int> : operating modes for scalable  coding");  for (x=0; (unsigned int) x < sizeof(opm_info)/sizeof(OP_MODE_INFO);x++){    fprintf(fp,"\n mode:  %d  ",x);    fprintf(fp," ch_no_core: %d  ", opm_info[x].ch_no_core );    fprintf(fp," ch_no_max : %d  ", opm_info[x].ch_no_max );    fprintf(fp," tf_layers : %d  \n", opm_info[x].  tf_layers );    for (y=0;y<    opm_info[x]. tf_layers ;y++){      fprintf(fp,"  no_channel for tf_layer %d: %d  ", y,opm_info[x].ch_no_tf[y]);          }      }}voiddegroup (double *rec_spectrum, int num_window_groups, int window_group_length[]){  int i, j, k;  int index, group_offset;  double tmp[BLOCK_LEN_LONG];  index = 0;  group_offset = 0;  for (i = 0; i < num_window_groups; i++)    {      for (j = 0; j < BLOCK_LEN_SHORT; j++)	for (k = 0; k < window_group_length[i]; k++)	  tmp[j + BLOCK_LEN_SHORT * k + group_offset] = rec_spectrum[index++];      group_offset += BLOCK_LEN_SHORT * window_group_length[i];    }  for (i = 0; i < BLOCK_LEN_LONG; i++)    rec_spectrum[i] = tmp[i];}voidMSInverseMatrix(int num_samples, double *left, double *right){  int i;  double dtmp;	  for(i = 0; i < num_samples; i++)  {    dtmp = left[i] + right[i];        right[i] = left[i] - right[i];    left[i] = dtmp;  }}voidltp_scal_reconstruct(WINDOW_SEQUENCE blockType,		     WINDOW_SHAPE windowShape,		     WINDOW_SHAPE windowShapePrev,		     int num_channels,		     double *p_reconstructed_spectrum_left, 		     double *p_reconstructed_spectrum_right,		     int num_window_groups, 		     int *window_group_length,		     int blockSizeSamples,		     int med_win_in_long,		     int short_win_in_long,		     int *sfb_offset,		     int *nr_of_sfb,		     NOK_LT_PRED_STATUS *nok_lt_status,		     TNS_INFO **tnsInfo){  int i, ch;  double tmpbuffer[BLOCK_LEN_LONG];  double *rec_spectrum[2];      rec_spectrum[0] = p_reconstructed_spectrum_left;  rec_spectrum[1] = p_reconstructed_spectrum_right;  if(blockType == EIGHT_SHORT_SEQUENCE && num_window_groups != -1)  {    degroup (rec_spectrum[0], num_window_groups, window_group_length);    if(num_channels == 2)      degroup (rec_spectrum[1], num_window_groups, window_group_length);  }        /* Inverse MS matrix */  if(num_channels == 2)    MSInverseMatrix(blockSizeSamples, rec_spectrum[0], rec_spectrum[1]);        for(ch = 0; ch < num_channels; ch++)  {    /* Add the LTP contribution to the reconstructed spectrum. */    nok_ltp_reconstruct(rec_spectrum[ch], blockType, sfb_offset, nr_of_sfb[ch], 			blockSizeSamples/short_win_in_long, &nok_lt_status[ch]);	    for(i = 0; i < blockSizeSamples; i++)      tmpbuffer[i] = rec_spectrum[ch][i];	    /* TNS synthesis filtering. */    if(tnsInfo[ch] != NULL)      TnsEncode2(nr_of_sfb[ch], nr_of_sfb[ch], blockType, sfb_offset,		 &(tmpbuffer[0]), tnsInfo[ch], 1);	    /* Update the time domain buffers of LTP. */    nok_ltp_update(&(tmpbuffer[0]), blockType, windowShape, windowShapePrev, 		   blockSizeSamples, blockSizeSamples/med_win_in_long, 		   blockSizeSamples/short_win_in_long,		   &nok_lt_status[ch]);    /* Disable the use of LTP in the upper layers. */    nok_lt_status[ch].global_pred_flag = 0;    nok_lt_status[ch].side_info = 0;  }    /* MS matrix */  if(num_channels == 2)    MSInverseMatrix(blockSizeSamples, rec_spectrum[0], rec_spectrum[1]);    }int aacScaleableFlexMuxEncode(  double      *p_spectrum[MAX_TIME_CHANNELS],  double      energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],  double      allowed_dist[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],  WINDOW_SEQUENCE  blockType[MAX_TIME_CHANNELS],  int         sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS],  int         nr_of_sfb[MAX_TIME_CHANNELS],  int         average_block_bits,			  int         available_bitreservoir_bits,  int         padding_limit,  BsBitStream *mainStream,  BsBitStream *var_stream,  int         nr_of_chan,  double      *p_reconstructed_spectrum[MAX_TIME_CHANNELS],  int         useShortWindows,  WINDOW_SHAPE     windowShape[MAX_TIME_CHANNELS],      /* offers the possibility to select different window functions */  WINDOW_SHAPE     windowShapePrev[MAX_TIME_CHANNELS],  /* needed for LTP - tool */  int         aacAllowScalefacs,  int         blockSizeSamples,  int         frameMaxNumBit,  float       **timeSig,  long        bitRate,  long        samplRate,  QC_MOD_SELECT qc_select,  TNS_INFO    *tnsInfo[MAX_TIME_CHANNELS],  ENC_FRAME_DATA* frameData,  enum CORE_CODEC coreCodecIdx,  int num_window_groups,   int window_group_length[8],  ntt_PARAM *param_ntt,  double *baselayer_spectrum[MAX_TIME_CHANNELS],  NOK_LT_PRED_STATUS* nok_lt_status,  int med_win_in_long,  int short_win_in_long,  int *sfb_offset,  double *nok_tmp_DTimeSigBuf[MAX_TIME_CHANNELS],  ntt_INDEX* ntt_index,  ntt_INDEX* ntt_index_scl  ){  int layerBits;  int i, lay, ch,tfLayer;  int frameBits, rem_bits;  OP_MODE_INFO omi;  enum DC_FLAG FssControl[MAX_TIME_CHANNELS][SFB_NUM_MAX];  enum DC_FLAG msFssControl[MAX_TIME_CHANNELS][SFB_NUM_MAX];  BsBitStream *layerStream;  enum JS_MASK ms_mask[SFB_NUM_MAX];  int lastLayer,  flexmuxOverhead;  int fullBandwidth;  int core_coder_bits, ubits;  memcpy( &omi, &opm_info[frameData->opMode], sizeof(OP_MODE_INFO) );  /* intermediate_layers = (op_mode >= 7) ? 1 : 0; */  omi.tf_layers += intermediate_layers;  lastLayer=omi.tf_layers+ ((omi.ch_no_core > 0) ? 1:0);  /* start of bitstream composition *//*   frameBits = bitRate * blockSizeSamples /samplRate - bitsPerFrame; *Q&D for TVQ * */  frameBits = average_block_bits + available_bitreservoir_bits - 150 ;  layerStream = BsOpenBufferWrite(dynpartBuf);  /* ms matrix */ if(coreCodecIdx != NTT_TVQ){  if( omi.ch_no_max == 2 ) {  /* always MS for now */    double dtmp;    for( i=0; i<blockSizeSamples; i++ ) {      if(pred_type == NOK_LTP)      {	dtmp = baselayer_spectrum[0][i] + baselayer_spectrum[1][i];	baselayer_spectrum[0][i] = (baselayer_spectrum[0][i] - baselayer_spectrum[1][i]) * 0.5;	baselayer_spectrum[1][i] = dtmp * 0.5;      }      dtmp = p_spectrum[0][i] + p_spectrum[1][i];      p_spectrum[0][i] = (p_spectrum[0][i] - p_spectrum[1][i]) * 0.5;      p_spectrum[1][i] = dtmp * 0.5;    }    for( i=0; i<SFB_NUM_MAX; i++ ) {      ms_mask[i] = JS_MASK_MS;    }  } }  /* Core Coder */  lay=0;  tfLayer=0;  layerBits=0;  if( omi.ch_no_core > 0 ) {    double coreSpectrum[MAX_TIME_CHANNELS][2048];    if( omi.ch_no_max > omi.ch_no_core ) {      for( i=0; i<blockSizeSamples; i++ ) {        for( ch=1; ch<omi.ch_no_max; ch++ ) {          timeSig[MONO_CHAN][i] += timeSig[ch][i];        }

⌨️ 快捷键说明

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