📄 ntt_vq_coder.c
字号:
/*****************************************************************************//* This software module was originally developed by *//* Naoki Iwakami (NTT) *//* and edited by *//* Naoki Iwakami and Satoshi Miki (NTT) on 1996-05-01, *//* Naoki Iwakami (NTT) on 1996-08-27, *//* Naoki Iwakami (NTT) on 1997-04-18, *//* Naoki Iwakami (NTT) on 1997-07-17, *//* Naoki Iwakami (NTT) on 1997-08-25 *//* 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. *//*****************************************************************************//* 25-aug-1997 NI bug fixes */#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 "reorderspecHandle.h" /* handler, defines, enums */#include "resilienceHandle.h" /* handler, defines, enums */#include "tf_mainHandle.h" /* handler, defines, enums */#include "all.h" /* structs */#include "nok_bwp_enc.h" /* structs */#include "nok_ltp_common.h" /* structs */#include "obj_descr.h" /* structs */#include "tf_mainStruct.h" /* structs */#include "tns.h" /* structs */#include "allVariables.h" /* variables *//*#include "tf_main.h"*/#include "bitstream.h"#include "nok_ltp_enc.h" #include "ntt_conf.h"#include "ntt_scale_conf.h"#include "ntt_encode.h"void ntt_vq_coder(double *in_init[MAX_TIME_CHANNELS], double *in[MAX_TIME_CHANNELS], double *spectral_line_vector[MAX_TIME_CHANNELS], double external_pw[], int pw_select, WINDOW_SEQUENCE windowSequence, ntt_INDEX *index, ntt_PARAM *param_ntt, int sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS], int nr_of_sfb[MAX_TIME_CHANNELS], int available_bits, double lpc_spectrum[], double *reconstructed_spectrum[MAX_TIME_CHANNELS]){ static double sig_tmp[ntt_T_FR_MAX*3], *sig; static double bark_env[ntt_T_FR_MAX]; static double spectrum[ntt_T_FR_MAX]; static double pitch_sequence[ntt_T_FR_MAX]; static double gain[ntt_T_SHRT_MAX]; static double perceptual_weight[ntt_T_FR_MAX]; static int InitFlag = 1; int sb, ismp, i_ch, top; double spectrum_gain; Info *sfbInfo[4], *p_sfbInfo; int nsbk, nfr; /*--- Initialization ---*/ if (InitFlag){ ntt_zerod(index->block_size_samples*index->numChannel*2, sig_tmp); sig = sig_tmp + index->block_size_samples * index->numChannel; for (i_ch=0; i_ch<index->numChannel; i_ch++){ top = index->block_size_samples * i_ch; ntt_movdd(index->block_size_samples, in_init[i_ch], sig+top); } } { if(index->w_type == EIGHT_SHORT_SEQUENCE){ p_sfbInfo = &eight_short_info; p_sfbInfo->nsbk = 8; p_sfbInfo->islong = 0; for(ismp=0; ismp<8; ismp++){ p_sfbInfo->bins_per_sbk[ismp] = index->block_size_samples/8; p_sfbInfo->sfb_per_sbk[ismp]= nr_of_sfb[0]; top =0; for(sb=0; sb<index->max_sfb[0] /*p_sfbInfo->sfb_per_sbk[ismp]*/; sb++){ top = top +sfb_width_table[0][sb]; p_sfbInfo->bk_sfb_top[sb] = top; } } } else{ p_sfbInfo = &only_long_info; p_sfbInfo->nsbk = 1; p_sfbInfo->islong = 1; p_sfbInfo->bins_per_bk = index->block_size_samples; p_sfbInfo->sfb_per_bk= nr_of_sfb[0]; top =0; for(sb=0; sb<index->max_sfb[0] /*p_sfbInfo->sfb_per_sbk[0]*/; sb++){ top = top +sfb_width_table[0][sb]; p_sfbInfo->bk_sfb_top[sb] = top; } } sfbInfo[index->w_type] = p_sfbInfo; } if(tvq_debug_level >5) fprintf(stderr, "UUUUUUU %5d %5d %5d available_bits ntt_NMTOOL_BITS\n", available_bits, ntt_NMTOOL_BITSperCH*index->numChannel+3, ntt_NMTOOL_BITS_SperCH*index->numChannel+1); for (i_ch=0; i_ch<index->numChannel; i_ch++){ top = index->block_size_samples * i_ch; ntt_movdd(index->block_size_samples, in[i_ch], sig+index->block_size_samples*index->numChannel+top); } /*--- Pre process ---*/ if (param_ntt->ntt_param_set_flag == 0){ ntt_tf_pre_process(sig, index, param_ntt, 1, InitFlag); } index->w_type = windowSequence; /*--- Bit number control ---*/ switch(windowSequence){ /* long frame */ case ONLY_LONG_SEQUENCE: case LONG_START_SEQUENCE: case LONG_STOP_SEQUENCE: index->nttDataBase->ntt_VQTOOL_BITS = available_bits - (ntt_NMTOOL_BITSperCH*index->numChannel+3); spectrum_gain = 1./sqrt((double)index->block_size_samples*2.); nsbk=1; nfr = index->block_size_samples; break; /* short frame */ case EIGHT_SHORT_SEQUENCE: index->nttDataBase->ntt_VQTOOL_BITS_S = available_bits - (ntt_NMTOOL_BITS_SperCH*index->numChannel+1); spectrum_gain = 1./sqrt((double)index->block_size_samples/8*2.); nsbk=8; nfr = index->block_size_samples/8; break; default: fprintf(stderr, "ntt_vq_coder(): Error. %d: No such window type.\n", windowSequence); exit(1); break; } /*--- Spectrum line normalization (for gain alignment of NTT & MPEG4 VM MDCT ---*/ for (i_ch=0; i_ch<index->numChannel; i_ch++){ top = i_ch * index->block_size_samples; for (ismp=0; ismp<index->block_size_samples; ismp++){ spectrum[ismp+top] = spectral_line_vector[i_ch][ismp] * spectrum_gain; } } if(index->numChannel == 2){ int sb, win; int sfbw; double buf[ntt_N_FR_MAX]; /* if(index->ms_mask ==1 ) */ { for( win=0; win<nsbk; win++ ) { int sboffs = win*nfr; for( sb=0; sb<index->max_sfb[0] /*nr_of_sfb[MONO_CHAN]*/; sb++ ) { sfbw = sfb_width_table[MONO_CHAN][sb]; if( index->msMask[win][sb] != 0 ) { for (ismp=sboffs; ismp<sboffs+sfbw; ismp++){ buf[ismp] = (spectrum[ismp] - spectrum[ismp+index->block_size_samples])/2.; spectrum[ismp] = (spectrum[ismp]+spectrum[ismp+index->block_size_samples])/2.; spectrum[ismp+index->block_size_samples] = buf[ismp]; } } sboffs += sfbw; } } }/* else if(index->ms_mask ==2){ for (ismp=0; ismp<index->block_size_samples; ismp++){ buf[ismp] = (spectrum[ismp] - spectrum[ismp+index->block_size_samples])/2.; spectrum[ismp] =(spectrum[ismp]+spectrum[ismp+index->block_size_samples])/2.; spectrum[ismp+index->block_size_samples] = buf[ismp]; } }*/ } /*--- Process spectrum ---*/ ntt_tf_proc_spectrum(spectrum, index, lpc_spectrum, bark_env, pitch_sequence, gain); switch(windowSequence){ /* pitch_q flag long frame */ case ONLY_LONG_SEQUENCE: case LONG_START_SEQUENCE: case LONG_STOP_SEQUENCE: if( index->pitch_q == 1) index->nttDataBase->ntt_VQTOOL_BITS -= ntt_PIT_TBITperCH*index->numChannel; break; case EIGHT_SHORT_SEQUENCE: /* T.Ishikawa 981012*/ break; case NUM_WIN_SEQ: break; } if(index->bandlimit == 1){ index->nttDataBase->ntt_VQTOOL_BITS -= ntt_BWID_BITS*index->numChannel; index->nttDataBase->ntt_VQTOOL_BITS_S -= ntt_BWID_BITS*index->numChannel; } /*--- Perceptual model ---*/ if (pw_select == NTT_PW_EXTERNAL && (index->w_type == ONLY_LONG_SEQUENCE || index->w_type == LONG_START_SEQUENCE || index->w_type == LONG_STOP_SEQUENCE )){ /* external perceptual weighting */ ntt_movdd(index->block_size_samples*index->numChannel, external_pw, perceptual_weight); } else{ /* internal perceptual weighting */ ntt_tf_perceptual_model(lpc_spectrum, bark_env, gain, windowSequence, spectrum, pitch_sequence, index->numChannel, index->block_size_samples, index->nttDataBase->bandUpper, perceptual_weight); } /*--- Quantize spectrum ---*/ ntt_tf_quantize_spectrum(spectrum, lpc_spectrum, bark_env, pitch_sequence, gain, perceptual_weight, index); ntt_vq_decoder(index, reconstructed_spectrum, sfbInfo); ntt_movdd(index->block_size_samples*index->numChannel*2, sig, sig-index->block_size_samples*index->numChannel); InitFlag = 0;}void ntt_headerenc(int iscl, BsBitStream* stream, ntt_INDEX* index, int *used_bits, int *nr_of_sfb, TNS_INFO *tnsInfo[MAX_TIME_CHANNELS], NOK_LT_PRED_STATUS *nok_lt_status, PRED_TYPE pred_type){ int g,sfb,win; int gwin, num_groups; short group_len[8]; QC_MOD_SELECT qc_select = NTT_VQ; if(index->numChannel > 1){ BsPutBit(stream, (unsigned int)index->ms_mask, 2); *used_bits += 2; } if( index->numChannel==2 ){ if (index->ms_mask==1){ if (index->w_type== EIGHT_SHORT_SEQUENCE ){ if(iscl < 0){ /* only core */ BsPutBit( stream,index->group_code,7); /* max_sfb */ *used_bits += 7; } num_groups = TVQ_decode_grouping ( index->group_code, group_len ); } else { num_groups = 1; group_len[0]=1; } win=0; for (g=0;g<num_groups;g++){ for (sfb=index->last_max_sfb[iscl+1];sfb<index->max_sfb[iscl+1];sfb++){ BsPutBit(stream,index->msMask[win][sfb],1);/*ms_mask*/ *used_bits += 1; } for (gwin=1;gwin< group_len[g]; gwin++){ for (sfb=index->last_max_sfb[iscl+1];sfb<index->max_sfb[iscl+1];sfb++){ index->msMask[win+gwin][sfb]=index->msMask[win][sfb]; /* apply same ms mask to a ll subwindows of same group */ } } /*win += (gwin -1);*/ win += group_len[g]; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -