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

📄 segc_05.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
字号:
// file: $isip/class/algo/SegmentConcat/segc_05.cc// version: $Id: segc_05.cc,v 1.4 2003/05/07 15:54:04 parihar Exp $//// isip include files//#include "SegmentConcat.h"// method: compute//// arguments://  Sdb& sdb: (input) sdb containing identifiers//  Filname& audiodb_file: (input) audio database file//  FeatureFile::FILE_TYPE f_type: (input) feature file type//  FeatureFile::FILE_FORMAT f_format: (input) feature file format//  Vector<VectorFloat>& min_max: (output) min and max values in each dimension//// return: a boolean value indicating status//// this method computes the minimum and maximum for each// feature-vector dimension by looping over all the feature-vectors in// the sdb feature file list.//boolean SegmentConcat::compute(Sdb& sdb_a, Filename& audiodb_file_a,			       FeatureFile::FILE_TYPE f_type_a,			       FeatureFile::FILE_FORMAT f_format_a,			       Vector<VectorFloat>& min_max_a) {    // local variables  //  long len_input = (long)0;  long num_files = (long)0;  Filename file_name;  VectorFloat min;  VectorFloat max;  Vector<VectorFloat> file_min;  Vector<VectorFloat> file_max;    // open the audio database  //  AudioDatabase audiodb;  audiodb.setDebug(debug_level_d);  if (audiodb_file_a.length() > 0) {    audiodb.open(audiodb_file_a);  }  else {    String msg(L"Error: no input audio database file specified ");    Console::put(msg);    Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);  }    // loop from start  //  if (!sdb_a.gotoFirst()) {    String msg(L"Error: no input identifier list specified ");    Console::put(msg);    Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);  }    // loop over all identifiers to get the number of features  // files needed to process  //  do {    // increment the number of input identifiers    //    len_input++;  } while (sdb_a.gotoNext());     // output message to the console  //  String output;  output.assign(L"       total ");  output.concat(len_input);  output.concat(L" input identifiers");  Console::putNoWrap(output);    // loop from start  //  sdb_a.gotoFirst();    // loop over all input identifiers  //  do {    // get the identifier    //    Filename id;    String identifier;    sdb_a.getName(id);    identifier.assign(id);        // get the feature-file corresponding to the identifier    //    Filename input_file;    if (!audiodb.getRecord(identifier, input_file)) {      String msg(L"Error: no input identifier list specified ");    Console::put(msg);    Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);    }        // incremement the number of files read    //    num_files++;    // read the features    //    FeatureFile ftr_file;    Vector<VectorFloat> temp_features;    // set the file type    //    ftr_file.setFileType(f_type_a);    // set the parameters for the RAW file    //    if (f_format_a == FeatureFile::RAW) {      ftr_file.setNumFeatures(dim_d);      ftr_file.setFileFormat(f_format_a);      //      ftr_file.setNumChannels(channel_a);    }        // open the feature file and read the header if sof    //    ftr_file.open(input_file);        // get the dimensions if sof file    //    if (f_format_a == FeatureFile::SOF) {            // set the file format      //      dim_d = ftr_file.getNumFeatures();    }        // get the feature-vectors from all the channels    //    long num = ftr_file.getNumFrames();    if (ftr_file.readFeatureData(temp_features, (long)0,				 FeatureFile::DEF_START_POS,				 num) != (num - 1)) {      String msg(L"Error: can't read from the FeatureFile");      Console::put(msg);      Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);    }        // transform the vector of vectorfloat    //    Vector<VectorFloat> trans;    trans.setLength(dim_d);    for (long i = 0; i < dim_d; i++) {      trans(i).setLength(num);      for (long j = 0; j < num; j++) {		trans(i)(j).assign(temp_features(j)(i));	      }    }        // get the min and max in each dimension of the feature-vectors    // belonging to the current feature file    //    // set the length of the vector    //    file_min.setLength(dim_d);    file_max.setLength(dim_d);        for (long i = 0; i < dim_d; i++) {      file_min(i).setLength(num_files);      file_max(i).setLength(num_files);      file_min(i)(num_files-(long)1) = trans(i).min();      file_max(i)(num_files-(long)1) = trans(i).max();    }        if (debug_level_d >= Integral::BRIEF) {      String output(L"\n");      Console::putNoWrap(output);    }    // report on the number of files processed    //    if (debug_level_d >= Integral::BRIEF) {      String output(L"processing file ");      output.concat(num_files);      output.concat(L": ");      output.concat(input_file);      Console::putNoWrap(output);          }        // close the feature file    //    ftr_file.close();  } while (sdb_a.gotoNext());      // get the min and max in each dimension  //  min.setLength(dim_d);  max.setLength(dim_d);  for (long i = 0; i < dim_d; i++) {    min(i) = file_min(i).min();    max(i) = file_max(i).max();  }      // set the min and max values  //  min_max_a.setLength((long)2);  min_max_a(0).assign(min);  min_max_a(1).assign(max);  // close the audio database  //  audiodb.close();    // exit gracefully  //  return true;}// method: compute//// arguments://  Sdb& sdb: (input) sdb containing list of feature-file//  Filname& audiodb_file: (input) audio database file//  Filname& transdb_file: (input) transcription database file//  FeatureFile::FILE_TYPE in_f_type: (input) input feature file type//  FeatureFile::FILE_FORMAT in_f_format: (input) input feature file format//  String& level: (input) level for frame alignments//  String& ratio: (input) ratios for segmental features//  boolean dur: (input) flag indicating log-duration in segmental features//  boolean norm: (input) flag indicating normalization of the input features//  Filname& min_max_file: (input) min-max sof file//  FeatureFile::FILE_TYPE o_f_type: (input) output feature file type//  FeatureFile::FILE_FORMAT o_f_format: (input) output feature file format//  String& suffix_a: (input) suffix for the output feature files//// return: a boolean value indicating status//// this method computes the minimum and maximum for each// feature-vector dimension by looping over all the feature-vectors in// the sdb feature file list.//boolean SegmentConcat::compute(Sdb& sdb_a, Filename& audiodb_file_a,			       Filename& transdb_file_a,			       FeatureFile::FILE_TYPE in_f_type_a,			       FeatureFile::FILE_FORMAT in_f_format_a,			       String& level_a, String& ratio_a, boolean dur_a,			       boolean norm_a, Filename& min_max_file_a,			       FeatureFile::FILE_TYPE o_f_type_a,			       FeatureFile::FILE_FORMAT o_f_format_a,			       String& suffix_a) {    // local variables  //  long len_input = (long)0;  long num_files = (long)0;  Filename file_name;    // open the audio database  //  AudioDatabase audiodb;  audiodb.setDebug(debug_level_d);  if (audiodb_file_a.length() > 0) {    audiodb.open(audiodb_file_a);  }  else {    String msg(L"Error: no input audio database file specified ");    Console::put(msg);    Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);  }    // open the transcription database  //  TranscriptionDatabase transdb;  transdb.setDebug(debug_level_d);    if (transdb_file_a.length() > 0) {    transdb.open(transdb_file_a);  }  else {    String msg(L"Error: no input transcription database file specified ");    Console::put(msg);    Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);  }    // parse the ratio on the based of enlimiter ":"  // ratio1:ratio2:ratio3:...  //  long pos = (long)0;  long num_ratio = (long)0;  VectorLong seg_ratio;  String temp_ratio;  while (ratio_a.tokenize(temp_ratio, pos, L":")) {    seg_ratio.setLength(++num_ratio);    temp_ratio.trim();    seg_ratio(num_ratio-(long)1).assign(temp_ratio);      }  // get the extension, output-directory and preserve-levels from the  // Sdb object  //  String ext = sdb_a.getOutputExtension();  String output_dir = sdb_a.getOutputDirectory();  long dir_preserve = sdb_a.getDirPresLevel();        // loop from start  //  if (!sdb_a.gotoFirst()) {    String msg(L"Error: no input identifier list specified ");    Console::put(msg);    Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);  }    // loop over all identifiers to get the number of features  // files needed to process  //  do {    // increment the number of input identifiers    //    len_input++;  } while (sdb_a.gotoNext());     // output message to the console  //  String output;  output.assign(L"       total ");  output.concat(len_input);  output.concat(L" input identifiers");  Console::putNoWrap(output);    // loop from start  //  sdb_a.gotoFirst();      // loop over all identifiers  //  do {    // get the identifier    //    Filename id;    String identifier;    sdb_a.getName(id);    identifier.assign(id);    // get the feature-file corresponding to the identifier    //    Filename input_file;    if (!audiodb.getRecord(identifier, input_file)) {      String msg(L"Error: no input identifier list specified ");      Console::put(msg);      Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);    }        // create a corresponding output filename    //    Filename output_file;    Filename uni_output_file;        // transform the output filename    //    output_file.transform(suffix_a, input_file, output_dir, ext,			  dir_preserve);    uni_output_file.transformUniquely(output_file);        // incremement the number of files read    //    num_files++;        // debuggging information    //    if (debug_level_d >= Integral::BRIEF) {      String output(L"\n");      Console::putNoWrap(output);    }    // report on the number of files processed    //    if (debug_level_d >= Integral::BRIEF) {      String output(L"processing file ");      output.concat(num_files);      output.concat(L": ");      output.concat(input_file);      output.concat(L"---> ");      String str;      uni_output_file.getBase(str);      str.concat(L".*");      output.concat(str);      Console::putNoWrap(output);          }        // read the features    //    FeatureFile ftr_file_in;    FeatureFile ftr_file_out;        // set the file type    //    ftr_file_in.setFileType(in_f_type_a);    ftr_file_out.setFileType(o_f_type_a);        // set the parameters for the RAW file    //    if (in_f_format_a == FeatureFile::RAW) {      ftr_file_in.setNumFeatures(dim_d);      ftr_file_in.setFileFormat(in_f_format_a);      // ftr_file.setNumChannels(channel_a);    }        // set the parameters for the RAW file    //    if (o_f_format_a == FeatureFile::RAW) {      ftr_file_out.setNumFeatures(dim_d);      ftr_file_out.setFileFormat(o_f_format_a);      // ftr_file.setNumChannels(channel_a);    }        // open the feature file, and read the header if sof    //    ftr_file_in.open(input_file);        // get the dimensions of sof file    //    if (o_f_format_a == FeatureFile::SOF) {            // set the file format      //      dim_d = ftr_file_in.getNumFeatures();    }        // get the feature-vectors from all the channels    //    Vector<VectorFloat> features;    long num = ftr_file_in.getNumFrames();    if (ftr_file_in.readFeatureData(features, (long)0,				    FeatureFile::DEF_START_POS,				    num) != (num - 1)) {      String msg(L"Error: can't read from the FeatureFile");      Console::put(msg);      Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);    }        // close the feature file    //    ftr_file_in.close();    // normalize the input features between [-1, 1] if needed    //    if (norm_a) {      // local variables      //      Vector<VectorFloat> min_max;      Vector<VectorFloat> temp_features;      Sof min_max_sof;            // open the min_max sof file      //      if (min_max_file_a.length() > (long)0) {	min_max_sof.open(min_max_file_a);      }      else {	String msg(L"Error: no input min-max file specified ");	Console::put(msg);	Error::handle(name(), L"compute", ERR, __FILE__, __LINE__);      }      // read the min and max vectors      //      min_max.read(min_max_sof, (long)0);      // close the sof min-max file      //      min_max_sof.close();            // normalize the features      //      normalizeFeature(features, min_max, temp_features);      features.assign(temp_features);    }        // get the timming information at the given level, corresponding    // to this feature file    //    VectorFloat start_times;    VectorFloat end_times;    Vector<String> annotations;    transdb.getRecord(identifier, level_a, annotations,		      start_times, end_times);    // get the segmental features for this file    //    Vector<VectorFloat> seg_features;    VectorLong start_frames;    VectorLong end_frames;    start_frames.assign(start_times);    end_frames.assign(end_times);    // sunstract one from    //    generateSegFeature(features, start_frames, end_frames, seg_ratio,		       dur_a, seg_features);    // store the segmental features    //    ftr_file_out.open(uni_output_file, File::WRITE_ONLY);    ftr_file_out.writeFeatureData(seg_features);    ftr_file_out.close();      } while (sdb_a.gotoNext());    // close the audio database  //  audiodb.close();  // close the transcription database  //  transdb.close();    // exit gracefully  //  return true;}

⌨️ 快捷键说明

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