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

📄 circularbufferdiagnose.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/dstr/CircularBuffer/CircularBufferDiagnose.h// version: $Id: CircularBufferDiagnose.h,v 1.7 2002/02/28 23:20:34 alphonso Exp $//// make sure definitions are only made once//#ifndef ISIP_CIRCULAR_BUFFER_DIAGNOSE#define ISIP_CIRCULAR_BUFFER_DIAGNOSE// isip include files//#ifndef ISIP_CIRCULAR_BUFFER#include <CircularBuffer.h>#endif// CircularBufferDiagnose: a class that contains the diagnose method// of the CircularBuffer class.//template<class TObject>class CircularBufferDiagnose : public CircularBuffer<TObject> {    //---------------------------------------------------------------------------  //  // public constants  //  //---------------------------------------------------------------------------public:    // define the class name  //    //----------------------------------------  //  // i/o related constants  //  //----------------------------------------  //----------------------------------------  //  // default values and arguments  //  //----------------------------------------    // default values  //    // default arguments to methods  //    //----------------------------------------  //  // error codes  //  //----------------------------------------      //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:    // method: name  //  static const String& name() {    return CircularBuffer<TObject>::name();  }  // other static methods  //    static boolean diagnose(Integral::DEBUG debug_level);    // debug methods  //  these methods are omitted since this class does not have data  //  members and operations    //    // destructor/constructor(s):  //  these methods are omitted since this class does not have data  //  members and operations  //  // assign methods:  //  these methods are omitted since this class does not have data  //  members and operations  //  // operator= methods:  //  these methods are omitted since this class does not have data  //  members and operations  //    // i/o methods:  //  these methods are omitted since this class does not have data  //  members and operations  //  // equality methods:  //  these methods are omitted since this class does not have data  //  members and operations  //  // memory-management methods:  //  these methods are omitted since this class does not have data  //  members and operations  //    //---------------------------------------------------------------------------  //  // class-specific public methods:  //  //---------------------------------------------------------------------------  //  these methods are omitted since this class does not have data  //  members and operations  //    //---------------------------------------------------------------------------  //  // private methods  //  //---------------------------------------------------------------------------private:};// below are all the methods for the CircularBufferDiagnose template class//      //----------------------------------------------------------------------//// required static methods////----------------------------------------------------------------------// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//template<class TObject>boolean CircularBufferDiagnose<TObject>::diagnose(Integral::DEBUG level_a) {  //----------------------------------------------------------------------  //  // 0. preliminaries  //  //----------------------------------------------------------------------  // output the class name  //  if (level_a > Integral::NONE) {    SysString output(L"diagnosing class ");    output.concat(CLASS_NAME);    output.concat(L": ");    Console::put(output);    Console::increaseIndention();  }  //---------------------------------------------------------------------  //  // 1. required public methods  //  //---------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing required public methods...\n");    Console::increaseIndention();  }  // test the debug methods  //  setDebug(debug_level_d);    if (level_a > Integral::BRIEF) {    Integral::debug(L"debug");  }  // test constructors  //  CircularBuffer<Float> cbuf(100);  // test getCapacity  //  if (cbuf.getCapacity() != 100) {    return Error::handle(name(), L"constructor/getCapacity", Error::TEST,			 __FILE__, __LINE__);  }  // test isEmpty  //  if (!cbuf.isEmpty()) {    return Error::handle(name(), L"constructor/isEmpty", Error::TEST,			 __FILE__, __LINE__);  }  // testing copy constructor  //     CircularBuffer<Float> copy_cbuf(cbuf);      if (!cbuf.eq(copy_cbuf)) {    if (level_a >= Integral::ALL) {      copy_cbuf.debug(L"copy_cbuf");      cbuf.debug(L"cbuf");    }        return Error::handle(name(), L"copy constructor/eq", Error::TEST,			 __FILE__, __LINE__);  }    // testing memory allocation and deletion  //  CircularBuffer<TObject>::setGrowSize((long)731);  CircularBuffer<TObject>** cbufs = new CircularBuffer<TObject>*[100];    // test new operator  //  for (long i = 0; i < 100; i++) {    cbufs[i] =  new CircularBuffer<TObject>();  }    // test delete operator  //  for (long i = 99; i >= 0; i--) {    delete cbufs[i];  }    // test delete[] operator  //  delete [] cbufs;  // test the i/o methods  //  CircularBuffer<Float> cb2(150);  CircularBuffer<Float> cb3;  CircularBuffer<Float> cb4;  // prepare some data    //  Vector<Float> val_assign(200);  for (long i = 0; i < 200; i++) {    val_assign(i) = (float)i;  }    // append single element at a time  // [0 - 49] were appended  //  for (long i = 0; i < 50; i++) {    cb2.append(val_assign(i));                        }  long fowd = cb2.getNumForward();  cb2.seekCurr(fowd);  cb2.setRead(fowd);  // [50 - 199] were appended  //  cb2.append(val_assign, 100, 50);                   cb2.seekCurr(fowd);    // 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);  cb2.write(tmp_file0, (long)0);  cb2.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 value back  //  cb3.read(tmp_file0, (long)0);  if (!cb3.eq(cb2)) {    if (level_a >= Integral::ALL) {      cb3.debug(L"cb3 is circular buffer read");    }    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  cb4.read(tmp_file0, (long)0);  if (!cb4.eq(cb2)) {    if (level_a >= Integral::ALL) {      cb4.debug(L"cb4");    }    return Error::handle(name(), L"read", 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();  }    // --------------------------------------------------------------------  //  // 2. testing class-specific public methods  //     operator overload methods  //  // --------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: operator overload methods...\n");    Console::increaseIndention();   }    // test some basic operation  //  CircularBuffer<Float> cbuf1;  Float f = 0.1;  cbuf1.append(f);  cbuf1.setRead(1);  f.assign(0.2);  cbuf1.append(f);  if ((cbuf1.getNumElements() != 1) ||      (cbuf1.getNumForward() != 0) ||      (cbuf1.getNumBackward() != 0) ||      (!cbuf1(0).almostEqual(0.2))) {    cbuf1.debug(L"cbuf1");    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);  }  // test some basic operation  //  CircularBuffer<Float> cbuf2(20);  f = 0.1;  cbuf2.append(f);  f.assign(0.2);  cbuf2.append(f);  if ((cbuf2.getNumElements() != 2) ||      (cbuf2.getNumForward() != 1) ||      (cbuf2.getNumBackward() != 0) ||      (!cbuf2(0).almostEqual(0.1)) ||      (!cbuf2(1).almostEqual(0.2))) {    cbuf2.debug(L"cbuf2");    return Error::handle(name(), L"diagnose", Error::TEST, __FILE__, __LINE__);  }  // test prepen  //  f = 0.4;

⌨️ 快捷键说明

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