AudioUtil Class Reference

Provides a number of utilities for pulling useful data from audio files. More...

#include <AudioUtil.h>

List of all members.

Public Types

enum  FileHandlingMode { FULL_CACHE, DISK_MODE }

Public Member Functions

 AudioUtil ()
 Default constructor.
 AudioUtil (string filePath)
 Alternate, single-parameter constructor.
bool setFile (string filePath)
 Sets the file to be wrapped by an instance of AudioUtil.
int getNumChannels ()
 The number of channels of the wrapped audio file.
int getSampleRate ()
 The sample rate of the wrapped audio file.
int getTotalFrames ()
 The total number of frames of the wrapped audio file.
vector< double > calculateNormalizedPeaks ()
 Calculates peak values for the normalized audio data of the audio file wrapped by an instance of AudioUtil.
vector< double > grabFrame (int frameIndex)
 Get a given frame of the wrapped audio file.
vector< double > peakForRegion (int region_start_frame, int region_end_frame)
 Peak for a given region of the wrapped audio file.
vector< double > getAllFrames ()
 The content of the wrapped audio file.
FileHandlingMode getFileHandlingMode ()
 Accessor for an instance of AudioUtil's file-handling mode.
void setFileHandlingMode (FileHandlingMode mode)
 The mutator for the file-handling mode of an instance of AudioUtil.

Detailed Description

Provides a number of utilities for pulling useful data from audio files.

This class began as a nice, object-oriented wrapper for certain functions that I found myself frequently using in Erik de Castro Lopo's libsndfile. It now supports an optional caching scheme (enabled by calling setFileHandlingMode(AudioUtil::FULL_CACHE) on an instance of AudioUtil) to dramatically speed up the performance of certain functions, like that for accessing arbitrary frames (grabFrame()) of an audio file and that for determining the peak value for a given region of an audio file (peakForRegion()).

Definition at line 27 of file AudioUtil.h.


Constructor & Destructor Documentation

AudioUtil::AudioUtil (  ) 

Default constructor.

Constructs instance of AudioUtil. An AudioUtil instance created using this constructor is effectively useless until its setFile() function has been invoked with a valid path to a WAV file. For this reason, you may elect to use the alternate AudioUtil constructor, which takes such a path as a parameter.

Definition at line 15 of file AudioUtil.cpp.

AudioUtil::AudioUtil ( string  filePath  ) 

Alternate, single-parameter constructor.

Alternate constructor. An instance of AudioUtil created using this constructor does not need to have its setFile() function explicitly invoked to be useful.

Parameters:
filePath path to a WAV file

Definition at line 30 of file AudioUtil.cpp.


Member Function Documentation

vector< double > AudioUtil::calculateNormalizedPeaks (  ) 

Calculates peak values for the normalized audio data of the audio file wrapped by an instance of AudioUtil.

Returns:
a vector containing the peak for each channel of the audio file wrapped by an instance of AudioUtil. in the case of an error, an empty vector is returned.

Definition at line 142 of file AudioUtil.cpp.

vector< double > AudioUtil::getAllFrames (  ) 

The content of the wrapped audio file.

Function to get all frames of the audio file wrapped by an instance of AudioUtil as a vector of double-precision floating-point values.

Returns:
a vector of double-precision floating-point values representing all frames of the audio file wrapped by this instance of AudioUtil.

Definition at line 462 of file AudioUtil.cpp.

AudioUtil::FileHandlingMode AudioUtil::getFileHandlingMode (  ) 

Accessor for an instance of AudioUtil's file-handling mode.

Returns:
the mode of this AudioUtil instance

Definition at line 82 of file AudioUtil.cpp.

int AudioUtil::getNumChannels (  ) 

The number of channels of the wrapped audio file.

Returns:
the number of channels in the audio file wrapped by an instance of AudioUtil

Definition at line 174 of file AudioUtil.cpp.

int AudioUtil::getSampleRate (  ) 

The sample rate of the wrapped audio file.

Returns:
the sample rate of the audio file wrapped by an instance of AudioUtil

Definition at line 191 of file AudioUtil.cpp.

int AudioUtil::getTotalFrames (  ) 

The total number of frames of the wrapped audio file.

Returns:
the number of frames of the wrapped audio file.

Definition at line 201 of file AudioUtil.cpp.

vector< double > AudioUtil::grabFrame ( int  frameIndex  ) 

Get a given frame of the wrapped audio file.

Function to get the frame at a given index in the audio file wrapped by an instance of AudioUtil. Will return a double-precision floating point vector of dimension equal to the number_of_channels in the wrapped file (either 1 or 2) containing the data of the requested frame. In the case that a frame is requested which is out of bounds, an error message will be printed and an empty vector returned.

Parameters:
frameIndex The desired frame.
Returns:
A vector of double-precision floating point values representing the contents of the requested frame. In the case that an out-of-bounds frame is requested, an empty vector will be returned.

Definition at line 227 of file AudioUtil.cpp.

vector< double > AudioUtil::peakForRegion ( int  region_start_frame,
int  region_end_frame 
)

Peak for a given region of the wrapped audio file.

Function to get the peak for each channel of a given region of the audio file wrapped by an instance of AudioUtil. Returns a vector of double-precision floating point values representing this data. In the case that an invalid region is specified by the function's parameters, prints an error message and returns an empty vector. This function performs drastically better when the AudioUtil instance it is being invoked with is operating in FULL_CACHE mode rather than DISK_MODE.

Parameters:
region_start_frame The frame marking the beginning of the region to be analyzed
region_end_frame The frame marking the end of the region to be analyzed
Returns:
A vector of double-precision floating point values representing the peak for each channel of the specified region of the audio file wrapped by an instance of AudioUtil. In the case that an invalid region has been specified, return value is an empty vector.

Definition at line 317 of file AudioUtil.cpp.

bool AudioUtil::setFile ( string  filePath  ) 

Sets the file to be wrapped by an instance of AudioUtil.

Set the audio file to be wrapped by an instance of AudioUtil. This function must be passed a string representing a valid path to a WAV file. In the case that it is not given such a string, it will print an error message and return false. Otherwise, it will return true.

Parameters:
filePath a string representing a valid path to a WAV file.
Returns:
true if file was successfully set, false otherwise.

Definition at line 98 of file AudioUtil.cpp.

void AudioUtil::setFileHandlingMode ( FileHandlingMode  mode  ) 

The mutator for the file-handling mode of an instance of AudioUtil.

AudioUtil objects can function in one of two modes: AudioUtil::DISK_MODE and AudioUtil::FULL_CACHE mode. The default mode for AudioUtil objects is DISK_MODE. In DISK_MODE, an instance of AudioUtil will dynamically load a region of the audio file it wraps from disk into memory when asked to analyze or return this region (when the peakForRegion, getAllFrames and grabFrame function are invoked, for example). This keeps memory use minimal, but has an immense consequence with respect to performance. Upon being set to FULL_CACHE mode, an AudioUtil instance will load the entire audio file that it wraps into memory (storing it as a vector of double-precision floating point values), and use this cached data to perform the operations that, in DISK_MODE, require that data be loaded dynamically from disk for processing. In FULL_CACHE mode, you get drastically increased performance, but pay a penalty in increased memory consumption.

Parameters:
mode file-handling scheme for the AudioUtil instance. Valid options: AudioUtil::DISK_MODE, AudioUtil::FULL_CACHE

Definition at line 68 of file AudioUtil.cpp.


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

Generated on Fri Jun 11 02:38:46 2010 for WaveformWidget by  doxygen 1.6.1