// file: $SPEECH_HOMEWORK4/hw4/class/snr_ratio/v1.0/snr_proc_0.cc // // isip include files // #include #include "signal_noise_ratio.h" #include "signal_noise_ratio_constants.h" // method: process_data_cc // // arguments: // float_4** energy (output) the energy signal for each sample frame // at each channel // int_4& num_energy (output) the total number of energy signals // int_4 samples_per_frame (input) the number of samples in one frame // int_4 samples_per_window (input) the number of samples in one window // int_4 total_num_frames (input) the total number of frames // // return: a logical_1 indicating status // logical_1 Signal::process_data_cc (float_4**& energy_a, int_4& num_energy_a, int_4 samples_per_frame_a, int_4 samples_per_window_a, int_4 total_num_frames_a) { // check arguments // if (samples_per_frame_a <= 0) { error_handler_cc((char_1*)"process_data_cc", (char_1*)"invalid number of samples per frame"); } if (samples_per_window_a <= 0) { error_handler_cc((char_1*)"process_data_cc", (char_1*)"invalid number of samples per window"); } if (total_num_frames_a <= 0) { error_handler_cc((char_1*)"process_data_cc", (char_1*)"invalid number of frames"); } // set up a buffer to keep up with the window // float_4* buffer = new float_4[samples_per_window_a * num_chans_d]; memset((void*)buffer, 0, samples_per_window_a * sizeof(float_4) * num_chans_d); // set up counters to keep track of the samples // int_4 offset = int_4 (rint((samples_per_window_a - samples_per_frame_a)/2)); int_4 start = -offset; int_4 end = samples_per_frame_a + offset; int_4 last_sample = calculate_file_size_cc(input_file_d) / (num_bytes_d * num_chans_d); int_4 samples_read = 0; // open input file // FILE* fp_a = fopen((char*)input_file_d, "r"); // loop through data // while (read_cc(fp_a, buffer, start, end, last_sample, samples_read) == ISIP_TRUE) { // do pre-emphasize // if (pre_emphasize_d == ISIP_TRUE) { perform_pre_emphasis_cc(buffer, samples_per_window_a); } // apply window methods // if (window_method_d != SIGNAL_WINDOW_METHOD_NONE) { perform_hamming_window_cc(buffer, samples_per_window_a); } // calculate the energy for all the channels // calculate_energy_cc(buffer, samples_per_window_a, num_energy_a, energy_a[num_energy_a++]); // reset buffer // memset((void*)buffer, 0, (samples_per_window_a * sizeof(float_4) * num_chans_d)); // move the start to the beginning of next window // start += samples_per_frame_a; end += samples_per_frame_a; // make sure the end time is within the correct boundary // if (end > last_sample) { end = last_sample; } } fclose(fp_a); // clean up // delete [] buffer; // exit gracefully // return ISIP_TRUE; }