📄 scal_enc_frame.c
字号:
BandwidthScalabilityMode = OFF; Wideband_VQ = OFF; BWS_nb_bitrate = 0; celp_initialisation_encoder ( p_bitstream, /*1 */ bit_rate, /*2in: bit rate */ samplRateCore, /*3in: sampling frequency */ ExcitationMode, /*In: Excitation Mode */ SampleRateMode, /*4In: SampleRate Mode */ QuantizationMode, /*5In: Type of Quantization */ FineRateControl, /*6In: Fine Rate Control switch */ LosslessCodingMode, /*7In: Lossless Coding Mode */ &RPE_configuration, /*8In: RPE_configuration */ Wideband_VQ, /*9Out: Wideband VQ mode */ &NB_Configuration, /*0Out: Narrowband configuration */ NumEnhLayers, /*1In: Number of Enhancement Layers */ BandwidthScalabilityMode, /*2In: bandwidth switch */ &BWS_configuration, /*3Out: BWS_configuration */ BWS_nb_bitrate, /*4In: narrowband bitrate for BWS */ &frame_size, /*5out: frame size */ &n_subframes, /*6out: number of subframes */ &sbfrm_size, /*7out: subframe size */ &lpc_order, /*8out: LP analysis order */ &num_lpc_indices, /*9out: number of LPC indices */ &num_shape_cbks, /* out:0number of shape indices */ &num_gain_cbks, /*1out: number of gain indices */ &n_lpc_analysis, /*2out: number of LP analysis per frame */ &window_offsets, /*3out: window size for each LP analysis */ &window_sizes, /*4out: window offset for each LP analysis */ &n_lag_candidates, /*5out: number of pitch candidates */ &min_pitch_frequency, /*6out: minimum pitch frequency */ &max_pitch_frequency, /*7out: maximum pitch frequency */ &org_frame_bit_allocation, /*8out: bit number for each index */ InstanceContextLPCEnc /*9in/out: instance context */ ); celp_initialisation_decoder ( p_bitstream, bit_rate, /* in: bit rate */ 0, /* In: complexity level decoder*/ 0, /* In: reduced order decoder */ 0, /* DecEnhStage */ 0, /* DecBwsMode */ 0, /* disable postfilter */ &frame_size, /* out: frame size */ &n_subframes, /* out: number of subframes */ &sbfrm_size, /* out: subframe size */ &lpc_order, /* out: LP analysis order */ &num_lpc_indices, /* out: number of LPC indices */ &num_shape_cbks, /* out: number of shape indices */ &num_gain_cbks, /* out: number of gain indices */ &org_frame_bit_allocation, /* out: bit number of each index */ &ExcitationMode, /* Out: Excitation Mode */ &SampleRateMode, /* Out: SampleRate Mode */ &QuantizationMode, /* Out: Type of Quantization */ &FineRateControl, /* Out: Fine Rate Control switch*/ &LosslessCodingMode, /* Out: Lossless Coding Mode */ &RPE_configuration, /* Out: RPE_configuration */ &Wideband_VQ, /* Out: Wideband VQ mode */ &NB_Configuration, /* Out: Narrowband configuration*/ &NumEnhLayers, /* Out: Number of Enhancement Layers */ &BandwidthScalabilityMode, /* Out: bandwidth switch */ &BWS_configuration, /* Out: BWS_configuration */ InstanceContextLPCDec, /* in/out: instance context */ 0 ); core_delay = 660; free(p_bitstream); BsFreeBuffer( coreBitBuf );#endif } break; case NTT_TVQ: /* only for TVQ core coder with AAC enhancement layers */ { float bit_rate_scl = 0.0F; /*long numChannel = 1;*/ int med_win_in_long,short_win_in_long; bit_rate = frameData->layer[0].bitRate; fprintf(stdout,"\ncore bitrate: %ld kbit/sec \n",bit_rate); core_delay = 0; short_win_in_long=8; frameNumSampleCore = frameNumSample;#if 0 if ((frameNumSampleCore != 1024) || (short_win_in_long !=8)){ fprintf(stderr, "%5d %5d \n", frameNumSampleCore,short_win_in_long); CommonExit( 1, "Initialization of TVQ core failed (parameters incompatible with AAC settings)"); }#endif } break; case NO_CORE: core_delay=0; break; default: CommonExit( 1, "Encode scalab. init: core coder not yet supported" ); } /* initialize Nokia's predictors */ if (pred_type == NOK_BWP) nok_InitPrediction (0); return( core_delay );}/********************************************************************************//********************************************************************************/static void aacEncodeScalFrameHeader( BsBitStream *fixedStream, int op_mode, enum CORE_CODEC core_cc, long samplRate, long bitRate, int intermediate_layers, int mainDataBegin, ENC_FRAME_DATA* frameData){ BsPutBit( fixedStream, 0x37 , 7 ); /* syncword */ BsPutBit( fixedStream, op_mode , 4 ); /* opMode */ if( opm_info[op_mode].ch_no_core > 0 ) { BsPutBit( fixedStream, core_cc , 4 ); /* coreCodecIdx*/ } if( ( op_mode >= 7 ) && ( op_mode <= 13 ) ){ BsPutBit( fixedStream, intermediate_layers, 2 ); /* number of intermediate layers */ } BsPutBit( fixedStream, getSamplIdx(samplRate) , 4 ); /* mainSamplingFreqIdx */ BsPutBit( fixedStream, getBitrateIdx(bitRate) , 4 );/* bitrateIndex */ BsPutBit( fixedStream, 0 , 1 ); /* paddingBit */ BsPutBit( fixedStream, 1 , 1 ); /* protectionBit */ BsPutBit( fixedStream, mainDataBegin , 10 ); /* mainDataBegin */}/********************************************************************************//********************************************************************************/static void EncodeCore( BsBitStream *fixedStream, float p_time_hsf[], float p_time_decoded[], int blockSizeSamples, int downsamplFac, enum CORE_CODEC coreCodecIdx){ int coreDecNumBit; int postProcMode = 1; /* don't use the postproc filter in g729 decoder for use with high layer signal*/ int numSampleCore = blockSizeSamples; float *coreSampleBuf[MAX_TIME_CHANNELS], core_buff[4096], *p_out[MAX_TIME_CHANNELS]; BsBitBuffer *coreBitBuf; coreSampleBuf[MONO_CHAN] = core_buff; p_out[MONO_CHAN] = p_time_decoded; coreBitBuf = BsAllocBuffer(2000); firLowPass( p_time_hsf, coreSampleBuf[MONO_CHAN], blockSizeSamples, lowpassFilt ); subSampl( coreSampleBuf[MONO_CHAN], coreSampleBuf[MONO_CHAN], downsamplFac, &numSampleCore ); switch( coreCodecIdx ) { case CC_G729: EncG729Frame( coreSampleBuf, coreBitBuf, (int)160, (int)160, (int)160, (int)160 ); BsPutBuffer( fixedStream, coreBitBuf ); DecG729Frame( coreBitBuf, p_out, &coreDecNumBit, postProcMode ); /* mem_time_sig_core_ptr */ break; case CC_CELP_MPEG4_60: {#ifdef CORE_BROKEN BITSTREAM bitstream; bitstream.p_bitstream_buffer_start = coreBitBuf->data; bitstream.buffer_length = ((coreBitBuf->size)+7)/8; bitstream.start_offset = 0; bitstream.valid_bits = 0; celp_coder( coreSampleBuf, /* in: input speech */ &bitstream, /* out: coded bitstream */ sampling_frequency, /* in: sampling frequency */ bit_rate, /* in: bit rate */ ExcitationMode, SampleRateMode, QuantizationMode, FineRateControl, LosslessCodingMode, RPE_configuration, Wideband_VQ, NB_Configuration, NumEnhLayers, BandwidthScalabilityMode, BWS_configuration, 0, frame_size, /* in: frame size */ n_subframes, /* in: number of subframes */ sbfrm_size, /* in: subframe size */ lpc_order, /* in: order of LPC */ num_lpc_indices, /* in: number of LPC indices */ num_shape_cbks, /* in: number of shape codebooks */ num_gain_cbks, /* in: number of gain codebooks */ n_lpc_analysis, /* in: number of LP analysis per frame */ window_offsets, /* out: window size for each LP analysis */ window_sizes, /* out: window offset for each LP analysis */ n_lag_candidates, /* in: number of pitch candidates */ min_pitch_frequency, /* in: minimum pitch frequency */ max_pitch_frequency, /* in: maximum pitch frequency */ org_frame_bit_allocation, /* out: bit number for each index */ InstanceContextLPCEnc /* in/out: instance context */ ); coreBitBuf->numBit = bitstream.valid_bits; BsPutBuffer( fixedStream, coreBitBuf ); celp_decoder ( &bitstream, /* in: received bitstream */ p_out, /* out: decoded signal (multi-channel) */ ExcitationMode, /* In: Excitation Mode */ SampleRateMode, /* In: SampleRate Mode */ QuantizationMode, /* In: Type of Quantization */ FineRateControl, /* In: Fine Rate Control switch */ LosslessCodingMode, /* In: Lossless Coding Mode */ RPE_configuration, /* In: RPE_configuration */ Wideband_VQ, /* In: Wideband VQ mode */ NB_Configuration, /* In: Narrowband configuration */ NumEnhLayers, /* In: Number of Enhanc. Layers */ BandwidthScalabilityMode, /* In: bandwidth switch */ BWS_configuration, /* In: BWS_configuration */ frame_size, /* in: frame size */ n_subframes, /* in: number of subframes */ sbfrm_size, /* in: subframe size */ lpc_order, /* in: order of LPC */ num_lpc_indices, /* in: number of LPC indices */ num_shape_cbks, /* in: number of shape codebooks */ num_gain_cbks, /* in: number of gain codebooks */ org_frame_bit_allocation, /* in: bit number for each index */ InstanceContextLPCDec /* in/out: instance context */ );#endif } break; default: CommonExit( 1, "Encode scalab.: core coder not yet supported" ); } BsFreeBuffer( coreBitBuf );}/********************************************************************************//********************************************************************************/#define FSS_BANDS 16typedef struct { int code[FSS_BANDS]; int length[FSS_BANDS];}FSS_CODE;static FSS_CODE fssCode={ {0,20,21,22,23,24,25,8,9,26,27,28,29,30,31,1}, {2, 5, 5, 5, 5, 5, 5,4,4, 5, 5, 5, 5, 5, 5, 2}};static void aacEncodeFssData( BsBitStream *fixedStream, WINDOW_SEQUENCE windowSequence, unsigned int numDiffCtrlBands, enum DC_FLAG FssControl[], enum JS_MASK ms_mask[]){ int i; if( windowSequence != EIGHT_SHORT_SEQUENCE ) { if( !ms_mask ) { unsigned int fssGroup; unsigned int fssNoGroups = numDiffCtrlBands >> 2 ; for( fssGroup=0; fssGroup<fssNoGroups; fssGroup++ ) { unsigned int group = 0; for( i=0; i<4; i++ ) { group <<= 1; if( FssControl[(fssGroup<<2)+i] == DC_SIMUL ) { group |= 0x1; } } BsPutBit( fixedStream, fssCode.code[group], fssCode.length[group] ); } } else { for( i=0; (unsigned int) i < numDiffCtrlBands; i++ ) { if( ms_mask[i] == JS_MASK_OFF ) { BsPutBit( fixedStream, FssControl[i], 1 ); } } } } else { for( i=0; i<8; i++ ) { BsPutBit( fixedStream, FssControl[i], 1 ); } }}/********************************************************************************//********************************************************************************//* FSS: switch decision */ static void CalcFssControl( double p_core[], double p_full[], double p_diff[], WINDOW_SEQUENCE blockType, enum DC_FLAG FssControl[], int blockSizeSamples, int sfb_width_table[], long samplRate, int diffContrSimu){ int win, no_win, i, offset, sb, no_spec_coeff, *diffBandWidth, numDiffBands; int FssBwShort; double e_full[SFB_NUM_MAX]; double e_diff[SFB_NUM_MAX];#ifdef DEL_ADJ static double avg_gain[SFB_NUM_MAX]; static int _cnt;#endif for (i=0;i<blockSizeSamples ;i++) { /* for now just always the difference signal */ p_diff[i] = p_full[i] - p_core[i]; } if( blockType == EIGHT_SHORT_SEQUENCE ) { no_win = 8; no_spec_coeff = blockSizeSamples/no_win; numDiffBands = 1; diffBandWidth = &FssBwShort; switch( samplRate ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -