void do_xref_map() { int_type pos; int knt,nnn,nnn_less,iii,jjj,kkk,iii_src,iii_dest,new_iii; size_t eachsize; cross_reference_entry_type *item_arr; cross_reference_entry_type *item_iii; cross_reference_entry_type *item_jjj; char blankname[XREF_IDENT_MAXNCH_P]; static char newline_fmt[] = "\n"; static char name_fmt[] = "%s%s "; static char pos_fmt[] = "%d c%d%s"; char enkpos[XREF_IDENT_MAXNCH_P+25]; char last_refcode,curr_refcode; Boolean undcl,unset,unuse,special; /*-------------------------------------------------------*/ if (!xref_map) return; list_page_need_test_only(32000); sys_memset(blankname,(int) ' ',(size_t) XREF_ID_TRUNC_NCH); *(blankname+XREF_ID_TRUNC_NCH) = '\0'; /*-------------------------------------------- size the file */ pos=ftell(xreffile); knt=eachsize=sizeof(cross_reference_entry_type); knt=(int) (pos/((int_type) knt)); /*-------------------------------------------- close & re-open to read */ fclose(xreffile); xreffile=open_binary_input_file(xref_filename); /*-------------------------------------------- allocate */ item_arr = (cross_reference_entry_type *) calloc((size_t) knt,eachsize); if (item_arr==((cross_reference_entry_type *) NULL)) return; /*-------------------------------------------- read file */ nnn=fread(item_arr,eachsize,(size_t) knt,xreffile); if (nnn!=knt) goto free_point; /*-------------------------------------------- sort */ qsort((char *) item_arr,(size_t) knt,eachsize,cmp_xref_entries); /*-------------------------------------------- remove duplicates */ for (nnn_less=nnn-1,iii_src=iii_dest=0;iii_src<nnn;++iii_dest){ if (iii_src != iii_dest) sys_memcpy(item_arr+iii_dest,item_arr+iii_src,eachsize); while ((iii_src<nnn) && (memcmp(item_arr+iii_dest,item_arr+iii_src,eachsize)==0)) ++iii_src;} nnn=iii_dest; /*-------------------------------------------- print_map */ for (iii=0;iii<nnn;++iii){ item_iii = item_arr + iii; undcl=unset=unuse=TRUE; last_refcode = (*item_iii).refcode; NEW_XREF_LINE((*item_iii).name,xref_label(last_refcode)); special = (Boolean) (*(*item_iii).name == '<'); for (new_iii=iii-1,jjj=iii,kkk=0;jjj<nnn;++jjj,++kkk){ new_iii=jjj; item_jjj = item_arr + jjj; curr_refcode = (*item_jjj).refcode; if (memcmp((*item_iii).name,(*item_jjj).name,XREF_ID_TRUNC_NCH)==0){ XREF_FIX_UNSET_ETC(curr_refcode); if (last_refcode != curr_refcode){ kkk=0; NEW_XREF_LINE(blankname,xref_label(curr_refcode));} if ((kkk>0)&&((kkk%5)==0)){ NEW_XREF_LINE(blankname," ");} sprintf(enkpos,pos_fmt, (int) (*item_jjj).linnum,(int) ((*item_jjj).pos+1), blankname); *(enkpos+10) = '\0'; fprintf(listfile,"%s",enkpos);} else{ new_iii=jjj-1; jjj=nnn;} last_refcode = curr_refcode;} iii=new_iii; if (undcl && (!special)) { NEW_XREF_LINE(blankname,"*** UNDCL ***"); } if (unset && (!special)) { NEW_XREF_LINE(blankname,"*** UNSET ***"); } if (unuse && (!special)) { NEW_XREF_LINE(blankname,"*** UNUSE ***"); } fprintf(listfile,"\n"); list_page_need_test_only(5); list_page_need(1);} /*-------------------------------------------- free */ free_point: free(item_arr); /*-------------------------------------------------------*/ }
int main( int argc, char *argv[] ) { int i; char fn_inspeech[80], fn_outspeech[80]; FILE *fin, *fout; int numread, nsamp; float temp[MAXSF]; unsigned long frame_num; unsigned long total_frames; unsigned long fer_count; struct ENCODER_MEM encoder_memory; struct DECODER_MEM decoder_memory; struct PACKET packet; struct CONTROL control; int input_format; int output_format; #if USE_CALLOC float *in_speech; float *out_speech; #else float in_speech[FSIZE+LPCSIZE-FSIZE+LPCOFFSET]; float out_speech[FSIZE]; #endif memset(&encoder_memory, 0, sizeof(encoder_memory)); memset(&decoder_memory, 0, sizeof(decoder_memory)); memset(&packet, 0, sizeof(packet)); memset(&control, 0, sizeof(control)); #if USE_CALLOC alloc_mem_for_speech(&in_speech, &out_speech); #endif for(i = 0; i < argc; i++) fprintf(stdout, "%s ", argv[i]); fprintf(stdout, "\n"); parse_command_line(argc, argv, fn_inspeech, fn_outspeech, &control); initialize_encoder_and_decoder(&encoder_memory, &decoder_memory, &control); print_welcome_message(); /*** Init TTY/TDD Routines and Varibles ***/ if( tty_debug_flag ) tty_debug(); if( tty_option == TTY_NO_GAIN ) { fprintf(stdout," TTY OPTION = NO GAIN\n"); init_tty_enc( &tty_enc_char, &tty_enc_header, &tty_enc_baud_rate); init_tty_dec(); } else { tty_option = 0; fprintf(stdout," TTY OPTION = OFF\n"); } if( trans_fname != NULL ) { fprintf(stdout,"FER SIMULATOR ON: seed = %d\n",fer_sim_seed); } for(i = 0; i < LPCORDER; i++) packet.lsp[i] = packet.lpc[i] = 0; encoder_memory.frame_num = 0; frame_num = 0; fer_count = 0; if (control.decode_only == YES) { /* Input is a CELP file */ switch (control.celp_file_format) { case FORMAT_PACKET: open_binary_input_file(&fin, fn_inspeech); total_frames = GetNumFrames(fin, sizeof(short)*WORDS_PER_PACKET); input_format = FORMAT_PACKET; break; case FORMAT_QCP: open_qcp_input_file(&fin, fn_inspeech); total_frames = get_qcp_packet_count(); input_format = FORMAT_QCP; break; default: fprintf(stderr, "unsupported decode_only input format %d\n", control.celp_file_format); exit(-2); } } else { /* Input is an audio file */ open_binary_input_file(&fin, fn_inspeech); input_format = FORMAT_RAW_AUDIO; total_frames = GetNumFrames(fin, sizeof(short)*FSIZE); } if ((control.form_res_out == YES) || (control.target_after_out == YES) || (control.cb_out == YES) || (control.pitch_out == YES)) { /* Output is encoder state for debugging */ open_binary_output_file(&fout, fn_outspeech); output_format = FORMAT_DEBUG_OUTPUT; } else if (control.encode_only == YES) { /* Output is a CELP file */ switch (control.celp_file_format) { case FORMAT_PACKET: open_binary_output_file(&fout, fn_outspeech); output_format = FORMAT_PACKET; break; case FORMAT_QCP: open_qcp_output_file(&fout, fn_outspeech, total_frames); output_format = FORMAT_QCP; break; default: fprintf(stderr, "unsupported encode_only output format %d\n", control.celp_file_format); exit(-2); } } else { /* Output is an audio file */ open_binary_output_file(&fout, fn_outspeech); output_format = FORMAT_RAW_AUDIO; } if(control.decode_only == NO) { #if 0 if (read_samples(fin, in_speech, LPCSIZE-FSIZE+LPCOFFSET) !=LPCSIZE-FSIZE+LPCOFFSET) { printf("Not even enough samples for 1 frame!\n"); usage(&control); } #else for( i=0 ; i < LPCSIZE-FSIZE+LPCOFFSET ; i++ ) { in_speech[i] = 0; } #endif } /*----------------------------------------------- * Main Loop *------------------------------------------------*/ while( control.num_frames == UNLIMITED || frame_num < control.num_frames ) { fprintf(stderr,"Processing %lu of %lu FER = %.2f%%\r", frame_num, total_frames, 100.0*fer_count/(frame_num+1)); if (control.decode_only==NO) { nsamp = read_samples(fin, &in_speech[LPCSIZE-FSIZE+LPCOFFSET], FSIZE); if( nsamp <= 0 ) { break; } else if(nsamp < FSIZE) { for (i=nsamp; i<FSIZE; i++) { in_speech[LPCSIZE-FSIZE+LPCOFFSET+i]=0; } } encoder(in_speech, &packet, &control, &encoder_memory, out_speech); update_snr(ENCODER, in_speech, out_speech, &(control.snr)); } if (control.decode_only==YES) { if (input_format == FORMAT_QCP) { numread = read_qcp_packet(fin, packet.data, WORDS_PER_PACKET); if (numread == 0) break; } else { /* FORMAT_PACKET */ numread = read_packet(fin, packet.data, WORDS_PER_PACKET); if( numread != WORDS_PER_PACKET) { if(numread != 0) { fprintf(stderr, "%s: Wrong number of words read: %d\n", argv[0], numread); } break; } } } if(control.encode_only==NO) { if (control.output_encoder_speech==NO) { decoder(out_speech, &packet, &control, &decoder_memory); if( packet.data[0] == ERASURE ) { fer_count++; } if(control.decode_only==NO) { update_snr(DECODER, in_speech, out_speech, &(control.snr)); } } i = write_samples(fout,out_speech,FSIZE); } else { if( trans_fname != NULL ) { fer_sim( &(packet.data[0]) ); } if( packet.data[0] == ERASURE ) { fer_count++; } if (output_format == FORMAT_QCP) { i = write_qcp_packet(fout, packet.data, WORDS_PER_PACKET); } else { i = write_packet(fout, packet.data, WORDS_PER_PACKET); } } /***** Update in_speech buffer ***************/ for (i=0; i<LPCSIZE-FSIZE+LPCOFFSET; i++) { in_speech[i]=in_speech[i+FSIZE]; } frame_num++; encoder_memory.frame_num = frame_num; } /* end main while() */ if (output_format == FORMAT_QCP) { finish_qcp_output_file(fout); } fclose(fin); fclose(fout); if ((control.encode_only==NO)&&(control.decode_only==NO)) { compute_snr(&(control.snr), &control); } if( control.decode_only == NO ) { /* calculate the avg. rate for active speech for the entire file */ temp[0] = (encoder_memory.full_cnt + encoder_memory.full_force + encoder_memory.full_cnt_t + encoder_memory.full_force_t)*14.4+ (encoder_memory.half_cnt + encoder_memory.half_force + encoder_memory.half_cnt_t + encoder_memory.half_force_t)*7.2+ (encoder_memory.quarter_cnt + encoder_memory.quarter_cnt_t)*3.6; temp[0] /= (encoder_memory.total_speech_frames+ (STATWINDOW-encoder_memory.block_cnt)); if(control.reduced_rate_flag != 0) { printf("\n The target_snr_threshold at the end of the run was %f", encoder_memory.target_snr_thr); printf("\n The average rate for the entire file was %f",temp[0]); i = STATWINDOW-encoder_memory.block_cnt+encoder_memory.total_speech_frames; temp[1] = i; printf("\n The # of speech frames in the file is = %d",i); i = encoder_memory.full_cnt+encoder_memory.full_cnt_t; printf("\n The percent of frames at 14.4 is %f",100.0*i/temp[1]); i = encoder_memory.full_force+encoder_memory.full_force_t; printf("\n The percent of frames forced to 14.4 is %f",100.*i/temp[1]); i = encoder_memory.half_cnt+encoder_memory.half_cnt_t; printf("\n The percent of frames at 7.2 is %f",100.*i/temp[1]); i = encoder_memory.half_force+encoder_memory.half_force_t; printf("\n The percent of frames forced to 7.2 is %f",100.*i/temp[1]); i = encoder_memory.quarter_cnt+encoder_memory.quarter_cnt_t; printf("\n The percent of frames coded at 3.6 is %f\n",100.*i/temp[1]); } } if(control.encode_only == NO) print_erasure_count(); free_encoder_and_decoder(&encoder_memory, &decoder_memory); #if USE_CALLOC free((char*) in_speech); free((char*) out_speech); #endif print_farewell_message(); exit(0); }/* end of main() */