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

📄 enrgy_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/algo/Energy/enrgy_02.cc// version: $Id: enrgy_02.cc,v 1.11 2001/11/22 17:05:11 parihar Exp $//// isip include files//#include "Energy.h"#include <Console.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Energy::diagnose(Integral::DEBUG level_a) {  //---------------------------------------------------------------------------  //  // 0. preliminaries  //  //---------------------------------------------------------------------------  // output the class name  //  if (level_a > Integral::NONE) {    String output(L"diagnosing class ");    output.concat(CLASS_NAME);    output.concat(L": ");    Console::put(output);    Console::increaseIndention();  }   //--------------------------------------------------------------------------  //  // 1. required public methods  //     class constructors  //  //--------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing required public methods...\n");    Console::increaseIndention();  }  // test destructor/constructor(s) and memory management  //  Energy egy0;  egy0.setAlgorithm(FILTER);  egy0.setImplementation(POWER);  egy0.setFloor(0.01);  Energy egy1(egy0);    if (!egy1.eq(egy0)) {    return Error::handle(name(), L"copy constructor", Error::TEST,			 __FILE__, __LINE__);  }    // test large allocation construction and deletion  //  if (level_a == Integral::ALL) {        Console::put(L"\ntesting large chunk memory allocation and deletion:\n");        // set the memory to a strange block size so we can hopefully catch any    // frame overrun errors    //    Energy::setGrowSize((long)500);        Energy* pegy = new Energy();    for (long j = 1; j <= 100; j++) {      Energy** pegys = new Energy*[j * 100];            // create the objects      //      for (long i = 0; i < j * 100; i++) {	pegys[i] = new Energy();      }            // delete objects      //      for (long i = (j * 100) - 1; i >= 0; i--) {	delete pegys[i];      }            delete [] pegys;    }        delete pegy;  }  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    //--------------------------------------------------------------------------  //  // 2. required public methods  //     i/o methods   //  //--------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing required public methods: i/o methods...\n");    Console::increaseIndention();  }  // declare a reference object  //  VectorFloat ma_coef(L"1.0, 1.0");  VectorFloat ar_coef(L"1.0, 0.5");  egy0.setAlgorithm(FILTER);  egy0.setImplementation(POWER);  egy0.setFloor(0.01);  egy0.setFilter(ma_coef, ar_coef);  egy0.init();  // we need binary and text sof files  //  String tmp_filename0;  Integral::makeTemp(tmp_filename0);  String tmp_filename1;  Integral::makeTemp(tmp_filename1);  // open files in write mode  //  Sof tmp_file0;  tmp_file0.open(tmp_filename0, File::WRITE_ONLY, File::TEXT);  Sof tmp_file1;  tmp_file1.open(tmp_filename1, File::WRITE_ONLY, File::BINARY);  egy0.write(tmp_file0, (long)0);  //  egy0.write(tmp_file1, (long)0);  // close the files  //  tmp_file0.close();  tmp_file1.close();  // open the files in read mode  //  tmp_file0.open(tmp_filename0);  tmp_file1.open(tmp_filename1);  // read the object back  //  egy1.read(tmp_file0, (long)0);  egy1.init();  if (!egy0.eq(egy1)) {    return Error::handle(name(), L"i/o", Error::TEST,			 __FILE__, __LINE__);  }      egy1.read(tmp_file1, (long)0);  egy1.init();  if (!egy0.eq(egy1)) {    return Error::handle(name(), L"i/o", Error::TEST,			 __FILE__, __LINE__);  }      // close and delete the temporary files  //  tmp_file0.close();  tmp_file1.close();  File::remove(tmp_filename0);  File::remove(tmp_filename1);  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 3. class-specific public methods:  //     set and get methods  //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {      Console::put(L"testing class-specific public methods: set and get methods...\n");    Console::increaseIndention();  }  // establish an object  //  egy0.setAlgorithm(SUM);  egy0.setImplementation(POWER);  egy0.setFloor(27.0);  // check that the values were set  //  if (egy0.algorithm_d != SUM) {    return Error::handle(name(), L"setAlgorithm", Error::TEST,			 __FILE__, __LINE__);  }  else if (egy0.implementation_d != POWER) {    return Error::handle(name(), L"setImplementation", Error::TEST,			 __FILE__, __LINE__);  }  else if (egy0.floor_d != (float)27.0) {    return Error::handle(name(), L"setDuration", Error::TEST,			 __FILE__, __LINE__);  }  // test setFilter  //  ma_coef.assign(L"1.0, 1.0");  ar_coef.assign(L"1.0, 0.5");  VectorFloat ma_tmp, ar_tmp;  egy0.setAlgorithm(FILTER);  egy0.setFilter(ma_coef, ar_coef);  egy0.getFilter(ma_tmp, ar_tmp);  if (!ma_tmp.eq(ma_coef)) {    return Error::handle(name(), L"setFilter - ma coef", Error::TEST,			 __FILE__, __LINE__);  }  if (!ar_tmp.eq(ar_coef)) {    return Error::handle(name(), L"setFilter - ar coef", Error::TEST,			 __FILE__, __LINE__);  }  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }    //---------------------------------------------------------------------------  //  // 4. class-specific public methods:  //     computation methods  //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: computational methods...\n");    Console::increaseIndention();  }  // declare local variables  //  VectorFloat input;  VectorFloat ans;  VectorFloat output;  // perform a simple test that compares SUM to FILTER:  //  run the filter twice to make sure the history works properly  //  input.assign(L"1, 2, 3, 4");  egy0.setAlgorithm(SUM);  egy0.setImplementation(IDENTITY);  egy0.compute(ans, input);  VectorFloat ma(L"1, 1, 1, 1");  VectorFloat ar;  egy0.setAlgorithm(FILTER);  egy0.setImplementation(IDENTITY);  egy0.setFilter(ma, ar);  input.assign(L"1, 0, 1, 0");  egy0.compute(output, input);  input.assign(L"1, 2, 3, 4");  egy0.compute(output, input);  if (!output.almostEqual(ans)) {    ans.debug(L"expected result:");    output.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  // check the complex mode  //  VectorComplexFloat input_cmplx(L"1+1j, 2+2j, 3+3j");  ans.assign(L"28");    egy0.setAlgorithm(SUM);  egy0.setImplementation(IDENTITY);  egy0.compute(output, input_cmplx);  if (!output.almostEqual(ans)) {    ans.debug(L"expected result:");    output.debug(L"wrong result:");    return Error::handle(name(), L"compute", Error::TEST, __FILE__, __LINE__);  }  // check the FILTER mode more extensively  //

⌨️ 快捷键说明

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