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

📄 sdb_02.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/shell/Sdb/sdb_02.cc// version: $Id: sdb_02.cc,v 1.8 2001/04/17 19:14:28 jelinek Exp $//// isip include files//#include "Sdb.h"#include <Console.h>#include <CommandLine.h>// method: diagnose//// arguments://  Integral::DEBUG level: (input) debug level for diagnostics//// return: a boolean value indicating status//boolean Sdb::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 constructors  //  Sdb sdb;  String input;  Filename output;  input.assign(L"   foo.raw");  boolean list = false;  if ((!sdb.parse(output, list, input))      || (!output.eq(L"foo.raw"))      || (list)) {    return Error::handle(name(), L"parse", Error::TEST, __FILE__, __LINE__);  }    output.clear();  input.assign(L"foo.\\");  if (sdb.parse(output, list, input)      || (!output.eq(L"foo."))      || (list)) {    return Error::handle(name(), L"parse", Error::TEST, __FILE__, __LINE__);  }  input.assign(L"raw");  if ((!sdb.parse(output, list, input))      || (!output.eq(L"foo.raw"))      || (list)) {    return Error::handle(name(), L"parse", Error::TEST, __FILE__, __LINE__);  }  output.clear();  input.assign(L"(list) foo.list");  if ((!sdb.parse(output, list, input))      || (!output.eq(L"foo.list"))      || (!list)) {    return Error::handle(name(), L"parse", Error::TEST, __FILE__, __LINE__);  }  output.clear();  input.assign(L"(list) foo.\\");  if ((sdb.parse(output, list, input)) || (!output.eq(L"(list) foo."))) {    output.debug(L"output");    return Error::handle(name(), L"parse", Error::TEST, __FILE__, __LINE__);  }  input.assign(L"list");  if ((!sdb.parse(output, list, input))      || (!output.eq(L"foo.list"))      || (!list)) {    return Error::handle(name(), L"parse", Error::TEST, __FILE__, __LINE__);  }  // test basic functionality  //  Sdb sdb1;  Sdb sdb2;  Sdb sdb3;  Sdb sdb4;  // append files  //  Filename file1[5];  file1[0].assign(L"foo1.sof");  sdb1.append(file1[0]);  file1[1].assign(L"foo2.sof");  sdb1.append(file1[1]);  file1[2].assign(L"foo3.sof");  sdb1.append(file1[2]);  file1[3].assign(L"foo4.sof");  sdb1.append(file1[3]);  file1[4].assign(L"foo5.sof");  sdb1.append(file1[4]);  // 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 the values  //  sdb1.write(tmp_file0, (long)0);  sdb1.write(tmp_file1, (long)0);  // close the files  //  tmp_file0.close();  tmp_file1.close();  // now use the basic iterate method  //  Filename fn;  sdb2.append(tmp_filename0, true);  sdb2.lookahead_d = 2;    if (!sdb2.gotoFirst()) {    return Error::handle(name(), L"gotoFirst", Error::TEST, __FILE__,			 __LINE__);  }  if ((!sdb2.getName(fn)) || (fn.ne(file1[0]))) {    fn.debug(L"fn [0]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[1]))) {    fn.debug(L"fn [1]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[2]))) {    fn.debug(L"fn [2]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[3]))) {    fn.debug(L"fn [3]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[4]))) {    fn.debug(L"fn [4]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if (!sdb2.gotoFirst()) {    return Error::handle(name(), L"gotoFirst", Error::TEST, __FILE__,			 __LINE__);  }  if ((!sdb2.getName(fn)) || (fn.ne(file1[0]))) {    fn.debug(L"fn [0]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[1]))) {    fn.debug(L"fn [1]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[2]))) {    fn.debug(L"fn [2]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[3]))) {    fn.debug(L"fn [3]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if ((!sdb2.gotoNext()) || (!sdb2.getName(fn)) || (fn.ne(file1[4]))) {    fn.debug(L"fn [4]");    return Error::handle(name(), L"getName", Error::TEST, __FILE__, __LINE__);  }  if (sdb2.gotoNext()) {    sdb2.getName(fn);    fn.debug(L"fn");    return Error::handle(name(), L"gotoNext", Error::TEST, __FILE__, __LINE__);  }  // open the files in read mode  //  tmp_file0.open(tmp_filename0);  tmp_file1.open(tmp_filename1);  // read the values back in  //  if (!sdb2.read(tmp_file0, (long)0)) {    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }    if (!sdb3.read(tmp_file1, (long)0)) {    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  if (!sdb2.sameFiles(sdb1)) {    sdb2.debug(L"sdb2");    sdb1.debug(L"sdb1");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  if (!sdb3.sameFiles(sdb1)) {    sdb3.debug(L"sdb3");    sdb1.debug(L"sdb1");    return Error::handle(name(), L"read", Error::TEST, __FILE__, __LINE__);  }  // close the files  //  tmp_file0.close();  tmp_file1.close();  // remove the files  //  File::remove(tmp_filename0);  File::remove(tmp_filename1);  // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 2. class-specific methods:  //     append methods  //  //---------------------------------------------------------------------------  // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific methods: append methods...\n");    Console::increaseIndention();  }  // test append methods  //  sdb.append(L"diagnose_main_list.sof", true);  sdb.append(L"diagnose_file5.sof");  Sdb sdb_ref;  sdb_ref.append(L"diagnose_full_list.sof", true);  if (!sdb.sameFiles(sdb_ref)) {    sdb.debug(L"main_list");    sdb_ref.debug(L"ref");    return Error::handle(name(), L"append", Error::TEST, __FILE__, __LINE__);  }  String line(L"run_me.exe -list diagnose_file1.sof diagnose_file2.sof diagnose_file3.sof -list diagnose_file4.sof diagnose_file5.sof");  CommandLine cmdl(sdb);  cmdl.parse(line);  if (!sdb.sameFiles(sdb_ref)) {    sdb.debug(L"main_list");    sdb_ref.debug(L"ref");    return Error::handle(name(), L"append", Error::TEST, __FILE__, __LINE__);  }    // reset indentation  //  if (level_a > Integral::NONE) {    Console::decreaseIndention();  }  //---------------------------------------------------------------------------  //  // 3. class-specific methods:  //     file access and transformation methods  //  //---------------------------------------------------------------------------    // set indentation  //  if (level_a > Integral::NONE) {    Console::put(L"testing class-specific methods: file access and transformation methods...\n");    Console::increaseIndention();  }  if (!sdb.gotoFirst()) {    return Error::handle(name(), L"gotoFirst", Error::TEST,			 __FILE__, __LINE__);  }  Filename tmp_name;  if (!sdb.getName(tmp_name) ||      !tmp_name.eq(L"diagnose_file10.sof")) {    return Error::handle(name(), L"getName", Error::TEST,			 __FILE__, __LINE__);  }  if (!sdb.gotoNext() || !sdb.getName(tmp_name) ||      !tmp_name.eq(L"diagnose_file11.sof")) {    return Error::handle(name(), L"getName", Error::TEST,			 __FILE__, __LINE__);  }  if (!sdb.gotoNext() || !sdb.getName(tmp_name) ||      !tmp_name.eq(L"diagnose_file12.sof")) {    return Error::handle(name(), L"getName", Error::TEST,			 __FILE__, __LINE__);  }  if (!sdb.gotoNext() || !sdb.getName(tmp_name) ||      !tmp_name.eq(L"diagnose_file2.sof")) {    return Error::handle(name(), L"getName", Error::TEST,			 __FILE__, __LINE__);  }  if (!sdb.gotoNext() || !sdb.getName(tmp_name) ||      !tmp_name.eq(L"diagnose_file3.sof")) {    return Error::handle(name(), L"getName", Error::TEST,			 __FILE__, __LINE__);  }  // skip over the big chunk of file  //  for (long i = 0; i < 26; i++) {    if (!sdb.gotoNext()) {      return Error::handle(name(), L"diagnose", Error::TEST,			   __FILE__, __LINE__);    }  }    if (!sdb.gotoNext() || ! sdb.getName(tmp_name) ||      !tmp_name.eq(L"diagnose_file5.sof")) {    tmp_name.debug(L"tmp_name");    return Error::handle(name(), L"getName", Error::TEST,			 __FILE__, __LINE__);  }  if (sdb.gotoNext()) {    return Error::handle(name(), L"gotoNext", Error::TEST, __FILE__, __LINE__);  }  // test transformation of filenames  //  line.assign(L"run_me.exe -list diagnose_file1.sof diagnose_file2.sof diagnose_file3.sof diagnose_file5.raw");  CommandLine cmdl0;  cmdl0.setSdb(sdb);  cmdl0.parse(line);  // no output directory, existing sof extension -> transformUniquely  //  Filename out_name;  Filename in_name;  sdb.gotoFirst();  sdb.getName(in_name);    if (in_name.ne(L"diagnose_file10.sof") ||      !sdb.transformName(out_name, in_name) ||      out_name.ne(L"diagnose_file10_0.sof")) {    in_name.debug(L"input");    out_name.debug(L"transformed");    sdb.debug(L"sdb");    return Error::handle(name(), L"transformName", Error::TEST,			 __FILE__, __LINE__);

⌨️ 快捷键说明

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