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

📄 rcp_05.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 3 页
字号:
    // if this node is black, propagate the input name forward    //    GraphVertex<Component>* gv = (GraphVertex<Component>*)recipe_d.getCurr();    if ((recipe_d.getColor(gv) == Integral::BLACK) &&	(gv->getItem()->getOutputName().length() > 0)) {      String vname(gv->getItem()->getOutputName());      for (boolean a = gv->gotoFirst(); a; a = gv->gotoNext()) {		GraphArc<Component>* ga = gv->getCurr();	GraphVertex<Component>* dst = ga->getVertex();	long weight = (long)ga->getWeight();	dst->getItem()->setInputName(weight, vname);		      }      continue;    }        for (boolean a = gv->gotoFirst(); a; a = gv->gotoNext()) {      GraphArc<Component>* ga = gv->getCurr();      GraphVertex<Component>* dst = ga->getVertex();      // if the destination node is black, propagate the output name      // backwards      //      if (recipe_d.getColor(dst) == Integral::BLACK) {	long weight = (long)ga->getWeight();	// make sure this arc has an input name	//	if (dst->getItem()->getNumInputs() > weight) {	  	  String vname(dst->getItem()->getInputName(weight));	  // make sure the name was not empty	  //	  if (vname.length() > 0) {	    gv->getItem()->setOutputName(vname);	  }	}      }    }  }  // now place dummy names on all other connections  //  long dummy_nc = 0;  for (boolean m = recipe_d.gotoFirst(); m;       m = recipe_d.gotoNext()) {    GraphVertex<Component>* gv = (GraphVertex<Component>*)recipe_d.getCurr();    // declare local dummy name for output data    //    String dummy_name;    dummy_name.assign(DUMMY_DATA_NAME);    boolean has_name = false;    // give output name to each component    // there are two cases:    //   if output name exists, directly using it    //   else assign a name to it    //    if (gv->getItem()->getOutputName().length() == 0) {      dummy_name.concat(dummy_nc++);      gv->getItem()->setOutputName(dummy_name);    }    else {      dummy_name.assign(gv->getItem()->getOutputName());      has_name = true;    }    // propagate the output name as input name to components which    // just follow the current component    //    for (boolean a = gv->gotoFirst(); a; a = gv->gotoNext()) {            GraphArc<Component>* ga = gv->getCurr();      GraphVertex<Component>* dst = ga->getVertex();      // put a dummy name on both the output of the current node and      // the input of the next node      //      long weight = (long)ga->getWeight();      if ((dst->getItem()->getNumInputs() > weight) &&	  (dst->getItem()->getInputName(weight).length() != 0) &&	  (dst->getItem()->getInputName(weight).ne(dummy_name))) {	dst->getItem()->debug(L"dst recipe");	gv->getItem()->debug(L"cur recipe");	dummy_name.debug(L"dummy_name");	String out_value;	out_value.concat(L"weight = %ld\n");	out_value.concat(weight);	Console::put(out_value);	return Error::handle(name(), L"readGraph", ERR,			     __FILE__, __LINE__);      }      if (!has_name) {	dst->getItem()->setInputName(weight, dummy_name);      }      else {	if ((dst->getItem()->getNumInputs() <= weight) ||	    (dst->getItem()->getInputName(weight).ne(dummy_name))) {	  dst->getItem()->debug(L"recipe");	  dummy_name.debug(L"dummy_name");	  return Error::handle(name(), L"readGraph",			       ERR, __FILE__, __LINE__);	}      }    }  }  // exit gracefully  //  return true;}// method: expandSubGraphs//// arguments://  Sof& sof: (input) open sof file//// return: whether or not any sub-graphs are expanded this pass//// loop through the vertices and expand sub-graphs//boolean Recipe::expandSubGraphs(Sof& sof_a) {  // declare a status flag  //  boolean res = false;  // loop over all components  //  for (boolean m = recipe_d.gotoFirst(); m; m = recipe_d.gotoNext()) {        GraphVertex<Component>* gv = (GraphVertex<Component>*)recipe_d.getCurr();        if (gv->getItem()->getAlgorithm().getType() ==	Algorithm::ALGORITHM_CONTAINER) {      // set the flag so we know that a sub-graph was expanded this      // pass      //      res = true;            // record the tag of the sub graph      //      long gtag = gv->getItem()->getAlgorithm().getContainerGraphTag();      // now we need to replace the container object with two      // coefficient label algorithms. all of the inputs to the      // container will go to the first coefficient label, so we can      // quickly do this by just changing the type of the container      // object to a coefficient label (this means all incomming arcs      // will not need to be changed). We will then make a new      // coefficient label and move all of the arcs currently      // emminating from the container to the new coefficient label.      //      Component* rcp = new Component();      Algorithm algo;      algo.setType(Algorithm::COEFFICIENT_LABEL);      rcp->setAlgorithm(algo);      // insert our new coefficient label into the graph      //      GraphVertex<Component>* src = recipe_d.insertVertex(rcp);            for (boolean a = gv->gotoFirst(); a; a = gv->gotoNext()) {		GraphArc<Component>* ga = gv->getCurr();	// first add a new arc	//	recipe_d.insertArc(src, ga->getVertex(), ga->getEpsilon(),				ga->getWeight());	// now delete the current arc	//	recipe_d.removeArc(gv, ga->getVertex());      }      // change the container object to a coefficient label      //      gv->getItem()->setAlgorithm(algo);      // now read in the sub-graph      //      GraphVertex<Component>* sub_input = (GraphVertex<Component>*)NULL;      GraphVertex<Component>* sub_output = (GraphVertex<Component>*)NULL;      readSubGraph(sub_input, sub_output, sof_a, gtag);      // now add arcs from the first coefficient label to the sub-graph input      //      recipe_d.insertArc(gv, sub_input);      recipe_d.insertArc(sub_output, src);          }  }  return res;}  // method: readSubGraph//// arguments://  GraphVertex<Component>*& sub_input: (output) container's input vertex//  GraphVertex<Component>*& sub_output: (output) container's output vertex//  Sof& sof: (input) Sof file//  long graph_tag: (input) tag for graph to read//// return: a boolean value indicating status//// this method reads a sub-graph from the file. it is very similar to// the readGraph method, except it does not delete the current// entries. upon read, it expands the sub-graph into the current// graph.//boolean Recipe::readSubGraph(GraphVertex<Component>*& sub_input_a,			     GraphVertex<Component>*& sub_output_a,			     Sof& sof_a, long graph_tag_a) {  // initialize output parameters  //  sub_input_a = (GraphVertex<Component>*)NULL;  sub_output_a = (GraphVertex<Component>*)NULL;  // local variables  //  DiGraph<Long> index_graph;  SingleLinkedList<Component> algos(DstrBase::USER);    // first read the graph that defines the connections  //  if (!index_graph.read(sof_a, graph_tag_a)) {    return Error::handle(name(), L"readSubGraph", Error::READ, __FILE__,			 __LINE__, Error::WARNING);  }  SingleLinkedList<Long> node_indices(DstrBase::USER);  SingleLinkedList< Triple< Pair<Long, Long>, Float, Boolean> > topo;  index_graph.get(node_indices, topo);  // sanity check -- the nodes should be consecutive integers  //  long count = graph_tag_a;  for (boolean m = node_indices.gotoFirst(); m; m = node_indices.gotoNext()) {    if (node_indices.getCurr()->ne(count++)) {      return Error::handle(name(), L"readSubGraph", ERR, __FILE__, __LINE__);    }  }    // now read in the Algorithms themselves -- put them into a  // hashtable based on the tag number.  //  for (boolean m = node_indices.gotoFirst(); m; m = node_indices.gotoNext()) {    long tag = *(node_indices.getCurr());      Algorithm algo;    if (!algo.read(sof_a, tag)) {      return Error::handle(name(), L"readSubGraph", Error::READ, __FILE__,			   __LINE__, Error::WARNING);    }    // subtract the graph tag from the index so that the indices will    // range from 0 to n (the same range as the list)    //    node_indices.getCurr()->assign(tag - graph_tag_a);        Component* recipe = new Component;    recipe->setAlgorithm(algo);    algos.insertLast(recipe);  }  recipe_d.setAllocationMode(DstrBase::USER);  // declare local variables for the graph copy  //  long src = 0;  long dst = 0;          float weight = 0.0;  boolean epsilon = false;    // create vertices for the input data. we will also catch the input  // and output coefficient buffer at this time.  //  GraphVertex<Component>* vertices[algos.length()];  for (int i = 0; i < algos.length(); i++) {    algos.gotoPosition(i);    vertices[i] = recipe_d.insertVertex(algos.getCurr());    if (algos.getCurr()->isCoefficientLabel(CoefficientLabel::INPUT)) {      if (sub_input_a != (GraphVertex<Component>*)NULL) {	return Error::handle(name(), L"readSubGraph", ERR,			     __FILE__, __LINE__);      }      sub_input_a = vertices[i];    }    if (algos.getCurr()->isCoefficientLabel(CoefficientLabel::OUTPUT)) {      if (sub_output_a != (GraphVertex<Component>*)NULL) {	return Error::handle(name(), L"readSubGraph", ERR,			     __FILE__, __LINE__);      }      sub_output_a = vertices[i];    }  }  // loop over all elements in the arc list  //  for (boolean more = topo.gotoFirst(); more; more = topo.gotoNext()) {    // define the source and destination objects    //    GraphVertex<Component>* src_vertex;    GraphVertex<Component>* dst_vertex;        // determine the parameters of the arc    //    weight = (float)topo.getCurr()->second();    epsilon = (boolean)topo.getCurr()->third();    src = (long)topo.getCurr()->first().first();    dst = (long)topo.getCurr()->first().second();        // check if the source is the start vertex    //    if ((src == DiGraph<Component>::START_INDEX) ||	(src == DiGraph<Component>::TERM_INDEX) ||	(dst == DiGraph<Component>::START_INDEX) ||	(dst == DiGraph<Component>::TERM_INDEX) ||	(src >= algos.length()) || (dst >= algos.length())) {      return Error::handle(name(), L"readSubGraph", ERR, __FILE__, __LINE__);    }    src_vertex = vertices[src];    dst_vertex = vertices[dst];    // insert an arc from the source to the destination vertices    //    recipe_d.insertArc(src_vertex, dst_vertex, epsilon, weight);  }  recipe_d.setAllocationMode(DstrBase::SYSTEM);  // exit gracefully  //  return true;}// method: checkInputs//// arguments: none//// return: a boolean value indicating status//// this method tests the graph to make sure only Connection objects// have multiple inputs//boolean Recipe::checkInputs() {    // loop over all components  //  for (boolean m = recipe_d.gotoFirst(); m;       m = recipe_d.gotoNext()) {        GraphVertex<Component>* gv = (GraphVertex<Component>*)recipe_d.getCurr();        for (boolean a = gv->gotoFirst(); a; a = gv->gotoNext()) {      GraphArc<Component>* ga = gv->getCurr();      Algorithm::TYPES type =	ga->getVertex()->getItem()->getAlgorithm().getType();      if ((ga->getWeight() != 0.0) &&	  (type != Algorithm::CONNECTION) &&	  (type != Algorithm::MATH) &&	  (type != Algorithm::CORRELATION)) {	ga->getVertex()->getItem()->getAlgorithm().debug(L"algo");	return Error::handle(name(), L"checkInputs", ERR, __FILE__, __LINE__);      }    }  }  // exit gracefully  //  return true;}

⌨️ 快捷键说明

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