Data structure to deal with the frames of a channel.
Module audioopy
Class ChannelFrames
Description
Constructor
Create a ChannelFrames instance.
Parameters
- frames: (str) Frames that must be MONO ONLY.
View Source
def __init__(self, frames=b''):
"""Create a ChannelFrames instance.
:param frames: (str) Frames that must be MONO ONLY.
"""
self._frames = frames
Public functions
get_frames
Return the frames
Returns
- (str) the frames
View Source
def get_frames(self):
"""Return the frames
:return: (str) the frames
"""
return self._frames
set_frames
Set the frames.
Parameters
- frames: (str) the frames to set
View Source
def set_frames(self, frames):
"""Set the frames.
:param frames: (str) the frames to set
"""
self._frames = frames
append_silence
Create n frames of silence and append it to the frames.
Parameters
- nframes: (int) the number of frames of silence to append
View Source
def append_silence(self, nframes):
"""Create n frames of silence and append it to the frames.
:param nframes: (int) the number of frames of silence to append
"""
nframes = int(nframes)
if nframes <= 0:
return False
self._frames += b' \x00' * nframes
return True
prepend_silence
Create n frames of silence and prepend it to the frames.
Parameters
- nframes: (int) the number of frames of silence to append
View Source
def prepend_silence(self, nframes):
"""Create n frames of silence and prepend it to the frames.
:param nframes: (int) the number of frames of silence to append
"""
nframes = int(nframes)
if nframes <= 0:
return False
self._frames = b' \x00' * nframes + self._frames
return True
resample
Resample the frames with a new frame rate.
Parameters
- sampwidth: (int) sample width of the frames.
- rate: (int) current frame rate of the frames
- newrate: (int) new frame rate of the frames
View Source
def resample(self, sampwidth, rate, newrate):
"""Resample the frames with a new frame rate.
:param sampwidth: (int) sample width of the frames.
:param rate: (int) current frame rate of the frames
:param newrate: (int) new frame rate of the frames
"""
if rate != newrate:
a = AudioFrames(self._frames, sampwidth, 1)
self._frames = a.resample(rate, newrate)
change_sampwidth
Change the number of bytes used to encode the frames.
Parameters
- sampwidth: (int) current sample width of the frames. (1 for 8 bits, 2 for 16 bits, 4 for 32 bits)
- newsampwidth: (int) new sample width of the frames. (1 for 8 bits, 2 for 16 bits, 4 for 32 bits)
View Source
def change_sampwidth(self, sampwidth, newsampwidth):
"""Change the number of bytes used to encode the frames.
:param sampwidth: (int) current sample width of the frames.
(1 for 8 bits, 2 for 16 bits, 4 for 32 bits)
:param newsampwidth: (int) new sample width of the frames.
(1 for 8 bits, 2 for 16 bits, 4 for 32 bits)
"""
if sampwidth != newsampwidth:
a = AudioFrames(self._frames, sampwidth, 1)
self._frames = a.change_sampwidth(newsampwidth)
get_minval
View Source
@staticmethod
def get_minval(size, signed=True):
return AudioFrames().get_minval(size, signed)
get_maxval
View Source
@staticmethod
def get_maxval(size, signed=True):
return AudioFrames().get_maxval(size, signed)