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

📄 scal_enc_frame.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 5 页
字号:
/**********************************************************************MPEG-4 Audio VMBit stream moduleThis software module was originally developed byBernhard Grill (University of Erlangen)and edited byin the course of development of the MPEG-2 NBC/MPEG-4 Audio standardISO/IEC 13818-7, 14496-1,2 and 3. This software module is animplementation of a part of one or more MPEG-2 NBC/MPEG-4 Audio toolsas specified by the MPEG-2 NBC/MPEG-4 Audio standard. ISO/IEC givesusers of the MPEG-2 NBC/MPEG-4 Audio standards free license to thissoftware module or modifications thereof for use in hardware orsoftware products claiming conformance to the MPEG-2 NBC/ MPEG-4 Audiostandards. Those intending to use this software module in hardware orsoftware products are advised that this use may infringe existingpatents. The original developer of this software module and his/hercompany, the subsequent editors and their companies, and ISO/IEC haveno liability for use of this software module or modifications thereofin an implementation. Copyright is not released for non MPEG-2NBC/MPEG-4 Audio conforming products. The original developer retainsfull right to use the code for his/her own purpose, assign or donatethe code to a third party and to inhibit third party from using thecode for non MPEG-2 NBC/MPEG-4 Audio conforming products. Thiscopyright notice must be included in all copies or derivative works.Copyright (c) 1997.*//* 23-oct-97   HP   merged Nokia's predictor 971013 & 971020 *//*                  tried to fix PRED_TYPE *//* 24-oct-97   Mikko Suonio   fixed PRED_TYPE */#include <memory.h>#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 "reorderspecHandle.h"   /* handler, defines, enums */#include "resilienceHandle.h"    /* handler, defines, enums */#include "tf_mainHandle.h"       /* handler, defines, enums */#include "bitstreamStruct.h"     /* structs */#include "nok_ltp_common.h"      /* structs */#include "obj_descr.h"           /* structs */#include "tf_mainStruct.h"       /* structs */#include "tns.h"                 /* structs */#include "common_m4a.h"#include "bitstream.h"#include "lpc_common.h"#include "util.h"/* ---  AAC --- */#include "aac.h"#include "nok_bwp_enc.h"#include "nok_ltp_enc.h"#include "tns3.h"#include "aac_qc.h"#include "util.h"#include "fir_filt.h"#include "scaleable.h"#include "dec_tf.h"#include "enc_tf.h"#include "bitmux.h"#include "bitstream.h"#include "celp_encoder.h"#include "celp_decoder.h"#include "flex_mux.h"#define MAX_TF_LAYERS 5/* --- TVQ --- */#include "ntt_conf.h"#include "ntt_encode.h"#include "ntt_scale_conf.h"typedef struct {  int ch_no_core;  int ch_no_tf[MAX_TF_LAYERS];  int ch_no_max;  int tf_layers;} OP_MODE_INFO;OP_MODE_INFO opm_info[16] = {  { 1, {0,0,0,0,0}, 1, 0 },  { 2, {0,0,0,0,0}, 2, 0 },  { 0, {1,0,0,0,0}, 1, 1 },  { 0, {2,0,0,0,0}, 2, 1 },  { 1, {1,0,0,0,0}, 1, 1 },  { 1, {2,0,0,0,0}, 2, 1 },  { 2, {2,0,0,0,0}, 2, 1 },  { 1, {1,1,0,0,0}, 1, 2 },  { 1, {1,2,0,0,0}, 2, 2 },  { 1, {2,2,0,0,0}, 2, 2 },  { 2, {2,2,0,0,0}, 2, 2 },  { 0, {1,1,0,0,0}, 1, 2 },  { 0, {1,2,0,0,0}, 2, 2 },  { 0, {2,2,0,0,0}, 2, 2 },  { 0, {1,1,1,0,0}, 1, 3 },};static FIR_FILT *lowpassFilt;static int  downsamplFac;static   BsBitBuffer *tmpBitBuf;static   BsBitBuffer *dynpartBuf;static   BsBitBuffer *fixedPartBuf[3];static float *coreDecodedSampleBuf[MAX_TIME_CHANNELS];static double *diffSpectrum[MAX_TIME_CHANNELS];static int granule=0;static int numGranules=3;static int op_mode = 4;static int diffContrSimu = 0;static int intermediate_layers = 0;/* Prediction */static PRED_TYPE pred_type = PRED_NONE;static NOK_BW_PRED_STATUS nok_bwp_status[MAX_TIME_CHANNELS];/* MPEG 4 Celp core */static long  bit_rate, sampling_frequency, frame_size, n_subframes, sbfrm_size, lpc_order;static long  num_lpc_indices, num_shape_cbks, num_gain_cbks, *org_frame_bit_allocation;static float min_pitch_frequency, max_pitch_frequency;    #ifdef CORE_BROKEN	/* HP990409 */static long ExcitationMode     = MultiPulseExc;static long SampleRateMode     = fs8kHz;  /* Default: 16 kHz */static long QuantizationMode   = VectorQuantizer;  /* Default: Scalar Quantizer */#elsestatic long ExcitationMode     = 0;static long SampleRateMode     = 0;static long QuantizationMode   = 0;#endifstatic long FineRateControl    = 1;  /* Default: FineRateControl is ON */static long LosslessCodingMode = 0;  /* Default: Lossless coding is OFF */static long RPE_configuration;static long Wideband_VQ = 0;static long NB_Configuration;static long NumEnhLayers;static long BandwidthScalabilityMode;static long BWS_configuration;static long BWS_nb_bitrate;static long n_lpc_analysis;static long *window_offsets;static long *window_sizes;static long n_lag_candidates; /* NTT Twin VQ */static int bitsPerFrame;static	void *InstanceContextLPCEnc;	/* one instance context */static	void *InstanceContextLPCDec;	/* one instance context */static long samplRateCore;extern int samplFreqIndex[];int aacScaleEncInit(   BsBitStream *headerStream,  char        *encPara,		 /* in: encoder parameter string */  int         numChannel,  int         frameNumSample,  long        samplRate,  ENC_FRAME_DATA* frameData,  enum CORE_CODEC coreCodecIdx,  int mode,  PRED_TYPE predictor_type,  ntt_INDEX* ntt_index,  ntt_INDEX* ntt_index_scl  ){  int frameNumSampleCore, delayNumSampleCore;      int tmp, ch, i, core_delay;  char *pc;  pred_type = predictor_type;    core_delay = 0;  if( (pc=strstr( encPara, "-aac_simulcast" )) ) {    sscanf( pc+14, "%1d", &diffContrSimu );    if (diffContrSimu)      fprintf (stdout,"aac scalable mode : using simulcast (no difference coding)\n");    else      fprintf (stdout,"aac scalable mode : using difference coding  for all bands \n");  }  if (frameData){    op_mode=frameData->opMode;  } else {    op_mode=mode;  }  switch( op_mode ) {    case 1:    case 3:    case 5:    case 6:    case 8:    case 9:    case 10:    case 12:    case 13:      if( numChannel < 2 ) {        CommonExit(1,"Encode scalab.: Stereo scalability mode selected, but mono input file");      }  }  /* write object descriptor in case of aac_sys */  if( frameData!=NULL ) {    int sx;    int layer, numLayers;    int coreLayer;    coreLayer = (opm_info[op_mode].ch_no_core==0)?0:1;    if(coreCodecIdx==NTT_TVQ){     coreLayer += ntt_index_scl->nttDataScl->ntt_NSclLay;    }    /* get the total number of layers: AAC + core */    numLayers = opm_info[op_mode].tf_layers + coreLayer;    initObjDescr(frameData->od);    presetObjDescr(frameData->od, numLayers);    frameData->od->streamCount.value=numLayers;    /* write ES descriptor of core layer */    for(layer = 0; layer<coreLayer; layer++) {      initESDescr( &(frameData->od->ESDescriptor[layer])); /* only TF coders */      presetESDescr( frameData->od->ESDescriptor[layer], layer);      frameData->od->ESDescriptor[layer]->DecConfigDescr.avgBitrate.value=      frameData->layer[layer].bitRate;      for (sx=0;sx<16;sx++) { 	 if (frameData->layer[layer].sampleRate== samplFreqIndex[sx]) break;      };      if (sx >= 16) CommonExit(-1,"\nSampling rate not supported");      frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value = sx;        frameData->od->ESDescriptor[layer]->DecConfigDescr.bufferSizeDB.value=6122;      frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.TFCodingType.value = 0x2; /* Twin VQ */      frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value=0;/* 1024 */    if ((pc=strstr( encPara, "-tvq_960" ))) {      frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value=1;/* 960 */    }    frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.channelConfiguration.value=numChannel;#ifdef AL_CONFIG	  /* Ad-hoc 981105 */	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.useAccessUnitStartFlag.value=1;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.useAccessUnitEndFlag.value=1;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.useRandomAccessPointFlag.value=0;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.usePaddingFlag.value=0;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.seqNumLength.value=0;#endif    }    for(layer=coreLayer; layer<numLayers; layer++) {      initESDescr( &(frameData->od->ESDescriptor[layer]));      presetESDescr( frameData->od->ESDescriptor[layer], layer);      frameData->od->ESDescriptor[layer]->DecConfigDescr.avgBitrate.value=frameData->layer[layer].bitRate;      if(tvq_debug_level>2)          fprintf(stderr, "UUUUUUUUYY %5d %5d \n",          layer, frameData->od->ESDescriptor[layer]->DecConfigDescr.\                 avgBitrate.value);      for (sx=0;sx<16;sx++) { if (frameData->layer[layer].sampleRate== samplFreqIndex[sx]) break;} ;       frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.samplingFreqencyIndex.value = sx;       frameData->od->ESDescriptor[layer]->DecConfigDescr.bufferSizeDB.value=6122;      frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.TFCodingType.value = 0x0; /* AAC scalable */      if(strstr(encPara, "-aac_sys_bsac"))        frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.TFCodingType.value = 0x1; /* BSAC */      frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value=0;/* 0: 1023; 1: 960 */    if ((pc=strstr( encPara, "-tvq_960" ))) {      frameData->od->ESDescriptor[layer]->DecConfigDescr.audioSpecificConfig.specConf.TFSpecificConfig.frameLength.value=1;/* 960 */    }#ifdef AL_CONFIG	  /* Ad-hoc 981105 */	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.useAccessUnitStartFlag.value=1;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.useAccessUnitEndFlag.value=1;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.useRandomAccessPointFlag.value=0;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.usePaddingFlag.value=0;	  frameData->od->ESDescriptor[layer]->ALConfigDescriptor.seqNumLength.value=0;#endif    }    advanceODescr (  headerStream, frameData->od,1) ;    for (layer=0; layer<numLayers; layer++) {      advanceESDescr ( headerStream, frameData->od->ESDescriptor[layer] ,1) ;          }  }  /* allocate memory */  tmpBitBuf = BsAllocBuffer(8000);  for(i=0;i<numGranules;i++){    fixedPartBuf[i] =BsAllocBuffer(300);  }  dynpartBuf =BsAllocBuffer(numGranules*6000);  for (ch=0; ch<numChannel; ch++){    if ((coreDecodedSampleBuf[ch]=(float*)malloc(frameNumSample*sizeof(float)))==NULL)      CommonExit(1,"Encode scalab.: memory allocation error");    if ((diffSpectrum[ch]=(double*)malloc(frameNumSample*sizeof(double)))==NULL)      CommonExit(1,"Encode scalab.: memory allocation error");  }  /* core coder initialization */  samplRateCore = 8000;  if( (samplRate%11025) == 0 ) {    samplRateCore = 44100/6;  }  switch( coreCodecIdx ) {   case CC_G729:     lowpassFilt = initFirLowPass( samplRate/4000, 120 );     downsamplFac = samplRate/samplRateCore;     EncG729Init( 1 /* numChannel */, (float)samplRateCore, 8000.0, encPara, &frameNumSampleCore, &delayNumSampleCore, NULL );     DecG729Init( 1, (float)samplRateCore, 8000, "", NULL, &tmp, &tmp );     core_delay = 660;     break;   case CC_CELP_MPEG4_60:    {#ifdef CORE_BROKEN     BITSTREAM *p_bitstream;     int bit_rate = 6000;     BsBitBuffer *coreBitBuf;          lowpassFilt = initFirLowPass( samplRate/4000, 120 );     downsamplFac = samplRate/samplRateCore;     coreBitBuf = BsAllocBuffer(2000);     if((p_bitstream=(BITSTREAM *)malloc(sizeof(BITSTREAM)))==NULL) {       CommonExit(1, "Memory allocation error for enc_lpc init in scal_enc_frame.c");     }          p_bitstream->p_bitstream_buffer_start = coreBitBuf->data;     p_bitstream->buffer_length            = ((coreBitBuf->size)+7)/8;     p_bitstream->valid_bits               = 0;     p_bitstream->start_offset             = 0;          SampleRateMode           = fs8kHz;     QuantizationMode         = VectorQuantizer;     FineRateControl          = OFF;     LosslessCodingMode       = OFF;     NumEnhLayers             = 0;

⌨️ 快捷键说明

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