AudioFile Class Reference

A class used to manipulate audio data.audio file access. More...

#include <audio.h>

Inheritance diagram for AudioFile:

Audio List of all members.

Public Member Functions

 AudioFile (const char *fname, unsigned long samples=0)
 AudioFile (const char *fname, Info *info, unsigned long min=0)
 AudioFile ()
virtual ~AudioFile ()
void open (const char *fname)
 Open an audio file and associate it with this object.
void create (const char *fname, Info *info)
 Create a new audio file and associate it with this object.
void close (void)
 Close an object associated with an open file.
void clear (void)
 Clear the AudioFile structure.
int getBuffer (void *addr, unsigned len)
 Retrieve bytes from the file into a memory buffer.
unsigned getLinear (Linear buffer, unsigned request)
 Retrieve and convert content to linear encoded audio data from it's original form.
int putBuffer (void *attr, unsigned len)
 Insert bytes into the file from a memory buffer.
unsigned putLinear (Linear buffer, unsigned request)
 Convert and store content from linear encoded audio data to the format of the audio file.
Error getSamples (void *addr, unsigned samples)
 Retrieve samples from the file into a memory buffer.
Error putSamples (void *addr, unsigned samples)
 Insert samples into the file from a memory buffer.
Error skip (long samples)
Error setPosition (unsigned long samples=~0l)
Error setLimit (unsigned long samples=0l)
Error getInfo (Info *info)
Error setMinimum (unsigned long samples)
unsigned long getAbsolutePosition (void)
 Get the current file pointer in bytes relative to the start of the file.
unsigned long getPosition (void)
 Get the current file pointer in samples relative to the start of the sample buffer.
virtual bool isOpen (void)
virtual bool hasPositioning (void)
Encoding getEncoding (void)
Format getFormat (void)
unsigned getSampleRate (void)
char * getAnnotation (void)
Error getError (void)
bool operator! (void)
bool isSigned (void)
 Return if the current content is signed or unsigned samples.

Protected Member Functions

virtual bool afCreate (const char *path)
virtual bool afOpen (const char *path)
virtual bool afPeek (unsigned char *data, unsigned size)
AudioCodecgetCodec (void)
virtual int afRead (unsigned char *data, unsigned size)
 Read a given number of bytes from the file, starting from the current file pointer.
virtual int afWrite (unsigned char *data, unsigned size)
 Write a number of bytes into the file at the current file pointer.
virtual bool afSeek (unsigned long pos)
 Seek to the given position relative to the start of the file and set the file pointer.
virtual void afClose (void)
virtual char * getContinuation (void)
const char * getErrorStr (Error err)
 Return a human-readable error message given a numeric error code of type Audio::Error.
Error setError (Error err)
unsigned long getHeader (void)
unsigned short getShort (unsigned char *data)
void setShort (unsigned char *data, unsigned short value)
unsigned long getLong (unsigned char *data)
void setLong (unsigned char *data, unsigned long value)

Protected Attributes

union {
   int   fd
   void *   handle
file
unsigned long limit

Detailed Description

A class used to manipulate audio data.audio file access.

This class provides file level access to audio data stored in different formats. This class also provides the ability to write audio data into a disk file.

Author:
David Sugar <dyfet@ostel.com>


Constructor & Destructor Documentation

AudioFile::AudioFile ( const char *  fname,
unsigned long  samples = 0 
)

AudioFile::AudioFile ( const char *  fname,
Info *  info,
unsigned long  min = 0 
)

AudioFile::AudioFile (  )  [inline]

virtual AudioFile::~AudioFile (  )  [inline, virtual]


Member Function Documentation

virtual void AudioFile::afClose ( void   )  [protected, virtual]

virtual bool AudioFile::afCreate ( const char *  path  )  [protected, virtual]

virtual bool AudioFile::afOpen ( const char *  path  )  [protected, virtual]

virtual bool AudioFile::afPeek ( unsigned char *  data,
unsigned  size 
) [protected, virtual]

virtual int AudioFile::afRead ( unsigned char *  data,
unsigned  size 
) [protected, virtual]

Read a given number of bytes from the file, starting from the current file pointer.

May be overridden by derived classes.

Parameters:
data A pointer to the buffer to copy the bytes to.
size The number of bytes to read.
Returns:
The number of bytes read, or -1 if an error occurs. On UNIX platforms, use strerror(errno) to get the human-readable error string or FormatMessage(GetLastError()) on Windows platforms.

virtual bool AudioFile::afSeek ( unsigned long  pos  )  [protected, virtual]

Seek to the given position relative to the start of the file and set the file pointer.

This does not use 64-bit clean seek functions, so seeking to positions greater than (2^32)-1 will result in undefined behavior.

Parameters:
pos The position to seek to.
Returns:
true if successful, false otherwise.

virtual int AudioFile::afWrite ( unsigned char *  data,
unsigned  size 
) [protected, virtual]

Write a number of bytes into the file at the current file pointer.

May be overridden by derived classes.

Parameters:
data A pointer to the buffer with the bytes to write.
size The number of bytes to write from the buffer.
Returns:
The number of bytes written, or -1 if an error occurs. On UNIX platforms, use strerror(errno) to get the human-readable error string or FormatMessage(GetLastError()) on Windows platforms.

void AudioFile::clear ( void   ) 

Clear the AudioFile structure.

Called by AudioFile::close(). Sets all fields to zero and deletes the dynamically allocated memory pointed to by the pathname and info.annotation members. See AudioFile::initialize() for the dynamic allocation code.

void AudioFile::close ( void   ) 

Close an object associated with an open file.

This updates the header metadata with the file length if the file length has changed.

void AudioFile::create ( const char *  fname,
Info *  info 
)

Create a new audio file and associate it with this object.

Called implicitly by the three-argument version of the constructor.

Parameters:
fname The name of the file to open.
info The type of the audio file to be created.

unsigned long AudioFile::getAbsolutePosition ( void   ) 

Get the current file pointer in bytes relative to the start of the file.

See getPosition() to determine the position relative to the start of the sample buffer.

Returns:
The current file pointer in bytes relative to the start of the file. Returns 0 if the file is not open, is empty, or an error has occured.

char* AudioFile::getAnnotation ( void   )  [inline]

int AudioFile::getBuffer ( void *  addr,
unsigned  len 
)

Retrieve bytes from the file into a memory buffer.

This increments the file pointer so subsequent calls read further bytes. If you want to read a number of samples rather than bytes, use getSamples().

Parameters:
addr A pointer to the memory area to copy the samples to.
len The number of bytes (not samples) to copy.
Returns:
The number of bytes (not samples) read. Returns -1 if no bytes are read and an error occurs.

AudioCodec* AudioFile::getCodec ( void   )  [protected]

virtual char* AudioFile::getContinuation ( void   )  [inline, protected, virtual]

Encoding AudioFile::getEncoding ( void   )  [inline]

Error AudioFile::getError ( void   )  [inline]

const char* AudioFile::getErrorStr ( Error  err  )  [protected]

Return a human-readable error message given a numeric error code of type Audio::Error.

Parameters:
err The numeric error code to translate.
Returns:
A pointer to a character string containing the human-readable error message.

Format AudioFile::getFormat ( void   )  [inline]

unsigned long AudioFile::getHeader ( void   )  [inline, protected]

Error AudioFile::getInfo ( Info *  info  ) 

unsigned AudioFile::getLinear ( Linear  buffer,
unsigned  request 
)

Retrieve and convert content to linear encoded audio data from it's original form.

Parameters:
addr A pointer to copy linear data into.
len Number of linear samples to extract.
Returns:
number of samples retrieved, 0 if no codec or eof.

unsigned long AudioFile::getLong ( unsigned char *  data  )  [protected]

unsigned long AudioFile::getPosition ( void   ) 

Get the current file pointer in samples relative to the start of the sample buffer.

Note that you must multiply this result by the result of a call to toBytes(info.encoding, 1) in order to determine the offset in bytes.

Returns:
the current file pointer in samples relative to the start of the sample buffer. Returns 0 if the file is not open, is empty, or an error has occured.

unsigned AudioFile::getSampleRate ( void   )  [inline]

Error AudioFile::getSamples ( void *  addr,
unsigned  samples 
)

Retrieve samples from the file into a memory buffer.

This increments the file pointer so subsequent calls read further samples. If a limit has been set using setLimit(), the number of samples read will be truncated to the limit position. If you want to read a certain number of bytes rather than a certain number of samples, use getBuffer().

Parameters:
addr A pointer to the memory area to copy the samples to.
samples The number of samples to read.
Returns:
errSuccess if successful, !errSuccess if error. Use getErrorStr() to retrieve the human-readable error string.

unsigned short AudioFile::getShort ( unsigned char *  data  )  [protected]

virtual bool AudioFile::hasPositioning ( void   )  [inline, virtual]

virtual bool AudioFile::isOpen ( void   )  [virtual]

bool AudioFile::isSigned ( void   ) 

Return if the current content is signed or unsigned samples.

Returns:
true if signed.

void AudioFile::open ( const char *  fname  ) 

Open an audio file and associate it with this object.

Called implicitly by the two-argument version of the constructor.

Parameters:
fname The name of the file to open. Don't forget to double your backslashes for DOS-style pathnames.

bool AudioFile::operator! ( void   )  [inline]

int AudioFile::putBuffer ( void *  attr,
unsigned  len 
)

Insert bytes into the file from a memory buffer.

This increments the file pointer so subsequent calls append further samples. If you want to write a number of samples rather than bytes, use putSamples().

Parameters:
attr A pointer to the memory area to append the samples from.
len The number of bytes (not samples) to append.
Returns:
The number of bytes (not samples) read. Returns -1 if an error occurs and no bytes are written.

unsigned AudioFile::putLinear ( Linear  buffer,
unsigned  request 
)

Convert and store content from linear encoded audio data to the format of the audio file.

Parameters:
addr A pointer to copy linear data from.
len Number of linear samples to save.
Returns:
number of samples saved, 0 if no codec or eof.

Error AudioFile::putSamples ( void *  addr,
unsigned  samples 
)

Insert samples into the file from a memory buffer.

This increments the file pointer so subsequent calls append further samples. If you want to write a certain number of bytes rather than a certain number of samples, use putBuffer().

Parameters:
addr A pointer to the memory area to append the samples from.
samples The number of samples (not bytes) to append.
Returns:
errSuccess if successful, !errSuccess if error. Use getErrorStr() to retrieve the human-readable error string.

Error AudioFile::setError ( Error  err  )  [protected]

Error AudioFile::setLimit ( unsigned long  samples = 0l  ) 

void AudioFile::setLong ( unsigned char *  data,
unsigned long  value 
) [protected]

Error AudioFile::setMinimum ( unsigned long  samples  ) 

Error AudioFile::setPosition ( unsigned long  samples = ~0l  ) 

void AudioFile::setShort ( unsigned char *  data,
unsigned short  value 
) [protected]

Error AudioFile::skip ( long  samples  ) 


Member Data Documentation

int AudioFile::fd [protected]

union { ... } AudioFile::file [protected]

void* AudioFile::handle [protected]

unsigned long AudioFile::limit [protected]


The documentation for this class was generated from the following file:
Generated on Sun Oct 22 22:53:34 2006 for ccAudio by  doxygen 1.4.7