Bridges-Python 3.5.0-dev1
Bridges(Python API)
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
bridges.audio_clip.AudioClip Class Reference

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

Public Member Functions

None __init__ (self, str filepath="", int sample_count=0, int num_channels=1, int sample_bits=32, int sample_rate=44100)
 AudioBase constructor.
 
int get_num_channels (self)
 Return the number of channels in this AudioClip.
 
AudioChannel get_channel (self, int index)
 Get the audio channel at index.
 
int get_sample_rate (self)
 Get the sample rate of this audio clip.
 
int get_sample_count (self)
 Get the number of samples in each channel of this audio object.
 
int get_sample (self, int channel, int index)
 Get the sample at the index of the sample data from a specific channel.
 
None set_sample (self, int channel, int index, int value)
 Set the sample at the index of the sample data to value.
 
int get_sample_bits (self)
 Get the number of bits for the samples in this audio clip.
 
int get_sample_bytes (self)
 Get the number of bytes for the samples in this audio clip.
 
str get_data_structure_type (self)
 Get the data structure type.
 
dict get_data_structure_representation (self)
 Return a dictionary of the data in this audio file.
 
None display (self)
 Print information about this audio file to the console.
 
'AudioClipaudio_from_json (dict json_dict)
 Create an AudioClip from a json dictionary created by another AudioClip object.
 

Public Attributes

 sample_count
 
 sample_rate
 
 sample_bits
 
 num_channels
 
 framebytes
 

Protected Member Functions

 _from_filepath (self, str filepath)
 
str _get_type_code (self)
 

Protected Attributes

 _channels
 

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 num_channels parameter that enables to pass the number of channels explicitly. If unsure, one can know how many channels are in an audio clip using get_num_channels().

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 get_sample_rate().

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 get_sample_count(); 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 get_sample_bits().

The individual samples are accessed with the get_sample() and set_sample() functions. The samples are integer values in the 2^(get_sample_bits()-1) ; 2^(get_sample_bits()-1)[ range. The functions allow to specify for channel and sample index.

Author
Luke Sloop, Erik Saule
Date
2020, 1/31/2020, 2021

Constructor & Destructor Documentation

◆ __init__()

None bridges.audio_clip.AudioClip.__init__ (   self,
str  filepath = "",
int  sample_count = 0,
int  num_channels = 1,
int  sample_bits = 32,
int  sample_rate = 44100 
)

AudioBase constructor.

specify either a filepath or all the other parameters.

(str) filepath: name of the wav file to creat a clip of. If this parameter is used, all the other ones are ignored.
(int) sample_count: The total number of samples in this audio object
(int) num_channels: number of channels (stereo would be 2)
(int) sample_rate: The number of samples in 1 second of audio (default to cd quality: 44100)
(int) sample_bits: Bit depth, that is to say, each sample will be in the [-2^(get_sample_bits()-1) ; 2^(get_sample_bits()-1)[ range
Returns
None

Member Function Documentation

◆ _from_filepath()

bridges.audio_clip.AudioClip._from_filepath (   self,
str  filepath 
)
protected

◆ _get_type_code()

str bridges.audio_clip.AudioClip._get_type_code (   self)
protected

◆ audio_from_json()

'AudioClip' bridges.audio_clip.AudioClip.audio_from_json ( dict  json_dict)

Create an AudioClip from a json dictionary created by another AudioClip object.

       (dict) json_dict: The json dictionary created by another AudioClip object

◆ display()

None bridges.audio_clip.AudioClip.display (   self)

Print information about this audio file to the console.

◆ get_channel()

AudioChannel bridges.audio_clip.AudioClip.get_channel (   self,
int  index 
)

Get the audio channel at index.

The index should be less than get_num_channels().

       (int) index: The index of the channel to get. 0 for front-left, 1 for front-right, etc.
Returns
AudioChannel The audio channel at index

◆ get_data_structure_representation()

dict bridges.audio_clip.AudioClip.get_data_structure_representation (   self)

Return a dictionary of the data in this audio file.

Returns
dict The data of this audio file

◆ get_data_structure_type()

str bridges.audio_clip.AudioClip.get_data_structure_type (   self)

Get the data structure type.

Returns
str data structure type

◆ get_num_channels()

int bridges.audio_clip.AudioClip.get_num_channels (   self)

Return the number of channels in this AudioClip.

1 for mono, 2 for stereo, etc.

Returns
int The number of channels of audio samples this object holds.

◆ get_sample()

int bridges.audio_clip.AudioClip.get_sample (   self,
int  channel,
int  index 
)

Get the sample at the index of the sample data from a specific channel.

       (int) channel: The index of the channel to get. 0 for front-left, 1 for front-right, etc.
       (int) index: The index of the sample to get. From 0 - get_sample_count()
Returns
int The sample in the [-2^(get_sample_bits()-1) ; 2^(get_sample_bits()-1)) range

◆ get_sample_bits()

int bridges.audio_clip.AudioClip.get_sample_bits (   self)

Get the number of bits for the samples in this audio clip.

Will be 8, 16, 24, or 32 bits.

Returns
int The number of bits for each sample

◆ get_sample_bytes()

int bridges.audio_clip.AudioClip.get_sample_bytes (   self)

Get the number of bytes for the samples in this audio clip.

Will be 1, 2, 3, or 4 bits.

Returns
int The number of bytes for each sample

◆ get_sample_count()

int bridges.audio_clip.AudioClip.get_sample_count (   self)

Get the number of samples in each channel of this audio object.

Each channel will contain this number of samples.

Returns
int The total number of samples in this audio object

◆ get_sample_rate()

int bridges.audio_clip.AudioClip.get_sample_rate (   self)

Get the sample rate of this audio clip.

This is the number of samples that are taken in one second.

Returns
int The sample rate or number of samples in 1 second of audio

◆ set_sample()

None bridges.audio_clip.AudioClip.set_sample (   self,
int  channel,
int  index,
int  value 
)

Set the sample at the index of the sample data to value.

       (int) channel: The index of the channel to get. 0 for front-left, 1 for front-right, etc.
       (int) index: The index of sampledata to set which must be less than get_sample_count()
       (int) value: The value to set the sample to which must be a valid signed integer with bit length get_sample_bits(). That is to say in the [-2^(get_sample_bits()-1) ;  2^(get_sample_bits()-1)) range).
Returns
None

Member Data Documentation

◆ _channels

bridges.audio_clip.AudioClip._channels
protected

◆ framebytes

bridges.audio_clip.AudioClip.framebytes

◆ num_channels

bridges.audio_clip.AudioClip.num_channels

◆ sample_bits

bridges.audio_clip.AudioClip.sample_bits

◆ sample_count

bridges.audio_clip.AudioClip.sample_count

◆ sample_rate

bridges.audio_clip.AudioClip.sample_rate

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