35 #ifndef PTLIB_PWAVFILE_H
36 #define PTLIB_PWAVFILE_H
60 struct RIFFChunkHeader
73 PUInt16l bytesPerSample;
74 PUInt16l bitsPerSample;
77 struct G7231ExtendedInfo
85 PWAV::ChunkHeader hdr;
99 virtual ~PWAVFileFormat() { }
103 virtual unsigned GetFormat()
const = 0;
107 virtual PString GetFormatString()
const = 0;
111 virtual PString GetDescription()
const = 0;
114 virtual bool CanSetChannels(
unsigned channels)
const = 0;
118 virtual void CreateHeader(PWAV::FMTChunk & header,
PBYTEArray & extendedHeader) = 0;
122 virtual void UpdateHeader(PWAV::FMTChunk & ,
PBYTEArray & )
127 virtual PBoolean WriteExtraChunks(PWAVFile & )
132 virtual PBoolean ReadExtraChunks(PWAVFile & )
137 virtual void OnStart()
142 virtual void OnStop()
147 virtual PBoolean Read(PWAVFile & file,
void * buf, PINDEX & len);
151 virtual PBoolean Write(PWAVFile & file,
const void * buf, PINDEX & len);
157 #define PCREATE_WAVFILE_FORMAT_FACTORY(cls, id, name) \
158 PFACTORY_CREATE(PWAVFileFormatByIDFactory, cls, id); \
159 typedef cls cls##_ByFormat; \
160 PFACTORY_CREATE(PWAVFileFormatByFormatFactory, cls##_ByFormat, name)
167 class PWAVFileConverter
170 virtual ~PWAVFileConverter() { }
171 virtual unsigned GetFormat (
const PWAVFile & file)
const = 0;
172 virtual off_t GetPosition (
const PWAVFile & file)
const = 0;
174 virtual unsigned GetSampleSize(
const PWAVFile & file)
const = 0;
175 virtual off_t GetDataLength (PWAVFile & file) = 0;
176 virtual PBoolean Read (PWAVFile & file,
void * buf, PINDEX len) = 0;
177 virtual PBoolean Write (PWAVFile & file,
const void * buf, PINDEX len) = 0;
184 class PWAVFile :
public PFile
208 fmt_VivoG7231 = 0x111,
211 PCM_WavFile = fmt_PCM,
212 G7231_WavFile = fmt_VivoG7231,
215 fmt_NotKnown = 0x10000
228 unsigned format = fmt_PCM
245 OpenOptions opts = ModeDefault,
246 unsigned format = fmt_PCM
260 OpenMode mode = ReadWrite,
261 OpenOptions opts = ModeDefault,
262 unsigned format = fmt_PCM
268 OpenMode mode = ReadWrite,
269 OpenOptions opts = ModeDefault
316 OpenMode mode = ReadWrite,
317 OpenOptions opts = ModeDefault
335 OpenMode mode = ReadWrite,
336 OpenOptions opts = ModeDefault
362 FilePositionOrigin origin = Start
379 virtual PBoolean SetFormat(
unsigned fmt);
384 virtual unsigned GetFormat()
const;
385 virtual PString GetFormatAsString()
const;
390 virtual unsigned GetChannels()
const;
391 virtual void SetChannels(
unsigned v);
395 virtual unsigned GetSampleRate()
const;
396 virtual void SetSampleRate(
unsigned v);
400 virtual unsigned GetSampleSize()
const;
401 virtual void SetSampleSize(
unsigned v);
405 virtual unsigned GetBytesPerSecond()
const;
406 virtual void SetBytesPerSecond(
unsigned v);
410 off_t GetHeaderLength()
const;
414 virtual off_t GetDataLength();
422 PBoolean IsValid()
const {
return isValidWAV; }
426 PString GetFormatString()
const
427 {
if (formatHandler == NULL)
return PString(
"N/A");
else return formatHandler->GetFormatString(); }
431 void SetAutoconvert();
435 PBoolean RawRead(
void * buf, PINDEX len);
436 PBoolean RawWrite(
const void * buf, PINDEX len);
438 PBoolean FileRead(
void * buf, PINDEX len);
439 PBoolean FileWrite(
const void * buf, PINDEX len);
441 off_t RawGetPosition()
const;
442 PBoolean RawSetPosition(off_t pos, FilePositionOrigin origin);
443 off_t RawGetDataLength();
445 void SetLastReadCount(PINDEX v) { lastReadCount = v; }
446 void SetLastWriteCount(PINDEX v) { lastWriteCount = v; }
449 static PWAVFile * format(
const PString & format);
450 static PWAVFile * format(
const PString & format, OpenMode mode, OpenOptions opts = ModeDefault);
455 bool SelectFormat(
unsigned fmt);
456 bool SelectFormat(
const PString & format);
463 PWAV::FMTChunk wavFmtChunk;
468 unsigned int origFmt;
469 PWAVFileFormat * formatHandler;
472 PWAVFileConverter * autoConverter;
477 bool header_needs_updating;
479 friend class PWAVFileConverter;
484 #endif // PTLIB_PWAVFILE_H