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

📄 hist_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 4 页
字号:
// file: $isip/class/stat/Histogram/hist_02.cc// version: $Id: hist_02.cc,v 1.1 2001/02/01 16:47:49 hamaker Exp $//// isip include files//#include "Histogram.h"#include <Console.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//// this is the diagnose method//boolean Histogram::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();  }  // create data to test with  //  VectorDouble test_bins(L"1, 3, 5, 7, 9");  VectorDouble test_edges_bins(L"0, 2.5, 5, 7.5, 10");  VectorDouble test_counts(L"3, 2, 2, 2, 2");  VectorDouble test_ones(L"1, 1, 1, 1, 1");  VectorDouble test_data(L"0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10");    // do a quick test of constructors, destructors and memory management  // methods  //  Histogram::setGrowSize(5);  Histogram* hist0 = new Histogram(CENTERS);  Histogram* hist1 = new Histogram(*hist0);  Histogram* hist2 = new Histogram[10];  // clear the pointers  //  delete hist0;  delete hist1;  delete [] hist2;  // set the internal data of hist0  //  hist0 = new Histogram(CENTERS);  hist0->setBins(test_bins);  hist0->setCounts(test_counts);  // test the assign and eq methods  //  hist1 = new Histogram;  hist1->assign(*hist0);  if (!hist1->eq(*hist0)) {    hist0->debug(L"expected Histogram");    hist1->debug(L"actual Histogram");    return Error::handle(name(), L"assign/eq", Error::TEST,			 __FILE__, __LINE__);  }  delete hist1;  // test copy constructor  //  hist1 = new Histogram(*hist0);  if (!hist1->eq(*hist0)) {    hist0->debug(L"expected Histogram");    hist1->debug(L"actual Histogram");    return Error::handle(name(), L"copy constructor", Error::TEST,			 __FILE__, __LINE__);  }  // test the clear method  //  hist0->clear();  if (hist1->eq(*hist0)) {    hist0->debug(L"hist0 not clear");    return Error::handle(name(), L"clear", Error::TEST, __FILE__, __LINE__);  }    // test the operator= method  //  *hist0 = *hist1;  if (!hist1->eq(*hist0)) {    hist1->debug(L"expected Histogram");    hist0->debug(L"actual Histogram");    return Error::handle(name(), L"operator=", Error::TEST, __FILE__,			 __LINE__);  }    // clear the pointers  //  delete hist0;  delete hist1;  // test the i/o methods  //  Histogram hist3;  Histogram hist4;  Histogram hist5;  Histogram hist6;  hist3.setMode(CENTERS);  hist4.setMode(EDGES);  hist3.setBins(test_bins);  hist3.setCounts(test_counts);  hist4.setBins(test_bins);  hist4.setCounts(test_counts);    // 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);  hist3.write(tmp_file0, (long)0);  hist4.write(tmp_file0, (long)1);  hist3.write(tmp_file1, (long)0);  hist4.write(tmp_file1, (long)1);  // 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 histograms back in  //  hist5.read(tmp_file0, (long)0);  hist6.read(tmp_file0, (long)1);  if (!hist5.eq(hist3)) {    hist3.debug(L"expected Histogram");    hist5.debug(L"hist5 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  if (!hist6.eq(hist4)) {    hist4.debug(L"expected Histogram");    hist6.debug(L"hist6 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  // read the model written in binary  //  hist5.clear();  hist6.clear();  hist5.read(tmp_file1, (long)0);  hist6.read(tmp_file1, (long)1);  if (!hist5.eq(hist3)) {    hist3.debug(L"expected Histogram");    hist5.debug(L"hist5 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  if (!hist6.eq(hist4)) {    hist4.debug(L"expected Histogram");    hist6.debug(L"hist6 actual");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  // close and  delete the temporary files  //  tmp_file0.close();  tmp_file1.close();    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 2. class-specific public methods:  //     set methods  //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific public methods: set methods...\n");    Console::increaseIndention();  }  // test setMode  //  hist6.setMode(CENTERS);  if (hist6.mode_d != CENTERS) {    return Error::handle(name(), L"setMode", Error::TEST, __FILE__,			 __LINE__);  }    // test setBins, all types  //  VectorByte byte_bins;  byte_bins.assign(test_bins);  VectorDouble double_bins;  double_bins.assign(test_bins);  VectorFloat float_bins;  float_bins.assign(test_bins);  VectorLlong llong_bins;  llong_bins.assign(test_bins);  VectorLong long_bins;  long_bins.assign(test_bins);  VectorShort short_bins;  short_bins.assign(test_bins);  VectorUllong ullong_bins;  ullong_bins.assign(test_bins);  VectorUlong ulong_bins;  ulong_bins.assign(test_bins);  VectorUshort ushort_bins;  ushort_bins.assign(test_bins);  if (!hist6.setBins(byte_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(double_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(float_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(llong_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(long_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(short_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(ullong_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(ulong_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins(ushort_bins) || !hist6.bins_d.eq(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  // test the scalar setBins, all types  //  double min = test_data.min();  double max = test_data.max();  long num_bins = test_bins.length();    if (!hist6.setBins((byte)min, (byte)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((double)min, (double)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((float)min, (float)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((llong)min, (llong)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((long)min, (long)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((short)min, (short)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((ullong)min, (ullong)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((ulong)min, (ulong)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((ushort)min, (ushort)max, num_bins) ||      !hist6.bins_d.almostEqual(test_bins)) {    test_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  // test setBins in EDGES mode  //  hist6.setMode(EDGES);  if (!hist6.setBins((byte)min, (byte)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((double)min, (double)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((float)min, (float)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((llong)min, (llong)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((long)min, (long)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((short)min, (short)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((ullong)min, (ullong)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((ulong)min, (ulong)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  if (!hist6.setBins((ushort)min, (ushort)max, num_bins) ||      !hist6.bins_d.almostEqual(test_edges_bins)) {    test_edges_bins.debug(L"expected bins");    hist6.bins_d.debug(L"actual bins");    return Error::handle(name(), L"setBins", Error::TEST, __FILE__,			 __LINE__);  }  // test setCounts, all types  //  VectorByte byte_counts;  byte_counts.assign(test_counts);  VectorDouble double_counts;  double_counts.assign(test_counts);  VectorFloat float_counts;  float_counts.assign(test_counts);  VectorLlong llong_counts;  llong_counts.assign(test_counts);  VectorLong long_counts;

⌨️ 快捷键说明

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