31 #ifndef PTLIB_PWAVFILE_H
32 #define PTLIB_PWAVFILE_H
56 struct RIFFChunkHeader
69 PUInt16l bytesPerSample;
70 PUInt16l bitsPerSample;
73 struct G7231ExtendedInfo
81 PWAV::ChunkHeader hdr;
95 virtual ~PWAVFileFormat() { }
99 virtual unsigned GetFormat()
const = 0;
103 virtual PString GetFormatString()
const = 0;
107 virtual PString GetDescription()
const = 0;
110 virtual bool CanSetChannels(
unsigned channels)
const = 0;
114 virtual void CreateHeader(PWAV::FMTChunk & header,
PBYTEArray & extendedHeader) = 0;
118 virtual void UpdateHeader(PWAV::FMTChunk & ,
PBYTEArray & )
123 virtual void ProcessHeader(
const PWAV::FMTChunk & ,
const PBYTEArray & )
128 virtual PBoolean WriteExtraChunks(PWAVFile & )
133 virtual PBoolean ReadExtraChunks(PWAVFile & )
138 virtual void OnStart()
143 virtual void OnStop()
148 virtual PBoolean Read(PWAVFile & file,
void * buf, PINDEX & len);
152 virtual PBoolean Write(PWAVFile & file,
const void * buf, PINDEX & len);
158 #define PCREATE_WAVFILE_FORMAT_FACTORY(cls, id, name) \
159 PFACTORY_CREATE(PWAVFileFormatByIDFactory, cls, id); \
160 typedef cls cls##_ByFormat; \
161 PFACTORY_CREATE(PWAVFileFormatByFormatFactory, cls##_ByFormat, name)
168 class PWAVFileConverter
171 virtual ~PWAVFileConverter() { }
172 virtual unsigned GetFormat (
const PWAVFile & file)
const = 0;
173 virtual off_t GetPosition (
const PWAVFile & file)
const = 0;
175 virtual unsigned GetSampleSize(
const PWAVFile & file)
const = 0;
176 virtual off_t GetDataLength (PWAVFile & file) = 0;
177 virtual PBoolean Read (PWAVFile & file,
void * buf, PINDEX len) = 0;
178 virtual PBoolean Write (PWAVFile & file,
const void * buf, PINDEX len) = 0;
187 class PWAVFile :
public PFile
210 fmt_VivoG7231 = 0x111,
213 PCM_WavFile = fmt_PCM,
214 G7231_WavFile = fmt_VivoG7231,
223 unsigned createFormat = fmt_PCM
236 OpenOptions opts = ModeDefault,
237 unsigned createFormat = fmt_PCM
251 OpenMode mode = ReadWrite,
252 OpenOptions opts = ModeDefault,
253 unsigned createFormat = fmt_PCM
259 OpenMode mode = ReadWrite,
260 OpenOptions opts = ModeDefault
334 FilePositionOrigin origin = Start
353 virtual PBoolean SetFormat(
unsigned fmt);
358 virtual unsigned GetFormat()
const;
359 virtual PString GetFormatString()
const;
364 virtual unsigned GetChannels()
const;
372 virtual bool SetChannels(
unsigned v);
376 virtual unsigned GetSampleRate()
const;
382 virtual bool SetSampleRate(
unsigned v);
386 virtual unsigned GetSampleSize()
const;
389 unsigned GetRawSampleSize()
const;
395 virtual bool SetSampleSize(
unsigned v);
399 virtual unsigned GetBytesPerSecond()
const;
405 virtual void SetBytesPerSecond(
unsigned v);
410 bool SetAutoconvert(
bool convert =
true);
414 bool RawRead(
void * buf, PINDEX len);
415 bool RawWrite(
const void * buf, PINDEX len);
417 off_t RawGetPosition()
const;
418 bool RawSetPosition(off_t pos, FilePositionOrigin origin);
419 off_t RawGetDataLength() {
return m_dataLength; }
422 static PWAVFile * format(
const PString & format);
423 static PWAVFile * format(
const PString & format, OpenMode mode, OpenOptions opts = ModeDefault);
424 __inline
bool IsValid()
const {
return IsOpen(); }
428 virtual bool InternalOpen(OpenMode mode, OpenOptions opts, PFileInfo::Permissions permissions);
429 void Construct(OpenMode mode);
430 bool SelectFormat(PWAVFileFormat * handler);
432 bool ProcessHeader();
433 bool GenerateHeader();
436 unsigned m_createFormat;
437 PWAV::FMTChunk m_wavFmtChunk;
440 off_t m_headerLength;
443 PWAVFileFormat * m_formatHandler;
444 PWAVFileConverter * m_autoConverter;
453 unsigned m_readSampleRate;
454 unsigned m_readChannels;
456 PINDEX m_readBufCount;
462 #endif // PTLIB_PWAVFILE_H
virtual PBoolean Close()
Close the file channel.
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the file channel.
This class represents a disk file.
Definition: file.h:57
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
virtual off_t GetLength() const
Get the current size of the file.
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
virtual PBoolean SetPosition(off_t pos, FilePositionOrigin origin=Start)
Set the current active position in the file for the next read or write operation. ...
PThreadLocalStorage< Status > m_status[NumErrorGroups+1]
Definition: channel.h:749
virtual bool InternalOpen(OpenMode mode, OpenOptions opts, PFileInfo::Permissions permissions)
Array of unsigned characters.
Definition: array.h:605
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the file channel.
#define PFACTORY_LOAD(ConcreteType)
Definition: pfactory.h:557
FilePositionOrigin
Options for the origin in setting the file position.
Definition: file.h:500
virtual off_t GetPosition() const
Get the current active position in the file for the next read or write operation. ...
bool PBoolean
Definition: object.h:174
The character string class.
Definition: pstring.h:108
Class for a factory to create concrete class instances without parameters during construction.
Definition: pfactory.h:396
virtual PBoolean IsOpen() const
Determine if the channel is currently open.
This template class maps the PAbstractArray to a specific element type.
Definition: array.h:504
virtual PBoolean SetLength(off_t len)
Set the size of the file, padding with 0 bytes if it would require expanding the file, or truncating it if being made shorter.