Bridges-C++
3.4.4
Bridges(C++ API)
|
#include <AudioClip.h>
This class provides support for reading, modifying, and playing audio waveforms.
This class provides a way to represent an AudioClip (think of a .WAV file) in Bridges as waveforms.
An AudioClip can be composed of multiple channels: a stereo sound would be composed of 2 channels (Left and Right), a mono sound would be composed of a single channel. A 5.1 sound would be composed of 6 channels. When building an AudioClip from a file, the number of channels is taken from the file; some constructors have a numChannels that enables to pass the number of channels explicitly. If unsure, one can know how many channels are in an audio clip using getNumChannels().
Each channel is essentially a 1D signal. That is to say, it is an array of values that represent how far the membrane of a speaker should be from its resting position. The quality of the sound is controlled by two parameters: sampling rate and sampling depth.
Sampling rate tells how many positions per second are encoded by the AudioClip. It is expressed in Hertz. CD quality is 44100Hz; while walkie-talkies use 8000Hz. It is set automatically if read from a file; or it can be passed as the sampleRate parameter to some of the constructors. The sampling rate can be obtained from an AudioClip using getSampleRate().
The length of an AudioClip is expressed in number of samples. So if an AudioClip is composed of 16,000 samples with a sampling rate of 8000Hz, the clip would be 2 seconds long. The number of samples can obtained with getSampleCount(); it is set from a file or can be passed as the sampleCount parameter of some of the constructor.
The sampling depth indicates how many different positions the membrane can take. It is typically expressed in bits with supported values being 8-bit, 16-bit, 24-bit, and 32-bit. If a clip is encoded with a depth of 8 bits, the membrane can take 2^8 different position ranging from -128 to +127, with 0 being the resting position. The sampling depth is read from files or passed as the sampleBits parameter of the constructor. The sampling depth of an existing clip can be obtained with getSampleBits().
The individual samples are accessed with the getSample() and setSample() functions. The samples are integer values in the [-2^(getSampleBits()-1) ; 2^(getSampleBits()-1)[ range. The functions allow to specify for channel and sample index.
Acknowledgements: The Wav file parser is adapted from Amit Sengupta's C version, posted at TRUELOGIC BLOG, http://truelogic.org/wordpress/2015/09/04/parsing-a-wav-file-in-c/
It was converted into C++ in this implementation.
Public Member Functions | |
AudioClip (int sampleCount, int numChannels, int sampleBits, int sampleRate) | |
create an audio clip More... | |
virtual const string | getDStype () const override |
AudioClip (const string &wave_file) | |
create an audio clip from a File More... | |
virtual const string | getDataStructureRepresentation () const override final |
int | getNumChannels () const |
returns the number of channels of the clip More... | |
int | getSampleRate () const |
returns the sampling rate of the clip More... | |
int | getSampleCount () const |
returns the number of samples in the clip More... | |
int | getSampleBits () const |
returns the sampling depth. More... | |
int | getSample (int channelIndex, int sampleIndex) const |
access a particular sample More... | |
void | setSample (int channelIndex, int sampleIndex, int value) |
change a particular sample More... | |
Public Member Functions inherited from bridges::datastructure::DataStructure | |
virtual | ~DataStructure ()=default |
|
inline |
create an audio clip
creates an AudioClip with numChannels channels, sampleCount samples at sampleRate Hz with a depth of sampleBits
|
inline |
create an audio clip from a File
wave_file | name of the file (should be a Wave file) |
|
inlinefinaloverridevirtual |
Ease of use function for the deletion of an entire datastructure. Overrides should call delete on itself and each linked data structure
Implements bridges::datastructure::DataStructure.
|
inlineoverridevirtual |
Implements bridges::datastructure::DataStructure.
|
inline |
returns the number of channels of the clip
|
inline |
access a particular sample
channelIndex | the index of the channel that will be accessed (in the [0;getNumChannels()-1] range). |
sampleIndex | the index of the sample that will be accessed (in the [0;getSampleCount()-1] range). |
|
inline |
returns the sampling depth.
The sampling depth indicates how many bits are used to encode each individual samples. The values supported are only 8, 16, 24, and 32.
All samples must be in the [-2^(getSampleBits()-1) ; 2^(getSampleBits()-1)) range. that is to say, for 8-bit, in the [-256;255] range.
|
inline |
returns the number of samples in the clip
The length of the clip in second is getSampleCount()/((double) getSampleRate())
|
inline |
returns the sampling rate of the clip
|
inline |
change a particular sample
channelIndex | the index of the channel that will be accessed (in the [0;getNumChannels()-1] range). |
sampleIndex | the index of the sample that will be accessed (in the [0;getSampleCount()-1] range). |
value | the sample value (in [-2^(getSampleBits()-1) ; 2^(getSampleBits()-1)) range). |