📄 reconst.c
字号:
{ if ( type == 0 ) *(*anafea_rec)->frame_len = last_u; else { if ( ext == UNVCD_STD ) *(*anafea_rec)->frame_len = uvced_frmlen; else { get_bits( fea2kb_rec, ih, ifp, RAW_LEN, debug, dfp, &value, &cnt, NO, &stuff ); *(*anafea_rec)->frame_len = value; if ( debug >= 2 ) debug_print( "LENGTH", (int) *(*anafea_rec)->frame_len, value, cnt, "RAW", dfp ); } } last_u = *(*anafea_rec)->frame_len; bs->frm_len = cnt; bs->frm_bits += cnt + stuff; bs->u_len += cnt; bs->stuff += stuff; return; } np = *(*anafea_rec)->num_pulses; if ( !re_sync && prev_type == VOICED ) { get_state_val( fea2kb_rec, ih, ifp, LENGTH, MAX_LEN, RAW_PULSE, debug, dfp, &value, &cnt, &stuff ); (*auxana_rec)->pulse_len_idx[0] = last_v + value; } else { get_bits( fea2kb_rec, ih, ifp, RAW_PULSE, debug, dfp, &value, &cnt, NO, &stuff ); (*auxana_rec)->pulse_len_idx[0] = value; if ( debug >= 2 ) debug_print( "LENGTH", (*auxana_rec)->pulse_len_idx[0], value, cnt, "RAW", dfp ); } for ( i = 1; i < np; i++ ) { get_state_val( fea2kb_rec, ih, ifp, LENGTH, MAX_LEN, RAW_PULSE, debug, dfp, &value, &temp, &stuff ); (*auxana_rec)->pulse_len_idx[i] = (*auxana_rec)->pulse_len_idx[i-1] + value; cnt += temp; } last_v = (*auxana_rec)->pulse_len_idx[np-1]; *(*anafea_rec)->frame_len = 0; bs->frm_len = cnt; bs->frm_bits += cnt + stuff; bs->v_len += cnt; bs->stuff += stuff;}/* ******************************************************************************** * Subroutine to decode SPEC field, and reconstruct spec_param_idx field of * the FEA_ANA data record. ******************************************************************************** */reconst_spec( order_unvcd, order_vcd, comb_frq, comb_vcg, cont_spc, prev_type, u_avg, v_avg, u_vect, v_vect, fea2kb_rec, ih, ifp, re_sync, debug, dfp, anafea_rec, auxana_rec, bs )FILE *dfp, *ifp;int debug, re_sync, *u_vect, *v_vect;long order_vcd, order_unvcd;short comb_frq, comb_vcg, cont_spc, prev_type, *u_avg, *v_avg;struct auxana **auxana_rec;struct anafea **anafea_rec;struct bit_stats *bs;struct fea2kb *fea2kb_rec;struct header *ih;{ int cnt = 0, /* Bit count */ i, /* Loop variable */ offset, /* Offset in type array */ same_type, /* Logical flag */ stuff = 0, /* Accumulated number of stuffed bits */ temp, /* Temporary variable */ value, /* State value */ *vect; /* Spectral breakdown array */ long order; /* Analysis order */ short *avg, /* Static average values */ *prev_index; /* Previous index array */ static char init = YES; /* Flag for initial entry */ static int *type, /* Array of table types */ type_vf[ 2*MAX_ORD ] = {SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC, SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC,SPEC}, type_0f[ 2*MAX_ORD ] = {VSPEC,VSPEC,VSPEC,VSPEC,VSPEC,VSPEC,VSPEC,VSPEC, VSPEC,VSPEC,USPEC,USPEC,USPEC,USPEC,USPEC,USPEC, USPEC,USPEC,USPEC,USPEC}, type_v0[ 2*MAX_ORD ] = {CF12,OF12,CF34,OF34,CF56,OF56,CF78,OF78,CF90,OF90, CF12,OF12,CF34,OF34,CF56,OF56,CF78,OF78,CF90,OF90}, type_00[ 2*MAX_ORD ] = {VCF12,VOF12,VCF34,VOF34,VCF56,VOF56,VCF78,VOF78, VCF90,VOF90,UCF12,UOF12,UCF34,UOF34,UCF56,UOF56,0,0,0,0}; static short prev_frm_index[ MAX_ORD ], /* Index array - previous frame */ prev_same_index[ MAX_ORD ]; /* Index array - same frame type *//* * On initial entry, set flag false and assign pointer to type array. */ if ( init ) { init = NO; if ( comb_vcg == NO && comb_frq == NO ) type = type_00; else if ( comb_vcg == NO && comb_frq == YES ) type = type_0f; else if ( comb_vcg == YES && comb_frq == NO ) type = type_v0; else if ( comb_vcg == YES && comb_frq == YES ) type = type_vf; } if ( *(*anafea_rec)->frame_type == VOICED ) { offset = 0; order = order_vcd; vect = v_vect; avg = v_avg; } else { offset = MAX_ORD; order = order_unvcd; vect = u_vect; avg = u_avg; } same_type = ( *(*anafea_rec)->frame_type == prev_type ); for ( i = 0; i < MAX( order_vcd, order_unvcd ); i++ ) (*auxana_rec)->spec_param_idx[i] = 0; if ( !re_sync && ( cont_spc == YES || same_type ) ) { if ( same_type ) prev_index = prev_frm_index; else prev_index = prev_same_index; for ( i = 0; i < order; i++ ) { get_state_val( fea2kb_rec, ih, ifp, type[ i + offset ] + INTER, MAX_SPEC, RAW_SPEC, debug, dfp, &value, &temp, &stuff ); (*auxana_rec)->spec_param_idx[i] = prev_index[i] + value; cnt += temp; vect[i] += temp; } if ( !same_type ) for ( i = 0; i < order; i++ ) prev_same_index[i] = (*auxana_rec)->spec_param_idx[i]; } else for ( i = 0; i < order; i++ ) { get_state_val( fea2kb_rec, ih, ifp, type[ i + offset ] + INTRA, MAX_SPEC, RAW_SPEC, debug, dfp, &value, &temp, &stuff ); (*auxana_rec)->spec_param_idx[i] = avg[i] + value; cnt += temp; vect[i] += temp; } for ( i = 0; i < order; i++ ) prev_frm_index[i] = (*auxana_rec)->spec_param_idx[i]; bs->frm_spec = cnt; bs->frm_bits += cnt + stuff; if ( *(*anafea_rec)->frame_type == VOICED ) bs->v_spec += cnt; else bs->u_spec += cnt; bs->stuff += stuff;}/* ******************************************************************************** * Subroutine to do inverse Huffman look-up and return state value. ******************************************************************************** */get_state_val( fea2kb_rec, ih, ifp, state, max, raw_len, debug, dfp, value, length, stuff )FILE *dfp, *ifp;int debug, *length, max, raw_len, state, *stuff, *value;struct fea2kb *fea2kb_rec;struct header *ih;{ char *mode = NULL; /* Escape suffix */ int code, /* Huffman code */ field, /* Bitstream field */ first, /* First table index */ j, /* Loop variable */ last, /* Last table index */ mask, /* Mask for sign extension */ match, /* Logical flag for table look-up */ num; /* Number of bits read from bitstream */ j = 0; while ( key_tbl[j].type != state ) j++; first = key_tbl[j].offset; last = first + 2*max; j = 0; code = 0; field = 0; *length = 0; for (;;) { get_bits( fea2kb_rec, ih, ifp, 1, debug, dfp, &field, &num, NO, stuff ); code = code << 1 | field; (*length)++; match = NO; for ( j = first; j <= last; j++ ) if ( huff_tbl[j].length == *length && huff_tbl[j].code == code ) { match = YES; break; } if ( match ) break; } if ( huff_tbl[j].type == AMP_ESC ) { get_bits( fea2kb_rec, ih, ifp, raw_len, debug, dfp, value, &num, NO, stuff ); *length += raw_len; mode = "HUFF_ESC + RAW"; /* * Build a mask of the form 1111...11100000, where the number of zeros is * one less than the raw length. The bitwise AND with the value will then * read the sign bit. If the value is negative, it is sign-extended. */ mask = 0xFFFFFFFF; for ( j = 1; j < raw_len; j++ ) mask <<= 1; if ( *value & mask ) *value |= mask; } else { *value = j - first; *value -= max; } if ( debug >= 2 ) debug_print( hist_types[ state ], *value, code, *length, mode, dfp );}/* ******************************************************************************** * Subroutine to print debug information. ******************************************************************************** */debug_print( state, datum, code, length, mode, dfp )FILE *dfp;char *state, *mode;int code, datum, length;{ Fprintf( dfp, "\tState = %s;", state ); Fprintf( dfp, " Datum = %d;", datum ); Fprintf( dfp, " Code = 0x%x;", code ); Fprintf( dfp, " Length = %d", length ); if ( mode == NULL ) Fprintf( dfp, "\n" ); else Fprintf( dfp, "; Mode = %s\n", mode );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -