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

📄 enc_tf.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 5 页
字号:
                                &ntt_IBPS_SCL[1],                                &ntt_IBPS_SCL[2],                                &ntt_IBPS_SCL[3],                                &ntt_IBPS_SCL[4],                                &ntt_IBPS_SCL[5],                                &ntt_IBPS_SCL[6],                                &ntt_IBPS_SCL[7])) == 0) {	  CommonExit(1, "Encode: parameter of -nttScl switch not found");	}      }      t_bit_rate_scl = 0.;      for (iscl=0; iscl<ntt_NSclLay; iscl++){	t_bit_rate_scl += (float)ntt_IBPS_SCL[iscl];      }      /* initialization of base coder */      tvq_flag_wshape =0;      if ((p_ctmp=strstr( encPara, "-tvq_wshape" ))) { 	tvq_flag_wshape =1;      }      tvq_flag_ppc =0;      if ((p_ctmp=strstr( encPara, "-tvq_ppc" ))) { 	tvq_flag_ppc =1;      }      tvq_flag_bandlimit =0;      if ((p_ctmp=strstr( encPara, "-tvq_bandlimit" ))) { 	tvq_flag_bandlimit =1;      }      tvq_flag_postproc =0;      if ((p_ctmp=strstr( encPara, "-tvq_postproc" ))) { 	tvq_flag_postproc =1;      }      tvq_flag_msmask1 =0;      if ((p_ctmp=strstr( encPara, "-tvq_msmask1" ))) { 	tvq_flag_msmask1 =1;      }      *frameNumSample = block_size_samples;      *delayNumSample = block_size_samples;       if(tvq_debug_level >= 1)        fprintf(stderr," \n encoding with TwinVQ mode at %8d bit/s/ch \n",	  ntt_IBPS);      if(ntt_IBPS > 16000 )        fprintf(stderr,"AAC or BSAC is recommended to use at this rate\n");     if(tvq_debug_level >5 )       fprintf(stderr, "JJJJJJJJJJJJ ntt_IBPS ntt_NSclLay %5d %5d \n",        ntt_IBPS, ntt_NSclLay);      ntt_TfInit(sampling_rate_f, (float)ntt_core_br+t_bit_rate_scl                  , t_bit_rate_scl, (long)max_ch, block_size_samples		 , &ntt_index, &ntt_index_scl); /* global init. */      t_bit_rate_scl = 0.;      for (iscl=0; iscl<ntt_NSclLay; iscl++){	ntt_scale_init(iscl, ntt_NSclLay,  	ntt_IBPS_SCL[iscl], sampling_rate_f, &ntt_index, &ntt_index_scl);	nttData->nttDataScl = ntt_index.nttDataScl;	t_bit_rate_scl += 	    ntt_index_scl.nttDataScl->ntt_NBITS_FR_SCL[iscl] 	       *sampling_rate_f/block_size_samples;	if( strstr( encPara, "-nttSclMsg" ) ) {	  ntt_scale_message(iscl,  ntt_IBPS, ntt_IBPS_SCL);	}      }        ntt_index.nttDataScl->ntt_NSclLay = ntt_NSclLay;         ntt_index_scl.nttDataScl->ntt_NSclLay = ntt_NSclLay;	nttData->nttDataBase = ntt_index.nttDataBase;	nttData->nttDataScl = ntt_index_scl.nttDataScl;	  total_frame_bits = (int)floor(bit_rate_f*block_size_samples/sampling_rate_f+0.5);	  mat_total_tvq_bits += ntt_index.nttDataBase->ntt_NBITS_FR;	  for(iscl=0;iscl<ntt_NSclLay;iscl++)	  mat_total_tvq_bits += ntt_index_scl.nttDataScl->ntt_NBITS_FR_SCL[iscl];	  if(mat_total_tvq_bits>total_frame_bits)		  {			  CommonExit(1,"TwinVQ : Bitrate mismatch. more than %7.1f bps/ch",(mat_total_tvq_bits-0.5)*sampling_rate_f/block_size_samples);		  }	  				  	  fprintf(stderr,"<<OLD>> BAND %f BPS %d\n",		ntt_index.nttDataBase->bandUpper,ntt_IBPS);	  for(iscl=0;iscl<ntt_NSclLay;iscl++)	  fprintf(stderr,"<<OLD>> BPS_SCL[%d] %d\n",iscl,ntt_IBPS_SCL[iscl]);	  fprintf(stderr,"<<OLD>> CH %d\n",numChannel);      if ( strstr( encPara, "-ntt_pw_ext" ) ){/* perceptual weight selection */	ntt_pw_select = NTT_PW_EXTERNAL;	if (max_ch > 1)	  CommonExit(1, "EncTfInit: Error in NTT_VQ: No stereo support with NTT_PW_EXTERNAL.");      }      if ( strstr( encPara, "-ntt_pw_int" ) ){	ntt_pw_select = NTT_PW_INTERNAL;      }      if (strstr( encPara, "-ntt_varbit_on") ){ /* Variable bit switch */	ntt_varbit = NTT_VARBIT_ON;      }      if (strstr (encPara, "-ntt_varbit_off")){	ntt_varbit = NTT_VARBIT_OFF;      }    }  }  /* ----- if no AAC_RAWDATA, write some header information -----*/  if( (transport_stream != AAC_RAWDATA_TSTREAM) &&       (transport_stream != NO_TSTREAM) && (qc_select !=NTT_VQ_SYS)) { /* T.Ishikawa 980525 */	  fprintf(stderr,"Warning : Write some header information\n");    BsPutBit( header_stream, 0x1234, 16 );    BsPutBit( header_stream, bit_rate, 24 );    BsPutBit( header_stream, sampling_rate, 24 );    BsPutBit( header_stream, block_size_samples, 16 );    BsPutBit( header_stream, med_win_in_long, 16 );    BsPutBit( header_stream, short_win_in_long, 16 );    BsPutBit( header_stream, *delayNumSample, 16 );    BsPutBit( header_stream, channel_configuration, 8 );    BsPutBit( header_stream, tf_select, 32 );           /* encode T/F mapping select */    BsPutBit( header_stream, qc_select, 32 );           /* encode Q&C select */  }    /* -- if AAC_RAWDATA, write  "aacraw" --- */  /*    if( transport_stream == AAC_RAWDATA_TSTREAM ) {    BsPutBit( header_stream, 'a', 8 );    BsPutBit( header_stream, 'a', 8 );    BsPutBit( header_stream, 'c', 8 );    BsPutBit( header_stream, 'r', 8 );    BsPutBit( header_stream, 'a', 8 );    BsPutBit( header_stream, 'w', 8 );    }  */  if (qc_select == NTT_VQ){    int iscl;    /* NTT_VQ supports both LENINFO_STREAM and NO_SYNCWORD. */    BsPutBit(header_stream, transport_stream, 2);    /* put ntt_varbit switch */    /* If the ntt_varbit is off, number of bits       per frame should be in the header. */    BsPutBit(header_stream, ntt_varbit, 1);    if (ntt_varbit == NTT_VARBIT_OFF){      int frameNumBit;      frameNumBit = (int)floor((double)bit_rate_f*(double)block_size_samples			  /(double)sampling_rate+0.5);      BsPutBit(header_stream, frameNumBit, 32);    }    /* long term predictor */    if (pred_type == NOK_LTP){      ntt_LTP_SW = 1;      BsPutBit(header_stream, 1, 1);    }    else{      ntt_LTP_SW = 0;      BsPutBit(header_stream, 0, 1);    }    /* header for base coder */	 /* T.Ishikawa 981118 */		BsPutBit(header_stream, (unsigned long)(ntt_IBPS*numChannel),16);	    BsPutBit(header_stream, (unsigned long)ntt_NSclLay, ntt_NSclLay_BITS);    for (iscl=0; iscl<ntt_NSclLay; iscl++){      BsPutBit(header_stream, (unsigned long)(ntt_IBPS_SCL[iscl]),	       ntt_IBPS_BITS_SCL);  }  }  else if(qc_select == NTT_VQ_SYS)	  {    int iscl,sx;    if (pred_type == NOK_LTP){ntt_LTP_SW = 1;}else{ntt_LTP_SW = 0;}    initObjDescr(frameData->od);    presetObjDescr(frameData->od, ntt_NSclLay);    frameData->od->streamCount.value=(ntt_NSclLay+1);    for(iscl=0;iscl<ntt_NSclLay+1;iscl++){    initESDescr( &(frameData->od->ESDescriptor[iscl]) );/* SET audioDecoderType = 0x0 */    presetESDescr( frameData->od->ESDescriptor[iscl],iscl );    frameData->od->ESDescriptor[iscl]->DecConfigDescr.avgBitrate.value = (frameData->layer[iscl].bitRate) ;    for(sx=0;sx<16;sx++){ if ( frameData->layer[iscl].sampleRate == samplFreqIndex[sx]) break; }    frameData->od->ESDescriptor[iscl]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value = sx;    frameData->od->ESDescriptor[iscl]->DecConfigDescr.bufferSizeDB.value = 6122;    frameData->od->ESDescriptor[iscl]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.TFCodingType.value = 0x2; /* all tvq scaleable */	/* T.Ishikawa 980813 */    if ((p_ctmp=strstr( encPara, "-tvq_960" ))) {     tvq_flag_960=1;   frameData->od->ESDescriptor[iscl]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value = 1; /* 1: 960 0:1024*/	        }    else{    tvq_flag_960=0;    frameData->od->ESDescriptor[iscl]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value = 0; /* 1: 960 0:1024*/	        }        frameData->od->ESDescriptor[iscl]->DecConfigDescr.audioSpecificConfig.channelConfiguration.value = numChannel;/* T.Ishikawa 980703 */    /* -- NEXT 2 formula is ad-hoc !! */    frameData->od->ESDescriptor[iscl]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.dependsOnCoreCoder.value = 0 ; /* tsushima ad-hoc */	        frameData->od->ESDescriptor[iscl]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.extension.value = 0; /* tsushima ad-hoc */	    #ifdef AL_CONFIG		/* Adhoc 981013 T.Ishikawa*/	frameData->od->ESDescriptor[iscl]->ALConfigDescriptor.useAccessUnitStartFlag.value=1;	frameData->od->ESDescriptor[iscl]->ALConfigDescriptor.useAccessUnitEndFlag.value=1;	frameData->od->ESDescriptor[iscl]->ALConfigDescriptor.useRandomAccessPointFlag.value=0;	frameData->od->ESDescriptor[iscl]->ALConfigDescriptor.usePaddingFlag.value=0;	frameData->od->ESDescriptor[iscl]->ALConfigDescriptor.seqNumLength.value=0;#endif    }   frameData->od->ESDescriptor[0]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value = 0; /* 1:960 0:1024 */    if ((p_ctmp=strstr( encPara, "-tvq_960" ))) {    tvq_flag_960=1;   frameData->od->ESDescriptor[0]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value = 1; /* 1: 960 0:1024*/	        }    else{    tvq_flag_960=0;    frameData->od->ESDescriptor[0]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value = 0; /* 1: 960 0:1024*/	        }    advanceODescr( header_stream,frameData->od,1 ); /* write down */    for (iscl=0;iscl<ntt_NSclLay+1;iscl++){ /* revised by Tomokazu Ishikawa */    advanceESDescr( header_stream, frameData->od->ESDescriptor[iscl],1 );     }  } /* qc_select == NTT_VQ_SYS T.Ishikawa 980525 */		    /* some global initializations */  {    int n_ch, i_ch;    n_ch = max_ch;    for (i_ch=0; i_ch<n_ch; i_ch++)      DTimeSigBuf[i_ch] = (double*)calloc(block_size_samples, sizeof(double));{	int jj;    for (i_ch=0; i_ch<n_ch; i_ch++)	for (jj=0; jj<block_size_samples; jj++)	DTimeSigBuf[i_ch][jj] = 0.0;}    for (i_ch=0; i_ch<n_ch; i_ch++)      DTimeSigLookAheadBuf[i_ch] =        (double*)calloc(block_size_samples, sizeof(double));    for (i_ch=0; i_ch<n_ch; i_ch++) {      coreTimeSigBuf[i_ch] = (float*)calloc(block_size_samples, sizeof(float));      coreTimeSigLookAheadBuf[i_ch] = (float*)calloc(block_size_samples, sizeof(float));    }    for (i_ch=0; i_ch<n_ch; i_ch++)    {      spectral_line_vector[i_ch] =        (double*)calloc(block_size_samples*2, sizeof(double));      {	int scal_codec = 0;		scal_codec = (qc_select == AAC_SYS || qc_select == NTT_VQ || qc_select == NTT_VQ_SYS);	if(pred_type == NOK_LTP && scal_codec)	  baselayer_spectral_line_vector[i_ch] =	    (double*)calloc(block_size_samples*2, sizeof(double));      }    }    for (i_ch=0; i_ch<n_ch; i_ch++)      reconstructed_spectrum[i_ch] =        (double*)calloc(block_size_samples, sizeof(double));    for (i_ch=0; i_ch<n_ch; i_ch++)      ntt_ms_buf[i_ch] =        (double*)calloc(block_size_samples, sizeof(double));    for (i_ch=0; i_ch<n_ch; i_ch++)      nok_tmp_DTimeSigBuf[i_ch] = (double*)calloc(2*block_size_samples, sizeof(double));     { int ii;      for (i_ch=0; i_ch<n_ch; i_ch++)       for(ii=0; ii<2*block_size_samples; ii++)        nok_tmp_DTimeSigBuf[i_ch][ii] = 0.0;     }  }  /* calc. no of audio channels */#if 0 /* commented out by NI, because no. of ch. is handed by the framework */  {    /* table to get the no. of audio channels depending on the value of channel_configuration */    static int  chc_2_chan_nr[CHC_MODES] = { 1, 2, 2, 5 };    max_ch  = chc_2_chan_nr[channel_configuration];  }#endif  /* calculate max. audio bandwidth */  {    /* table: audio_bandwidth( bit_rate ) */    static long bandwidth[8][2] = { {64000,20000},{56000,16000},{48000,14000},                                    {40000,12000},{32000,9000},{24000,6000},                                    {16000,3500},{-1,0}     };    int i;    i = 0;    while( bandwidth[i][0] > bit_rate ) {      if( bandwidth[i][0] < 0 ) {        i--;        break;      }      i++;    }    bw_lines_long  = bandwidth[i][1] * block_size_samples *2 / sampling_rate;    bw_lines_med   = bandwidth[i][1] * block_size_samples *2 / sampling_rate / med_win_in_long;    bw_lines_short = bandwidth[i][1] * block_size_samples *2 / sampling_rate / short_win_in_long;    /* Use a minimal band-width for a bit rate <= 6 kbps. */    start_line = 0;    if ( bit_rate <= 6000 )      {        bw_lines_long = 140;        start_line = 6;      }  }    /* son_AACpp */  if (pp_select == AAC_PP)    {      int band;      /* added 971010 YT */      int i_ch, n_ch;      n_ch = max_ch;      for (i_ch=0; i_ch<n_ch; i_ch++){        max_band[i_ch] = (NBANDS * (start_line + bw_lines_long - 1) /                          block_size_samples); /* max_bands[] =0,1,2,3 */        spectral_line_vector_for_gc[i_ch]      = (double *)calloc(block_size_samples, sizeof(double));        DTimeSigPQFDelayCompensationBuf[i_ch]  = (double *)calloc(PQFDELAY, sizeof(double));        DTimeSigLookAheadBufForGC[i_ch]        = (double *)calloc(block_size_samples, sizeof(double));        DBandSigLookAheadBuf[i_ch]             = (double **)calloc(NBANDS, sizeof(double *));        DBandSigBufForGCAnalysis[i_ch]         = (double **)calloc(NBANDS, sizeof(double *));        DBandSigWithGCBuf[i_ch]                = (double **)calloc(NBANDS, sizeof(double *));        gainInfo[i_ch]                         = (GAINC  **)calloc(NBANDS, sizeof(GAINC *));            for (band = 0; band < NBANDS; band++) {          DBandSigLookAheadBuf[i_ch][band]     = (double *)calloc(block_size_samples/NBANDS, sizeof(double));          DBandSigBufForGCAnalysis[i_ch][band] = (double *)calloc(block_size_samples/NBANDS*3, sizeof(double));          DBandSigWithGCBuf[i_ch][band]        = (double *)calloc(block_size_samples/NBANDS*2, sizeof(double));          gainInfo[i_ch][band]                 = (GAINC  *)calloc(short_win_in_long,sizeof(GAINC));        }      } /* for(i_ch...*/    }/* if (pp_select...*/  /* initialize psychoacoustic module */  EncTf_psycho_acoustic_init();  /* initialize t/f mapping */

⌨️ 快捷键说明

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