Gamma  0.9.5
Generic Synthesis Library
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
SoundFile Class Reference

Class for reading and writing sound file data. More...

#include <SoundFile.h>

List of all members.

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.
SoundFileencoding (EncodingType v)
 Set encoding type.
SoundFileformat (Format v)
 Set format.
SoundFilechannels (int num)
 Set number of channels.
SoundFileframeRate (double hz)
 Set frames/second.
SoundFileinfo (const SoundFile &src)
 Copy file information from an other file.
SoundFilepath (const std::string &path)
 Set path of sound file.
void print ()
 Print information about file to stdout.

Detailed Description

Class for reading and writing sound file data.


Member Enumeration Documentation

Sound file sample encoding types.

Enumerator:
PCM_S8 

Signed 8 bit data

PCM_16 

Signed 16 bit data

PCM_24 

Signed 24 bit data

PCM_32 

Signed 32 bit data

PCM_U8 

Unsigned 8 bit data (WAV and RAW only)

FLOAT 

32 bit float data

DOUBLE 

64 bit float data

ULAW 

U-Law encoded.

ALAW 

A-Law encoded.

enum Format

Sound file formats.

Enumerator:
WAV 

Microsoft WAV format (little endian default).

AIFF 

Apple/SGI AIFF format (big endian).

AU 

Sun/NeXT AU format (big endian).

RAW 

RAW PCM data.


Constructor & Destructor Documentation

SoundFile ( const std::string &  path = "")

Creates object given a path.

The sound file info structure will be zero.


Member Function Documentation

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.


The documentation for this class was generated from the following files: