man AudioFile (Fonctions bibliothèques) - A class used to manipulate audio data. audio file access.

NAME

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

SYNOPSIS



#include <audio.h>

Inherits Audio.

Public Methods

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. 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. bool isSigned (void)

Return if the current content is signed or unsigned samples.

Protected Methods

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. const char * getErrorStr (Error err)

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

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>

MEMBER FUNCTION DOCUMENTATION

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.

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.

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.

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::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.

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.

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.

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.

AUTHOR

Generated automatically by Doxygen for ccAudio from the source code.