// file: $ECE_8993/util/calculate_lpc/v1.0/calculate_lpc.cc // // this program calculates the lpc model of a window of data // // system include files // #include // isip include files // #include "calculate_lpc.h" #include #include "calculate_lpc_constants.h" #include // main program // main(int argc, char** argv) { // declare local variables // logical_1 use_hamming = CLPC_DEF_USE_HAMMING; // flag for use of hamming wind logical_1 apply_pre_emphasis = CLPC_DEF_PRE_EMPH; // flag for use of pre-emphasis float_4 pre_emph_coeff = CLPC_DEF_PRE_EMPH_COEFF; float_4 window_dur = CLPC_DEF_WINDOW_DUR; // window duration in msecs float_4 sample_freq = CLPC_DEF_SF; // sample frequency int_4 num_chans = (int_4)1; // number of channels in data logical_1 swap_byte = CLPC_DEF_SWAP; // whether or not to swap bytes int_4 lp_order = CLPC_DEF_LP_ORDER; // order of the lp model float_4 mid_time = CLPC_DEF_MID_TIME; // order of the lp model char_1* input_file = (char_1*)NULL; // name of input data file int_4 debug_mode = ISIP_DEBUG_NONE; // debugging mode // allocate memory for the input file name // input_file = new char_1[ISIP_MAX_FNAME_SIZE]; // get the command line parameters // if (get_parameter_cc(argc, argv, use_hamming, apply_pre_emphasis, pre_emph_coeff, window_dur, sample_freq, swap_byte, lp_order, mid_time, input_file, debug_mode) == ISIP_FALSE) { // output error message and exit // fprintf(stderr, "%s : Error reading command line parameters\n", argv[0]); exit(ISIP_ERROR); } // allocate memory for the signal data // Signal data_sig; // set the parameters of the signal object // data_sig.set_cc(input_file, num_chans, CLPC_NUM_BYTES, sample_freq, swap_byte); // open the signal file // if (data_sig.open_cc(input_file, ISIP_READ_ONLY) == ISIP_FALSE) { // output error message and exit // fprintf(stderr, "%s : Error opening file %s\n", argv[0], input_file); exit(ISIP_ERROR); } // determine the number of samples that will make up a window of data // int_4 window_num_samples = (int_4)rint((window_dur * sample_freq)); // allocate memory for the window buffer // float_4* window_buffer = new float_4[window_num_samples]; // zero out a single window buffer // memset((void*)window_buffer, (int)0, (window_num_samples * sizeof(float_4))); // set the start sample of the window // int_4 start_samp = (int_4)(mid_time * sample_freq) - (window_num_samples / (int_4)2); // position a pointer within the window and determine the number of samples // that will be read // float_4* data_ptr = window_buffer; int_4 num_samps_to_read = window_num_samples; if (start_samp < (int_4)0) { data_ptr = data_ptr + start_samp; num_samps_to_read += start_samp; start_samp = 0; } // set a variable for the number of variables read // int_4 num_samps_read = (int_4)0; // read in the window of data // data_sig.read_cc(data_ptr, start_samp, (start_samp + num_samps_to_read), num_samps_read); // close the signal file // data_sig.close_cc(); // print the data // if (debug_mode > ISIP_DEBUG_NONE) { for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "WINDOW_DATA: index = %ld value = %.6f \n", i, window_buffer[i]); } } // debias the input signal // debias_cc(window_buffer, window_num_samples); // print the debiased/pre-emphasized data // if (debug_mode > ISIP_DEBUG_NONE) { for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "AFTER_DEBIAS: index = %ld value = %.6f \n", i, window_buffer[i]); } } // preemphasize the data if necessary // if (apply_pre_emphasis == ISIP_TRUE) { pre_emphasize_data_cc(window_buffer, window_num_samples, num_chans, pre_emph_coeff); } // print the debiased/pre-emphasized data // if (debug_mode > ISIP_DEBUG_NONE) { for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "AFTER_PRE_EMPH: index = %ld value = %.6f \n", i, window_buffer[i]); } } // apply the hamming window if necessary // if (use_hamming == ISIP_TRUE) { window_hamming_cc(window_buffer, window_num_samples, num_chans); } // print the hamming-windowed data // if (debug_mode > ISIP_DEBUG_NONE) { for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "AFTER_HAMMING: index = %ld value = %.6f \n", i, window_buffer[i]); } } // allocate memory for the dft coefficients and the lp spectrum coefficients // float_4* dft_coeffs = new float_4[window_num_samples]; float_4* lp_spectrum_coeffs = new float_4[window_num_samples]; // compute the dft of the data // compute_dft_cc(window_buffer, dft_coeffs, window_num_samples); // print the dft data // if (debug_mode > ISIP_DEBUG_NONE) { for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "DFT_SPECTRUM: index = %ld value = %.6f \n", i, dft_coeffs[i]); } } // compute the lpc coefficients of the data // compute_lp_cc(window_buffer, lp_spectrum_coeffs, window_num_samples, lp_order); // print the lpc data // if (debug_mode > ISIP_DEBUG_NONE) { for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "LPC SPECTRUM: index = %ld value = %.6f \n", i, lp_spectrum_coeffs[i]); } } // print the dft data and the lpc data // for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "%.6f %.6f\n", ((float_4)i * sample_freq / (float_4)window_num_samples), (float_4)20.0 * log10(dft_coeffs[i])); } fprintf (stdout, "\n"); for (int_4 i = (int_4)0; i < window_num_samples; i++) { fprintf(stdout, "%.6f %.6f\n", ((float_4)i * sample_freq / (float_4)window_num_samples), (float_4)20.0 * log10(lp_spectrum_coeffs[i])); } // clean up // delete [] input_file; delete [] window_buffer; delete [] dft_coeffs; delete [] lp_spectrum_coeffs; // return without error // return ISIP_NO_ERROR; }