UtiLite  0.3.1
A lite utilities library
audio/include/utilite/UWav.h
Go to the documentation of this file.
00001 
00007 #ifndef UWAV_H
00008 #define UWAV_H
00009 
00010 #include "utilite/UtiLiteAudioExp.h" // DLL export/import defines
00011 
00012 #include <stdio.h>
00013 
00020 class UTILITEAUDIO_EXP UWav
00021 {
00022 
00023 public:
00024         static void writeWavHeader(FILE *fp, unsigned int length, float rate, int channels, int bits);
00025 
00026 public:
00027     UWav();
00028     ~UWav();
00029 
00035     int init(const char* fileName);
00036 
00037     //getters
00038     unsigned short getChannels() const       {return _fmtChunk.wChannels;}
00039     unsigned long getSamplesPerSec() const   {return _fmtChunk.dwSamplesPerSec;}
00040     unsigned long getAvgBytesPerSec() const  {return _fmtChunk.dwAvgBytesPerSec;}
00041     unsigned short getBlockAlign() const     {return _fmtChunk.wBlockAlign;}
00042     unsigned short getBitsPerSample() const  {return _fmtChunk.wBitsPerSample;}
00043 
00044     unsigned long getDataLength() const      {return _dataChunk.header.size;}
00045 
00046     unsigned long getNumSamplesPerChannel() const;
00047     unsigned long getNumTotalSamples() const;
00048     unsigned short getBytesPerSample() const;
00049 
00058     long readData(unsigned char data[], 
00059                   long offset, 
00060                   long dataLength);
00061 
00070     long readNextData(unsigned char data[], 
00071                       long dataLength);
00072 
00079     long readNextSamples(short samples[], 
00080                          long numSamples);
00081 
00082 protected:
00083 
00084 private:
00085     // Define wav structures
00086     struct ChunkHeader {
00087         signed char id[4];
00088         int        size;
00089     } ;
00090 
00091     struct WavHeader {
00092         ChunkHeader      header;
00093         signed char  rifftype[4];
00094     };
00095 
00096     struct FmtChunk {
00097       ChunkHeader        header;
00098       short          wFormatTag;
00099       unsigned short wChannels;
00100       unsigned int  dwSamplesPerSec;
00101       unsigned int  dwAvgBytesPerSec;
00102       unsigned short wBlockAlign;
00103       unsigned short wBitsPerSample;
00104       /* Note: there may be additional fields here, depending upon wFormatTag. */
00105     };
00106 
00107     struct DataChunk{
00108       ChunkHeader        header;
00109     };
00110 
00111 private:
00112     WavHeader _wavHeader;
00113     FmtChunk _fmtChunk;
00114     DataChunk _dataChunk;
00115 
00116     const char* _fileName;
00117     FILE* _pFile;
00118     bool _initialized;
00119     long _dataOffset;
00120 };
00121 
00122 #endif
 All Classes Files Functions Variables Enumerations Friends Defines