Bela
Real-time, ultra-low-latency audio and sensor processing system for BeagleBone Black
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
Functions
AudioFileUtilities Namespace Reference

A collection of functions for loading and storing audio files. More...

Functions

int getSamples (const std::string &file, float *buf, unsigned int channel, unsigned int startFrame, unsigned int endFrame)
 
int getNumChannels (const std::string &file)
 
int getNumFrames (const std::string &file)
 
int write (const std::string &filename, float *buf, unsigned int channels, unsigned int frames, unsigned int samplerate)
 
int write (const std::string &filename, const std::vector< std::vector< float > > &dataIn, unsigned int sampleRate)
 
std::vector< std::vector< float > > load (const std::string &filename, int maxCount=-1, unsigned int start=0)
 
std::vector< float > loadMono (const std::string &file)
 

Detailed Description

A collection of functions for loading and storing audio files.

A collection of functions for loading and storing audio files.

Function Documentation

int AudioFileUtilities::getSamples ( const std::string &  file,
float *  buf,
unsigned int  channel,
unsigned int  startFrame,
unsigned int  endFrame 
)

Load audio frames between startFrame and endFrame from channel of the specified file into the preallocated memory location buf.

Returns
0 on success, or an error code upon failure.
Examples:
Audio/sample-streamer/render.cpp.
int AudioFileUtilities::getNumChannels ( const std::string &  file)

Get the number of audio channels in file.

Returns
the number of audio channels on success, or a negative error code upon failure.
int AudioFileUtilities::getNumFrames ( const std::string &  file)

Get the number of audio frames in file.

Returns
the number of frames on success, or a negative error code upon failure.
Examples:
Audio/sample-streamer/render.cpp.
int AudioFileUtilities::write ( const std::string &  filename,
float *  buf,
unsigned int  channels,
unsigned int  frames,
unsigned int  samplerate 
)

Store samples from memory into an audio file on disk.

Parameters
filenamethe file to write to
bufa vector containing channels * frames of interlaved data
channelsthe channels in the data and output file
framesthe frames in the data and output file
sampleRatethe sampling rate of the data
Examples:
Audio/record-audio/render.cpp.
int AudioFileUtilities::write ( const std::string &  filename,
const std::vector< std::vector< float > > &  dataIn,
unsigned int  sampleRate 
)

Write non-interlaved samples from memory into an audio file on disk.

Parameters
filenamethe file to write to
dataIna vector containing one vector of data per channel
sampleRatethe sampling rate of the data
std::vector< std::vector< float > > AudioFileUtilities::load ( const std::string &  filename,
int  maxCount = -1,
unsigned int  start = 0 
)

Load audio samples from a file into memory.

Loads at most count samples from each channel of filename, starting from frame start.

Parameters
filenamethe file to load
maxCountthe maximum number of samples to load from each channel. Pass a negative value for no limit.
startthe first sample to load.
Returns
a vector containing one vector of data per channel.
Examples:
Audio/sample-loader/render.cpp, Audio/sample-piezo-trigger/render.cpp, and Audio/sample-streamer/render.cpp.
std::vector< float > AudioFileUtilities::loadMono ( const std::string &  file)

Load audio samples from a file into memory.

Simplified version of load(), which only loads the first channel of the file.

Examples:
terminal-only/filter-FIR/render.cpp, terminal-only/filter-IIR/render.cpp, and terminal-only/samples/render.cpp.