📄 fb_02.cc
字号:
// file: $isip/class/algo/FilterBank/fb_02.cc// version: $Id: fb_02.cc,v 1.12 2002/07/10 00:53:24 picone Exp $//// isip include files//#include "FilterBank.h"#include <Console.h>// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean FilterBank::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 // //--------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing required public methods...\n"); Console::increaseIndention(); } // test destructor/constructor(s) and memory management methods // FilterBank mel_FilterBanker; FilterBank bark_FilterBanker; FilterBank::setGrowSize((long)500); for (long j = 1; j <= 10; j++) { FilterBank** FilterBanks = new FilterBank*[j * 100]; // create the objects // for (long i = 0; i < j * 100; i++) { FilterBanks[i] = new FilterBank(); } // delete objects // for (long i = (j * 100) - 1; i >= 0; i--) { delete FilterBanks[i]; } delete [] FilterBanks; } // 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(); } // test the i/o methods // FilterBank fb0o, fb0w; FilterBank fb1o, fb1w; FilterBank fb2o, fb2w; fb0o.set(FREQUENCY, TRIANGULAR, FULL, BARK, (long)30, (float)8000); fb0w.set(FREQUENCY, TRIANGULAR, FULL, MEL, (float)2.1, (float)8000); // 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); fb0o.write(tmp_file0, (long)0); fb0o.write(tmp_file1, (long)0); fb0w.write(tmp_file0, (long)1); fb0w.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 first value back // if (!fb1o.read(tmp_file0, (long)0) || (!fb1o.eq(fb0o))) { fb1o.debug(L"fb1o"); fb0o.debug(L"fb0o"); return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!fb2o.read(tmp_file1, (long)0) || (!fb2o.eq(fb0o))) { fb2o.debug(L"fb2o"); fb0o.debug(L"fb0o"); return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } // read the second value back // if (!fb1w.read(tmp_file0, (long)1) || (!fb1w.eq(fb0w))) { fb1w.debug(L"fb1w"); fb0w.debug(L"fb0w"); return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (!fb2w.read(tmp_file1, (long)1) || (!fb2w.eq(fb0w))) { 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); // test the conditional i/o methods // FilterBank fb_0; fb_0.setOrder(20); Sof tmp_file2; String tmp_filename2; Integral::makeTemp(tmp_filename2); tmp_file2.open(tmp_filename2, File::WRITE_ONLY); tmp_file2.put(CLASS_NAME, 5, -1); String line; line.assign(L"algorithm = FREQUENCY;\n"); tmp_file2.puts(line); tmp_file2.put(CLASS_NAME, 10, -1); line.assign(L"algorithm = TIME;\n"); tmp_file2.puts(line); // close the file // tmp_file2.close(); // open the file in read mode // tmp_file2.open(tmp_filename2); fb_0.read(tmp_file2, (long)5); fb_0.clear(); fb_0.read(tmp_file2, (long)10); if (fb_0.getAlgorithm() != TIME) { return Error::handle(name(), L"readData", Error::TEST, __FILE__, __LINE__); } // close and delete the temporary files // tmp_file2.close(); File::remove(tmp_filename2); // 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(); } // test the set methods // FilterBank fb1; fb1.setAlgorithm(FREQUENCY); fb1.setImplementation(TRIANGULAR); fb1.setInputMode(FULL); fb1.setScale(MEL); fb1.setFrequencySampling(BANDWIDTH); fb1.setBandwidth((float)85.0); if (fb1.algorithm_d != FREQUENCY) { return Error::handle(name(), L"setAlgorithm", Error::TEST, __FILE__, __LINE__); } if (fb1.implementation_d != TRIANGULAR) { return Error::handle(name(), L"setImplementation", Error::TEST, __FILE__, __LINE__); } if (fb1.input_mode_d != FULL) { return Error::handle(name(), L"setInputMode", Error::TEST, __FILE__, __LINE__); } if (fb1.scale_d != MEL) { return Error::handle(name(), L" setScale", Error::TEST, __FILE__, __LINE__); } if (fb1.fsmp_d != BANDWIDTH) { return Error::handle(name(), L"setFrequencySampling", Error::TEST, __FILE__, __LINE__); } if (fb1.bandwidth_d != (float)85.0) { return Error::handle(name(), L"setBandwidth", Error::TEST, __FILE__, __LINE__); } fb1.setFrequencySampling(ORDER); fb1.setOrder((long)12.0); if (fb1.fsmp_d != ORDER) { return Error::handle(name(), L" setFrequencySampling", Error::TEST, __FILE__, __LINE__); } if (fb1.order_d != (long)12.0) { return Error::handle(name(), L"setBandwidth", Error::TEST, __FILE__, __LINE__); } fb1.set(FREQUENCY, RAISED_COSINE, FULL, BARK, (long)11, (float)8000); if (fb1.algorithm_d != FREQUENCY) { return Error::handle(name(), L"setAlgorithm", Error::TEST, __FILE__, __LINE__); } if (fb1.implementation_d != RAISED_COSINE) { return Error::handle(name(), L"setImplementation", Error::TEST, __FILE__, __LINE__); } if (fb1.input_mode_d != FULL) { return Error::handle(name(), L"setInputMode", Error::TEST, __FILE__, __LINE__); } if (fb1.scale_d != BARK) { return Error::handle(name(), L" setScale", Error::TEST, __FILE__, __LINE__); } if (fb1.fsmp_d != ORDER) { return Error::handle(name(), L"setFrequencySampling", Error::TEST, __FILE__, __LINE__); } if (fb1.order_d != (long)11.0) { return Error::handle(name(), L"setOrder", Error::TEST, __FILE__, __LINE__); } fb1.set(FREQUENCY, UNIFORM, SYMMETRIC, BARK, (float)90.0, (float)8000); if (fb1.algorithm_d != FREQUENCY) { return Error::handle(name(), L"setAlgorithm", Error::TEST, __FILE__, __LINE__); } if (fb1.implementation_d != UNIFORM) { return Error::handle(name(), L"setImplementation", Error::TEST, __FILE__, __LINE__); } if (fb1.input_mode_d != SYMMETRIC) { return Error::handle(name(), L"setInputMode", Error::TEST, __FILE__, __LINE__); } if (fb1.scale_d != BARK) { return Error::handle(name(), L" setScale", Error::TEST, __FILE__, __LINE__); } if (fb1.fsmp_d != BANDWIDTH) { return Error::handle(name(), L"setFrequencySampling", Error::TEST, __FILE__, __LINE__); } if (fb1.bandwidth_d != (float)90.0) { return Error::handle(name(), L"setBandwidth", Error::TEST, __FILE__, __LINE__); } // test the get methods // ALGORITHM algo = FREQUENCY; IMPLEMENTATION impl = UNIFORM;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -