quick start:g++ [flags ...] file ... -l /isip/tools/lib/$ISIP_BINARY/lib_mmedia.a #include <AudioFile.h> AudioFile(); long getData(Vector& data, double start_time = DEF_START_TIME, double duration = DEF_DURATION); long getData(VectorFloat& data, long channel_tag, double start_time = DEF_START_TIME, double duration = DEF_DURATION); long getRange(Vector & data, double start_time, double end_time); boolean setFileType(FILE_TYPE file_type);
description:AudioFile src; src.open(L"/tmp/input.raw"); Vector <VectorFloat> data(1); src.getData(data(0), 0, 50, 50l); Filename output(L"/tmp/output.raw"); AudioFile dst; dst.open(output, File::WRITE_ONLY); dst.writeAudioData(data, 0);
static const String CLASS_NAME = L"AudioFile";
enum FILE_TYPE { TEXT = 0, BINARY, DEF_FILE_TYPE = TEXT };
enum FILE_FORMAT { SOF = 0, RAW, SPHERE, AIFF, AIFFC, AU, BICSF, WAV, DEF_FILE_FORMAT = SOF };
enum COMP_TYPE { LINEAR = 0, ULAW, ALAW, DEF_COMP_TYPE = LINEAR };
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 };
static NameMap FILE_TYPE_MAP;
static NameMap FILE_FORMAT_MAP;
static NameMap COMP_TYPE_MAP;
static NameMap SAMPLE_PRECISION_MAP;
static NameMap DATA_TYPE_MAP;
static NameMap BMODE_MAP;
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;
static const long ALL_SAMPLES = -2;
static const String PARAM_BYTE_ORDER = L"byte_order";
static const String PARAM_FILE_TYPE = L"file_type";
static const String PARAM_FILE_FORMAT = L"file_format";
static const String PARAM_DATA_TYPE = L"data_type";
static const String PARAM_COMP_TYPE = L"comp_type";
static const String PARAM_RANGE = L"amplitude_range";
static const String PARAM_DATA = L"data";
static const String PARAM_TAG = L"tag";
static const String PARAM_SAMPLE_FREQUENCY = L"sample_frequency";
static const String PARAM_SAMPLE_NUM_BYTES = L"sample_num_bytes";
static const String PARAM_SAMPLE_PRECISON = L"sample_precision";
static const String PARAM_NUM_CHANNELS = L"num_channels";
static const String PARAM_BLOCK_SIZE = L"block_size";
static const String PARAM_BUF_SIZE = L"buf_size";
static const String PARAM_ID = L"id";
static const String PARAM_MA_COEFF = L"ma_coeff";
static const String PARAM_AR_COEFF = L"ar_coeff";
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;
static const long DEF_BLOCK_SIZE = 8192;
static const long DEF_BUF_SIZE = 4;
static VectorFloat DEF_MA_COEFF(L"1.0");
static VectorFloat DEF_AR_COEFF(L"1.0");
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;
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;
Vector<CircularBuffer<Float> > buffers_d;
Vector<Long> buf_end_samp_d;
FILE_TYPE file_type_d; // file type
FILE_FORMAT file_format_d; // file format
COMP_TYPE compression_type_d; // compression type
Double range_threshold_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
double sample_max_val_d;
Long block_size_d;
Long buf_size_d;
String id_d;
VectorFloat ma_coeff_d;
VectorFloat ar_coeff_d;
Vector< CircularBuffer<Float> > ma_mem_d;
Vector< CircularBuffer<Float> > ar_mem_d;
byte* io_buf_d;
VectorFloat interleaved_d;
AudioFile* backup_config_d;
boolean no_data_d;
boolean end_of_file_d;
Vector < VectorFloat > sampled_data_d;
Sof* sof_d;
Long tag_d;
long sof_length_pos_d;
long samples_written_d;
static Integral::DEBUG debug_level_d;
static MemoryManager mgr_d;
static MemoryManager scratch_mgr_d;
#ifdef HAVE_SPHERE
SP_FILE* sp_file_d;
#endif
#ifdef HAVE_AUDIOFILE
AFfilehandle af_file_d;
#endif
inline static const String& name();
static boolean diagnose(Integral::DEBUG debug_level);
boolean debug(const unichar* message) const;
inline boolean setDebug(Integral::DEBUG debug_level);
~AudioFile();
AudioFile(FILE_TYPE ftype = DEF_FILE_TYPE, FILE_FORMAT fformat = DEF_FILE_FORMAT, DATA_TYPE dtype = DEF_DATA_TYPE);
AudioFile(const AudioFile& copy_audio_file);
boolean assign(const AudioFile& copy_adf);
inline AudioFile& operator= (const AudioFile& arg);
long sofSize() const;
boolean read(Sof& sof, long tag, const String& name);
boolean write(Sof& sof, long tag, const String& 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;
boolean eq(const AudioFile& arg) const;
static void* operator new(size_t size);
static void* operator new[](size_t size);
static void operator delete(void* ptr);
static void operator delete[](void* ptr);
static boolean setGrowSize(long grow_size);
boolean clear();
AudioFile(FILE_TYPE ftype = DEF_FILE_TYPE, FILE_FORMAT fformat = DEF_FILE_FORMAT, DATA_TYPE dtype = DEF_DATA_TYPE, double sample_frequency, long sample_num_bytes, long num_channels););
boolean open(const Filename& filename, MODE mode = READ_ONLY);
boolean open(const unichar* filename, MODE mode = READ_ONLY);
boolean isOpen() const;
boolean close();
long getData(Vector<VectorFloat>& data, double start_time = DEF_START_TIME, double duration = DEF_DURATION);
long getData(VectorFloat& data, long channel_tag, double start_time = DEF_START_TIME, double duration = DEF_DURATION);
long getData(Vector<VectorFloat>& data, long start_samp, long num_samp);
long getData(VectorFloat& data, long channel_tag, long start_samp, long num_samp);
long getWindow(Vector<VectorFloat>& data, double center_time, double duration = DEF_DURATION);
long getWindow(VectorFloat& data, long channel_tag, double center_time, double duration = DEF_DURATION);
long getRange(Vector<VectorFloat>& data,double start_time, double end_time);
long getRange(VectorFloat& data, long channel_tag, double start_time, double end_time);
long readAudioData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG, long start_samp = DEF_START_SAMP, long num_samp = DEF_NUM_SAMP);
long writeAudioData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG);
double getAmplitudeRange() const;
COMP_TYPE getCompType() const;
FILE_FORMAT getFileFormat() const;
FILE_TYPE getFileType() const;
const String& getID() const;
long getNumChannels() const;
long getNumSamples() const;
double getSampleFrequency() const;
long getSampleNumBytes() const;
SAMPLE_PRECISION getSamplePrecision() const;
boolean setAmplitudeRange(double range_threshold);
boolean setBlockSize(long nbytes);
boolean setBufferSize(long nblocks);
boolean setCompType(COMP_TYPE comp_type);
boolean setFileFormat(FILE_FORMAT file_format);
boolean setFileType(FILE_TYPE file_type);
boolean setID(const String& id);
boolean setNumChannels(long num_channels);
boolean setSampleFrequency(double sample_freq);
boolean setSampleNumBytes(long sample_num_bytes);
boolean setSamplePrecision(SAMPLE_PRECISION sample_precision);
const VectorFloat& getMaCoeff() const;
const VectorFloat& getArCoeff() const;
boolean setMaCoeff(VectorFloat& ma_coeff);
boolean setArCoeff(VectorFloat& ar_coeff);
long timeToSample(double time) const;
double sampleToTime(long index) const;
boolean readSofData(Sof& sof);
boolean writeSofData(Sof& sof) const;
boolean readSofStart(Sof& sof, long tag, const String& name);
boolean writeSofStart(Sof& sof, long tag, const String& name) const;
boolean readSofStartData(Sof& sof, const String& pname = String::getEmptyString(), long size = SofParser::FULL_OBJECT, boolean param = true, boolean nested = false);
boolean writeSofStartData(Sof& sof, const String& pname = String::getEmptyString()) const;
boolean readSofConfig(Sof& sof, SofParser& parser);
boolean writeSofConfig(Sof& sof) const;
long getStartSamp(long channel_tag = DEF_CHANNEL_TAG) const;
long getEndSamp(long channel_tag = DEF_CHANNEL_TAG) const;
boolean appendData();
boolean revertData(VectorLong& whole_data, Vector<VectorFloat>& data, long channel_tag) const;
long blockFloor(long samp_num) const;
long blockCeil(long samp_num) const;
boolean resetBuffer(long channel_tag);
boolean resetFilter(long channel_tag);
boolean openSofStream(const Filename& filename, MODE mode = READ_ONLY);
boolean openSof(const Filename& filename, MODE mode = READ_ONLY);
boolean readSofHeader();
boolean writeSofHeader();
long readSofData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG, long start_samp = DEF_START_SAMP, long num_samp = DEF_NUM_SAMP);
long writeSofData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG);
boolean openRawStream(const Filename& filename, MODE mode = READ_ONLY);
boolean openRaw(const Filename& filename, MODE mode = READ_ONLY);
boolean readRawHeader();
boolean writeRawHeader();
long readRawData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG, long start_samp = DEF_START_SAMP, long num_samp = DEF_NUM_SAMP);
long writeRawData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG);Format: NIST Speech File Manipulation Software (SPHERE)
boolean openSphereStream(const Filename& filename, MODE mode = READ_ONLY);
boolean openSphere(const Filename& filename, MODE mode = READ_ONLY);
boolean readSphereHeader();
boolean writeSphereHeader();
long readSphereData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG, long start_samp = DEF_START_SAMP, long num_samp = DEF_NUM_SAMP);
long writeSphereData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG);Format: SGI Audio File (WAV, AIFF, etc.)
boolean openAFStream(const Filename& filename, MODE mode = READ_ONLY);
boolean openAF(const Filename& filename, MODE mode = READ_ONLY);
boolean readAFHeader();
boolean writeAFHeader();
long readAFData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG, long start_samp = DEF_START_SAMP, long num_samp = DEF_NUM_SAMP);
long writeAFData(Vector<VectorFloat>& data, long channel_tag = DEF_CHANNEL_TAG);examples:
// isip include files // #include <AudioFile.h> // main program starts here // int main() { // declare AudioFile objects for read // AudioFile src; src.setFileFormat(AudioFile::RAW); // set file format src.setFileType(AudioFile::BINARY); // set file type // open file, default is read only // src.open(L"$ISIP_DEVEL/doc/examples/data/audio/bg_119oo39a.raw"); long N = 80; // defined the sample number for one process Long len; // define local variable len = src.getNumSamples(); // get number of samples in this file len = (long)len / N; // get how many frames we need to process // loop through N samples at a time // for (long i = 0; i < len; i++) { // define local variable to hold data // Vector<VectorFloat> data(1); // get sample data // src.getData(data(0), 0, i * N, N); // write these N samples to the output // data.debug(L"data"); } // close file // src.close(); // exit gracefully // Integral::exit(); }