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

📄 sof_07.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/io/Sof/sof_07.cc// version: $Id: sof_07.cc,v 1.1 2000/09/22 21:34:44 zhao Exp $//// isip include files//#include "Sof.h"// method: put//// arguments://  const SysString& name: (input) object name//  long size: (input) object size//// return: a boolean value indicating status//// put this entry into the file. if it doesn't exist, add it.//boolean Sof::put(const SysString& name_a, long size_a) {    // check command line arguments  //  if (file_type_d == File::BINARY) {    return Error::handle(name(), L"put", ERR_BINARY, __FILE__, __LINE__);  }  // no need to check if it already exists, all implicitly tagged  // items are new  //  if (!add(name_a, size_a)) {    return Error::handle(name(), L"put", Error::IO, __FILE__, __LINE__);  }    // exit gracefully  //  return true;}// method: put//// arguments://  const SysString& name: (input) object name//  long tag: (input) object tag//  long size: (input) object size//// return: a boolean value indicating status//// put this entry into the file. if it doesn't exist, add it.//boolean Sof::put(const SysString& name_a, long tag_a, long size_a) {  // check arguments  //  if ((file_type_d == File::BINARY) && (size_a < 0)) {    return Error::handle(name(), L"put", Error::ARG, __FILE__, __LINE__);  }  if (tag_a == FREE_TAG) {    return put(name_a, size_a);  }  else if (tag_a < FREE_TAG) {    Error::handle(name(), L"put", Error::ARG, __FILE__, __LINE__);  }    // determine if the name.tag already exists  //  if (find(name_a, tag_a)) {    // it exists, do we know the size    //    if (size_a < 0) {            // size not specified, delete and re-insert at end      //      if (!remove(name_a, tag_a)) {	return Error::handle(name(), L"put", Error::IO, __FILE__, __LINE__);      }      if (!add(name_a, -1, tag_a)) {	return Error::handle(name(), L"put", SofList::ERR, __FILE__, __LINE__);      }    }    else {            // for efficiency, delete and re-insert at end      //      if (!remove(name_a, tag_a)) {	return Error::handle(name(), L"put", Error::IO, __FILE__, __LINE__);      }      if (!add(name_a, size_a, tag_a)) {	return Error::handle(name(), L"put", SofList::ERR, __FILE__, __LINE__);      }    }  }  else {    // new entry    //    if (!add(name_a, size_a, tag_a)) {      return Error::handle(name(), L"put", Error::IO, __FILE__, __LINE__);    }  }    // exit gracefully  //  return true;}// method: add//// arguments://  const SysString& name: (input) object name//  long size: (input) object size//  long tag: (input) object tag//// return: an long value containing the position of the object in the index//// add a new instance of specified class to the file//boolean Sof::add(const SysString& name_a, long size_a, long tag_a) {  // add to the symbol table  //  long index = table_d.add(name_a);    if (index == SofSymbolTable::NO_SYMB) {    return Error::handle(name(), L"add", SofSymbolTable::ERR,			 __FILE__, __LINE__);  }		    // call the master function  //  return add(index, size_a, tag_a);}// method: add//// arguments://  long name: (input) object name//  long size: (input) object size//  long tag: (input) object tag//// return: an long value containing the position of the object in the index//// add a new instance of specified class to the file//boolean Sof::add(long name_a, long size_a, long tag_a) {  // make sure we are not in partial write mode  //  if (partial_write_d) {    return Error::handle(name(), L"add", ERR_PARTIAL, __FILE__, __LINE__);  }    // write the tag to the file  //  long pos = 0;  // check the tag for the implicit flag  //  if (tag_a == FREE_TAG) {    tag_a = implicit_count_d++;    // check to make sure we didn't overflow    //    if (implicit_count_d > IMPLICIT_END) {      Error::handle(name(), L"add", ERR_IMPLIC, __FILE__, __LINE__,		    Error::WARNING);            // recover from error      //      table_d.remove(name_a);      implicit_count_d--;      return false;    }  }    if (index_d.add(name_a, tag_a, (long)-1, size_a)) {        if (file_type_d == File::TEXT) {            // NOTE: future editions might do there own garbage collecting and      // add items back into the middle of the file if convenient      //      if (!fseek(0, File::POS_PLUS_END)) {	return Error::handle(name(), L"add", Error::SEEK, __FILE__, __LINE__);      }      // save the position      //      pos = ftell();            // write the label to the file at the current position      //      if (!writeLabel(name_a, tag_a)) {	Error::handle(name(), L"add", ERR_LABEL, __FILE__, __LINE__);      }      // set current data pointer      //      cur_data_d = ftell();    }    else {            // seek to the end of the data segment      //      if (!fseek(end_of_data_d, File::POS)) {	return Error::handle(name(), L"add", Error::SEEK, __FILE__, __LINE__);      }      // save the positions      //      pos = ftell();      cur_data_d = pos;      end_of_data_d += size_a;    }        // now fill the space with nulls if size was specified    //    if (size_a > 0) {      if (!clearSpace(size_a)) {	return Error::handle(name(), L"add", Error::IO, __FILE__, __LINE__);      }      if (!fseek(-size_a, File::POS_PLUS_CUR)) {	return Error::handle(name(), L"add", Error::SEEK, __FILE__, __LINE__);      }    }        // set the position in the index    //    if (!index_d.setPosition(pos)) {      return Error::handle(name(), L"add", Error::INTERNAL_DATA,			   __FILE__, __LINE__);    }  }  else {    Error::handle(name(), L"add", SofList::ERR, __FILE__, __LINE__,		  Error::WARNING);        // recover from warning    //    table_d.remove(name_a);    return false;  }    // exit gracefully  //  return true;}// method: remove//// arguments://  const SysString& name: (input) class name //  long tag: (input) object tag//// return: a boolean value indicating status//// remove specified object from Sof file//boolean Sof::remove(const SysString& name_a, long tag_a) {  // get the index of the name from symbol table  //  long oname = table_d.getIndex(name_a);    if (oname < 0) {    return Error::handle(name(), L"remove", SofSymbolTable::ERR_NOTFND,			 __FILE__, __LINE__);  }    // call the master function  //  return remove(oname, tag_a);}// method: remove//// arguments://  long name: (input) class name //  long tag: (input) object tag//// return: a boolean value indicating status//// remove specified object from Sof file//boolean Sof::remove(long name_a, long tag_a) {  // check the file mode  //  if (!fp_d.isWritable()) {    return Error::handle(name(), L"remove", Error::MOD_READONLY,			 __FILE__, __LINE__);  }  // make sure we are not in partial write mode  //  if (partial_write_d) {    return Error::handle(name(), L"remove", ERR_PARTIAL, __FILE__, __LINE__);  }  // find the current entry  //  if (!index_d.find(name_a, tag_a)) {    return Error::handle(name(), L"remove", ERR_NOOBJ,			 __FILE__, __LINE__, Error::WARNING);  }    // seekData is called here because we circumvented the normal Sof  // indexing (which automatically positions)  //  if (!seekData()) {    return Error::handle(name(), L"remove", Error::SEEK, __FILE__, __LINE__);  }  long obj_size = index_d.getSize();  long obj_pos = index_d.getPosition();    long tag_size = ftell() - index_d.getPosition();  if (!fseek(-tag_size, File::POS_PLUS_CUR)) {    return Error::handle(name(), L"remove", Error::SEEK, __FILE__, __LINE__);  }    if (!clearSpace(tag_size + getObjectSize())) {    return Error::handle(name(), L"remove", Error::WRITE, __FILE__, __LINE__);  }  if (isBinary() && ((obj_size + obj_pos) == end_of_data_d)) {    end_of_data_d -= obj_size;  }    // delete instance of name from the symbol table  //  if (!table_d.remove(name_a)) {    return Error::handle(name(), L"remove", SofSymbolTable::ERR,			 __FILE__, __LINE__);  }  // remove node from index list  //  if (!index_d.remove()) {    return Error::handle(name(), L"remove", SofList::ERR, __FILE__, __LINE__);  }    // exit gracefully  //  return true;}

⌨️ 快捷键说明

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