// file: clpc_file_0.cc // // this function reads in the data // // system include file // #include // local include file // #include "global_constants.h" #include "calculate_lpc_constants.h" #include "calculate_lpc.h" // function: read_signal_cc // // arguments: // float*& signal_window_a: (output) buffer contain the signal // int num_chans_a: (input) number of channels // int start_time_a: (input) starting time of window // char* datafile_a: (input) name of data file // int debug_mode_a: (input) debug level // // return: an int to indicate status // // this function parses the command line arguments // // int read_signal_cc (float*& signal_window_a, int num_chans_a, int start_sample_a, int end_sample_a, int end_file_sample_a, char* datafile_a, int debug_mode_a) { if (datafile_a == (char*)NULL) { fprintf(stdout, "NULL buffer\n"); return FALSE; } // open the file // FILE* fp = fopen(datafile_a, "r"); if (fp == (FILE*)NULL) { fprintf(stdout, "Unable to open %s\n", datafile_a); return FALSE; } // make sure that start and end sample are within bounds // int new_start = start_sample_a; int new_end = end_sample_a; int num_samples = 0; if (start_sample_a < 0) { // pad it with 0s if window starts before file starts // for (int i = start_sample_a; i < 0; i++) { signal_window_a[num_samples++] = 0; } new_start = 0; } if (end_sample_a > end_file_sample_a) { new_end = end_file_sample_a; } if (new_start > new_end) { // fprintf(stdout, "start sample is greater than end sample\n"); return FALSE; } // seek to the point in the file we want to read the data // fseek(fp, (int)new_start * CLPC_BYTES_PER_SAMPLE * num_chans_a, SEEK_SET); int samples_read = (new_end - new_start) * num_chans_a; short int* temp_values = new short int[samples_read]; fread(temp_values, sizeof(short int), samples_read, fp); for (int i = 0; i < samples_read; i++) { // convert short int to floating point values // signal_window_a[num_samples++] = (float)temp_values[i]; } // pad it with 0s if window ends after file ends // if (end_sample_a > end_file_sample_a) { for (int i = end_file_sample_a; i < end_sample_a; i++) { signal_window_a[num_samples++] = 0; } } if (debug_mode_a > DEBUG_FULL) { for (int chan = 0; chan < num_chans_a; chan++) { for (int sample = chan; sample < num_samples; sample += num_chans_a) { fprintf(stdout, "chan %d :: signal data [%d] = %.6f\n", chan, sample, signal_window_a[sample]); } } fprintf(stdout, "\n"); } // close the file // fclose(fp); if (temp_values != (short int*)NULL) { delete [] temp_values; temp_values = (short int*)NULL; } // exit gracefully // return TRUE; }