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

📄 enc_tf.c

📁 MPEG2/MPEG4编解码参考程序(实现了MPEG4的部分功能)
💻 C
📖 第 1 页 / 共 5 页
字号:
/* $Id: enc_tf.c,v 1.62 1999/07/22 15:52:19 purnhage Exp $************************* MPEG-2 NBC Audio Decoder ************************** *                                                                           * "This software module was originally developed by  Fraunhofer Gesellschaft IIS / University of Erlangen (UER)  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-4 Audio  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 developer retains 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 must be included in all copies or derivative works."  Copyright(c)1996. *                                                                           * ****************************************************************************//* CREATED BY :  Bernhard Grill -- June-96  *//******************************************************************************************* * * Master module for T/F based codecs * * Authors: * BG    Bernhard Grill, Fraunhofer Gesellshaft / University of Erlangen * HP    Heiko Purnhagen, Uni Hannover <purnhage@tnt.uni-hannover,de> * OS    Otto Schnurr, Motorola <schnurr@email.mot.com> * NI    Naoki Iwakami, NTT <iwakami@splab.hil.ntt.jp> * TK    Takashi Koike, Sony Corporation <koike@av.crl.sony.co.jp> * SK    Sang-Wook Kim, Samsung, <swkim@dspsun.sait.samsung.co.kr> * MS    Mikko Suonio, Nokia, <Mikko.Suonio@research.nokia.com> * * * Changes: * fixed bit stream handling: Heiko Purnhagen, Uni Hannover, 960705  * 29-jul-96   OS   Modified source for 80 column width display. * 01-aug-96   OS   Integrated HQ source code module. *                  Integrated original TF mapping source code module. *                  Re-activated command line strings for run-time selection *                  of these modules. * 19-aug-96   BG   merge + inclusion of window switching / first short block support  * 21-aug-96   HP   renamed to enc_tf.c, adapted to new enc.h * 26-aug-96   HP   updated to vm0_tf_02a * HP 960826   spectra_index2sf_index alloc bug fix (still repeated alloc !!!) * 28-aug-96   NI   Integrated NTT's VQ coder. *                  Provided automatic window switching. * 05-feb-97   TK   integrated NBC compliant pre processing module * 18-apr-97   NI   Integrated scalable coder. * 09-may-97   HP   merged contributions by NTT, Sony, FhG * 16-may-97   HP   included bug fix by TK (Sony) * 28-may-97   HP   -nttScl help * 17-Jul-97   NI   add include file for VQ encoder * 25-aug-97   NI   bug fixes * 29-aug-97   SK   added BSAC * 11-sep-97   HP   merged BSAC into current VM * 23-oct-97   HP   merged Nokia's predictor 971013 & 971020 *                  tried to fix nok_PredCalcPrediction() call, PRED_TYPE * 26-nov-97   MS   adjusted AAC grouping, energy and allowed distortion *                  calculations * 08-apr-98   HP   removed LDFB ******************************************************************************************/#include <limits.h>#include <math.h>#include <memory.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 "nok_ltp_common.h"      /* structs */#include "obj_descr.h"           /* structs */#include "tf_mainStruct.h"       /* structs */#include "tns.h"                 /* structs */#include "bitstream.h"#include "enc_tf.h"#include "tf_main.h"#include "psych.h"#include "common_m4a.h"	/* common module *//* son_AACpp */#include "sony_local.h"/* Nokia's predictors */#include "nok_bwp_enc.h"#include "nok_ltp_enc.h"/* aac */#include "tns3.h"#include "aac_qc.h"#include "scaleable.h"/* NTT VQ: */#include "ntt_conf.h"#include "ntt_scale_conf.h"#include "ntt_encode.h"#include "mat_def_ntt.h"#include "ntt_nok_pred.h"ntt_PARAM *test_pointer;static int     block_size_samples = 1024;  /* nr of samples per block in one! audio channel */static int     coreDelay=-1; /* delay in samples for the timesignal of the core coder , maximum is the block_size_samles */static int     med_win_in_long    = 2;     /* for NTT */static int     short_win_in_long  = 8;static int     bw_lines_long, bw_lines_med, bw_lines_short;  /* no of lines of the spectrum which are processed */static int     start_line = 0;static int     max_ch;    /* no of of audio channels */static int     debugLevel;static double *spectral_line_vector[MAX_TIME_CHANNELS];static double *baselayer_spectral_line_vector[MAX_TIME_CHANNELS];static double *reconstructed_spectrum[MAX_TIME_CHANNELS];static double *ntt_ms_buf[MAX_TIME_CHANNELS];static double *overlap_buffer[MAX_TIME_CHANNELS];static double *DTimeSigBuf[MAX_TIME_CHANNELS];static double *DTimeSigLookAheadBuf[MAX_TIME_CHANNELS];static float *coreTimeSigBuf[MAX_TIME_CHANNELS];static float *coreTimeSigLookAheadBuf[MAX_TIME_CHANNELS];static TNS_INFO *tnsInfo[MAX_TIME_CHANNELS];/* static variables for the pre processing module *//* son_AACpp */static int     max_band[MAX_TIME_CHANNELS];static double *spectral_line_vector_for_gc[MAX_TIME_CHANNELS];static double *DTimeSigLookAheadBufForGC[MAX_TIME_CHANNELS];static double *DTimeSigPQFDelayCompensationBuf[MAX_TIME_CHANNELS];static double **DBandSigLookAheadBuf[MAX_TIME_CHANNELS];static double **DBandSigBufForGCAnalysis[MAX_TIME_CHANNELS];static double **DBandSigWithGCBuf[MAX_TIME_CHANNELS];static GAINC  **gainInfo[MAX_TIME_CHANNELS];/* static variables used by the T/F mapping */static enum WIN_SWITCH_MODE win_switch_mode = STATIC_SHORT;static WINDOW_SHAPE windowShape[MAX_TIME_CHANNELS]     = {WS_FHG};static WINDOW_SHAPE windowShapePrev[MAX_TIME_CHANNELS] = {WS_FHG};static WINDOW_SEQUENCE last_windowSequence[MAX_TIME_CHANNELS];static enum CH_CONFIG        channel_configuration = CHC_MONO;     /* later f(encPara) */static enum PP_MOD_SELECT    pp_select = NONE;                     /* latef f(encPara) */static GC_DATA_SWITCH gc_switch = GC_PRESENT; /*later f(encPara)*//*static enum GC_DATA_SWITCH gc_switch = GC_NON_PRESENT ; */static QC_MOD_SELECT    qc_select = NTT_VQ;                   /* later f(encPara) */static enum TF_MOD_SELECT    tf_select = MDCT_UER;                 /* later f(encPara) */static enum TRANSPORT_STREAM transport_stream =  LENINFO_TSTREAM;  /* later f(encPara) */static enum CORE_CODEC coreCodecIdx;                /* alm *//* Prediction */static PRED_TYPE pred_type = PRED_NONE;static NOK_LT_PRED_STATUS nok_lt_status[MAX_TIME_CHANNELS];static NOK_BW_PRED_STATUS nok_bwp_status[MAX_TIME_CHANNELS];/*static int sfb_offset[MAX_TIME_CHANNELS][(MAX_SCFAC_BANDS > ntt_N_CRB_MAX * numChannel_MAX ? MAX_SCFAC_BANDS : ntt_N_CRB_MAX * numChannel_MAX) + 1];*/static int sfb_offset[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS+1];static double *nok_tmp_DTimeSigBuf[MAX_TIME_CHANNELS]; /* temporary fix to the buffer size problem. *//* Perceptual weight mode for the NTT_VQ coder */static enum NTT_PW_SELECT    ntt_pw_select = NTT_PW_INTERNAL;/* Variable bit switch for the NTT_VQ coder */static enum NTT_VARBIT ntt_varbit = NTT_VARBIT_OFF;/* TNS for TWIN VQ layer */static TNS_INFO *tvqTnsInfo[MAX_TIME_CHANNELS];int tvq_tns_enable = 0;/* AAC shorter windows 960-480-120 */static int useShortWindows=0;static int aacAllowScalefacs=1;/* NTT_VQ_SYS T.Ishikawa 980525 */static BsBitBuffer *mat_dynpartBuf;extern int samplFreqIndex[];#include "flex_mux.h"/* TNS options */int tns_enable = 0;int   tvq_flag_960;int   tvq_flag_wshape;int   tvq_flag_ppc;int   tvq_flag_bandlimit;int   tvq_flag_postproc;int   tvq_flag_msmask1;int   tvq_flag_msmask2;/********************************************************//* functions EncTfInfo() and EncTfFree()   HP 21-aug-96 *//********************************************************/#define PROGVER "t/f-based encoder core V5.0 20-nov-97"/* EncTfInfo() *//* Get info about t/f-based encoder core. */char *EncTfInfo (                 FILE *helpStream)		/* in: print encPara help text to helpStream */				/*     if helpStream not NULL */				/* returns: core version string */{  if (helpStream != NULL) {    fprintf(helpStream,	    PROGVER "\n"	    "encoder parameter string format:\n"	    "possible options:\n"	    "-qc_mdct16\n"	    "-qc_mdct16_960\n"	    "-qc_uer\n"	    "-qc_src\n"	    "-qc_ntt [-no_syncword] [-ntt_pw_{int,ext}] [-ntt_varbit_{on,off}] \n"	    "-pp_aac\n"	    "-qc_aac\n"            "-qc_aac_960\n"	    "-aac_sca\n"	    "-mode <n> :  see below   for more info \n"	    "-core_coder <n> :  n=0: :g729   n=5: MPEG-4 Celp 6 kbps  n=9: NTT VQ 6 kbps 10: NO_CORE\n"	    "-aac_raw   caution: works only with framework switch -vr !\n"	    "-aac_pns <start_band_for_perceptual_noise_subst>\n"            "-aac_tns\n"	    "-aac_nosfacs: make all scalefacs be equal\n"	    "-no_tstream\n"	    "-len_tstream\n"	    "-pred_ltp\n"	    "-pred_nok_bwp\n"	    "-wsm <win_switch_mode>\n"	    "-wlp <blksize> <med> <short>\n"	    "-nttScl <Br1> [<Br2> [<Br3> [<Br4> ...]]] (scalable, Br in kbit/s)\n"			"-core_br <Br>\n"            "-tvq_tns\n"            "-tvq_960\n"            "-tvq_wshape\n"            "-tvq_ppc\n"            "-tvq_bandlimit\n"            "-tvq_postproc\n"            "-tvq_msmask1\n"	    "\n");    printOpModeInfo(helpStream);  }  return PROGVER;}/* EncTfFree() *//* Free memory allocated by t/f-based encoder core. */void EncTfFree (){}/***************************************************************************************** *** *** Function: EncTfInit *** *** Purpose:  Initialize the T/F-part and the macro blocks of the T/F part of the VM *** *** Description: ***  *** *** Parameters: *** *** *** Return Value: *** *** **** MPEG-4 VM **** *** ****************************************************************************************/void EncTfInit (                int         numChannel,	 /* in: num audio channels */                float       sampling_rate_f,   /* in: sampling frequancy [Hz] */                         float       bit_rate_f,        /* in: bit rate [bit/sec] */                char        *encPara,		 /* in: encoder parameter string */                int         quantDebugLevel,   /* in : quantDebugLevel */                int         *frameNumSample,	 /* out: num samples per frame */                int         *delayNumSample,	 /* out: encoder delay (num samples) */                BsBitBuffer *bitHeader    ,     /* out: header for bit stream */                ENC_FRAME_DATA* frameData,		TF_DATA*    tfData,		ntt_DATA*   nttData) {  BsBitStream *header_stream;  ntt_INDEX    ntt_index_scl;  ntt_INDEX    ntt_index;  int          ntt_IBPS, ntt_IBPS_SCL[8];  int          ntt_NSclLay;  int          aac_BPS_SCL[8];  int          ntt_NSclLay_aac;  int reserved_bits = 0;	/* was earlier given as function parameter */  int sampling_rate = (int)(sampling_rate_f+.5);  int bit_rate = (int)(bit_rate_f+.5);  char *p_ctmp;  long superframe_blocks     = 1;        /* no of blocks in a superframe; later f(encPara) */  int   op_mode = NO_CORE  ;  int ntt_LTP_SW;  debugLevel=  quantDebugLevel;  tvq_debug_level = debugLevel;  header_stream = BsOpenBufferWrite(bitHeader);  if( strstr( encPara, "-qc_mdct16" ) ) {    qc_select = MDCT_VALUES_16BIT;  }  if( strstr( encPara, "-qc_mdct16_960" ) ) {    qc_select = MDCT_VALUES_16BIT;    block_size_samples=960;  }  if( strstr( encPara, "-qc_uer" ) ) {    qc_select = UER_QC;  }  if( strstr( encPara, "-qc_src" ) ) {    qc_select = VM_QC_SOURCE;  }  if( strstr( encPara, "-qc_ntt" ) ) {    qc_select = NTT_VQ;  }  /* T.Ishikawa 980526 */  if( strstr( encPara,"-nttScl") )    {      if( strstr( encPara, "-tvq_sys" ) )        {          qc_select = NTT_VQ_SYS;        }	        else        {          qc_select = NTT_VQ;        }    }  /* T.Ishikawa 980625 */  if( strstr( encPara,"-tvq_sys") /*&& strstr( encPara,"-core_br")*/)    {

⌨️ 快捷键说明

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