📄 ftrf_02.cc
字号:
if (!flag1 || !flag2) { vf_read.debug(L"vf_read"); vf_expected.debug(L"vecf_expected"); return Error::handle(name(), L"readFeatureData float text", Error::TEST, __FILE__, __LINE__); } } // end of j loop // close the files // read_float_vec_text.close(); // text raw features writing method test // if (level_a > Integral::NONE) { Console::put(L"testing raw features writing methods in text..."); } // local variable // long num_vecfloats = 3056; FeatureFile raw_features; Vector <AlgorithmData> vf; vf.setLength(num_vecfloats); vf_expected.clear(); vf_expected.setLength(num_vecfloats); // prepare data to write // for (long i = 0; i < num_vecfloats; i++) { vf(i).makeVectorFloat().setLength(8); vf(i).getVectorFloat().assign((i + 1) * 2.6350); vf_expected(i).makeVectorFloat().setLength(8); vf_expected(i).getVectorFloat().assign((i + 1) * 2.6350); } // open the raw file in text // raw_features.setFileType(TEXT); raw_features.setFileFormat(FeatureFile::RAW); text_filename.concat(L".raw"); File::registerTemp(text_filename); raw_features.open(text_filename, File::WRITE_ONLY); // set the required variables // raw_features.setNumFeatures(8); raw_features.setNumChannels(1); // write the raw features to the file in text // raw_features.writeFeatureData(vf); raw_features.close(); // text raw features reading method test // if (level_a > Integral::NONE) { Console::put(L"testing raw features reading methods in text..."); } // open back the raw feature text file in read-mode // raw_features.open(text_filename, File::READ_ONLY); // initializing elements // vf.clear(); long number_input = 8; long num_features = 0; // read one feature-vector at a time // while (number_input) { number_input = raw_features.readFeatureData(vf); if (number_input == 0) break; // check this feature-vector with the expected value // if (!vf(0).getVectorFloat().almostEqual(vf_expected(num_features).getVectorFloat())) { Long(num_features).debug(L"num_features"); vf(0).getVectorFloat().debug(L"vf"); vf_expected(num_features).getVectorFloat().debug(L"vf_expected"); return Error::handle(name(), L"read partial float text", Error::TEST, __FILE__, __LINE__); } num_features++; } raw_features.close(); // binary raw features writing method test // if (level_a > Integral::NONE) { Console::put(L"testing raw features writing methods in binary..."); } // prepare data to write // vf.setLength(num_vecfloats); for (long i = 0; i < num_vecfloats; i++) { vf(i).makeVectorFloat().setLength(8); vf(i).getVectorFloat().assign((i + 1) * 2.6350); vf_expected(i).makeVectorFloat().setLength(8); vf_expected(i).getVectorFloat().assign((i + 1) * 2.6350); } // open the raw file in binary // raw_features.setFileType(BINARY); raw_features.setFileFormat(FeatureFile::RAW); bin_filename.concat(L".raw"); File::registerTemp(bin_filename); raw_features.setNumFeatures(8); raw_features.setNumChannels(1); raw_features.open(bin_filename, File::WRITE_ONLY); // write the feature-vectors to raw file in binary // raw_features.writeFeatureData(vf, 0); raw_features.close(); // binary raw features reading test // if (level_a > Integral::NONE) { Console::put(L"testing raw features reading methods in binary..."); } // open back the raw feature binary file in read-mode // raw_features.open(bin_filename, File::READ_ONLY); // initializing elements // vf.clear(); number_input = 8; num_features = 0; // read one feature-vector at a time // while (number_input) { number_input = raw_features.readFeatureData(vf, 0); if (number_input == 0) break; // check this feature-vector with the expected value // if (!vf(0).getVectorFloat().almostEqual(vf_expected(num_features).getVectorFloat())) { Long(num_features).debug(L"num_features"); vf(0).getVectorFloat().debug(L"vf"); vf_expected(num_features).getVectorFloat().debug(L"vf_expected"); return Error::handle(name(), L"read partial float text", Error::TEST, __FILE__, __LINE__); } num_features++; } raw_features.close(); // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 4. 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(); } // declare the reference object // FeatureFile ftr_set; // set various variables // ftr_set.setName(L"FEATURES"); ftr_set.setFileType(BINARY); ftr_set.setFileFormat(RAW); // ftr_set.setCompType(ULAW); // not yet implemented ftr_set.setAmplitudeRange(2); ftr_set.setNumChannels(4); ftr_set.setID(L"tidigits"); ftr_set.setNumFeatures(20); ftr_set.setDataType(VECTOR_FLOAT); ftr_set.setCoefType(AlgorithmData::SPECTRUM); ftr_set.setFrameDuration(0.05); ftr_set.setSampleFrequency(4000.0); ftr_set.setLength(2); // check the set variables // if (!ftr_set.name_d.eq(L"FEATURES")) { return Error::handle(name(), L"setName", Error::TEST, __FILE__, __LINE__); } if (ftr_set.file_type_d != BINARY) { return Error::handle(name(), L"setFileType", Error::TEST, __FILE__, __LINE__); } if (ftr_set.file_format_d != RAW) { return Error::handle(name(), L"setFileFormat", Error::TEST, __FILE__, __LINE__); } // if (ftr_set.compression_type_d != ULAW) { // return Error::handle(name(), L"setCompType", Error::TEST, // __FILE__, __LINE__); // } if (ftr_set.amplitude_range_d != ((double)2)) { return Error::handle(name(), L"setAmplitudeRange", Error::TEST, __FILE__, __LINE__); } if (ftr_set.num_channels_d != (long)4) { return Error::handle(name(), L"setNumChannels", Error::TEST, __FILE__, __LINE__); } if (!ftr_set.id_d.eq(L"tidigits")) { return Error::handle(name(), L"setID", Error::TEST, __FILE__, __LINE__); } if (ftr_set.num_features_d != (long)20) { return Error::handle(name(), L"setNumFeatures", Error::TEST, __FILE__, __LINE__); } if (ftr_set.data_type_d != VECTOR_FLOAT) { return Error::handle(name(), L"setDataType", Error::TEST, __FILE__, __LINE__); } if (ftr_set.coef_type_d != AlgorithmData::SPECTRUM) { return Error::handle(name(), L"setCoefType", Error::TEST, __FILE__, __LINE__); } if (!(Integral::almostEqual((double)ftr_set.frame_duration_d, 0.05))) { return Error::handle(name(), L"setFrameDuration", Error::TEST, __FILE__, __LINE__); } if (!(Integral::almostEqual((double)ftr_set.sample_frequency_d, 4000.0))) { return Error::handle(name(), L"setSampleFrequency", Error::TEST, __FILE__, __LINE__); } if (ftr_set.v_d.length() != (long)2) { return Error::handle(name(), L"setLength", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 5. class-specific public methods: // get methods // //--------------------------------------------------------------------------- // set indentation // if (level_a > Integral::NONE) { Console::put(L"testing class-specific public methods: get methods...\n"); Console::increaseIndention(); } // check the get variables // if (!ftr_set.getName().eq(L"FEATURES")) { return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__); } if (ftr_set.getFileType() != BINARY) { return Error::handle(name(), L"getFileType", Error::TEST, __FILE__, __LINE__); } if (ftr_set.getFileFormat() != RAW) { return Error::handle(name(), L"getFileFormat", Error::TEST, __FILE__, __LINE__); } // if (ftr_set.getCompType() != ULAW) { // return Error::handle(name(), L"getCompType", Error::TEST, // __FILE__, __LINE__); // } if (ftr_set.getAmplitudeRange() != (long)2) { return Error::handle(name(), L"getAmplitudeRange", Error::TEST, __FILE__, __LINE__); } if (ftr_set.getNumChannels() != (long)4) { return Error::handle(name(), L"getNumChannels", Error::TEST, __FILE__, __LINE__); } if (!ftr_set.getID().eq(L"tidigits")) { return Error::handle(name(), L"getID", Error::TEST, __FILE__, __LINE__); } if (ftr_set.getNumFeatures() != (long)20) { return Error::handle(name(), L"getNumFeatures", Error::TEST, __FILE__, __LINE__); } if (ftr_set.getDataType() != VECTOR_FLOAT) { return Error::handle(name(), L"getDataType", Error::TEST, __FILE__, __LINE__); } if (ftr_set.getCoefType() != AlgorithmData::SPECTRUM) { return Error::handle(name(), L"getCoefType", Error::TEST, __FILE__, __LINE__); } if (!(Integral::almostEqual((double)(ftr_set.getFrameDuration()), 0.05))) { return Error::handle(name(), L"getFrameDuration", Error::TEST, __FILE__, __LINE__); } if (!(Integral::almostEqual((double)(ftr_set.getSampleFrequency()), 4000.0))) { return Error::handle(name(), L"getSampleFrequency", Error::TEST, __FILE__, __LINE__); } // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } //--------------------------------------------------------------------------- // // 6. print completion message // //--------------------------------------------------------------------------- // reset indentation // if (level_a > Integral::NONE) { Console::decreaseIndention(); } if (level_a > Integral::NONE) { SysString output(L"diagnostics passed for class "); output.concat(name()); output.concat(L"\n"); Console::put(output); } // exit gracefully // return true; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -