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

📄 audiofile.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/mmedia/AudioFile/AudioFile.h// version: $Id: AudioFile.h,v 1.34 2002/10/17 19:30:46 gao Exp $//// make sure definitions are only made once//#ifndef ISIP_AUDIO_FILE#define ISIP_AUDIO_FILE// isip include files//#ifndef ISIP_FILE#include <File.h>#endif#ifndef ISIP_FILENAME#include <Filename.h>#endif#ifndef ISIP_LONG#include <Long.h>#endif#ifndef ISIP_DOUBLE#include <Double.h>#endif#ifndef ISIP_NAME_MAP#include <NameMap.h>#endif#ifndef ISIP_CIRCULAR_BUFFER#include <CircularBuffer.h>#endif#ifndef ISIP_VECTOR#include <Vector.h>#endif#ifndef ISIP_VECTOR_FLOAT#include <VectorFloat.h>#endif#ifndef ISIP_VECTOR_LONG#include <VectorLong.h>#endif// AudioFile: a class that manipulates audio data for sources including// various types of proprietary file formats and streams.//class AudioFile : public File {    //---------------------------------------------------------------------------  //  // public constants  //  //---------------------------------------------------------------------------public:    // define the class name  //  static const String CLASS_NAME;    //---------------------------------------  //  // other important constants  //  //---------------------------------------    // define the supported file types, file format, data type,  //  compression modes and channel tags  //  enum FILE_TYPE { TEXT = 0, BINARY, DEF_FILE_TYPE = TEXT };  enum FILE_FORMAT { SOF = 0, RAW, WAV, SPHERE, DEF_FILE_FORMAT = SOF };    enum COMP_TYPE { LINEAR = 0, ULAW, ALAW, DEF_COMP_TYPE = LINEAR };  // enumeration for sample precision  //  enum SAMPLE_PRECISION { NONE = 0, USE_SIZE, EIGHT_BITS, TWELVE_BITS,			  SIXTEEN_BITS, TWENTY_BITS, TWENTY_FOUR_BITS,			  THIRTY_TWO_BITS, DEF_SAMPLE_PRECISION = NONE };    // define the names for each of the enumerated values  //  static NameMap FILE_TYPE_MAP;  static NameMap FILE_FORMAT_MAP;  static NameMap DATA_TYPE_MAP;    static NameMap COMP_TYPE_MAP;  static NameMap SAMPLE_PRECISION_MAP;    static NameMap BMODE_MAP;    // define the channel related constants  //  static const long CHANNEL_TAG_RIGHT = 1;  static const long CHANNEL_TAG_LEFT = 0;  static const long CHANNEL_TAG_ALL = -2;  static const long DEF_CHANNEL_TAG = CHANNEL_TAG_ALL;  // define a special values to indicate processing of all samples  //  static const long ALL_SAMPLES = -2;  //----------------------------------------  //  // i/o related constants  //  //----------------------------------------  static const String PARAM_BYTE_ORDER;  static const String PARAM_FILE_TYPE;  static const String PARAM_FILE_FORMAT;  static const String PARAM_DATA_TYPE;    static const String PARAM_COMP_TYPE;  static const String PARAM_RANGE;  static const String PARAM_DATA;  static const String PARAM_TAG;  static const String PARAM_SAMPLE_FREQUENCY;  static const String PARAM_SAMPLE_NUM_BYTES;  static const String PARAM_SAMPLE_PRECISION;  static const String PARAM_NUM_CHANNELS;  static const String PARAM_BLOCK_SIZE;  static const String PARAM_BUF_SIZE;  static const String PARAM_ID;  static const String PARAM_MA_COEFF;  static const String PARAM_AR_COEFF;  //----------------------------------------  //  // default values and arguments  //  //----------------------------------------  // default values  //  static const double DEF_AMPLITUDE_RANGE = 1.0;  static const double DEF_SAMPLE_FREQ = 8000.0;  static const long DEF_SAMPLE_NUM_BYTES = 2;  static const long DEF_NUM_CHANNELS = 1;    // a buffer contains DEF_BUF_SIZE * DEF_BLOCK_SIZE elements  //  static const long DEF_BLOCK_SIZE = 8192;  static const long DEF_BUF_SIZE = 4;           // coefficients of the built-in filter  //  static const VectorFloat DEF_MA_COEFF;  static const VectorFloat DEF_AR_COEFF;    // default arguments to methods  //  static const double DEF_START_TIME = 0.0;  static const double DEF_CENTER_TIME = 0.25;  static const double DEF_DURATION = 0.5;  static const long DEF_START_SAMP = 0;  static const long DEF_NUM_SAMP = 4000;  static const long DEF_TAG = 0;    //----------------------------------------  //  // error codes  //  //----------------------------------------      static const long ERR = 50000;  static const long ERR_TYPE = 50001;  static const long ERR_ARCOEF = 50002;  static const long ERR_PTYPE = 50003;  static const long ERR_PMODE = 50004;  static const long ERR_PRECFG = 50005;    //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:    // buffer of audio data   //  Vector< CircularBuffer<Float> > buffers_d;  Vector<Long> buf_end_samp_d;    // parameters of the audio file  //  FILE_TYPE file_type_d;                  // file type  FILE_FORMAT file_format_d;              // file format  COMP_TYPE compression_type_d;           // compression type  Double amplitude_range_d;               // range threshold for compression    Double sample_freq_d;                   // sample frequency  Long sample_num_bytes_d;                // number of bytes per sample  SAMPLE_PRECISION sample_precision_d;    // sample precision in bits  Long num_channels_d;                    // number of channels  // maximum sample value: computed from sample_precision_d  //  and sample_num_bytes_d  //  double max_sample_val_d;    // we read this many bytes from the file at a time  //  Long block_size_d;  Long buf_size_d;  // the file's id (for databases)  //  String id_d;    // parameters of the IIR filter  //  VectorFloat ma_coeff_d;  VectorFloat ar_coeff_d;  Vector< CircularBuffer<Float> > ma_mem_d;  Vector< CircularBuffer<Float> > ar_mem_d;      // internal buffers for reading and writing from the file  //  byte* io_buf_d;  VectorFloat interleaved_d;  // in case this is an Sof file  //  Sof* sof_d;  Long tag_d;    // old confguration: if we open a file that has its own  // configuration we should store the user's configuration wishes in  // case we later encounter a file without parameters. for example,  // the user sets the byte order to native, reads in an Sof file that  // is rev4, then later encounters a raw file.  //  AudioFile* backup_config_d;    // since the AudioFile class can either hold configuration  // information for auxiliary file types (RAW, SPHERE, WAV, etc) or  // the actual signal data, this flag lets the class keep track of if  // data is actually present in the file or not.  //  boolean no_data_d;  // have we reached the end of file?  //  boolean end_of_file_d;    // if we are writing to an Sof file we need to keep track of where  // we write the AudioFile object's size and the vector's length  //  long sof_length_pos_d;  long samples_written_d;  // buf to store the whole data when read AudioFile object in one time  // instead of reading frame by frame or piece by piece  //  Vector< VectorFloat> sampled_data_d;    // debugging parameters:  //  this debug_level_d is not inherited because the AudioFile needs  //  to have its own debug level  //  static Integral::DEBUG debug_level_d;  // a static memory manager for AudioFile objects  //  static MemoryManager mgr_d;  // a static memory manager for the byte* scratch space  //  static MemoryManager scratch_mgr_d;    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:    // method: name  //  inline static const String& name() {    return CLASS_NAME;  }  // other static methods  //  static boolean diagnose(Integral::DEBUG debug_level);    // method: setDebug  //  inline static boolean setDebug(Integral::DEBUG debug_level) {    debug_level_d = debug_level;    return true;  }  // other debug methods  //  boolean debug(const unichar* message) const;      // destructor/constructor(s)  //  ~AudioFile();  AudioFile(FILE_TYPE ftype = DEF_FILE_TYPE,	    FILE_FORMAT fformat = DEF_FILE_FORMAT);  // copy constructor  //  AudioFile(const AudioFile& copy_audio_file);    // assign methods  //  boolean assign(const AudioFile& copy_audio_file);  // method: operator=  //  inline AudioFile& operator=(const AudioFile& arg) {    if (!assign(arg)) {      Error::handle(name(), L"operator=", Error::ARG,                    __FILE__, __LINE__);    }          return *this;  }    // i/o methods:  //  sofSize determines the amount of disk storage needed to store this object  //  the read and write methods are for full object i/o;  //  the readData and writeData methods handle i/o when this object is  //  a component of another object  //  long sofSize() const;    boolean read(Sof& sof, long tag, const String& name = CLASS_NAME);  boolean write(Sof& sof, long tag, const String& name = CLASS_NAME) const;    boolean readData(Sof& sof, const String& pname = String::getEmptyString(),		   long size =  SofParser::FULL_OBJECT,		   boolean param = true,                   boolean nested = false);    boolean writeData(Sof& sof,		    const String& pname = String::getEmptyString()) const;  long readSofData(Sof& sof_a);  long writeSofData(Sof& sof_a) const;    boolean readHeader(Sof& sof, long tag, const String& name = CLASS_NAME);  boolean readStart(Sof& sof, const String& pname = String::getEmptyString(),		    long size =  SofParser::FULL_OBJECT,		    boolean param = true,		    boolean nested = false);    boolean readConfig(Sof& sof_a, SofParser& parser);  boolean writeHeader(Sof& sof, long tag,		      const String& name = CLASS_NAME) const;  boolean writeStart(Sof& sof,		     const String& pname = String::getEmptyString()) const;  boolean writeConfig(Sof& sof_a) const;    // equality methods  //  boolean eq(const AudioFile& compare_audio_file) const;    // method: operator new

⌨️ 快捷键说明

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