📄 enc_tf.c
字号:
{ int i_ch, n_ch; n_ch = max_ch; for (i_ch=0; i_ch<n_ch; i_ch++) overlap_buffer[i_ch] = (double*)calloc(block_size_samples, sizeof(double)); } /* initialize spectrum processing */ /* initialize quantization and coding */ { int average_block_bits; /* calculate the avaerage amount of bits available for one block */ average_block_bits = (int)floor((double)bit_rate*(double)block_size_samples*(double)max_ch/(double)sampling_rate); /* the frame program may reserve a constant amount of bits e.g. for other scalability layers or ancillary bits or ... */ average_block_bits -= ((reserved_bits/superframe_blocks)+1); /* The above two lines make shure that the used bit no is smaller than the available amount by (line 1) integer division and (line 2) the +1 Any integer or non integer remaining bits are counted and accumulated in the master frame program, and may be made available via the bit reservoir technique to the coding process */ /* The maximum allowed and actual value of bits in the bit reservoir is calculated in the master frame program. The numbers are updated for every block and are parameters to the tf_encoder module */ /* maybe it is better to move the above two lines to the master frame program */ switch( qc_select ) { case AAC_QC: tf_init_encode_spectrum_aac( qc_select, quantDebugLevel); /* YB : 971106 */ break; case AAC_SCALABLE: case AAC_SYS: { int tmp; tf_init_encode_spectrum_aac( qc_select, quantDebugLevel); /* YB : 971106 */ tmp = aacScaleEncInit( header_stream, (char*)encPara, (int)numChannel, (int)block_size_samples, (long)sampling_rate, ( ENC_FRAME_DATA* ) frameData, (enum CORE_CODEC) coreCodecIdx, (int)op_mode, (PRED_TYPE)pred_type, &ntt_index, &ntt_index_scl); nttData->nttDataBase = ntt_index.nttDataBase; nttData->nttDataScl = ntt_index_scl.nttDataScl; if( coreDelay < 0 ) { /* if not set from the cmdline */ coreDelay = tmp; } } break; case UER_QC: /* tf_init_encode_spectrum( ); */ CommonExit(1,"tf_init_encode_spectrum() is no more available\n"); break; case NTT_VQ: case NTT_VQ_SYS: /* T.Ishikawa 980525 */ coreDelay =0; break; default: /* CommonExit(-1,"\ncase not handled in swicht" ); */ CommonWarning("case not handled in swicht" ); /* HP 970509 */ break; } } /* initialize local T/F bitstream mux */ { /* adjust/set absolute level/gain factor depending on the arithmetic and algorithmit implementation (T/F- module normalization factors, ... ) */ } /* initialize Nokia's predictors */ if (pred_type == NOK_LTP) { int ch; for(ch = 0; ch < numChannel; ch++) nok_init_lt_pred (&nok_lt_status[ch]); } else if (pred_type == NOK_BWP) nok_InitPrediction (quantDebugLevel); BsClose(header_stream); ntt_index.numChannel = numChannel; ntt_index_scl.numChannel = numChannel; ntt_index.block_size_samples = block_size_samples; ntt_index_scl.block_size_samples = block_size_samples; tfData->block_size_samples = block_size_samples;}/***************************************************************************************** *** *** Function: EncTfFrame *** *** Purpose: processes a block of time signal input samples into a bitstream *** based on T/F encoding *** *** Description: *** *** *** Parameters: *** *** *** Return Value: returns the number of used bits *** *** **** MPEG-4 VM **** *** ****************************************************************************************/ntt_PARAM param_ntt;void EncTfFrame ( float *p_time_signal[MAX_TIME_CHANNELS], /* array of pointers to the modulo time signal input buffers for each channel */ BsBitBuffer *fixed_bitstream, /* bits before bitres size ptr */ int frameAvailNumBit, /* in: total num bits available for this frame (incl. bit reservoir) */ int frameNumBit, /* in: average num bits per frame */ int frameMaxNumBit, /* in: max num bits per frame */ long bitRateLong, long fSampleLong, ENC_FRAME_DATA* frameData, TF_DATA* tfData, ntt_DATA* nttData ){ /* determine the function parameters used earlier: HP 21-aug-96 */ int i; int average_bits = frameNumBit; int available_bitreservoir_bits = frameAvailNumBit-frameNumBit; /* actual amount of bits currently in the bit reservoir */ /* it is the job of this module to determine the no of bits to use in addition to average_block_bits max. available: average_block_bits + available_bitreservoir_bits */ int max_bitreservoir_bits = frameMaxNumBit-frameNumBit; /* max. allowed amount of bits in the reservoir (used to avoid padding bits) */ long num_bits_available; /* the generated bitstreams are copied into the buffers designated by the */ /* two pointers fixed_bitstream and bitres_bitstream */ BsBitBuffer *bitres_bitstream = NULL; /* bits after bitres size ptr */ double *p_ratio[MAX_TIME_CHANNELS], allowed_distortion[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS], p_energy[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS]; int nr_of_sfb[MAX_TIME_CHANNELS], sfb_width_table[MAX_TIME_CHANNELS][MAX_SCFAC_BANDS]; WINDOW_SEQUENCE windowSequence[MAX_TIME_CHANNELS]; int no_sub_win, sub_win_size, bw_lines; int i_ch, ch, k; /*-----------------------------------------------------------------------*/ /* VQ: Variables for NTT_VQ coder */ static int ntt_InitFlag=1; ntt_INDEX ntt_index, ntt_index_scl; int ntt_NSclLay; /*-----------------------------------------------------------------------*/ /* structures holding the output of the psychoacoustic model */ CH_PSYCH_OUTPUT chpo_long[MAX_TIME_CHANNELS]; CH_PSYCH_OUTPUT chpo_short[MAX_TIME_CHANNELS][MAX_SHORT_WINDOWS]; /* AAC window grouping information */ int num_window_groups; int window_group_length[8]; BsBitStream *fixed_stream; BsBitStream *var_stream; BsBitStream *tmp_stream; BsBitBuffer *tmpBitBuf; /* son_AACpp */ BsBitStream *gc_stream[MAX_TIME_CHANNELS]; BsBitBuffer *gcBitBuf[MAX_TIME_CHANNELS]; /* bit buffer for gain_control_data() */ { /* convert float input to double, which is the internal format */ /* store input data in look ahead buffer which may be necessary for the window switching decision and AAC pre processing */ int i, i_ch; for (i_ch=0; i_ch<max_ch; i_ch++){ for( i=0; i<block_size_samples; i++ ) { /* temporary fix: a linear buffer for LTP containing the whole time frame */ nok_tmp_DTimeSigBuf[i_ch][i] = DTimeSigBuf[i_ch][i]; nok_tmp_DTimeSigBuf[i_ch][block_size_samples + i] = DTimeSigLookAheadBuf[i_ch][i]; /* last frame input data are encoded now */ DTimeSigBuf[i_ch][i] = DTimeSigLookAheadBuf[i_ch][i]; /* new data are stored here for use in window switching decision and AAC pre processing */ if (pp_select == AAC_PP) { DTimeSigLookAheadBuf[i_ch][i] = (i < PQFDELAY) ? DTimeSigPQFDelayCompensationBuf[i_ch][i] : (double)p_time_signal[i_ch][i-PQFDELAY] ; DTimeSigLookAheadBufForGC[i_ch][i] = (double)p_time_signal[i_ch][i]; } else { /* pp_select != AAC_PP */ DTimeSigLookAheadBuf[i_ch][i] = (double)p_time_signal[i_ch][i]; } } } if (pp_select == AAC_PP) { int i, i_ch; /* added 971010 YT*/ for (i_ch=0; i_ch<max_ch; i_ch++){ for (i = 0; i < PQFDELAY; i++) { DTimeSigPQFDelayCompensationBuf[i_ch][i] = (double)p_time_signal[MONO_CHAN][block_size_samples-PQFDELAY+i]; } } /* for i_ch...*/ }/* if pp_select...*/ } if (fixed_bitstream == NULL) return; /* quick'n'dirty fix for encoder startup HP 21-aug-96 */ fixed_stream = BsOpenBufferWrite(fixed_bitstream); if (bitres_bitstream != NULL) var_stream = BsOpenBufferWrite(bitres_bitstream); else var_stream = NULL; tmpBitBuf = BsAllocBuffer(32768); tmp_stream = BsOpenBufferWrite(tmpBitBuf); /* son_AACpp */ /* added 971010 YT*/ { int i_ch; for (i_ch=0; i_ch<max_ch; i_ch++){ /* added 971010 YT*/ gcBitBuf[i_ch] = BsAllocBuffer(4096); gc_stream[i_ch] = BsOpenBufferWrite(gcBitBuf[i_ch]); } } if ((qc_select != AAC_QC) ) { ntt_index_scl.nttDataScl = nttData->nttDataScl; ntt_index.nttDataScl = nttData->nttDataScl; ntt_index.nttDataBase = nttData->nttDataBase; block_size_samples = tfData->block_size_samples; ntt_index.block_size_samples = block_size_samples; ntt_index_scl.block_size_samples = block_size_samples; ntt_index.numChannel = max_ch; ntt_index_scl.numChannel = max_ch; ntt_index.isampf = fSampleLong/1000; ntt_index_scl.isampf = fSampleLong/1000; ntt_NSclLay = ntt_index_scl.nttDataScl->ntt_NSclLay; windowShape[MONO_CHAN] =0; if(tvq_flag_wshape ==1) windowShape[MONO_CHAN]=1; windowShape[max_ch-1] = windowShape[MONO_CHAN]; ntt_index.tvq_tns_enable = 0; if (tvq_tns_enable) ntt_index.tvq_tns_enable = 1; ntt_index.tvq_ppc_enable = 0; if (tvq_flag_ppc) ntt_index.tvq_ppc_enable = 1; ntt_index.bandlimit =0; if (tvq_flag_bandlimit ) ntt_index.bandlimit = 1; ntt_index.pf=0; if (tvq_flag_postproc ) ntt_index.pf=1; ntt_index.ms_mask = 0; if ( tvq_flag_msmask1) ntt_index.ms_mask = 1; } /*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/ /* VQ: Frame initialization for NTT_VQ coder*/ param_ntt.ntt_param_set_flag = 0; /*-----------------------------------------------------------------------*/#if 0 { /* convert float input to double, which is the internal format */ /* store input data in look ahead buffer which may be necessary for the window switching decision and AAC pre processing */ for( i=0; i<block_size_samples; i++ ) { /* last frame input data are encoded now */ DTimeSigBuf[MONO_CHAN][i] = DTimeSigLookAheadBuf[MONO_CHAN][i]; /* new data are stored here for use in window switching decision and AAC pre processing */ if (pp_select == AAC_PP) { DTimeSigLookAheadBuf[MONO_CHAN][i] = (i < PQFDELAY) ? DTimeSigPQFDelayCompensationBuf[MONO_CHAN][i] : (double)p_time_signal[MONO_CHAN][i-PQFDELAY] ; DTimeSigLookAheadBufForGC[MONO_CHAN][i] = (double)p_time_signal[MONO_CHAN][i]; } else { /* pp_select != AAC_PP */ DTimeSigLookAheadBuf[MONO_CHAN][i] = (double)p_time_signal[MONO_CHAN][i]; } } if (pp_select == AAC_PP) { for (i = 0; i < PQFDELAY; i++) { DTimeSigPQFDelayCompensationBuf[MONO_CHAN][i] = (double)p_time_signal[MONO_CHAN][block_size_samples-PQFDELAY+i]; } } }#endif { for( i=0; i<coreDelay; i++ ) { /* last frame input data are encoded now */ coreTimeSigBuf[MONO_CHAN][i] = coreTimeSigLookAheadBuf[MONO_CHAN][i]; /* new data are stored here for use in window switching decision look ahead can be shorter, but for the moment we don't care */ coreTimeSigLookAheadBuf[MONO_CHAN][i] = (float)p_time_signal[MONO_CHAN][i+(block_size_samples - coreDelay)]; } for ( i=coreDelay;i<block_size_samples; i++ ) { coreTimeSigBuf[MONO_CHAN][i] = (float)p_time_signal[MONO_CHAN][(i - coreDelay)]; } } /****************************************************************************************************************************** * * pre processing * ******************************************************************************************************************************/ { switch( win_switch_mode ) { case STATIC_LONG: if (debugLevel>2) printf("WSM: ONLY_LONG_SEQUENCE\n"); windowSequence[MONO_CHAN] = ONLY_LONG_SEQUENCE; break; case STATIC_SHORT : if (debugLevel>2) printf("WSM:EIGHT_SHORT_SEQUENCE\n"); windowSequence[MONO_CHAN] = EIGHT_SHORT_SEQUENCE; break; case LS_STARTSTOP_SEQUENCE : if (debugLevel>2) printf("WSM: LS_STARTSTOP_SEQUENCE\n"); { static WINDOW_SEQUENCE long_short_seq[3] = { ONLY_LONG_SEQUENCE, LONG_START_SEQUENCE, LONG_STOP_SEQUENCE }; static int ls_seq_no; windowSequence[MONO_CHAN] = long_short_seq[ls_seq_no++]; if( ls_seq_no == 3 ) ls_seq_no = 0; } break; case LONG_SHORT_SEQUENCE : if (debugLevel>2) printf("WSM: LONG_SHORT_SEQUENCE\n"); { static WINDOW_SEQUENCE long_short_seq[4] = { ONLY_LONG_SEQUENCE, LONG_START_SEQUENCE, EIGHT_SHORT_SEQUENCE, LONG_STOP_SEQUENCE }; static int ls_seq_no; windowSequence[MONO_CHAN] = long_short_seq[ls_seq_no++]; if( ls_seq_no == 4 ) ls_seq_no = 0; } break; case FFT_PE_WINDOW_SWITCHING : /* VQ: Stand-alone automatic window switch provided by NTT */ { static double *sig_tmptmp, *sig_tmp;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -