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

📄 adf_07.cc

📁 这是一个从音频信号里提取特征参量的程序
💻 CC
字号:
// file: $isip/class/mmedia/AudioFile/adf_07.cc// version: $Id: adf_07.cc,v 1.10 2003/05/05 21:02:38 parihar Exp $//// isip include files//#include "AudioFile.h"#include <VectorByte.h>#include <VectorShort.h>#include <VectorLong.h>// method: isOpen//// arguments: none//// return: boolean answer//// this method gets the file type of this AudionFile//boolean AudioFile::isOpen() const {    // branch on file type  //  if (file_format_d == RAW) {    return File::isOpen();  }  else if (file_format_d == SOF) {    if (sof_d != (Sof*)NULL) {      return sof_d->isOpen();    }  }  // enum error  //  else {    return Error::handle(name(), L"isOpen", Error::ENUM, __FILE__, __LINE__);  }  // must not be open  //  return false;}// method: open//// arguments://  const unichar* filename: (input) file to open//  MODE mode: (input) open mode//// return: a boolean value indicating status//// open the file//boolean AudioFile::open(const unichar* filename_a, MODE mode_a) {  Filename temp(filename_a);  // call the master function  //  return open(temp, mode_a);}// method: open//// arguments://  const Filename& filename: (input) file to open//  MODE mode: (input) open mode//// return: a boolean value indicating status//// open the file//boolean AudioFile::open(const Filename& filename_a, MODE mode_a) {  // save the configuration  //  if (backup_config_d != (AudioFile*)NULL) {    return Error::handle(name(), L"open", Error::MEM, __FILE__, __LINE__);  }  backup_config_d = new AudioFile;  backup_config_d->assign(*this);    // if the filename is a '-', open the pipe  //  if (filename_a.eq(STREAM_FILE)) {    if (file_format_d != RAW) {      return Error::handle(name(), L"open", ERR_PTYPE, __FILE__, __LINE__);    }    // a read only pipe pulls data from stdin    //    if (mode_a == READ_ONLY) {      File::open(STREAM_FILE, mode_a);     }    // a write only pipe pushes to stdout    //    else if (mode_a == WRITE_ONLY) {      File::open(STREAM_FILE, mode_a);    }    // no other pipes are supported    //    else {      return Error::handle(name(), L"open", ERR_PMODE, __FILE__, __LINE__);    }    // set the id to the stream file symbol    //    id_d.assign(STREAM_FILE);  }  // non-piped file, branch on type  //  else {    if (!exists(filename_a)) {      // the file doesn't need to exist if we are in write only mode      //      if (mode_a == WRITE_ONLY) {	if (num_channels_d == (Long)0) {	  return Error::handle(name(), L"open", ERR, __FILE__, __LINE__);	}	if (file_format_d == RAW) {	  File::TYPE type = File::BINARY;	  if (file_type_d == TEXT) {	    type = File::TEXT;	  }	  // call the master function in the File class	  //	  if (!File::open(filename_a, mode_a, type)) {	    return Error::handle(name(), L"open", Error::IO, __FILE__,				 __LINE__, Error::WARNING);	  }	}	else if (file_format_d == SOF) {	  if (sof_d != (Sof*)NULL) {	    return Error::handle(name(), L"open", Error::MEM, __FILE__,				 __LINE__);	  }	  sof_d = new Sof;	  sof_d->fp_d.setBMode(byte_mode_d);	  File::TYPE type = File::BINARY;	  if (file_type_d == TEXT) {	    type = File::TEXT;	  }	  	  if (!sof_d->open(filename_a, mode_a, type)) {	    return Error::handle(name(), L"open", Error::IO,				 __FILE__, __LINE__, Error::WARNING);	  }	  // start the Sof write	  //	  if (!writeSofStart()) {	    return Error::handle(name(), L"open", Error::WRITE,				 __FILE__, __LINE__, Error::WARNING);	  }	    	}	else {	  return Error::handle(name(), L"open", Error::ENUM,			       __FILE__, __LINE__);	}      }      // file does not exist but should, error      //      else {	return Error::handle(name(), L"open", Error::FILE_NOTFND,			     __FILE__, __LINE__, Error::WARNING);      }    }    // else read existing file    //    else {      // this flag allows a short-circuit so that isSof will not be      // run unecessarily      //      boolean is_sof = false;            // is this an Sof file?      //      if (file_format_d == SOF) {		// make sure it is valid	//	if ((!is_sof) && (mode_a != WRITE_ONLY) && (!Sof::isSof(filename_a))) {	  Error::handle(name(), L"open", Sof::ERR_NOTSOF,			__FILE__, __LINE__, Error::WARNING);	}	if (sof_d != (Sof*)NULL) {	  return Error::handle(name(), L"open", Error::MEM, __FILE__,			       __LINE__);	}		sof_d = new Sof;      	// if we READ an existing file these commands will be ignored by Sof	//	sof_d->fp_d.setBMode(byte_mode_d);	File::TYPE type = File::BINARY;	if (file_type_d == TEXT) {	  type = File::TEXT;	}	if (!sof_d->open(filename_a, mode_a, type)) {	  filename_a.debug(L"file_name");	  return Error::handle(name(), L"open", Error::IO, __FILE__, __LINE__,			       Error::WARNING);	}		// set the byte order from the sof file	//	byte_mode_d = sof_d->fp_d.getBMode();		// start the partial read or write	//	if (mode_a == READ_ONLY) {	  if (!readSofStart()) {	    return Error::handle(name(), L"open", Error::READ,				 __FILE__, __LINE__, Error::WARNING);	  }	}	else if (mode_a == WRITE_ONLY) {	  if (!writeSofStart()) {	    return Error::handle(name(), L"open", Error::WRITE,				 __FILE__, __LINE__, Error::WARNING);	  }	}		// bad enumeration value	//	else {	  return Error::handle(name(), L"open", Error::ENUM, __FILE__,			     __LINE__);	}      }            else if (file_format_d == RAW) {		// call the master function in the File class	//	if (!File::open(filename_a, mode_a)) {	  return Error::handle(name(), L"open", Error::IO, __FILE__, __LINE__,			       Error::WARNING);	}	if (num_channels_d == (Long)0) {	  return Error::handle(name(), L"open", ERR, __FILE__, __LINE__);	}	// get the file basename as the id	//	filename_a.getBase(id_d);      }            // bad enumeration value      //      else {	return Error::handle(name(), L"open", Error::ENUM, __FILE__, __LINE__);      }    }  }    // reset the buffers and filters  //  resetBuffer();  resetFilter();    // exit gracefully  //  return true;}// method: close//// arguments://// return: a boolean value indicating status//// close the file//boolean AudioFile::close() {  // close the Sof file and delete object  //  if (sof_d != (Sof*)NULL) {    if (sample_num_bytes_d == (Long)sizeof(byte8)) {            VectorByte buffer;      if (sof_d->getPartialRead()) {	// call the partial read terminate method	//	buffer.readTerminate(*sof_d);      }      else if (sof_d->getPartialWrite()) {	// call the partial write terminate method	//	buffer.writeTerminate(*sof_d, PARAM_DATA);      }    }    else if (sample_num_bytes_d == (Long)sizeof(int16)) {            VectorShort buffer;      if (sof_d->getPartialRead()) {	// call the partial read terminate method	//	buffer.readTerminate(*sof_d);      }      else if (sof_d->getPartialWrite()) {	// call the partial write terminate method	//	buffer.writeTerminate(*sof_d, PARAM_DATA);      }    }        else if (sample_num_bytes_d == (Long)sizeof(int32)) {            VectorLong buffer;      if (sof_d->getPartialRead()) {	// call the partial read terminate method	//	buffer.readTerminate(*sof_d);      }      else if (sof_d->getPartialWrite()) {	// call the partial write terminate method	//	buffer.writeTerminate(*sof_d, PARAM_DATA);      }    }    else {      return Error::handle(name(), L"unaligned word", ERR, __FILE__,			   __LINE__);    }    sof_d->close();    delete sof_d;    sof_d = (Sof*)NULL;  }  // call the master function in the File class  //  else if (!File::close()) {    return Error::handle(name(), L"close", Error::IO, __FILE__, __LINE__,			 Error::WARNING);  }  // reset the buffers  //  resetBuffer();  // if the configuration was saved, restore it and delete object  //  if (backup_config_d != (AudioFile*)NULL) {    assign(*backup_config_d);    delete backup_config_d;    backup_config_d = (AudioFile*)NULL;  }  // initialize the id  //  id_d.clear();    // exit gracefully  //  return true;}

⌨️ 快捷键说明

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