📄 dec_tf.c
字号:
/* $Id: dec_tf.c,v 1.68 1999/07/22 19:08:51 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 *//* fixed bit stream handling: Heiko Purnhagen, Uni Hannover, 960705 *//* 21-aug-96 HP added DecTfInfo(), DecTfFree() *//* renamed to dec_tf.c, adapted to new dec.h *//* 26-aug-96 HP updated to vm0_tf_02a *//* 28-aug-96 NI integrated NTT's VQ coder. *//* 09-feb-97 TK integrated NBC compliant post processing module. *//* 18-apr-97 NI integrated scalable coder. *//* 28-may-97 HP -nttDecLyr help *//* 25-aug-97 NI bugfix *//* 23-oct-97 HP merged Nokia's predictor 971013 & 971020 *//* 08-apr-98 HP removed LDFB *//******************************************************************************************* * * Master module for T/F based codecs * ******************************************************************************************/#include <math.h>#include <memory.h>#include <string.h>#include <stdio.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 "reorderspecHandle.h" /* handler, defines, enums */#include "resilienceHandle.h" /* handler, defines, enums */#include "tf_mainHandle.h" /* handler, defines, enums */#include "all.h" /* structs */#include "bitstreamStruct.h" /* structs */#include "lpc_common.h" /* structs */#include "monopredStruct.h" /* structs */#include "nok_ltp_common.h" /* structs */#include "nok_prediction.h" /* structs */#include "obj_descr.h" /* structs */#include "tf_mainStruct.h" /* structs */#include "tns.h" /* structs */#include "allVariables.h" /* variables */#include "bitstream.h"#include "common_m4a.h"#include "dec_tf.h"#include "flex_mux.h"#include "mod_buf.h"#include "tf_main.h"/* son_NBCpp */#include "sony_local.h"/* NTT VQ */ #include "ntt_conf.h"#include "ntt_scale_conf.h"#include "mat_def_ntt.h"/* Long term predictor */#include "nok_lt_prediction.h"#include "ntt_nok_lt_predict_dec.h"#include "ntt_nok_pred.h"/* --- AAC --- */#include "aac.h"#include "buffers.h"#include "statistics_aac.h"#include "port.h" /* 981207 for tvq_tns */TNS_frame_info tns_info[MAX_TIME_CHANNELS];/* currently the psych module contains the sfb-width info this should be moved into a separate file */#include "psych.h"#include "mp4_tf.h"CH_PSYCH_OUTPUT chpo_long[MAX_TIME_CHANNELS];CH_PSYCH_OUTPUT chpo_short[MAX_TIME_CHANNELS][MAX_SHORT_WINDOWS];extern int samplFreqIndex[]; /* undesired, but ... */static int block_size_samples; /* nr of samples per block in one! audio channel */static int med_win_in_long = 2; /* for NTT */static int short_win_in_long = 8;static int max_ch; /* no of of audio channels */static double *spectral_line_vector[MAX_TF_LAYER][MAX_TIME_CHANNELS];static double *time_sample_vector[MAX_TIME_CHANNELS];static double *overlap_buffer[MAX_TIME_CHANNELS];/* son_NBCpp */static int max_band[MAX_TIME_CHANNELS];static double *spectral_line_vector_for_gc[MAX_TIME_CHANNELS];static double *imdctBufForGC[MAX_TIME_CHANNELS];static double **DBandSigBufForOverlapping[MAX_TIME_CHANNELS];static double **DBandSigBuf[MAX_TIME_CHANNELS];static GAINC **gainInfo[MAX_TIME_CHANNELS];static int ssr_decoder_band = NBANDS;static int frameNumBit;static enum CH_CONFIG channel_configuration = CHC_MONO; /* later f(encPara) */static QC_MOD_SELECT qc_select = MDCT_VALUES_16BIT; /* 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 int scalOutSelect = 100;static int lopLong = 0, lopShort = 0;static float normBw=0.0F;/* Variable bit switch for the NTT_VQ coder */static enum NTT_VARBIT ntt_varbit = NTT_VARBIT_OFF;/* Number of scalable layers to be decoded */static int ntt_NSclLayDec_gl;static int ntt_NSclLay_gl;/* AAC shorter windows 960-480-120 */static int useShortWindows=0;/* Predictor type */static PRED_TYPE pred_type = MONOPRED;/* Long term prediction */static NOK_LT_PRED_STATUS *nok_lt_status[MAX_TIME_CHANNELS];/* Nokia LTP for TwinVQ *//* static Info ntt_info; */NOK_LT_PRED_STATUS *ntt_nok_lt_status[MAX_TIME_CHANNELS];/********************************************************//* functions DecTfInfo() and DecTfFree() HP 21-aug-96 *//********************************************************/#define PROGVER "t/f-based decoder core V5.0 20-nov-97"/* DecTfInfo() *//* Get info about t/f-based decoder core. */char *DecTfInfo (FILE *helpStream) /* in: print decPara help text to helpStream */ /* if helpStream not NULL */ /* returns: core version string */{ if (helpStream != NULL) { fprintf(helpStream, PROGVER "\n" "decoder parameter string format:\n" "possible options:\n" "-qc_mdct16\n" "-qc_mdct16_960\n" "-qc_ntt\n" "-qc_aac_960\n" "-qc_aac\n" "-aac_raw\n" " -ssr\n" " -main\n" "-aac_sca\n" " -out <n> select output layer for -aac_sca (n=0 : base layer)\n" " -lop <n long> <n short> <bandwidth> set lowpass line limits\n" "-pred_ltp\n" "-pred_nok_bwp\n" "-nttDecLyr <n> (scalable, n=0: base layer)\n" "\n"); } return PROGVER;}/* DecTfFree() *//* Free memory allocated by t/f-based decoder core. */void DecTfFree ( HANDLE_EP_INFO hEpInfo, HANDLE_RESILIENCE hResilience ){}/***************************************************************************************** *** *** Function: DecTfInit *** *** 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 **** *** ****************************************************************************************/static Info** sfbInfo;static char* aacDebugString;static long sampling_rate_decoded;void DecTfInit ( int numChannel, /* in: num audio channels */ float fSample, /* in: sampling frequancy [Hz] */ float bitRate, /* in: bit rate [bit/sec] */ char* decPara, /* in: decoder parameter string */ int profile, /* in: bitstream profile as indicated in the ADIF header */ BsBitBuffer* bitHeader, /* in: header from bit stream */ int* frameNumSample, /* out: num samples per frame */ int* delayNumSample, /* out: encoder delay (num samples) */ char* aacDebugStr, HANDLE_BUFFER* hVm, HANDLE_BUFFER* hHcrSpecData, FRAME_DATA* frameData, TF_DATA* tfData, ntt_DATA* nttData, int mainDebugLevel ){ unsigned long ultmp; long bit_rate_decoded = 0; int delay_samples_decoded = 0; int x; int i_ch; ntt_INDEX ntt_index; ntt_INDEX ntt_index_scl; int ntt_NSclLayDec; int ntt_NSclLay; int ntt_IBPS; int ntt_IBPS_SCL[8]; int ntt_LTP_SW; BsBitStream* header_stream; /* char * ssrPara; */ WINDOW_SHAPE prev_windowShape[2] = {WS_FHG, WS_FHG}; #if 0 if (numChannel != 1) CommonExit(1,"DecTfInit: audio data has more than one channel (%d)", numChannel);#endif header_stream = BsOpenBufferRead(bitHeader); *hVm = CreateBuffer(VIRTUELL); *hHcrSpecData = CreateBuffer(AAC_MAX_INPUT_BUF_BITS); /* ----- Set qc_select ----- */ if ( ( strstr(decPara, "-qc_aac")) || ( strstr(decPara, "-qc_aac_960"))) { tf_select = MDCT_AAC; qc_select = AAC_QC; } /* set profile */ mc_info.profile = profile; if( strstr( decPara, "-aac_raw" ) ) { if( mainDebugLevel ) { printf("AAC-"); switch(profile) { case Main_Profile: printf("Main"); break; case LC_Profile: printf("LC"); break; case SSR_Profile: printf("SSR"); break; default: printf("invalid"); break; } printf(" profile decoding\n"); } /* currently fix coded !!! */ bit_rate_decoded = (long int )bitRate; sampling_rate_decoded = (long int)fSample; block_size_samples = 1024; delay_samples_decoded = 2048; channel_configuration = CHC_MONO; if (numChannel ==2){ channel_configuration =CHC_DUAL; } qc_select = AAC_QC; tf_select = MDCT_AAC; transport_stream = AAC_RAWDATA_TSTREAM; } /*if( ( ssrPara = strstr( decPara, "-ssr" ) ) ) { */ if( profile == SSR_Profile ) { /* sscanf(&ssrPara[8],"%d",&ssr_decoder_band); currently not supported */ if ( mainDebugLevel ) { printf(" AAC-SSR %d band decoding\n",ssr_decoder_band); } } if( strstr( decPara, "-aac_sca" ) ) { char * outLayNr; char * lopPara; /* currently fix coded !!! */ if ( mainDebugLevel ) { printf(" TF scaleable decoding OLD bitstream syntax\n"); } bit_rate_decoded = (long int)bitRate; sampling_rate_decoded = (long int)fSample; block_size_samples = 960; delay_samples_decoded = 2048; channel_configuration = CHC_MONO; if (numChannel ==2){ channel_configuration =CHC_DUAL; } qc_select = AAC_SCALABLE; tf_select = MDCT_AAC; transport_stream = AAC_RAWDATA_TSTREAM; if ( ( lopPara = strstr ( decPara, "-lop"))) { sscanf(&lopPara[4],"%d%d%f",&lopLong,&lopShort,&normBw); if ((lopLong < 0 ) || (lopLong > 950)) { CommonExit(-1,"\n lopLong parameter out of range: %d", lopLong); } if ((lopShort < 0 ) || (lopShort > 110)) { CommonExit(-1,"\n lopShort parameter out of range: %d", lopShort); } if ((normBw < 0.0F) || (normBw > 1.0F)) { CommonExit(-1,"\n normalized bandwidth out of range: %f", lopShort); } if ( mainDebugLevel ) { printf("lopLong=%d, lopShort=%d, normalized bandwidth=%3.2f\n", lopLong, lopShort, normBw); } } if ( ( outLayNr = strstr( decPara, "-out") ) ){ sscanf(&outLayNr[4],"%d",&scalOutSelect); if ( (scalOutSelect < 0 ) || ( scalOutSelect > 7 ) ){ CommonExit(-1,"\n errorn in output layer select %d ",scalOutSelect); } if ( mainDebugLevel ) { printf("\n layer nr. %d is selected \n",scalOutSelect); } } tfData->output_select = scalOutSelect;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -