📄 algo_02.cc
字号:
// file: $isip/class/algo/Algorithm/algo_02.cc// version: $Id: algo_02.cc,v 1.32 2002/07/14 14:56:24 picone Exp $//// isip include files//#include "Algorithm.h"#include <Console.h>#include <Filename.h>#include <AlgorithmContainer.h>#include <Calculus.h>#include <Cepstrum.h>#include <CoefficientLabel.h>#include <Connection.h>#include <Constant.h>#include <Correlation.h>#include <Covariance.h>#include <DisplayData.h>#include <Energy.h>#include <Filter.h>#include <FilterBank.h>#include <FourierTransform.h>#include <Generator.h>#include <LogAreaRatio.h>#include <Mask.h>#include <Math.h>#include <Prediction.h>#include <Reflection.h>#include <Spectrum.h>#include <Statistics.h>#include <Window.h>// method: diagnose//// arguments:// Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Algorithm::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(); } // perform full diagnostic // Algorithm a; a.setType(DEF_TYPES); // test the i/o methods // Algorithm write_cep; write_cep.setType(CEPSTRUM); Algorithm write_ft; write_ft.setType(FOURIER_TRANSFORM); Cepstrum* cep = (Cepstrum*)write_cep.virtual_algo_d; FourierTransform* ft = (FourierTransform*)write_ft.virtual_algo_d; ft->setOrder(233); cep->setOrder(55); Algorithm write_fba; write_fba.setType(FILTER_BANK); FilterBank* fba0 = (FilterBank*)write_fba.virtual_algo_d; fba0->setOrder(50); Algorithm write_buf; write_buf.setType(COEFFICIENT_LABEL); CoefficientLabel* buf0 = (CoefficientLabel*)write_buf.virtual_algo_d; buf0->setVariable(String(L"my_var")); Algorithm read_text; Algorithm read_bin; // 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); write_fba.write(tmp_file0, 0); write_fba.write(tmp_file1, 0); write_buf.write(tmp_file0, 1); write_buf.write(tmp_file1, 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 value back // read_text.read(tmp_file0, 0); if (!read_text.eq(write_fba)) { read_text.debug(L"read text"); return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } read_text.clear(); read_text.read(tmp_file0, 1); if (!read_text.eq(write_buf)) { read_text.debug(L"read text"); 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); { String filename(L"diagnose_params.sof"); Sof sof; sof.open(filename); Algorithm algo; // do a "good" read // for (long i = (long)ALGORITHM_CONTAINER; i <= (long)WINDOW; i++) { if (!algo.read(sof, i)) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (algo.getType() != (TYPES)i) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } } // open files in write mode // String tmp_filename; Integral::makeTemp(tmp_filename); // do a "bad" read // for (long i = (long)ALGORITHM_CONTAINER; i <= (long)WINDOW; i++) { Console::open(tmp_filename, File::WRITE_ONLY); boolean res = algo.read(sof, 50 + i); Console::close(); if (res) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } if (algo.virtual_algo_d != (AlgorithmBase*)&NO_ALGORITHM) { return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__); } } sof.close(); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //-------------------------------------------------------------------------- // // 2. class-specific public methods: // computational methods // //-------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: computational methods...\n"); Console::increaseIndention(); } Vector< CircularBuffer<AlgorithmData> > uw_sig(1); AlgorithmData ad; ad.makeVectorFloat().assign(L"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,32,32,0,32,-32,16,48,48,16,-48,0,16,32,-32,-16,0,0,16,16,-32,-32,32,0,-16,-48,0,0,-16,0,-32,-48,48,-32,48,16,0,-48,-48,0,48,-32,0,16,0,16,48,48,-48,0,48,0,48,-32,48,16,-48,-16,32,32,-48,48,32,0,-48,-32,-16,48,48,16,32,0,-16,16,0,-32,-48,-48,0,16,0,-32,32,-48,32,0,48,-48,-48,32,32,0,48,48,-48,-48,0,16,-16,32,-16,16,-32,-16,0,32,48,0,0,48,0,0,-16,0,16,16,0,0,0,-32,0,32,16,0,32,-48,16,32,16,32,16,48,0,32,-16,16,-48,0,48,-32,0,-16,-48,-32,-32,16,-48,00,-16,16,-48"); uw_sig(0).append(ad); uw_sig(0)(0).setCoefType(AlgorithmData::SIGNAL); Vector< CircularBuffer<AlgorithmData> > signal(1); ad.makeVectorFloat().assign(L"0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25.3972,17.3962,17.8608,0,18.7878,-19.2493,9.85443,30.249,30.9303,10.5356,-32.2773,0,11.1997,22.8325,-23.2601,-11.8409,0,0,12.4533,12.6502,-25.686,-26.0633,26.4318,0,-13.5706,-41.2218,0,0,-14.2196,0,-29.0227,-43.9456,44.3391,-29.8096,45.0708,15.1361,0,-46.0244,-46.3025,0,46.7977,-31.3428,0,15.7946,0,15.8893,47.7775,47.8653,-47.9313,0,47.9972,0,47.9752,-31.9542,47.8653,15.9258,-47.6679,-15.8455,31.5892,31.4731,-47.0141,46.7977,31.0403,0,-46.0244,-30.4841,-15.1361,45.0708,44.7143,14.7797,29.2971,0,-14.3683,14.2196,0,-27.8111,-41.2218,-40.7117,0,13.2159,0,-25.686,25.3003,-37.36,24.5054,0,35.5226,-34.8901,-34.2487,22.3994,21.9611,0,31.6067,30.9303,-30.249,-29.5633,0,9.39392,-9.16242,17.8608,-8.6981,8.46573,-16.4671,-8.00175,0,15.0806,21.9334,0,0,19.8972,0,0,-5.9717,0,5.54416,5.33492,0,0,0,-9.06581,0,8.31135,3.97367,0,7.24759,-10.3688,3.29392,6.27378,2.98535,5.67889,2.69932,7.69537,0,4.63003,-2.19936,2.09012,-5.96225,0,5.40597,-3.43892,0,-1.57516,-4.54064,-2.91806,-2.82335,1.37153,-4.01586,0,-1.29467,1.28367,-3.84"); signal(0).append(ad); VectorComplexFloat exp_full_spec(L"213.54+0j,-98.4317-66.3989j,20.414-22.5332j,-18.3641-117.681j,-244.286+306.743j,432.23-15.7173j,-141.806-316.598j,-106.143+138.435j,-22.1858+94.4657j,77.6981-32.3186j,-17.9067+1.67488j,180.767-30.3753j,-346.874-66.853j,280.487+104.613j,-220.615-49.331j,185.989+111.068j,-16.2566-147.374j,-79.0549+6.47962j,-37.9195+55.036j,129.596+93.4283j,-73.2533-268.423j,-51.8748+343.865j,165.473-273.824j,-154.921+119.768j,61.3019-91.4918j,-78.7142+187.877j,159.298-227.344j,-192.879+227.01j,285.885-168.906j,-324.455-69.5254j,63.0646+247.154j,237.729-135.335j,-264.001+66.651j,226.281-214.296j,-237.582+249.87j,142.344-158.647j,-89.1673+134.23j,132.876+27.7403j,78.3628-294.066j,-429.878+204.037j,417.342+100.192j,-199.44-93.4447j,163.589-98.9199j,-138.002+211.688j,107.723-385.284j,-379.001+418.19j,614.091+26.7781j,-309.321-426.985j,-77.371+201.788j,-28.2436+140.651j,224.375-17.0141j,-52.807-169.946j,-119.069+5.01486j,-37.3025+112.979j,138.281+132.892j,113.106-311.771j,-323.684+72.4452j,139.354+217.411j,130.483-200.411j,-144.059+121.397j,83.0865-191.541j,-116.035+194.115j,107.171-64.2338j,-88.2139-52.3065j,138.244+276.615j,3.63187-608.332j,-371.399+612.545j,500.6-248.277j,-291.681+22.458j,122.27+3.12732j,-0.973726-119.711j,-260.421+124.983j,411.669+201.121j,-245.406-438.693j,48.1288+254.238j,-64.6888+50.8051j,196.158-129.457j,-264.876+2.2067j,150.148+110.594j,76.5673-14.4247j,-160.076-198.906j,102.595+248.921j,-143.905-176.391j,194.259+228.011j,-7.04008-298.651j,-255.429+166.437j,318.978+38.2254j,-231.853-146.337j,89.861+220.021j,91.1781-249.608j,-150.331+142.83j,-15.5059-8.02728j,195.121+9.95152j,-180.332-105.744j,50.1433+146.923j,16.1551-67.3868j,49.9787-52.4733j,-167.019+33.2638j,144.766+163.363j,90.0536-282.284j,-290.659+94.7904j,158.444+213.334j,199.699-272.661j,-397.403+75.7847j,315.833+73.1655j,-138.352-74.1787j,-37.8636+47.234j,171.771+14.3399j,-146.325-127.47j,62.4803+168.966j,-130.521-187.337j,131.671+316.991j,184.824-346.586j,-428.153+113.925j,258.893+53.482j,-41.186-2.25672j,1.38646+26.879j,129.024-83.4756j,-269.357-110.683j,139.805+290.698j,-41.6795-150.97j,260.733+18.4517j,-428.195-136.186j,278.29+241.65j,-51.5393-193.921j,-68.5357+58.3203j,48.2095+155.662j,132.499-239.97j,-258.826+0j,132.499+239.97j,48.2095-155.662j,-68.5357-58.3203j,-51.5393+193.921j,278.29-241.65j,-428.195+136.186j,260.733-18.4517j,-41.6795+150.97j,139.805-290.698j,-269.357+110.683j,129.024+83.4756j,1.38646-26.879j,-41.186+2.25672j,258.893-53.482j,-428.153-113.925j,184.824+346.586j,131.671-316.991j,-130.521+187.337j,62.4803-168.966j,-146.325+127.47j,171.771-14.3399j,-37.8636-47.234j,-138.352+74.1787j,315.833-73.1655j,-397.403-75.7847j,199.699+272.661j,158.444-213.334j,-290.659-94.7904j,90.0536+282.284j,144.766-163.363j,-167.019-33.2638j,49.9787+52.4733j,16.1551+67.3868j,50.1433-146.923j,-180.332+105.744j,195.121-9.95152j,-15.5059+8.02728j,-150.331-142.83j,91.1781+249.608j,89.861-220.021j,-231.853+146.337j,318.978-38.2254j,-255.429-166.437j,-7.04008+298.651j,194.259-228.011j,-143.905+176.391j,102.595-248.921j,-160.076+198.906j,76.5673+14.4247j,150.148-110.594j,-264.876-2.2067j,196.158+129.457j,-64.6888-50.8051j,48.1288-254.238j,-245.406+438.693j,411.669-201.121j,-260.421-124.983j,-0.973726+119.711j,122.27-3.12732j,-291.681-22.458j,500.6+248.277j,-371.399-612.545j,3.63187+608.332j,138.244-276.615j,-88.2139+52.3065j,107.171+64.2338j,-116.035-194.115j,83.0865+191.541j,-144.059-121.397j,130.483+200.411j,139.354-217.411j,-323.684-72.4452j,113.106+311.771j,138.281-132.892j,-37.3025-112.979j,-119.069-5.01486j,-52.807+169.946j,224.375+17.0141j,-28.2436-140.651j,-77.371-201.788j,-309.321+426.985j,614.091-26.7781j,-379.001-418.19j,107.723+385.284j,-138.002-211.688j,163.589+98.9199j,-199.44+93.4447j,417.342-100.192j,-429.878-204.037j,78.3628+294.066j,132.876-27.7403j,-89.1673-134.23j,142.344+158.647j,-237.582-249.87j,226.281+214.296j,-264.001-66.651j,237.729+135.335j,63.0646-247.154j,-324.455+69.5254j,285.885+168.906j,-192.879-227.01j,159.298+227.344j,-78.7142-187.877j,61.3019+91.4918j,-154.921-119.768j,165.473+273.824j,-51.8748-343.865j,-73.2533+268.423j,129.596-93.4283j,-37.9195-55.036j,-79.0549-6.47962j,-16.2566+147.374j,185.989-111.068j,-220.615+49.331j,280.487-104.613j,-346.874+66.853j,180.767+30.3753j,-17.9067-1.67488j,77.6981+32.3186j,-22.1858-94.4657j,-106.143-138.435j,-141.806+316.598j,432.23+15.7173j,-244.286-306.743j,-18.3641+117.681j,20.414+22.5332j,-98.4317+66.3989j"); VectorFloat exp_mag_spec(L"213.54,118.733,30.4052,119.105,392.132,432.516,346.905,174.444,97.036,84.1516,17.9848,183.302,353.257,299.361,226.063,216.629,148.268,79.32,66.8345,159.763,278.239,347.756,319.939,195.818,110.13,203.7,277.599,297.885,332.054,331.821,255.073,273.551,272.285,311.65,344.791,213.144,161.147,135.741,304.328,475.843,429.2,220.246,191.172,252.698,400.06,564.38,614.675,527.253,216.113,143.459,225.019,177.961,119.175,118.978,191.786,331.653,331.692,258.239,239.145,188.388,208.786,226.152,124.947,102.556,309.237,608.343,716.344,558.786,292.544,122.31,119.715,288.859,458.172,502.668,258.753,82.2544,235.025,264.885,186.482,77.9142,255.319,269.235,227.645,299.542,298.734,304.869,321.261,274.172,237.664,265.74,207.364,17.4606,195.375,209.049,155.244,69.2962,72.466,170.299,218.277,296.301,305.725,265.737,337.969,404.565,324.197,156.984,60.5368,172.369,194.061,180.148,228.322,343.25,392.787,443.05,264.36,41.2478,26.9148,153.673,291.211,322.57,156.618,261.385,449.33,368.565,200.653,89.9911,162.957,274.119"); VectorFloat exp_fba(L"136.426,565.169,722.371,286.152,321.025,765.071,445.8,532.437,889.883,865.41,1168.73,1138.94,1317.3,1749.66,1799.57,1192.56,1418.06,2547.19,2052.66,1842.88,1893.26,1887.01,2375.51,2523.27"); VectorFloat exp_gen(L"0.0, 0.309017, 0.587785, 0.809017, 0.951057, 1, 0.951057, 0.809017, 0.587785, 0.309017, -0, -0.309017, -0.587785, -0.809017, -0.951507, -1, -0.951057, -0.809017, -0.587785, -0.309017"); VectorFloat exp_liftered(L"0.0, -8.34266,-2.85678,-0.819747,0.852541,-0.960955,-2.01004,-3.54612,-0.774719,-6.65277,-2.79684,-3.57074,-10.5832"); VectorFloat exp_cepstrum(L"47.951, -3.25191, -0.696934, -0.147185, 0.12272, -0.117138, -0.215822, -0.345839, -0.0703947, -0.575776, -0.235266, -0.297559, -0.890239"); Double exp_energy(11.869536406860874); Algorithm trf0; Vector<AlgorithmData> output(1); // test Window // if (level_a > Integral::BRIEF) { Console::put(L"testing Window\n"); } trf0.setType(WINDOW); Window* w = (Window*)trf0.virtual_algo_d; w->setFrameDuration(0.25); w->setAlignment(Window::LEFT); w->setAlgorithm(Window::HAMMING); w->init(); trf0.apply(output, uw_sig);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -