Main Page   Namespace List   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   Related Pages  

wav_writer.h

00001 //----------------------------------------------------------------------------
00008 //----------------------------------------------------------------------------
00009 #ifndef WAVWRITER_H_INCLUDED
00010 #define WAVWRITER_H_INCLUDED
00011 //----------------------------------------------------------------------------
00012 #include <string>
00013 #include <fstream>
00014 #include "datatypes.h"
00015 //----------------------------------------------------------------------------
00016 namespace ac3 {
00017 //----------------------------------------------------------------------------
00018 #define WAVWRITER_UNKNOWN_ERROR -1            
00019 #define WAVWRITER_NO_ERROR 0
00020 #define WAVWRITER_COULD_NOT_CREATE_FILE 1
00021 #define WAVWRITER_FILE_NOT_OPEN 2
00022 #define WAVWRITER_WRITE_ERROR 3
00023 #define WAVWRITER_INVALID_FORMAT 4
00024 #define WAVWRITER_UNSUPPORTED_FORMAT 5
00025 
00026 #define WAVWRITER_ERROR_NUM 6
00027 
00035 class CWAVWriterException
00036 {
00037 public:
00039   CWAVWriterException() : m_nReason(WAVWRITER_UNKNOWN_ERROR) {}
00041   CWAVWriterException(int nReason) : m_nReason(nReason) {}
00043   CWAVWriterException(int nReason, const std::string& sHint)
00044     : m_nReason(nReason), m_sHint(sHint) {}
00045   
00046 public:
00048   int GetReason() const { return m_nReason; }
00050   std::string GetHint() const { return m_sHint; }
00051   std::string GetString() const;
00052   
00053 private:
00054   int m_nReason;
00055   std::string m_sHint;
00056 
00057   static std::string m_sUnknownError;
00058   static std::string m_sError[WAVWRITER_ERROR_NUM];
00059 };
00060 //----------------------------------------------------------------------------
00074 class CWAVWriter
00075 {
00076 public:
00077   CWAVWriter();
00078 private:
00079   CWAVWriter(const CWAVWriter& ww) {}
00080 public:
00081   CWAVWriter(const char* pszFilename, UINT32 nSampleRate,
00082              UINT16 nChannelNum, UINT16 nBitResolution);
00083   CWAVWriter(const std::string& sFilename, UINT32 nSampleRate,
00084              UINT16 nChannelNum, UINT16 nBitResolution);
00085   ~CWAVWriter();
00086 
00087 
00088 public:
00089   void OpenFile(const char* pszFilename, UINT32 nSampleRate,
00090                 UINT16 nChannelNum, UINT16 nBitResolution);
00091   void OpenFile(const std::string& sFilename, UINT32 nSampleRate,
00092                 UINT16 nChannelNum, UINT16 nBitResolution);
00093   void CloseFile();
00094 
00095   void Write8BitSamples(UINT8** ppSource, UINT32 nCount);
00096   void Write16BitSamples(INT16** ppSource, UINT32 nCount);
00097   void Write24BitSamples(INT32** ppSource, UINT32 nCount);
00098   void Write32BitSamples(INT32** ppSource, UINT32 nCount);
00099 
00100 
00101 private:
00102   void WriteHeader();
00103   
00104   void WriteFOURCC(std::string sFOURCC);
00105   void WriteUINT8(UINT8 nValue);
00106   void WriteINT8(INT8 nValue);
00107   void WriteUINT16(UINT16 nValue);
00108   void WriteINT16(INT16 nValue);
00109   void WriteUINT24(UINT32 nValue);
00110   void WriteINT24(INT32 nValue);
00111   void WriteUINT32(UINT32 nValue);
00112   void WriteINT32(INT32 nValue);
00113   
00114   CWAVWriter& operator=(const CWAVWriter& ww) { return *this; }
00115 
00116 
00117 private:
00118   bool m_bFileOpen;
00119   std::ofstream m_file;
00120   UINT32 m_nSampleRate;
00121   UINT16 m_nChannels;
00122   UINT16 m_nBitsPerSample;
00123 
00124   UINT32 m_nAllSize;
00125   std::streampos m_allSizePos;
00126   UINT32 m_nDataSize;
00127   std::streampos m_dataSizePos;
00128 };
00129 //----------------------------------------------------------------------------
00130 } // namespace ac3
00131 //----------------------------------------------------------------------------
00132 #endif // WAVWRITER_H_INCLUDED

Generated on Sat Sep 25 14:06:44 2004 for ac3 by doxygen1.2.18