int main(int argc, char * argv[]) { fprintf(stdout, "This is bsc, Block Sorting Compressor. Version 3.0.0. 26 August 2011.\n"); fprintf(stdout, "Copyright (c) 2009-2011 Ilya Grebnov <*****@*****.**>.\n\n"); #if defined(_OPENMP) && defined(__INTEL_COMPILER) kmp_set_warnings_off(); #endif ProcessCommandline(argc, argv); if (bsc_init(paramEnableLargePages ? LIBBSC_FEATURE_LARGEPAGES : LIBBSC_FEATURE_NONE) != LIBBSC_NO_ERROR) { fprintf(stderr, "\nInternal program error, please contact the author!\n"); exit(2); } switch (*argv[1]) { case 'e' : case 'E' : Compression(argv); break; case 'd' : case 'D' : Decompression(argv); break; default : ShowUsage(); } return 0; }
int main(int argc,char **argv) { int filedes1,filedes2; if(argc!=3)//checking for number of arguments { printf("\nHey argument must be 3!!"); printf("\nThe correct format is ./MyCompress <inputfilename> <outputfilename>\n"); //exit(0); } else { printf("You have given correct number of Arguments\n"); strncpy(ipfile,argv[1],MAXLEN-1);//Storing the input and output file name from arugments strncpy(opfile,argv[2],MAXLEN-1); printf(" ip:%s\n op:%s\n",ipfile,opfile); filedes1=open(ipfile,O_RDONLY); if(filedes1==-1) { printf("\nCannot open file : %s\n",ipfile); } filedes2=open(opfile,O_CREAT|O_RDWR,S_IRUSR|S_IWUSR|S_IRWXU|S_IRGRP|S_IROTH); Compression(filedes1,filedes2); close(filedes1); close(filedes2); return 0; } }//End of Main
int main(int argc, char ** argv){ int fd_in, fd_out; if(argc != 4){ fprintf(stderr, "Usage %s -[cd] <fichier entrée> <fichier sortie>\n", argv[0]); return EXIT_FAILURE; } if(argv[1][0] != '-'){ fprintf(stderr, "Usage %s -[cd] <fichier entrée> <fichier sortie>\n", argv[0]); return EXIT_FAILURE; } if(argv[1][1] == 'c'){ //Quand on veut compresser un fichier if((fd_in = open(argv[2],O_RDONLY)) == -1){ perror("open fd_in"); exit(1); } if((fd_out = open(argv[3],O_WRONLY|O_CREAT|O_TRUNC,0600)) == -1){ perror("open fd_out"); exit(2); } Compression(fd_in,fd_out); }else if(argv[1][1] == 'd'){ //Quand on veut decompresser un fichier if((fd_in = open(argv[2],O_RDONLY)) == -1){ perror("open fd_in"); exit(1); } if((fd_out = open(argv[3],O_WRONLY|O_CREAT|O_TRUNC,0600)) == -1){ perror("open fd_out"); exit(2); } Decompression(fd_in,fd_out); }else{ fprintf(stderr, "Usage %s -[cd] <fichier entrée> <fichier sortie>\n", argv[0]); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int source = 0, target = 0, funcsion = 0, i; clock_t start, end; if (argc < 6) { printf("\n程序参数输入有误!\n\n"); Instruction(argv[0]); return EXIT_FAILURE; } start = clock(); //参数解析 for (i = 1; i < 6; ++i) { if (!strcmp(argv[i], "-c")) { funcsion = i; } else if (!strcmp(argv[i], "-s")) { if (i != 5) { source = i + 1; } else { printf("参数输入有误!\n\n"); Instruction(argv[0]); return EXIT_FAILURE; } } else if (!strcmp(argv[i], "-t")) { if (i != 5) { target = i + 1; } else { printf("参数输入有误!\n\n"); return EXIT_FAILURE; } } else if (!strcmp(argv[i], "-d")) { funcsion = i; } } if ((!strcmp(argv[funcsion], "-c")) && source != 0 && target != 0) { if (Compression(argv[source], argv[target]) == 0) { printf("压缩失败!\n"); return EXIT_FAILURE; } else { end = clock(); printf("压缩时间:%lf秒\n\n",((double)end - start) / CLOCKS_PER_SEC); } } else if ((!strcmp(argv[funcsion], "-d")) && source != 0 && target != 0) { if (Decompression(argv[source], argv[target]) == 0) { printf("解压缩失败!\n"); return EXIT_FAILURE; } else { end = clock(); printf("解压成功!\n"); printf("解压缩时间:%lf秒\n\n",((double)end - start) / CLOCKS_PER_SEC); } } else { printf("命令错误!\n"); Instruction(argv[0]); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { /* Start counter */ double time1 = (double)clock(); /* Check command line format */ if(Check_command_line(argc) == EXIT_FAILURE) return EXIT_FAILURE; /* Read default configuration file and assign parameters */ struct config_t *conf_def = Read_config(argv[2]); if(conf_def == NULL) return EXIT_FAILURE; PARAM params; if(Assign_config_parameters(argv[1],conf_def,¶ms,DEF_CONF) == EXIT_FAILURE) { config_destroy(conf_def); free(conf_def); return EXIT_FAILURE; } /* Read user configuration file and assign parameters */ if(argc == 4) { struct config_t *conf_usr = Read_config(argv[3]); if(conf_usr == NULL) return EXIT_FAILURE; if(Assign_config_parameters(argv[1],conf_usr,¶ms,USR_CONF) == EXIT_FAILURE) { config_destroy(conf_usr); free(conf_usr); return EXIT_FAILURE; } } /* Print synthesis settings */ Print_synthesis_settings_start(¶ms); /*******************************************************************/ /* READ PULSE LIBRARY / PULSE */ /*******************************************************************/ /* Allocate space for pulse library and read data */ gsl_matrix *pulses,*pulses_rs,*plsf,*ptilt,*pharm,*phnr,*pwaveform,*pca_pc,*pca_w_lib; gsl_vector *pgain,*pulse_lengths,*ph1h2,*pnaq,*pca_mean,*stoch_env,*stoch_sp; if(Read_pulse_library(¶ms,&pulses,&pulses_rs,&plsf,&ptilt,&pharm,&phnr,&pwaveform,&pca_pc, &pca_w_lib,&stoch_env,&stoch_sp,&pgain,&ph1h2,&pnaq,&pca_mean,&pulse_lengths) == EXIT_FAILURE) return EXIT_FAILURE; /* Read pulse file if pulse library is not used */ gsl_vector *original_pulse = NULL; if(params.use_pulselib == 0) { original_pulse = ReadPulseFile(¶ms); if(original_pulse == NULL) return EXIT_FAILURE; } /* Read DNN pulse generation weights and allocate parameters */ gsl_matrix **DNN_W = (gsl_matrix**)malloc(params.dnn_weight_dims->size/2*sizeof(gsl_matrix*)); if(Read_DNN_weights(¶ms,DNN_W) == EXIT_FAILURE) return EXIT_FAILURE; gsl_vector **input_minmax = (gsl_vector**)malloc(sizeof(gsl_vector*)); if(Read_input_minmax(¶ms,input_minmax) == EXIT_FAILURE) return EXIT_FAILURE; gsl_vector *dnnpulseindices = NULL; gsl_vector *dnnpulses = NULL; /* Define variables */ gsl_vector *gain,*fundf,*excitation_voiced,*excitation_unvoiced; gsl_vector *gain_new,*pulse_clus_id,*h1h2,*naq,*resynthesis_pulse_index; gsl_matrix *LSF,*LSF2,*glflowsp,*glflowsp_new,*hnr,*hnr_new,*harmonics,*waveform,*pulse_clusters,*pca_w,*LSF_interp = NULL; int i; /****************************************************************************************/ /* START SYNTHESING FILE(S) */ /****************************************************************************************/ /* Start loop for synthesis list */ for(i=0; i<params.synlistlen; i++) { /* Initialize params */ if(Initialize_params(¶ms,i) == EXIT_FAILURE) return EXIT_FAILURE; /* Print synthesis settings */ Print_synthesis_settings_middle(¶ms); /* Compatibility check */ if(Compatibility_check(¶ms) == EXIT_FAILURE) return EXIT_FAILURE; /*****************************************************************************/ /* LOAD AND MODIFY PARAMETERS */ /*****************************************************************************/ /* Allocate and read synthesis parameters, initialize pulse clustering if used */ Allocate_params(&excitation_voiced,&excitation_unvoiced,&resynthesis_pulse_index,&gain_new,&glflowsp_new,&hnr_new,¶ms); if(Read_synthesis_parameters(&gain,&fundf,&LSF,&LSF2,&glflowsp,&hnr,&harmonics,&waveform,&h1h2,&naq,&pca_w,¶ms) == EXIT_FAILURE) continue; if(Pulse_clustering(&pulse_clus_id, &pulse_clusters, ¶ms) == EXIT_FAILURE) continue; /* Miscellaneous operations */ Convert_logF0_to_lin(fundf,¶ms); Merge_voiced_unvoiced_spectra(LSF,LSF2,fundf,¶ms); Integrate_LSFs(&LSF,¶ms); if(params.use_tilt == 1) Integrate_LSFs(&glflowsp,¶ms); LSF_fix_matrix(LSF); LSF_fix_matrix(glflowsp); Smooth_matrix(hnr,params.hnr_smooth_len); if(params.use_hmm == 0) Smooth_matrix(harmonics,params.harmonics_smooth_len); if(params.use_hmm == 0) MA(gain,params.gain_smooth_len); /* Modification for noise robust speech */ Noise_robust_speech2(gain,harmonics,¶ms); /* Formant enhancement for LSFs */ Postfilter(LSF,¶ms); /* Apply noise reduction */ Noise_reduction(gain,¶ms); /* Normalize pulse library parameters according to synthesis parameters (normalize mean) */ Normalize_pulse_library_var(plsf,ptilt,pharm,phnr,pwaveform,pgain,ph1h2,pnaq,LSF,glflowsp, harmonics,hnr,waveform,gain,h1h2,naq,fundf,¶ms); /* Adapt synthesis parameters according to pulse library parameters (normalize mean) */ Adapt_synthesis_parameters_var(plsf,ptilt,pharm,phnr,pwaveform,pgain,ph1h2,pnaq,LSF,glflowsp, harmonics,hnr,waveform,gain,h1h2,naq,fundf,pulse_lengths,¶ms); /* Select vocal tract LSFs from pulse library */ // TODO: Viterbi int winsize = 5; Select_LSFs_from_pulse_library(LSF,plsf,fundf,winsize,¶ms); /* Smooth and interpolate LSFs to signal length */ LSF_interp = gsl_matrix_alloc(params.signal_length,params.lpc_order_vt); Smooth_interp_lsf(LSF_interp,LSF,params.signal_length,params.use_hmm,params.lsf_smooth_len); /* DNN pulse gen */ if(params.use_dnn_pulsegen == 1) { dnnpulseindices = gsl_vector_alloc(params.signal_length); dnnpulses = gsl_vector_alloc(2*params.signal_length); } /*******************************************************************/ /* CREATE EXCITATION */ /*******************************************************************/ printf(" - Creating excitation...\n"); /* Create excitation for estimating the HNR of the voiced excitation */ CreateExcitation(¶ms,excitation_voiced,excitation_unvoiced,fundf,gain,LSF,glflowsp,hnr,harmonics,waveform,h1h2,naq, original_pulse,pulses,pulses_rs,pulse_lengths,pgain,plsf,ptilt,phnr,pharm,pwaveform,ph1h2,pnaq, resynthesis_pulse_index,pulse_clus_id,pulse_clusters,gain,glflowsp_new,hnr_new,pca_mean,pca_pc,pca_w,pca_w_lib, stoch_env,stoch_sp,DNN_W,input_minmax,dnnpulseindices,dnnpulses); /* Compensate HNR etc */ HNR_compensation(hnr,hnr_new,¶ms); Fill_pulse_indices(resynthesis_pulse_index); params.resynth = 1; /* Create excitation */ CreateExcitation(¶ms,excitation_voiced,excitation_unvoiced,fundf,gain,LSF,glflowsp,hnr,harmonics,waveform,h1h2,naq, original_pulse,pulses,pulses_rs,pulse_lengths,pgain,plsf,ptilt,phnr,pharm,pwaveform,ph1h2,pnaq, resynthesis_pulse_index,pulse_clus_id,pulse_clusters,gain,glflowsp_new,hnr_new,pca_mean,pca_pc,pca_w,pca_w_lib, stoch_env,stoch_sp,DNN_W,input_minmax,dnnpulseindices,dnnpulses); Print_elapsed_time(¶ms); /* Compensate for the pre-emphasis during analysis (de-emphasis) */ if(params.unvoiced_pre_emphasis == 1) Integrate(excitation_unvoiced, 0.97); // Slightly less than leaky factor /*******************************************************************/ /* SPECTRAL MATCHING */ /*******************************************************************/ if((params.use_pulselib == 0 && params.use_dnn_pulsegen == 0) || (params.use_pulselib_pca == 1 && params.pca_spectral_matching == 1) || (params.use_dnn_pulsegen == 1 && params.use_dnn_specmatch == 1)) { printf(" - Spectral matching...\n"); Spectral_match(excitation_voiced, glflowsp, glflowsp_new, ¶ms); if(params.use_pulselib_pca == 0 && params.use_dnn_pulsegen == 0 && params.two_pitch_period_diff_pulse == 0) LipRadiation(excitation_voiced); Print_elapsed_time(¶ms); } /*******************************************************************/ /* FILTER EXCITATION */ /*******************************************************************/ /* Combine excitations and filter */ printf(" - Filtering excitation...\n"); gsl_vector_add(excitation_voiced,excitation_unvoiced); Filter_excitation(excitation_voiced,LSF_interp,¶ms); Print_elapsed_time(¶ms); /*******************************************************************/ /* RESYNTHESIS FOR GAIN NORMALIZATION */ /*******************************************************************/ /* Evaluate new gain for re-synthesis */ printf(" - Re-synthesis for gain normalization...\n"); Evaluate_new_gain(excitation_voiced,gain_new,gain,fundf,¶ms); /* Re-synthesize with new gain */ CreateExcitation(¶ms,excitation_voiced,excitation_unvoiced,fundf,gain_new,LSF,glflowsp,hnr,harmonics,waveform,h1h2,naq, original_pulse,pulses,pulses_rs,pulse_lengths,pgain,plsf,ptilt,phnr,pharm,pwaveform,ph1h2,pnaq, resynthesis_pulse_index,pulse_clus_id,pulse_clusters,gain,glflowsp_new,hnr_new,pca_mean,pca_pc,pca_w,pca_w_lib, stoch_env,stoch_sp,DNN_W,input_minmax,dnnpulseindices,dnnpulses); if(params.unvoiced_pre_emphasis == 1) Integrate(excitation_unvoiced, 0.97); // Slightly less than leaky factor /* Spectral matching */ if((params.use_pulselib == 0 && params.use_dnn_pulsegen == 0) || (params.use_pulselib_pca == 1 && params.pca_spectral_matching == 1) || (params.use_dnn_pulsegen == 1 && params.use_dnn_specmatch == 1)) { Spectral_match(excitation_voiced, glflowsp, glflowsp_new, ¶ms); if(params.use_pulselib_pca == 0 && params.use_dnn_pulsegen == 0 && params.two_pitch_period_diff_pulse == 0) LipRadiation(excitation_voiced); } /* Combine excitations and filter */ gsl_vector_add(excitation_voiced,excitation_unvoiced); /* Save excitation to wav file */ Save_excitation_to_wav(excitation_voiced,¶ms); /* Filter excitation */ Filter_excitation(excitation_voiced,LSF_interp,¶ms); /*******************************************************************/ /* POSTPROCESSING AND SAVE TO FILE */ /*******************************************************************/ /* Filter out signal below F0 */ Hp_filt_below_f0(excitation_voiced,fundf,¶ms); /* Compression of speech signal (only in noise robust speech) */ Compression(excitation_voiced, params.compcoeff); /* Scale (if > 1) and save signal to file */ Scale_signal(excitation_voiced,SCALE_IF_GREATER_THAN_ONE); Save_signal_to_file(excitation_voiced,¶ms,NULL); /* Report */ Print_synthesis_settings_end(¶ms,time1); } /*******************************************************************/ /* FREE MEMORY AND FINISH */ /*******************************************************************/ /* Free memory */ Free_pulselib_variables(pulses,pulses_rs,pwaveform,pulse_lengths,plsf,ptilt,pharm,phnr,pgain,ph1h2,pnaq,pca_mean,pca_pc,pca_w_lib,stoch_env,stoch_sp,¶ms); Free_variables(original_pulse,excitation_voiced,excitation_unvoiced,fundf,gain,gain_new,LSF,LSF2,LSF_interp,glflowsp,glflowsp_new, hnr,hnr_new,harmonics,waveform,h1h2,naq,resynthesis_pulse_index,pulse_clus_id,pulse_clusters,pca_w, DNN_W,input_minmax,dnnpulseindices,dnnpulses,¶ms); /* Exit */ return EXIT_SUCCESS; }