📄 win_02.cc
字号:
// file: $isip/class/algo/Window/win_02.cc// version: $Id: win_02.cc,v 1.21 2002/05/31 21:57:32 picone Exp $//// isip include files//#include "Window.h"#include <Console.h>// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Window::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(); } Window win0; win0.setAlgorithm(RECTANGULAR); win0.setNormalization(NONE); win0.setDuration(0.025); // win0.init(); Window win1(win0); if (!win1.eq(win0)) { win0.debug(L"win0"); win1.debug(L"win1"); 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 // Window::setGrowSize((long)500); Window* pwin = new Window(); for (long j = 1; j <= 100; j++) { Window** pwins = new Window*[j * 100]; // create the objects // for (long i = 0; i < j * 100; i++) { pwins[i] = new Window(); } // delete objects // for (long i = (j * 100) - 1; i >= 0; i--) { delete pwins[i]; } delete [] pwins; } delete pwin; } // 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 // win0.setAlgorithm(HAMMING); win0.setAlignment(LEFT); win0.setNormalization(NONE); win0.setDuration(0.0250); win0.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); win0.write(tmp_file0, (long)0); win0.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 // win1.read(tmp_file0, (long)0); win1.init(); if (!win0.eq(win1)) { return Error::handle(name(), L"i/o", Error::TEST, __FILE__, __LINE__); } win1.read(tmp_file1, (long)0); win1.init(); if (!win0.eq(win1)) { 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 // win0.setAlgorithm(HAMMING); VectorFloat tmp(L"27.0, 9.0, 3.0"); // set the parameters manually // win0.setAlgorithm(RECTANGULAR); win0.setAlignment(LEFT); win0.setNormalization(UNIT_ENERGY); win0.setDuration(2.0); win0.setComputeMode(CROSS_FRAME); win0.setSize(3); // check that the values were set // if (win0.algorithm_d != RECTANGULAR) { return Error::handle(name(), L"setAlgorithm", Error::TEST, __FILE__, __LINE__); } else if (win0.cmode_d != CROSS_FRAME) { return Error::handle(name(), L"setMode", Error::TEST, __FILE__, __LINE__); } else if (win0.alignment_d != LEFT) { return Error::handle(name(), L"setAlignment", Error::TEST, __FILE__, __LINE__); } else if (win0.normalization_d != UNIT_ENERGY) { return Error::handle(name(), L"setNormalization", Error::TEST, __FILE__, __LINE__); } else if (win0.duration_d != (float)2.0) { return Error::handle(name(), L"setDuration", Error::TEST, __FILE__, __LINE__); } else if (win0.data_d.length() != 3) { return Error::handle(name(), L"setSize", Error::TEST, __FILE__, __LINE__); } // test setConstants // win0.setAlgorithm(BLACKMAN); win0.setConstants(tmp); if (!win0.constants_d.eq(tmp)) { return Error::handle(name(), L"setData", Error::TEST, __FILE__, __LINE__); } // test setData // win0.setAlgorithm(CUSTOM); win0.setData(tmp); if (!win0.data_d.eq(tmp)) { return Error::handle(name(), L"setData", 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(); } // test the basic compute method: // create a vector, multiplying it by the window, and see if it gives us // back the window. // VectorFloat input(L"1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2"); VectorFloat scale(L"1, 0.5, 1, 0.5, 1, 0.5, 1, 0.5, 1, 0.5, 1, 0.5, 1, 0.5, 1, 0.5, 1, 0.5, 1, 0.5"); VectorFloat output; VectorFloat ans; win0.clear(); win0.setSize(input.length()); win0.setAlgorithm(RECTANGULAR); win0.setNormalization(NONE); win0.setDuration(0.01); win0.init(); ans.assign(win0.getData()); win0.compute(output, input); output.mult(scale);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -