Class for reading and writing sound file data. More...
#include <SoundFile.h>
Public Types | |
enum | Format { WAV = 1, AIFF, AU, RAW } |
Sound file formats. More... | |
enum | EncodingType { PCM_S8 = 1, PCM_16, PCM_24, PCM_32, PCM_U8, FLOAT, DOUBLE, ULAW, ALAW } |
Sound file sample encoding types. More... | |
Public Member Functions | |
SoundFile (const std::string &path="") | |
Creates object given a path. | |
SoundFile (const std::string &path, const SoundFile &src) | |
Creates object given a path and an other object from which to get its header info. | |
~SoundFile () | |
The destructor will automatically close any open files. | |
bool | openRead () |
Opens sound file for reading. | |
bool | openWrite () |
Opens sound file for writing. | |
bool | close () |
Closes sound file. Files are closed in destructor. | |
template<class T > | |
int | read (T *dst, int numFrames) |
Reads next chunk of frames from file into array. | |
template<class T > | |
int | readAll (T *dst) |
Copy all contents of file into array interleaved. Returns number of frames read. | |
template<class T > | |
int | readAllD (T *dst) |
Copy all contents of file into array deinterleaved. Returns number of frames read. | |
template<class T > | |
int | write (const T *src, int numFrames) |
Writes interleaved frames from array to file. | |
EncodingType | encoding () const |
Get encoding type. | |
Format | format () const |
Get format. | |
double | frameRate () const |
Get frames/second. | |
int | frames () const |
Get number of frames. | |
int | channels () const |
Get number of channels. | |
int | samples () const |
Get number of samples ( = frames x channels) | |
const char * | extension () |
Get file extension. | |
const std::string & | path () const |
Get path of sound file. | |
SoundFile & | encoding (EncodingType v) |
Set encoding type. | |
SoundFile & | format (Format v) |
Set format. | |
SoundFile & | channels (int num) |
Set number of channels. | |
SoundFile & | frameRate (double hz) |
Set frames/second. | |
SoundFile & | info (const SoundFile &src) |
Copy file information from an other file. | |
SoundFile & | path (const std::string &path) |
Set path of sound file. | |
void | print () |
Print information about file to stdout. |
Class for reading and writing sound file data.
enum EncodingType |
enum Format |
SoundFile | ( | const std::string & | path = "" | ) |
Creates object given a path.
The sound file info structure will be zero.
bool openRead | ( | ) |
Opens sound file for reading.
Returns true on success and false otherwise.
bool openWrite | ( | ) |
Opens sound file for writing.
Before calling this method it is necessary to set the format of the file using format(), e.g. format(SF_FORMAT_AIFF | SF_FORMAT_PCM_16). Returns true on success and false otherwise.
int read | ( | T * | dst, |
int | numFrames | ||
) |
Reads next chunk of frames from file into array.
From the libsndfile docs:
The file read frames functions fill the array pointed to by ptr with the requested number of frames of data. The array must be large enough to hold the product of frames and the number of channels.
int readAllD | ( | T * | dst | ) |
Copy all contents of file into array deinterleaved. Returns number of frames read.
If the number of channels is > 1, memory will be dynamically allocated and freed for the deinterleaving.
int write | ( | const T * | src, |
int | numFrames | ||
) |
Writes interleaved frames from array to file.
From the libsndfile docs:
The file write frames functions write the data in the array pointed to by ptr to the file. The array must be large enough to hold the product of frames and the number of channels.