00001 /* 00002 * pwavfile.h 00003 * 00004 * WAV file I/O channel class. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 2001 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is 00023 * Roger Hardiman <roger@freebsd.org> 00024 * and Shawn Pai-Hsiang Hsiao <shawn@eecs.harvard.edu> 00025 * 00026 * All Rights Reserved. 00027 * 00028 * Contributor(s): ______________________________________. 00029 * 00030 * $Log: pwavfile.h,v $ 00031 * Revision 1.13 2003/03/07 06:12:05 robertj 00032 * Added more WAV file "magic numbers". 00033 * 00034 * Revision 1.12 2002/09/16 01:08:59 robertj 00035 * Added #define so can select if #pragma interface/implementation is used on 00036 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00037 * 00038 * Revision 1.11 2002/06/20 00:51:38 craigs 00039 * Added virtuals to allow overriding 00040 * 00041 * Revision 1.10 2002/05/21 01:56:53 robertj 00042 * Removed the enum which made yet another set of magic numbers for audio 00043 * formats, now uses the WAV file format numbers. 00044 * Fixed failure to write header when destroying object without and explicit 00045 * call to Close(). 00046 * Fixed missing Open() function which does not have file name parameter. 00047 * Added ability to set the audio format after construction. 00048 * 00049 * Revision 1.9 2002/01/22 03:55:07 craigs 00050 * Added #define guards when file moved to PTCLib 00051 * 00052 * Revision 1.8 2002/01/13 21:00:41 rogerh 00053 * The type of new .WAV files must now be specified in the class constructor. 00054 * Take out Open() function from the last commit and create a new Open() 00055 * function which replaces the one in the PFile base class. 00056 * 00057 * Revision 1.7 2002/01/11 16:33:46 rogerh 00058 * Create a PWAVFile Open() function, which processes the WAV header 00059 * 00060 * Revision 1.6 2001/10/16 13:27:37 rogerh 00061 * Add support for writing G.723.1 WAV files. 00062 * MS Windows can play G.723.1 WAV Files in Media Player and Sound Recorder. 00063 * Sound Recorder can also convert them to normal PCM format WAV files. 00064 * Thanks go to M.Stoychev <M.Stoychev@cnsys.bg> for sample WAV files. 00065 * 00066 * Revision 1.5 2001/10/15 11:48:15 rogerh 00067 * Add GetFormat to return the format of a WAV file 00068 * 00069 * Revision 1.4 2001/07/23 01:20:20 rogerh 00070 * Add updates from Shawn - ensure isvalidWAV is false for zero length files. 00071 * GetDataLength uses actual file size to support file updates as well as appends. 00072 * Add updates from Roger - Update Header() just writes to specific fields which 00073 * preserves any 'extra' data in an existing header between FORMAT and DATA chunks. 00074 * 00075 * Revision 1.3 2001/07/20 07:06:27 rogerh 00076 * Fix a typo 00077 * 00078 * Revision 1.2 2001/07/20 03:30:59 robertj 00079 * Minor cosmetic changes to new PWAVFile class. 00080 * 00081 * Revision 1.1 2001/07/19 09:55:48 rogerh 00082 * Add PWAVFile, a class to read and write .wav files, written by 00083 * Roger Hardiman and <roger@freebsd.org> and 00084 * Shawn Pai-Hsiang Hsiao <shawn@eecs.harvard.edu> 00085 * 00086 * 00087 */ 00088 00089 #ifndef _PWAVFILE 00090 #define _PWAVFILE 00091 00092 //#ifdef P_USE_PRAGMA 00093 //#pragma interface 00094 //#endif 00095 00096 00099 class PWAVFile : public PFile 00100 { 00101 PCLASSINFO(PWAVFile, PFile); 00102 00103 public: 00109 enum { 00110 fmt_PCM = 1, 00111 fmt_ALaw = 6, 00112 fmt_uLaw = 7, 00113 fmt_GSM = 0x31, 00114 fmt_G728 = 0x41, 00115 fmt_G723 = 0x42, 00116 fmt_MSG7231 = 0x42, 00117 fmt_G726 = 0x64, 00118 fmt_G722 = 0x65, 00119 fmt_G729 = 0x84, 00120 fmt_VivoG7231 = 0x111, 00121 00122 // For backward compatibility 00123 PCM_WavFile = fmt_PCM, 00124 G7231_WavFile = fmt_VivoG7231 00125 }; 00126 00127 00137 PWAVFile( 00138 unsigned format = fmt_PCM 00139 ); 00140 00153 PWAVFile( 00154 OpenMode mode, 00155 int opts = ModeDefault, 00156 unsigned format = fmt_PCM 00157 ); 00158 00168 PWAVFile( 00169 const PFilePath & name, 00170 OpenMode mode = ReadWrite, 00171 int opts = ModeDefault, 00172 unsigned format = fmt_PCM 00173 ); 00174 00177 ~PWAVFile() { Close(); } 00179 00189 virtual BOOL Read( 00190 void * buf, 00191 PINDEX len 00192 ); 00193 00201 virtual BOOL Write( 00202 const void * buf, 00203 PINDEX len 00204 ); 00205 00217 virtual BOOL Open( 00218 OpenMode mode = ReadWrite, // Mode in which to open the file. 00219 int opts = ModeDefault // Options for open operation. 00220 ); 00221 00235 virtual BOOL Open( 00236 const PFilePath & name, // Name of file to open. 00237 OpenMode mode = ReadWrite, // Mode in which to open the file. 00238 int opts = ModeDefault // #OpenOptions enum# for open operation. 00239 ); 00240 00246 virtual BOOL Close(); 00247 00262 virtual BOOL SetPosition( 00263 off_t pos, 00264 FilePositionOrigin origin = Start 00265 ); 00266 00274 virtual off_t GetPosition() const; 00276 00281 virtual BOOL SetFormat(unsigned fmt); 00282 00285 virtual unsigned GetFormat() const; 00286 00290 virtual unsigned GetChannels() const; 00291 00294 virtual unsigned GetSampleRate() const; 00295 00298 virtual unsigned GetSampleSize() const; 00299 00302 off_t GetHeaderLength() const; 00303 00306 virtual off_t GetDataLength(); 00307 00314 BOOL IsValid() const { return isValidWAV; } 00316 00317 00318 protected: 00319 BOOL ProcessHeader(); 00320 BOOL GenerateHeader(); 00321 BOOL UpdateHeader(); 00322 00323 BOOL isValidWAV; 00324 00325 unsigned format; 00326 unsigned numChannels; 00327 unsigned sampleRate; 00328 unsigned bitsPerSample; 00329 00330 off_t lenHeader; 00331 off_t lenData; 00332 00333 BOOL header_needs_updating; 00334 00335 }; 00336 00337 #endif 00338 00339 // End Of File ///////////////////////////////////////////////////////////////