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

📄 const_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/algo/Constant/const_02.cc// version: $Id: const_02.cc,v 1.5 2002/08/14 22:40:06 gao Exp $//// isip include files//#include "Constant.h"#include <Console.h>#include <Filename.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Constant::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  //  Constant const0;  const0.setAlgorithm(DATA);  const0.setImplementation(READ);  Constant const1(const0);    if (!const1.eq(const0)) {    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    //    Constant::setGrowSize((long)500);        Constant* pconst = new Constant();    for (long j = 1; j <= 100; j++) {      Constant** pconsts = new Constant*[j * 100];            // create the objects      //      for (long i = 0; i < j * 100; i++) {	pconsts[i] = new Constant();      }            // delete objects      //      for (long i = (j * 100) - 1; i >= 0; i--) {	delete pconsts[i];      }            delete [] pconsts;    }        delete pconst;  }  // 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();  }  const0.setAlgorithm(DATA);  const0.setImplementation(READ);  // 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);  const0.write(tmp_file0, (long)0);  //  const0.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  //  const1.read(tmp_file0, (long)0);  const1.init();  if (!const0.eq(const1)) {    return Error::handle(name(), L"i/o", Error::TEST,			 __FILE__, __LINE__);  }      const1.read(tmp_file1, (long)0);  const1.init();  if (!const0.eq(const1)) {    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  //  const0.setAlgorithm(DATA);  const0.setImplementation(READ);  // check that the values were set  //  if (const0.algorithm_d != DATA) {    return Error::handle(name(), L"setAlgorithm", Error::TEST,			 __FILE__, __LINE__);  }  else if (const0.implementation_d != READ) {    return Error::handle(name(), L"setImplementation", 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();  }  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing reading from a file...\n");    Console::increaseIndention();  }  {    Constant c1;    c1.setFilename(L"diagnose_file.sof");    c1.setChannel(4);    Vector < CircularBuffer < AlgorithmData> > in;    Vector < AlgorithmData> out;    // multip-channel and VectorFloat test    //    c1.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 compute from file", ERR,			      __FILE__, __LINE__);      }    }    Constant c2;    c2.setFilename(L"diagnose_file.sof");    c2.setChannel(1);    Vector<AlgorithmData> out1;      // VectorDouble type test    //    c2.setDataType(AlgorithmData::VECTOR_DOUBLE);    c2.apply(out1, in);    VectorDouble result_01;    result_01.assign(L"1.2, 0.5, 1.851, 1.000009");    if (!out1(0).getVectorDouble().almostEqual(result_01)) {      out1(0).getVectorFloat().debug(L"out_coeffs");      result_01.debug(L"exp_coeffs");      return  Error::handle(name(), L"apply compute from file", ERR,			    __FILE__, __LINE__);    }    // VectorComplexDouble type test    //    c2.clear();    c2.setDataType(AlgorithmData::VECTOR_COMPLEX_DOUBLE);    c2.apply(out1, in);    VectorComplexDouble result_02;    result_02.assign(L"1.2+8j,0.5+0.90002j,1.8500001+9j,1+7.87000001j");    if (!out1(0).getVectorComplexDouble().almostEqual(result_02)) {      out1(0).getVectorFloat().debug(L"out_coeffs");      result_02.debug(L"exp_coeffs");      return  Error::handle(name(), L"apply compute from file", ERR,			    __FILE__, __LINE__);    }    // VectorComplexFloat type test    //    c2.clear();    c2.setDataType(AlgorithmData::VECTOR_COMPLEX_FLOAT);    c2.apply(out1, in);    VectorComplexFloat result_03;    result_03.assign(L"1+2.3j,3+4.5j,5+6.7j,7+3.234j,9+4.765j");    if (!out1(0).getVectorComplexFloat().almostEqual(result_03)) {      out1(0).getVectorFloat().debug(L"out_coeffs");      result_03.debug(L"exp_coeffs");      return  Error::handle(name(), L"apply compute from file", ERR,			    __FILE__, __LINE__);    }    // MatrixDouble type test    //    c2.clear();    c2.setDataType(AlgorithmData::MATRIX_DOUBLE);    c2.apply(out1, in);    MatrixDouble result_04;    result_04.assign(3, 3, L"4, 3, 1, 7, 0, 4, 2, 8, 1");    if (!out1(0).getMatrixDouble().almostEqual(result_04)) {      out1(0).getMatrixDouble().debug(L"out_coeffs");      result_04.debug(L"exp_coeffs");      return  Error::handle(name(), L"apply compute from file", ERR,			    __FILE__, __LINE__);    }    // MatrixFloat type test    //

⌨️ 快捷键说明

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