35 #ifndef PTLIB_PWAVFILE_H
36 #define PTLIB_PWAVFILE_H
42 #include <ptbuildopts.h>
55 P_PACK_FIELD(PInt32l len);
58 struct RIFFChunkHeader
67 P_PACK_FIELD(PUInt16l format);
68 P_PACK_FIELD(PUInt16l numChannels);
69 P_PACK_FIELD(PUInt32l sampleRate);
70 P_PACK_FIELD(PUInt32l bytesPerSec);
71 P_PACK_FIELD(PUInt16l bytesPerSample);
72 P_PACK_FIELD(PUInt16l bitsPerSample);
83 virtual ~PWAVFileFormat() { }
87 virtual unsigned GetFormat()
const = 0;
91 virtual PString GetFormatString()
const = 0;
95 virtual PString GetDescription()
const = 0;
98 virtual bool CanSetChannels(
unsigned channels)
const = 0;
102 virtual void CreateHeader(PWAV::FMTChunk & header,
PBYTEArray & extendedHeader) = 0;
106 virtual void UpdateHeader(PWAV::FMTChunk & ,
PBYTEArray & )
111 virtual PBoolean WriteExtraChunks(PWAVFile & )
116 virtual PBoolean ReadExtraChunks(PWAVFile & )
121 virtual void OnStart()
126 virtual void OnStop()
131 virtual PBoolean Read(PWAVFile & file,
void * buf, PINDEX & len);
135 virtual PBoolean Write(PWAVFile & file,
const void * buf, PINDEX & len);
146 class PWAVFileConverter
149 virtual ~PWAVFileConverter() { }
150 virtual unsigned GetFormat (
const PWAVFile & file)
const = 0;
151 virtual off_t GetPosition (
const PWAVFile & file)
const = 0;
153 virtual unsigned GetSampleSize(
const PWAVFile & file)
const = 0;
154 virtual off_t GetDataLength (PWAVFile & file) = 0;
155 virtual PBoolean Read (PWAVFile & file,
void * buf, PINDEX len) = 0;
156 virtual PBoolean Write (PWAVFile & file,
const void * buf, PINDEX len) = 0;
163 class PWAVFile :
public PFile
187 fmt_VivoG7231 = 0x111,
190 PCM_WavFile = fmt_PCM,
191 G7231_WavFile = fmt_VivoG7231,
194 fmt_NotKnown = 0x10000
207 unsigned format = fmt_PCM
224 OpenOptions opts = ModeDefault,
225 unsigned format = fmt_PCM
239 OpenMode mode = ReadWrite,
240 OpenOptions opts = ModeDefault,
241 unsigned format = fmt_PCM
247 OpenMode mode = ReadWrite,
248 OpenOptions opts = ModeDefault
295 OpenMode mode = ReadWrite,
296 OpenOptions opts = ModeDefault
314 OpenMode mode = ReadWrite,
315 OpenOptions opts = ModeDefault
341 FilePositionOrigin origin = Start
358 virtual PBoolean SetFormat(
unsigned fmt);
363 virtual unsigned GetFormat()
const;
364 virtual PString GetFormatAsString()
const;
369 virtual unsigned GetChannels()
const;
370 virtual void SetChannels(
unsigned v);
374 virtual unsigned GetSampleRate()
const;
375 virtual void SetSampleRate(
unsigned v);
379 virtual unsigned GetSampleSize()
const;
380 virtual void SetSampleSize(
unsigned v);
384 virtual unsigned GetBytesPerSecond()
const;
385 virtual void SetBytesPerSecond(
unsigned v);
389 off_t GetHeaderLength()
const;
393 virtual off_t GetDataLength();
401 PBoolean IsValid()
const {
return isValidWAV; }
405 PString GetFormatString()
const
406 {
if (formatHandler == NULL)
return PString(
"N/A");
else return formatHandler->GetFormatString(); }
410 void SetAutoconvert();
414 PBoolean RawRead(
void * buf, PINDEX len);
415 PBoolean RawWrite(
const void * buf, PINDEX len);
417 PBoolean FileRead(
void * buf, PINDEX len);
418 PBoolean FileWrite(
const void * buf, PINDEX len);
420 off_t RawGetPosition()
const;
421 PBoolean RawSetPosition(off_t pos, FilePositionOrigin origin);
422 off_t RawGetDataLength();
424 void SetLastReadCount(PINDEX v) { lastReadCount = v; }
425 void SetLastWriteCount(PINDEX v) { lastWriteCount = v; }
428 static PWAVFile * format(
const PString & format);
429 static PWAVFile * format(
const PString & format, OpenMode mode, OpenOptions opts = ModeDefault);
434 bool SelectFormat(
unsigned fmt);
435 bool SelectFormat(
const PString & format);
442 PWAV::FMTChunk wavFmtChunk;
447 unsigned int origFmt;
448 PWAVFileFormat * formatHandler;
451 PWAVFileConverter * autoConverter;
456 bool header_needs_updating;
458 friend class PWAVFileConverter;
463 #endif // PTLIB_PWAVFILE_H