Bridges-Java  3.4.2
Bridges(Java API)
Public Member Functions | List of all members
bridges.base.AudioClip Class Reference
Inheritance diagram for bridges.base.AudioClip:
bridges.base.DataStruct

Detailed Description

This class provides support for reading, modifying, and playing, audio waveform.

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.

A tutorial is available at: https://bridgesuncc.github.io/tutorials/AudioClip.html

Public Member Functions

 AudioClip (int sampleCount, int numChannels, int sampleBits, int sampleRate)
 create an audio clip More...
 
 AudioClip (WavFile wavFile) throws IOException
 create an audio clip from a WavFile object More...
 
 AudioClip (String file) throws IOException
 create an audio clip from a File More...
 
 AudioClip (int sampleCount, int numChannels)
 create an audio clip More...
 
int getNumChannels ()
 returns the number of channels of the clip More...
 
int getSampleRate ()
 returns the sampling rate of the clip More...
 
int getSampleCount ()
 returns the number of samples in the clip More...
 
int getSampleBits ()
 returns the sampling depth. More...
 
int getSample (int channelIndex, int sampleIndex)
 access a particular sample More...
 
void setSample (int channelIndex, int sampleIndex, int value)
 change a particular sample More...
 
String getDataStructType ()
 
String getDataStructureRepresentation ()
 

Additional Inherited Members

- Protected Attributes inherited from bridges.base.DataStruct
String QUOTE = "\""
 
- Package Attributes inherited from bridges.base.DataStruct
String COMMA = ","
 
String COLON = ":"
 
String OPEN_CURLY = "{"
 
String CLOSE_CURLY = "}"
 
String OPEN_PAREN = "("
 
String CLOSE_PAREN = ")"
 
String OPEN_BOX = "["
 
String CLOSE_BOX = "]"
 

Constructor & Destructor Documentation

◆ AudioClip() [1/4]

bridges.base.AudioClip.AudioClip ( int  sampleCount,
int  numChannels,
int  sampleBits,
int  sampleRate 
)

create an audio clip

Parameters
numChannelsthe number of channels
sampleCountthe total number of samples
sampleBitsthe bits per sample
sampleRatethe sampling rate (Hz, or cycles per sec)

◆ AudioClip() [2/4]

bridges.base.AudioClip.AudioClip ( WavFile  wavFile) throws IOException

create an audio clip from a WavFile object

◆ AudioClip() [3/4]

bridges.base.AudioClip.AudioClip ( String  file) throws IOException

create an audio clip from a File

Parameters
filename of the file (should be a Wave file)

◆ AudioClip() [4/4]

bridges.base.AudioClip.AudioClip ( int  sampleCount,
int  numChannels 
)

create an audio clip

creates an AudioClip with numChannels channels, sampleCount samples at 44100 Hz with a depth of 32 bits

Parameters
numChannelsthe number of channels
sampleCountthe total number of samples

Member Function Documentation

◆ getDataStructType()

String bridges.base.AudioClip.getDataStructType ( )

Reimplemented from bridges.base.DataStruct.

◆ getDataStructureRepresentation()

String bridges.base.AudioClip.getDataStructureRepresentation ( )

Reimplemented from bridges.base.DataStruct.

◆ getNumChannels()

int bridges.base.AudioClip.getNumChannels ( )

returns the number of channels of the clip

Returns
the number of channels of the clip (1 for mono, 2 for stereo, ...)

◆ getSample()

int bridges.base.AudioClip.getSample ( int  channelIndex,
int  sampleIndex 
)

access a particular sample

Parameters
channelIndexthe index of the channel that will be accessed (in the [0;getNumChannels()-1] range).
sampleIndexthe index of the sample that will be accessed (in the [0;getSampleCount()-1] range).
Returns
the sample value (in [-2^(getSampleBits()-1) ; 2^(getSampleBits()-1)) range).

◆ getSampleBits()

int bridges.base.AudioClip.getSampleBits ( )

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.

Returns
the sampling depth.

◆ getSampleCount()

int bridges.base.AudioClip.getSampleCount ( )

returns the number of samples in the clip

The length of the clip in second is getSampleCount()/((double) getSampleRate())

Returns
the number of samples in the clip

◆ getSampleRate()

int bridges.base.AudioClip.getSampleRate ( )

returns the sampling rate of the clip

Returns
the sampling rate of the clip in Hertz. (CD quality is 44100Hz for instance)

◆ setSample()

void bridges.base.AudioClip.setSample ( int  channelIndex,
int  sampleIndex,
int  value 
)

change a particular sample

Parameters
channelIndexthe index of the channel that will be accessed (in the [0;getNumChannels()-1] range).
sampleIndexthe index of the sample that will be accessed (in the [0;getSampleCount()-1] range).
valuethe sample value (in [-2^(getSampleBits()-1) ; 2^(getSampleBits()-1)) range).

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