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

📄 gen_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/algo/Generator/gen_02.cc// version: $Id: gen_02.cc,v 1.14 2002/07/18 21:49:44 parihar Exp $//// isip include files//#include "Generator.h"#include <VectorFloat.h>#include <MatrixFloat.h>#include <String.h>#include <Console.h>#include <Float.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: logical error status//// this is the diagnostics method////  level               function////  NONE                test nothing//  BRIEF               fully test functionality, no output//  DETAILED            fully test functionality, stub output//  ALL                fully test functionality, full output//boolean Generator::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  //     class constructors  //  //--------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing required public methods...\n");    Console::increaseIndention();  }    Generator gen0;  Generator gen1(gen0);  if (!gen1.eq(gen0)) {    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    //    Generator::setGrowSize((long)500);    Generator* pft = new Generator();        for (long j = 1; j <= 100; j++) {      Generator** pfts = new Generator*[j * 100];            // create the objects      //      for (long i = 0; i < j * 100; i++) {        pfts[i] = new Generator();      }          // delete objects      //      for (long i = (j * 100) - 1; i >= 0; i--) {        delete pfts[i];      }          delete [] pfts;    }         delete pft;  }  // 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();  }    Generator gen2;  Generator gen3;  Generator gen4;  gen2.setAlgorithm(GAUSSIAN);  gen2.setComputeMode(ACCUMULATE);  float mean0 = 1.5;  float variance0 = 2.0;  gen2.setGaussian(mean0, variance0);  // 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);  gen2.write(tmp_file0, (long)0);  gen2.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  //   gen3.read(tmp_file0, (long)0);  if (!gen3.eq(gen2)) {    gen3.debug(L"gen3");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  gen4.read(tmp_file1, (long)0);  if (!gen4.eq(gen2)) {    gen4.debug(L"gen4");    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();  }    //--------------------------------------------------------------------------  //  // 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();  }  // declare an object  //  Generator gen5;  // set the parameters manually  //  double sample_freq0 = 600.0;  double sample_freq1;  gen5.setSampleFrequency(sample_freq0);  sample_freq1 = gen5.getSampleFrequency();  double frame_duration0 = 1.0;  double frame_duration1;  gen5.setFrameDuration(frame_duration0);  frame_duration1 = gen5.getFrameDuration();  float freq0 = 100.0;  float freq1;  gen5.setFrequency(freq0);  freq1 = gen5.getFrequency();  float amp0 = 2.0;  float amp1;  gen5.setAmplitude(amp0);  amp1 = gen5.getAmplitude();    if (sample_freq0 != sample_freq1) {    return Error::handle(name(), L"setSampleFrequency", Error::TEST,                         __FILE__, __LINE__);  }  else if (frame_duration0 != frame_duration1) {    return Error::handle(name(), L"setFrameDuration", Error::TEST,                         __FILE__, __LINE__);  }  else if (freq0 != freq1) {    return Error::handle(name(), L"setFrequency", Error::TEST,                         __FILE__, __LINE__);  }  else if (amp0 != amp1) {    return Error::handle(name(), L"setFrequency", Error::TEST,                         __FILE__, __LINE__);  }  // declare an object  //  Generator gen6;  // set the parameters manually  //  float mean1 = 1.2;  float mean2;  gen6.setAlgorithm(GAUSSIAN);  gen6.setComputeMode(ACCUMULATE);  gen6.setMean(mean1);  mean2 = gen6.getMean();  float var0 = 0.8;  float var1;  gen6.setVariance(var0);  var1 = gen6.getVariance();    if (mean1 != mean2) {    return Error::handle(name(), L"setMean", Error::TEST,                         __FILE__, __LINE__);  }  else if (var0 != var1) {    return Error::handle(name(), L"setVariance", Error::TEST,                         __FILE__, __LINE__);  }  // declare the object  //  Generator gen7;  // set the parameters manually  //  float val0 = 50.0;  float val1;  gen7.setAlgorithm(PULSE);  gen7.setComputeMode(ACCUMULATE);  val1 = gen7.getDutyCycle();  float phase0 = (-22.0) / (2 * 7.0);  float phase1, phase2;  gen7.setPhase(phase0);  phase1 = gen7.getPhase();  gen7.setPhaseMode(RANDOM);  gen7.setSeed(800);  gen7.setPhase(phase0);  phase2 = gen7.getPhase();  float bias0 = 0;  float bias1;  gen7.setBias(bias0);  bias1 = gen7.getBias();    if (val0 != val1) {    return Error::handle(name(), L"setDutyCycle", Error::TEST,                         __FILE__, __LINE__);  }  else if (phase0 != phase1) {    return Error::handle(name(), L"setPhase", Error::TEST,                         __FILE__, __LINE__);  }  else if (gen7.getPhaseMode() != RANDOM) {    return Error::handle(name(), L"setPhaseMode", Error::TEST,                         __FILE__, __LINE__);  }  else if (bias0 != bias1) {    return Error::handle(name(), L"setBias", Error::TEST,                         __FILE__, __LINE__);  }  else if (gen7.getAlgorithm() != PULSE) {    return Error::handle(name(), L"setAlgorithm", Error::TEST,                         __FILE__, __LINE__);  }

⌨️ 快捷键说明

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