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

📄 afnd_06.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
      for (long c = 0; c < nchan; c++) {	AlgorithmData obj;	tmp_buf(c).append(obj);	Vector<AlgorithmData>* bufs = &(tmp_buf(c)(0).makeCombination());	bufs->setLength(num_inputs);	for (long i = 0; i < num_inputs; i++) {	  (*bufs)(i).swap(buf_d.getBuffer(proc_ptr->getInputName(i))(c)(real_offset));	  //(*bufs)(i).assign(buf_d.getBuffer(proc_ptr->getInputName(i))(c)(real_offset));	}      }      // call the Component set method      //      if (data_mode_d == AlgorithmBase::SAMPLE_BASED) {		proc_ptr->setLeftoverSamps(buf_d.getLeftoverSamps());      }            // call the Component apply method      //      proc_ptr->apply(output, tmp_buf);            // swap the data back out of temporary storage      //      for (long c = 0; c < nchan; c++) {	Vector<AlgorithmData>* bufs = &(tmp_buf(c)(0).getCombination());	for (long i = 0; i < num_inputs; i++) {	  (*bufs)(i).swap(buf_d.getBuffer(proc_ptr->getInputName(i))(c)(real_offset));	}      }            skip = false;    }    else {            String in_name(proc_ptr->getInputName(0));            // determine the number of channels in the input      //      long nchan = buf_d.getBuffer(in_name).length();            long algo_trail_pad = (long)Integral::max(0, proc_ptr->getTrailingPad());      long algo_lead_pad = (long)Integral::max(0, proc_ptr->getLeadingPad());      if ((real_offset > buf_d.getBuffer(in_name)(0).getNumForward()) ||	  (!append_a &&	   (buf_d.getBuffer(in_name)(0).getNumForward() < 	    (algo_lead_pad + real_offset)))) {	num_skipped++;	skip = true;	if (debug_level_d >= Integral::ALL) {	  proc_ptr->getOutputName().debug(L"skipping this coefficient");	}      }       else {	skip = false;      	// seek forward to the offset time alignment	//	for (long i = 0; i < nchan; i++) {	  buf_d.getBuffer(in_name)(i).seekCurr(real_offset);	}		// add the necessary pad before the samples	//	buf_d.ensureBufferTrailingPad(in_name, algo_trail_pad);		// add the necessary pad after the samples, if append is set	//	if (append_a) {	  buf_d.ensureBufferLeadingPad(in_name, algo_lead_pad);	}		// sanity check	//	if (buf_d.getBuffer(in_name)(0).getNumForward() < algo_lead_pad) {	  return Error::handle(name(), L"processComponents",			       ERR, __FILE__, __LINE__);	}	// call the Component set method	//	if (data_mode_d == AlgorithmBase::SAMPLE_BASED) {		  proc_ptr->setLeftoverSamps(buf_d.getLeftoverSamps());	}		// call the Component apply method	//	if (!proc_ptr->apply(output, buf_d.getBuffer(in_name))) {	  return Error::handle(name(), L"processComponents",			       ERR, __FILE__, __LINE__);	}			// seek back	//	for (long i = 0; i < nchan; i++) {	  buf_d.getBuffer(in_name)(i).seekCurr(-real_offset);	}      }    }    if (!skip) {            // now place the output onto the hashtable. note that we append      // an empty object then swap the real data with the newly added      // input. this is because a CircularBuffer only allows assigns      // to its members.      //      long nchano = output.length();      // make sure the buffer has enough channels      //      if (nchano > 1) {	buf_d.ensureChannels(proc_ptr->getOutputName(), nchano);      }            Vector< CircularBuffer<AlgorithmData> >* ptr =	&(buf_d.getBuffer(proc_ptr->getOutputName()));      if (debug_level_d >= Integral::ALL) {	proc_ptr->getOutputName().debug(L"appending this coefficient");      }      for (long i = 0; i < nchano; i++) {	AlgorithmData obj;	(*ptr)(i).append(obj);	(*ptr)(i)((*ptr)(i).getNumForward()).swap(output(i));	// sanity check	//	if (output(i).getDataType() != AlgorithmData::NONE) {	  return Error::handle(name(), L"processComponents",			       ERR, __FILE__, __LINE__);	}      }    }  }  if ((num_recip > 0) && (num_skipped == num_recip)) {    return false;  }    // exit gracefully  //  return true;}// method: open//// arguments://  const Filename& input: (input) input filename//// return: a boolean value indicating status//// this method opens the input files so we can begin processing//boolean AudioFrontEnd::open(const Filename& input_a) {  if (input_flag_d) {        if ( input_data_type_d == FrontEndBase::SAMPLED_DATA) {      // this is an audio file      //      if (!audio_input_d.open(input_a)) {	return Error::handle(name(), L"open", Error::ARG, __FILE__, __LINE__);      }    }        else if (input_data_type_d == FrontEndBase::FEATURES) {      // this is a features file      //      if (!feature_input_d.open(input_a)) {	return Error::handle(name(), L"open", Error::ARG, __FILE__, __LINE__);      }     }        else {      // not support type      //      return Error::handle(name(), L"open", Error::READ, __FILE__,			   __LINE__);          }      } // input flag if end  buf_d.setCoefName(coef_name_d);  // reset the buffers  //  resetBuffer();    // now that we have all the input names set, compute the Component  //  processTarget();      if (debug_level_d >= Integral::DETAILED) {    coef_components_d.debug(L"delayed components");  }  // to check if the file is empty or the data is too small for one  // frame  if (getNumFrames() < 1) {    return Error::handle(name(), L"open", ERR_EMPTY, __FILE__, __LINE__);  }    // exit gracefully  //  return true;}// method: close//// arguments: none//// return: a boolean value indicating status//// this method closes the input files//boolean AudioFrontEnd::close() {  if (audio_input_d.isOpen()) {    audio_input_d.close();  }    if (feature_input_d.isOpen()) {    feature_input_d.close();  }  resetBuffer();  // exit gracefully  //  return true;}// method: run//// arguments://  const Filename& output: (input) output filename//  const Filename& input: (input) input filename//  // return: a boolean value indicating status//// this method processes the given frame of data//boolean AudioFrontEnd::run(const Filename& output_a, const Filename& input_a) {  if (debug_level_d >= Integral::BRIEF) {    String str;    if (debug_level_d >= Integral::DETAILED) {      str.assign(L"\n\n--------------------------------------------------------\n\n");    }        str.concat(L"processing ");    str.concat(input_a);    str.concat(L" -> ");    str.concat(output_a);    if (debug_level_d >= Integral::DETAILED) {      str.concat(L"\n\n--------------------------------------------------------\n\n");    }    str.concat(L"\n");    Console::putNoWrap(str);  }  // get the file basename as the id  //  id_d.assign(output_a);    // strip the extension  //  id_d.deleteRange(id_d.lastChr(L'.'), -1);    // open the input file  //  if (!open(input_a)) {    return Error::handle(name(), L"run", Error::ARG, __FILE__, __LINE__,			 Error::WARNING);  }  // run through the data and output the features  //  outputFeatures(output_a);  // close the input file  //  close();    // exit gracefully  //  return true;}// method: outputFeatures//// arguments://  const Filename& output: (input) output filename//// return: a boolean value indicating status//// this method runs through all the features and outputs to the given file//boolean AudioFrontEnd::outputFeatures(const Filename& output_a) {  // first we get the first frame worth of output so we know how many  // channels there are  //  Vector<VectorFloat> data;  if (!getVector(data, 0)) {    // ISIP_BUG #514: this needs to output an empty file    //    return Error::handle(name(), L"outputFeatures",			 ERR, __FILE__, __LINE__);  }  long num_frames = getNumFrames();  if (debug_level_d >= Integral::DETAILED) {    Long((long)Integral::round(num_frames)).debug(L"****num_frames****");  }    // set the name of the features  //  if (coef_name_d.firstStr(Recipe::OUTPUT_PREFIX) != 0) {    return Error::handle(name(), L"outputFeatures",			 ERR, __FILE__, __LINE__);  }    String str;  coef_name_d.substr(str, Recipe::OUTPUT_PREFIX.length());  long samples_processed = 0;  // get the number of inputs  //  long num_samples = 0;    if (audio_input_d.isOpen()) {    num_samples = audio_input_d.getNumSamples();  }          for (long i = 0; i < num_frames; i++) {    if (i > 0) {      getVector(data, i);    }        // for the last frame we need to truncate so that the number of    // samples in is the number of samples out    //    // This needs to check if the last algorithm    // applied to the data was frame_based or sample_based, only do    // the truncate if it was sample_based.    //    // get the samples processed up to this loop    //    samples_processed += data(0).length() * data.length();    // this is code for generator class to output audio file    //    if (!input_flag_d) {       num_samples = samples_processed;    }    if ( i == num_frames - 1 && data_mode_d == AlgorithmBase::SAMPLE_BASED) {      for (long ctag = 0; ctag < data.length(); ctag++) {	data(ctag).setLength(buf_d.getLeftoverSamps());      }    }    if (data(0).length() == 0)      continue;  }    // exit gracefully  //  return true;}// method: getVector//// arguments://  VectorFloat& data: (output) the audio data//  long ctag: (input) the channel to read//  long frame_index: (input) the requested frame//  // return: a boolean value indicating status//// this method gets the processed data. if the frame's data is already// in the buffer, it is returned directly. if not the circular buffer// is advanced until the frame is included.//// it returns false if the frame is out of the file's range//boolean AudioFrontEnd::getVector(VectorFloat& data_a,				 long ctag_a, long frame_index_a) {  long user_index = 0;    // check argument  //  if (ctag_a < 0) {    Error::handle(name(), L"getVector", Error::ARG, __FILE__, __LINE__);    return -1;  }  // bad arguments  //  if (frame_index_a < 0) {    Error::handle(name(), L"getVector", Error::ARG, __FILE__, __LINE__);    return -1;  }  // possibly clear out the buffer if the new location is too far out of range  //  if (buf_d.contains(coef_name_d)) {    long buf_max_frame = getLastFrame() +      buf_d.getBuffer()(ctag_a).getCapacity();    if ((frame_index_a < getFirstFrame()) || (frame_index_a > buf_max_frame)) {          resetBuffer();      // set new time index      //      buf_d.setFrameIndex(frame_index_a - 1);    }  }  // process data until we have the needed frame  //  while (frame_index_a > getLastFrame()) {    if (end_of_data_d) {      data_a.clear();      return false;    }        // this means we are out of data    //    if (!processNextFrame()) {      end_of_data_d = true;    }  }      // copy over the user's output   //  user_index = frame_index_a - getLastFrame();  if (buf_d.getData(ctag_a, user_index, coef_name_d).getDataType() !=       AlgorithmData::VECTOR_FLOAT) {    return Error::handle(name(), L"getVector",			 ERR_NOVEC, __FILE__, __LINE__);  }    data_a.assign(buf_d.getData(ctag_a,			      user_index, coef_name_d).getVectorFloat());  if (debug_level_d >= Integral::DETAILED) {    data_a.debug(L"AudioFrontEnd::getVector(0)");  }  // exit gracefully  //  return true;}// method: processTarget//// arguments: none//// return: a boolean value indicating status//boolean AudioFrontEnd::processTarget() {  if (recipe_d.isEmpty()) {        if (component_list_d.length() == 0) {      return Error::handle(name(), L"processTarget",			   ERR, __FILE__, __LINE__);    }    Sof sof;    sof.open(component_list_d);    recipe_d.readGraph(sof, 0);    sof.close();  }  SingleLinkedList<Component> components(DstrBase::USER);  recipe_d.findComponent(components, *this, getCoefName());  makeBuffers(components);  recipe_d.delayComponent(coef_components_d, buf_d, *this, components);  configureComponents();  // exit gracefully  //  return true;}// method: processTarget//// arguments://  Vector<String>& names: (output) target names//  // return: a boolean value indicating status//boolean AudioFrontEnd::processTarget(Vector<String>& names_a) {  SingleLinkedList<Component> components(DstrBase::USER);  recipe_d.findComponent(components, *this, names_a);  makeBuffers(components);  recipe_d.delayComponent(coef_components_d, buf_d, *this, components);  configureComponents();      // exit gracefully  //  return true;  }

⌨️ 快捷键说明

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