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

📄 algo_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
  if (!output(0).getVectorFloat().almostEqual(signal(0)(0).getVectorFloat())) {    output(0).getVectorFloat().debug(L"computed");    signal(0)(0).getVectorFloat().debug(L"expected");    return Error::handle(name(), L"window", Error::TEST, __FILE__, __LINE__);  }    // test FourierTransform  //  if (level_a > Integral::BRIEF) {    Console::put(L"testing FourierTransform\n");  }    trf0.clear();  trf0.setType(FOURIER_TRANSFORM);  ft = (FourierTransform*)trf0.virtual_algo_d;  ft->setOrder(256);  trf0.apply(output, signal);  if (!output(0).getVectorComplexFloat().almostEqual(exp_full_spec)) {    output(0).getVectorComplexFloat().debug(L"output");    exp_full_spec.debug(L"expected");    return Error::handle(name(), L"fft", Error::TEST, __FILE__, __LINE__);  }    // test Generator  //  if (level_a > Integral::BRIEF) {    Console::put(L"testing Generator\n");  }  Vector< CircularBuffer<AlgorithmData> > input(1);  trf0.clear();  trf0.setType(GENERATOR);  Generator* g = (Generator*)trf0.virtual_algo_d;  g->setAlgorithm(Generator::SINE);  g->setComputeMode(ACCUMULATE);  g->setSignalDuration(1);  g->setSampleFrequency(40);  g->setFrameDuration(0.5);  g->setAmplitude(1);  g->setFrequency(2);  g->setPhase(0);  g->setBias(0);  trf0.apply(output, input);  if (!output(0).getVectorFloat().almostEqual(exp_gen)) {    output(0).getVectorFloat().debug(L"output");    exp_gen.debug(L"expected");    return Error::handle(name(), L"generator",			 Error::TEST, __FILE__, __LINE__);  }  if (output(0).getCoefType() != AlgorithmData::SIGNAL) {    return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__);  }  // test Spectrum  //  if (level_a > Integral::BRIEF) {    Console::put(L"testing Spectrum\n");  }    trf0.clear();  trf0.setType(SPECTRUM);  Spectrum* spec = (Spectrum*)trf0.virtual_algo_d;  spec->setFtOrder(256);  spec->setAlgorithm(Spectrum::FOURIER);  spec->setImplementation(Spectrum::COMPLEX);    signal(0)(0).setCoefType(AlgorithmData::SIGNAL);    trf0.apply(output, signal);  if (!output(0).getVectorComplexFloat().almostEqual(exp_full_spec)) {    output(0).getVectorComplexFloat().debug(L"output");    exp_full_spec.debug(L"expected");    return Error::handle(name(), L"fft", Error::TEST, __FILE__, __LINE__);  }  spec->setImplementation(Spectrum::MAGNITUDE);    trf0.apply(output, signal);  VectorFloat half_spec(output(0).getVectorFloat());  half_spec.setLength(half_spec.length() / 2);  if (!half_spec.almostEqual(exp_mag_spec)) {    half_spec.debug(L"output");    exp_mag_spec.debug(L"expected");    return Error::handle(name(), L"fft", Error::TEST, __FILE__, __LINE__);  }  // test FilterBank  //  if (level_a > Integral::BRIEF) {    Console::put(L"testing FilterBank\n");  }    trf0.clear();  trf0.setType(FILTER_BANK);  FilterBank* fb = (FilterBank*)trf0.virtual_algo_d;  fb->setAlgorithm(FilterBank::FREQUENCY);  fb->setImplementation(FilterBank::TRIANGULAR);  fb->setScale(FilterBank::MEL);  exp_mag_spec.setLength(exp_mag_spec.length() * 2);  ad.makeVectorFloat().assign(exp_mag_spec);  ad.setCoefType(AlgorithmData::SPECTRUM);  input(0).append(ad);    trf0.apply(output, input);  if (!output(0).getVectorFloat().almostEqual(exp_fba)) {    input(0)(0).getVectorFloat().debug(L"input");    output(0).getVectorFloat().debug(L"output");    exp_fba.debug(L"expected");    return Error::handle(name(), L"fba", Error::TEST, __FILE__, __LINE__);  }  if (output(0).getCoefType() != AlgorithmData::SPECTRUM) {    output(0).debug(L"output(0)");    return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__);  }  // test Energy  //  if (level_a > Integral::BRIEF) {    Console::put(L"testing Energy\n");  }    DoubleLinkedList<Algorithm> list_algo;  trf0.clear();  trf0.setType(ENERGY);  ((Energy*)trf0.virtual_algo_d)->setImplementation(Energy::LOG);  list_algo.insert(&trf0);  trf0.apply(output, uw_sig);    if (!exp_energy.almostEqual((double)output(0).getVectorFloat()(0))) {    output(0).getVectorFloat()(0).debug(L"computed");    exp_energy.debug(L"expected");    return Error::handle(name(), L"energy", Error::TEST, __FILE__, __LINE__);  }  if (output(0).getCoefType() != AlgorithmData::ENERGY) {    return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__);  }    trf0.clear();  trf0.setType(WINDOW);  ((Window*)trf0.virtual_algo_d)->setAlgorithm(Window::LIFTER);  ((Window*)trf0.virtual_algo_d)->setDuration(0.001625);  ((Window*)trf0.virtual_algo_d)->setFrameDuration(0.001625);   input(0)(0).makeVectorFloat().assign(exp_cepstrum);  input(0)(0).setCoefType(AlgorithmData::SIGNAL);  output.clear();  trf0.apply(output, input);  if (!output(0).getVectorFloat().almostEqual(exp_liftered)) {    output(0).getVectorFloat().debug(L"output");    exp_liftered.debug(L"expected");    return Error::handle(name(), L"window", Error::TEST, __FILE__, __LINE__);  }  if (output(0).getCoefType() != AlgorithmData::SIGNAL) {    return Error::handle(name(), L"apply", Error::TEST, __FILE__, __LINE__);  }  // test Constant class  //  trf0.clear();  trf0.setType(CONSTANT);    ((Constant*)trf0.virtual_algo_d)->setFilename(L"diagnose_constant.sof");  ((Constant*)trf0.virtual_algo_d)->setChannel(4);  Vector < CircularBuffer < AlgorithmData> > in;  Vector < AlgorithmData> out;    // multip-channel and VectorFloat test  //  trf0.apply(out, in);    Vector<VectorFloat> result;  result.setLength(4);  result(0).assign(L"1, 3, 5, 7, 9");  result(1).assign(L"10, 30, 50, 70, 90");    result(2).assign(L"100, 300, 500, 700, 900");  result(3).assign(L"1000, 3000, 5000, 7000, 9000");  for (long i = 0; i < 4; i++) {    if (!out(i).getVectorFloat().almostEqual(result(i))) {      out(i).getVectorFloat().debug(L"out_coeffs");      result(i).debug(L"exp_coeffs");      return  Error::handle(name(), L"apply", ERR,			    __FILE__, __LINE__);    }  }  Filename output1(L"diagnose_constant.sof");  Filename output2(L".diagnose_output.sof");  trf0.clear();  trf0.setType(CONSTANT);    ((Constant*)trf0.virtual_algo_d)->setFilename(L".diagnose_output.sof");  ((Constant*)trf0.virtual_algo_d)->setChannel(4);  ((Constant*)trf0.virtual_algo_d)->setSignalDuration(0.01);  ((Constant*)trf0.virtual_algo_d)->setImplementation(Constant::WRITE);  ((Constant*)trf0.virtual_algo_d)->setDataType(AlgorithmData::VECTOR_FLOAT);      long N = 4;  in.clear();  in.setLength(N);    for (long i = 0; i < N; i++) {    in(i)(0).makeVectorFloat();    in(i)(0).getVectorFloat().assign(result(i));    in(i)(0).setCoefType(AlgorithmData::SIGNAL);  }    // multip-channel and VectorFloat test  //  trf0.apply(out, in);  if (File::size(output1) != File::size(output2)) {    return  Error::handle(name(), L"apply compute from file", ERR,			  __FILE__, __LINE__);  }  File::remove(output2);    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    // --------------------------------------------------------------------  //  // 3. print completion message  //  // --------------------------------------------------------------------  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    if (level_a > Integral::NONE) {    String output(L"diagnostics passed for class ");    output.concat(name());    output.concat(L"\n");    Console::put(output);  }    // exit gracefully  //  return true;}

⌨️ 快捷键说明

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