// file: $SPEECH_HOMEWORK4/hw4/class/snr_ratio/v1.0/snr_read_0.cc // // isip include files // #include "signal_noise_ratio.h" #include "signal_noise_ratio_constants.h" #include // method: read_cc // // arguments: // FILE* fp (input) pointer to the input file // float_4*& buffer (output) the buffer to fill // int_4 start (input) the starting point to read // int_4 end (input) the end point to read // int_4 num_samples (input) the number of samples to read // // return: a logical_1 indicating status // logical_1 Signal::read_cc (FILE* fp_a, float_4*& buffer_a, int_4 start_a, int_4 end_a, int_4 last_sample_a, int_4& samples_read_a) { // check arguments // if (fp_a == (FILE*)NULL) { error_handler_cc((char_1*)"read_cc", (char_1*)"input file is not opened"); } // rewind the file pointer // rewind(fp_a); if (end_a > last_sample_a) { end_a = last_sample_a; } // make sure the end time is within the correct boundary // if (start_a > end_a) { return ISIP_FALSE; } int_4 sample = 0; if (start_a < 0) { // pad with zeros // for (int_4 i=start_a;i<0;i++) { buffer_a[sample++] = 0; } start_a = 0; } // seek to the starting of the first sample to process // fseek(fp_a, start_a * SIGNAL_BYTES_PER_SAMPLE * num_chans_d, SEEK_SET); // calculate the number of samples to read // int_4 num_samples_to_read = (end_a - start_a) * num_chans_d; if (num_samples_to_read > (last_sample_a - start_a)) { num_samples_to_read = last_sample_a - start_a; } int_2* read_data = new int_2[num_samples_to_read]; // read the data // samples_read_a = fread(read_data, sizeof(int_2), num_samples_to_read, fp_a); if (num_samples_to_read != samples_read_a) { error_handler_cc((char_1*)"read_cc", (char_1*)"incorrect number of samples read"); } // int_4 read_value; for (int_4 i=0;i 2) { for (int_4 i=0;i