当前位置: 首页>>代码示例>>C++>>正文


C++ MarSystem::control方法代码示例

本文整理汇总了C++中MarSystem::control方法的典型用法代码示例。如果您正苦于以下问题:C++ MarSystem::control方法的具体用法?C++ MarSystem::control怎么用?C++ MarSystem::control使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MarSystem的用法示例。


在下文中一共展示了MarSystem::control方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main(int argc, char *argv[])
{
  if (argc < 3)
  {
    cerr << "Usage: <input file> <output file>" << endl;
    return 1;
  }

  char *input_filename = argv[1];
  char *output_filename = argv[2];

  detector::registerScripts();

  ScriptTranslator translator;
  MarSystem *system = translator.translateRegistered("detector.mrs");
  if (!system)
  {
    cerr << "Failure loading script!" << endl;
    return 1;
  }

  MarControlPtr input_control = system->control("input");
  MarControlPtr output_control = system->control("output");
  MarControlPtr done_control = system->control("done");

  if ( input_control.isInvalid() ||
       output_control.isInvalid() ||
       done_control.isInvalid() )
  {
    cerr << "Failure: Invalid script!" << endl;
    delete system;
    return 1;
  }

  input_control->setValue(string(input_filename));
  //output_control->setValue(string("features.out"));

  mrs_real sample_rate = system->remoteControl("sndfile/osrate")->to<mrs_real>();
  mrs_natural block_size = system->remoteControl("sndfile/onSamples")->to<mrs_natural>();
  mrs_real block_duration = block_size / sample_rate;

  MarControlPtr output = system->getControl("mrs_realvec/processedData");
  MarControlPtr confidence_ctl = system->remoteControl("onsets/confidence");
  assert(!output.isInvalid());
  assert(!confidence_ctl.isInvalid());

  MarSystem *rms_sys = system->remoteSystem("rms");
  assert(rms_sys);
  MarControlPtr rms_out = rms_sys->getControl("mrs_real/value");
  assert(!rms_out.isInvalid());

  std::vector<onset> onsets;
  int block = 0;
  const int block_offset = 5;

  while(!done_control->to<bool>())
  {
    system->tick();

    const realvec & data = output->to<realvec>();
    assert(data.getSize() == 2);

    mrs_real confidence = confidence_ctl->to<mrs_real>();

    if (!(data(0) > 0.0) || confidence < 10.0 / 100.0)
    {
      ++block;
      continue;
    }

    mrs_real centroid = data(1);

    double rms = rms_out->to<mrs_real>();

    onset o;

    o.time = (block - block_offset + 0.5) * block_duration;

    if (centroid < 0.04)
      o.type = 0;
    else if (centroid < 0.3)
      o.type = 1;
    else
      o.type = 2;

    o.strength = rms;

    onsets.push_back(o);

    ++block;
  }

  string separator(",");

  ofstream out_file(output_filename);
  if (!out_file.is_open())
  {
    cerr << "Failed to open output file for writing: " << output_filename << endl;
    return 1;
  }
//.........这里部分代码省略.........
开发者ID:EQ4,项目名称:drum-detection,代码行数:101,代码来源:detector.cpp


注:本文中的MarSystem::control方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。