📄 decoder_tf.c
字号:
/************************* MPEG-2 NBC Audio Decoder ************************** * *"This software module was originally developed by AT&T, Dolby Laboratories, Fraunhofer Gesellschaft IIS and edited byYoshiaki Oikawa (Sony Corporation),Mitsuyuki Hatanaka (Sony Corporation),Ralph Sperschneider (Fraunhofer Gesellschaft IIS)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-4Audio 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 developerretains 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 mustbe included in all copies or derivative works." Copyright(c)1996, 1997, 1998. * * ****************************************************************************/#include <stdio.h>#include "bitstreamHandle.h" /* handler, defines, enums */#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 "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 "aac.h"#include "lpc_common.h"#include "dec_tf.h"#include "dolby_def.h"#include "tf_main.h"#include "common_m4a.h"#include "nok_lt_prediction.h"#include "port.h"#include "buffers.h"#include "buffersHandle.h"#include "bitstream.h"#include "reorderspecHandle.h"#include "resilienceHandle.h"#include "allVariables.h"/* merged HP 971104 */int debug[256];int adif_header_present;char *aacDebugOptions=NULL;/* prediction */static PRED_STATUS *sp_status[Chans];static NOK_PRED_STATUS *nok_sp_status[Chans];static PRED_TYPE pred_type;void init( int block_size_samples, Info*** sfbInfo){#if (CChans > 0) init_cc();#endif huffbookinit( block_size_samples); predinit(); winmap[0] = win_seq_info[ONLY_LONG_SEQUENCE]; winmap[1] = win_seq_info[ONLY_LONG_SEQUENCE]; winmap[2] = win_seq_info[EIGHT_SHORT_SEQUENCE]; winmap[3] = win_seq_info[ONLY_LONG_SEQUENCE]; *sfbInfo = winmap;}voidpredinit(void){ int i, ch; if (pred_type == MONOPRED) for (ch = 0; ch < Chans; ch++) { for (i = 0; i < LN2; i++) { init_pred_stat(&sp_status[ch][i], PRED_ORDER,PRED_ALPHA,PRED_A,PRED_B); } } else if (pred_type == NOK_BWP) for (ch = 0; ch < Chans; ch++) { nok_init_pred_stat(nok_sp_status[ch]); for (i = 0; i < LN2; i++) { nok_sp_status[ch]->prev_quant[i] = 0.; } }}static int getdata ( int* tag, int* dt_cnt, byte* data_bytes, HANDLE_RESILIENCE hResilience, HANDLE_BUFFER hVm, HANDLE_EP_INFO hEpInfo ){ int i, align_flag, cnt; *tag = GetBits ( ELEMENT_INSTANCE_TAG, LEN_TAG, hResilience, hVm, hEpInfo ); align_flag = GetBits ( DATA_BYTE_ALIGN_FLAG, LEN_D_ALIGN, hResilience, hVm, hEpInfo ); if ((cnt = GetBits ( COUNT, LEN_D_CNT, hResilience, hVm, hEpInfo )) == (1<<LEN_D_CNT)-1) cnt += GetBits ( ESC_COUNT, LEN_D_ESC, hResilience, hVm, hEpInfo ); *dt_cnt = cnt; if (debug['x']) fprintf(stderr, "data element %d has %d bytes\n", *tag, cnt); if (align_flag) byte_align(); for (i=0; i<cnt; i++){ data_bytes[i] = GetBits ( DATA_STREAM_BYTE, LEN_BYTE, hResilience, hVm, hEpInfo ); if (debug['X']) fprintf(stderr, "%6d %2x\n", i, data_bytes[i]); } return 0;}static void getfill ( HANDLE_RESILIENCE hResilience, HANDLE_BUFFER hVm, HANDLE_EP_INFO hEpInfo ){ int i, cnt; if ((cnt = GetBits ( COUNT, LEN_F_CNT, hResilience, hVm, hEpInfo )) == (1<<LEN_F_CNT)-1) cnt += GetBits ( ESC_COUNT, LEN_F_ESC, hResilience, hVm, hEpInfo ) - 1; if (debug['x']) fprintf(stderr, "fill element has %d bytes\n", cnt); for (i=0; i<cnt; i++) GetBits ( FILL_BYTE, LEN_BYTE, hResilience, hVm, hEpInfo );}/*voidmain(int argc, char *argv[]){}--- Global variables from aac-decoder ---*/static Float* coef[Chans]; static Float* data[Chans];static Float* state[Chans];static byte hasmask[Winds];static byte* mask[Winds];static byte* group[Winds];static WINDOW_SEQUENCE wnd[Winds];static byte* cb_map[Chans];static byte d_bytes[Avjframe];short* factors[Chans];int* lpflag[Chans];int* prstflag[Chans];static TNS_frame_info* tns[Chans];static Wnd_Shape wnd_shape[Winds];#if (CChans > 0)static Float* cc_coef[CChans];static Float* cc_gain[CChans][Chans];static byte cc_wnd[CChans];static Wnd_Shape cc_wnd_shape[CChans];#endif#if (ICChans > 0)Float* cc_state[ICChans];#endifstatic int i, j, ch, wn, ele_id, d_tag, d_cnt;static int left, right;static Info* info;MC_Info mc_info;static MC_Info* mip = &mc_info;Ch_Info* cip;/* -------------------------------------- *//* -------------------------------------- *//* Init AAC-Decoder *//* -------------------------------------- *//* -------------------------------------- */static int blockSize;void aac_decode_init(int sampling_rate_decoded, char *aacDebugStr, int block_size_samples, Info *** sfbInfo, int predictor_type){ blockSize= block_size_samples; aacDebugOptions = aacDebugStr; pred_type = (PRED_TYPE)predictor_type; for(i=0; i<Chans; i++){ coef[i] = (Float *)mal1(LN2*sizeof(*coef[0])); data[i] = (Float *)mal1(LN2*sizeof(*data[0])); state[i] = (Float *)mal1(LN*sizeof(*state[0])); /* changed LN4 to LN 1/97 mfd */ for (j = 0; j < LN; j++) (state [i]) [j] = 0.; fltclr(state[i], LN); factors[i] = (short *)mal1(MAXBANDS*sizeof(*factors[0])); cb_map[i] = (byte *)mal1(MAXBANDS*sizeof(*cb_map[0])); group[i] = (byte *)mal1(NSHORT*sizeof(group[0])); lpflag[i] = (int *)mal1(MAXBANDS*sizeof(*lpflag[0])); prstflag[i] = (int *)mal1((LEN_PRED_RSTGRP+1)*sizeof(*prstflag[0])); tns[i] = (TNS_frame_info *)mal1(sizeof(*tns[0])); wnd_shape[i].prev_bk = WS_FHG; fltclr(state[i], LN4); if (pred_type == MONOPRED) sp_status[i] = (PRED_STATUS *)mal1(LN2*sizeof(*sp_status[0])); else if (pred_type == NOK_BWP) { nok_sp_status[i] = (NOK_PRED_STATUS *)mal1(sizeof(*nok_sp_status[0])); nok_sp_status[i]->prev_quant = (Float *)mal1(LN2*sizeof(*nok_sp_status[i]->prev_quant)); } } for(i=0; i<Winds; i++) { mask[i] = (byte *)mal1(MAXBANDS*sizeof(mask[0])); }#if (CChans > 0) for(i=0; i<CChans; i++){ cc_coef[i] = (Float *)mal1(LN2*sizeof(*cc_coef[0])); for(j=0; j<Chans; j++) cc_gain[i][j] = (Float *)mal1(MAXBANDS*sizeof(*cc_gain[0][0]));#if (ICChans > 0) if (i < ICChans) { cc_state[i] = (Float *)mal1(LN*sizeof(*state[0])); fltclr(cc_state[i], LN); cc_wnd_shape[i].prev_bk = 0; }#endif }#endif /* set defaults */ adif_header_present = 0; current_program = -1; default_config = 1; /* mc_info.profile = Main_Profile; this is specified by DecPara()*/ mc_info.sampling_rate_idx = Fs_48; /* multi-channel info is invalid so far */ mc_info.mcInfoCorrectFlag = 0; /* Set AAC-Debugging options , also update sampling rate for aac if specified */ set_aac_options(sampling_rate_decoded); /* Init hufftables, ... */ init( block_size_samples,sfbInfo); }/* ---------------------------------------------- *//* ---------------------------------------------- *//* ----- Set Options, samplingrate for AAC ----- *//* ---------------------------------------------- *//* ---------------------------------------------- */voidset_aac_options(int aacSamplingRate){ unsigned int i; int *p; /* --- reset all debug options --- */ for (i=0;i<256;i++) debug[i]=0; if (aacDebugOptions!=NULL){ for (i=0;i<strlen(aacDebugOptions);i++){ debug[(int)aacDebugOptions[i]]=1; fprintf(stderr," !!! AAC debug option: %c reconized.\n", aacDebugOptions[i]); } } /* Set sampling rate */ /* aacSamplingRate = samplingRate; */ p = &prog_config.sampling_rate_idx; for (i=0; i<(1<<LEN_SAMP_IDX); i++) { if (aacSamplingRate == samp_rate_info[i].samp_rate) break; } if (i == (1<<LEN_SAMP_IDX)) CommonExit(1,"Unsupported sampling frequency %d", aacSamplingRate); *p = mc_info.sampling_rate_idx = i;}/* -------------------------------------- *//* -------------------------------------- *//* DECODE 1 frame *//* -------------------------------------- *//* -------------------------------------- */ int AacDecodeFrame ( BsBitStream* fixed_stream, BsBitStream* gc_stream[MAX_TIME_CHANNELS], double* spectral_line_vector[MAX_TIME_CHANNELS], WINDOW_SEQUENCE windowSequence[MAX_TIME_CHANNELS], WINDOW_SHAPE window_shape[MAX_TIME_CHANNELS], enum AAC_BIT_STREAM_TYPE bitStreamType, byte max_sfb[Winds], int numChannels, int commonWindow, Info** sfbInfo, byte sfbCbMap[MAX_TIME_CHANNELS][MAXBANDS], HANDLE_RESILIENCE hResilience, HANDLE_BUFFER hVm, HANDLE_BUFFER hHcrSpecData, HANDLE_HCR hHcrInfo, HANDLE_EP_INFO hEpInfo, HANDLE_CONCEALMENT hConcealment, QC_MOD_SELECT qc_select, NOK_LT_PRED_STATUS** nok_lt_status){ int chCnt; int outCh; int sfb; Info* sfbInfoP;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -