⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sig_read_0.cc

📁 这是处理语音信号的程序
💻 CC
字号:
// file: sig_read_0.cc//// isip include files//#include "Signal.h"#include "signal_constants.h"// method: read_cc//// arguments://   float_8*& data: (output) portion of the signal to output. this memory//                   is allocated internally. pointer must be null on entry//   float_8 start_time: (input) beginning point of the desired data//   float_8 end_time: : (input) end point of the desired data//   int_4 channel: : (input) channel being processed//   int_4& num_samples: : (output) number of samples read//// return: logical_1 indicating status//// this method gets the desired time window. if the start time is less than// zero, then the start of the data is at 0.0. if the end time is greater than// the end of the file, then the end time is set to the end of the file.// if the end time is less than the start time, then an error is returned.//logical_1 Signal::read_cc(float_8*& data_a, float_8 start_time_a,			  float_8 end_time_a, int_4 channel_a,			  int_4& num_samples_a) {  // zero out the number of samples  //  num_samples_a = (int_4)0;    // make sure that the file is open  //  if (fp_d == (FILE*)NULL) {    // return with error    //    error_handler_cc((char_1*)"read_cc", (char_1*)"signal file is not open");    return ISIP_FALSE;  }  // make sure that the data pointer is null, else error  //  if (data_a != (float_8*)NULL) {    // return with error    //    error_handler_cc((char_1*)"read_cc", (char_1*)"data is already allocated");    return ISIP_FALSE;  }  // rewind the input file  //  rewind(fp_d);  // make sure that the end and start times are within bounds  //  if (end_time_a > end_file_time_d) {    // set the end time to the end of file time    //    end_time_a = end_file_time_d;  }  if (end_time_a < start_time_a) {    // return with error    //    return ISIP_FALSE;  }  // test the bounds of the start and end time  //  if (start_time_a < (float_8)0.0) {    // set start time to 0.0    //    start_time_a = 0.0;  }  // compute the number of samples to be obtained  //  num_samples_a = (int_4)rint((end_time_a - start_time_a) * sf_d);  // allocate memory for the data and memory for reading in the data  //  data_a = new float_8[num_samples_a];  char_1* in_data = new char_1[num_samples_a * num_chans_d * num_bytes_d];    // seek to the starting point in the file  //  fseek(fp_d, (int_4)(start_time_a * sf_d) * num_bytes_d * num_chans_d,	SEEK_SET);  // read the data into the data buffer  //  int_4 samples_read = fread(in_data, num_chans_d * num_bytes_d,			     num_samples_a, fp_d);  // check that the number of samples read is correct  //  if (samples_read != num_samples_a) {    // return with error    //    error_handler_cc((char_1*)"read_cc",		     (char_1*)"could not read all samples");    return ISIP_FALSE;  }  // swap bytes if necessary  //  if (swap_byte_flag_d == ISIP_TRUE) {        // loop over all two-byte sequences and swap bytes    //    // determine how many times through the loop we should go    //    int_4 loop_its = (num_samples_a * num_bytes_d * num_chans_d) / (int_4)2;    // set a pointer to the beginning of the buffer    //    char_1* temp = in_data;    for (int_4 i = 0; i < loop_its; i++) {      char_1 samp = temp[0];      temp[0] = temp[1];      temp[1] = samp;      temp += 2;    }  }  // loop over all data and convert it to floating point values  //  int_4 sample_val = 0;  for (int_4 i = 0; i < num_samples_a; i++) {    // compute the sample value    //    if (num_bytes_d == (int_4)2) {      sample_val = *((short*)(in_data +			      (i * num_chans_d + channel_a) * num_bytes_d)		     - 1);    }    else if (num_bytes_d == (int_4)4) {      sample_val = *((int_4*)(in_data +			     (i * num_chans_d + channel_a) * num_bytes_d));    }        else {      // free memory      //      delete [] in_data;      delete [] data_a;      data_a = (float_8*)NULL;            // return with error      //      error_handler_cc((char_1*)"read_cc",		       (char_1*)"number of bytes per sample is invalid");      return ISIP_FALSE;    }    // assign the value of this sample    //    data_a[i] = (float_8)sample_val;  }  // delete memory and clean up  //  delete [] in_data;    // exit gracefully  //  return ISIP_TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -