class PWAVFile

A class representing a WAV audio file

Inheritance:


Public Methods

[more] Overrides from class PFile
[more] Member variable access

Public Members

[more] Construction


Inherited from PFile:

Public Methods

Overrides from class PObject

Overrides from class PChannel

File manipulation functions

File channel functions

Protected Fields

oPFilePath path
oBOOL removeOnClose


Inherited from PChannel:

Public Methods

Information functions

Reading functions

Writing functions

Miscellaneous functions

ostatic BOOL ConvertOSError( int libcReturnValue, Errors & lastError, int & osError )

Public Members

Error functions

Protected Fields

oint os_handle
oErrors lastErrorCode[NumErrorGroups+1]
oint lastErrorNumber[NumErrorGroups+1]
oPINDEX lastReadCount
oPINDEX lastWriteCount
oPTimeInterval readTimeout
oPTimeInterval writeTimeout

Protected Methods

ovirtual BOOL ConvertOSError( int libcReturnValue, ErrorGroup group = LastGeneralError )
oBOOL SetErrorValues( Errors errorCode, int osError, ErrorGroup group = LastGeneralError )
oint ReadCharWithTimeout( PTimeInterval & timeout )


Inherited from PObject:

Public Methods

Run Time Type functions

I/O functions

Public Members

Comparison functions


Documentation

A class representing a WAV audio file
o Construction

oenum When a file is opened for writing, we can specify if this is a PCM wav file or a G7231 wav file
When a file is opened for writing, we can specify if this is a PCM wav file or a G7231 wav file

o fmt_ALaw
PCM, 8kHz, 16 bit, mono

o fmt_uLaw
A-Law 8kHz

o fmt_GSM
u-Law 8kHz

o fmt_G728
GSM

o fmt_G723
RFC2361

o fmt_MSG7231
RFC2361

o fmt_G726
Microsoft G7231

o fmt_G722
RFC2361

o fmt_G729
RFC2361

o fmt_VivoG7231
RFC2361

o PCM_WavFile
VivoActive G7231

o PWAVFile( unsigned format = fmt_PCM )
Create a WAV file object but do not open it. It does not initially have a valid file name. However, an attempt to open the file using the PFile::Open() function will generate a unique temporary file.

If a WAV file is being created, the type parameter can be used to create a PCM Wave file or a G.723.1 Wave file by using WaveType enum

Parameters:
format - Type of WAV File to create

o PWAVFile( OpenMode mode, int opts = ModeDefault, unsigned format = fmt_PCM )
Create a unique temporary file name, and open the file in the specified mode and using the specified options. Note that opening a new, unique, temporary file name in ReadOnly mode will always fail. This would only be usefull in a mode and options that will create the file.

If a WAV file is being created, the type parameter can be used to create a PCM Wave file or a G.723.1 Wave file by using WaveType enum

The PChannel::IsOpen() function may be used after object construction to determine if the file was successfully opened.

Parameters:
mode - Mode in which to open the file.
opts - OpenOptions enum for open operation.
format - Type of WAV File to create

o PWAVFile( const PFilePath & name, OpenMode mode = ReadWrite, int opts = ModeDefault, unsigned format = fmt_PCM )
Create a WAV file object with the specified name and open it in the specified mode and with the specified options. If a WAV file is being created, the type parameter can be used to create a PCM Wave file or a G.723.1 Wave file by using WaveType enum

The PChannel::IsOpen() function may be used after object construction to determine if the file was successfully opened.

Parameters:
name - Name of file to open.
mode - Mode in which to open the file.
opts - OpenOptions enum for open operation.
format - Type of WAV File to create

o ~PWAVFile()
Close the file before destruction

o Overrides from class PFile

ovirtual BOOL Read( void* buf, PINDEX len )
Call PFile::Read() to read in audio data and perform necessary processing such as byte-order swaping.

Parameters:
buf - Pointer to a block of memory to receive the read bytes.
len - Maximum number of bytes to read into the buffer.
Returns:
TRUE indicates that at least one character was read from the channel. FALSE means no bytes were read due to timeout or some other I/O error.

ovirtual BOOL Write( const void* buf, PINDEX len )
Call PFile::Write() to write out audio data and perform necessary processing such as byte-order swaping.

Parameters:
buf - Pointer to a block of memory to receive the write bytes.
len - Maximum number of bytes to write to the channel.
Returns:
TRUE indicates that at least one character was written to the channel. FALSE means no bytes were written due to timeout or some other I/O error.

ovirtual BOOL Open( OpenMode mode = ReadWrite, int opts = ModeDefault )
Open the current file in the specified mode and with the specified options. If the file object already has an open file then it is closed.

If there has not been a filename attached to the file object (via SetFilePath(), the name parameter or a previous open) then a new unique temporary filename is generated.

Returns:
TRUE if the file was successfully opened.

ovirtual BOOL Open( const PFilePath & name, OpenMode mode = ReadWrite, int opts = ModeDefault )
Open the specified WAV file name in the specified mode and with the specified options. If the file object already has an open file then it is closed. This reads (and validates) the header for existing files. For new files, it creates a new file (and header) using the type of WAV file specified in the class constructor.

Note: if mode is StandardInput, StandardOutput or StandardError, then the name parameter is ignored.

Returns:
TRUE if the file was successfully opened.

ovirtual BOOL Close()
Close the file channel. If a WAV file has been written to, this will update the header to contain the correct size information.
Returns:
TRUE if close was OK.

ovirtual BOOL SetPosition( off_t pos, FilePositionOrigin origin = Start )
Set the current active position in the file for the next read or write operation. The pos variable is a signed number which is added to the specified origin. For origin == PFile::Start only positive values for pos are meaningful. For origin == PFile::End only negative values for pos are meaningful.

Note that for a WAV file, the origin of the file is right after the header. That is, the WAV header is not included when perform SetPosition().

Parameters:
pos - New position to set.
origin - Origin for position change.
Returns:
TRUE if the new file position was set.

ovirtual off_t GetPosition() const
Get the current active position in the file for the next read or write operation. The WAV header is excluded from calculation the position.

Returns:
current file position relative to the end of the WAV header.

o Member variable access

ovirtual BOOL SetFormat(unsigned fmt)
Find out the format of the WAV file. Eg 0x01 for PCM, 0x42 or 0x111 for G.723.1.

ovirtual unsigned GetFormat() const
Find out the format of the WAV file. Eg 0x01 for PCM, 0x42 or 0x111 for G.723.1.

ovirtual unsigned GetChannels() const
Find out the number of channels the WAV file has. Typically this is 1 for mono and 2 for stereo.

ovirtual unsigned GetSampleRate() const
Find out the sample rate of the WAV file in Hz

ovirtual unsigned GetSampleSize() const
Find out how may bits there are per sample, eg 8 or 16

ooff_t GetHeaderLength() const
Find out the size of WAV header presented in the file

ovirtual off_t GetDataLength()
Find out how many bytes of audio data there are

oBOOL IsValid() const
Determine if the WAV file is a valid wave file.

Returns:
TRUE indicates that the WAV file is valid FALSE indicates that the WAV file is invalid


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java



This page was generated with the help of DOC++.