int download_file(char* url, char* filename) { FILE *fp; CURL *curl; CURLcode download_status = CURLE_FAILED_INIT; if ((curl = curl_easy_init()) != NULL) { open_binary_output_file(&fp, filename); set_curl_options (curl, url, write_data_callback, fp); download_status = perform_curl_download(curl); fclose(fp); } if (download_status == CURLE_OK) return 1; else return 0; }
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() */