#include <audio.h>
Inheritance diagram for AudioFile:
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) |
AudioCodec * | getCodec (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 |
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.
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] |
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.
data | A pointer to the buffer to copy the bytes to. | |
size | The number of bytes to read. |
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.
pos | The position to seek to. |
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.
data | A pointer to the buffer with the bytes to write. | |
size | The number of bytes to write from the buffer. |
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.
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.
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().
addr | A pointer to the memory area to copy the samples to. | |
len | The number of bytes (not samples) to copy. |
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.
err | The numeric error code to translate. |
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.
addr | A pointer to copy linear data into. | |
len | Number of linear samples to extract. |
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.
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().
addr | A pointer to the memory area to copy the samples to. | |
samples | The number of samples to read. |
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.
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.
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().
attr | A pointer to the memory area to append the samples from. | |
len | The number of bytes (not samples) to append. |
unsigned AudioFile::putLinear | ( | Linear | buffer, | |
unsigned | request | |||
) |
Convert and store content from linear encoded audio data to the format of the audio file.
addr | A pointer to copy linear data from. | |
len | Number of linear samples to save. |
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().
addr | A pointer to the memory area to append the samples from. | |
samples | The number of samples (not bytes) to append. |
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 | ) |
int AudioFile::fd [protected] |
union { ... } AudioFile::file [protected] |
void* AudioFile::handle [protected] |
unsigned long AudioFile::limit [protected] |