def convert(self): """ Convert the channel to the expected sample width and frame rate. """ newchannel = Channel() newchannel.set_frames( self.__convert_frames( self.channel.frames ) ) newchannel.sampwidth = self.sampwidth newchannel.framerate = self.framerate self.channel = newchannel
def remove_offset(self): """ Convert the channel by removing the offset in the channel. """ newchannel = Channel() newchannel.sampwidth = self.sampwidth newchannel.framerate = self.framerate a = AudioFrames( self.channel.get_frames(self.channel.get_nframes()), self.channel.get_sampwidth(), 1) avg = a.avg() newchannel.set_frames( a.bias( - avg ) ) self.channel = newchannel
def append_frames(self, frames): """ Convert the channel by appending frames. @param frames (string) the frames to append """ if len(frames)==0: return newchannel = Channel() newchannel.set_frames( self.channel.frames + frames ) newchannel.sampwidth = self.sampwidth newchannel.framerate = self.framerate self.channel = newchannel
def add_frames(self, frames, position): """ Convert the channel by adding frames. @param position (int) the position where the frames will be inserted """ if len(frames)==0: return newchannel = Channel() newchannel.set_frames( self.channel.frames[:position*self.sampwidth] + frames + self.channel.frames[position*self.sampwidth:] ) newchannel.sampwidth = self.sampwidth newchannel.framerate = self.framerate self.channel = newchannel
def remove_frames(self, begin, end): """ Convert the channel by removing frames. @param begin (int) the position of the beginning of the frames to remove @param end (int) the position of the end of the frames to remove """ if begin == end: return if end < begin: raise ValueError newchannel = Channel() newchannel.set_frames( self.channel.frames[:begin*self.sampwidth] + self.channel.frames[end*self.sampwidth:] ) newchannel.sampwidth = self.sampwidth newchannel.framerate = self.framerate self.channel = newchannel
def bias(self, biasvalue): """ Convert the channel with a bias added to each frame. Samples wrap around in case of overflow. @param biasvalue (int) the value to bias the frames """ if biasvalue == 0: return newchannel = Channel() newchannel.sampwidth = self.sampwidth newchannel.framerate = self.framerate a = AudioFrames( self.channel.get_frames(self.channel.get_nframes()), self.channel.get_sampwidth(), 1) newchannel.set_frames( a.bias( biasvalue ) ) self.channel = newchannel
def mul(self, factor): """ Convert the channel that has all frames in the original channel are multiplied by the floating-point value factor. Samples are truncated in case of overflow. @param factor (float) the factor to multiply the frames """ if factor == 1.: return newchannel = Channel() newchannel.sampwidth = self.sampwidth newchannel.framerate = self.framerate a = AudioFrames( self.channel.get_frames(self.channel.get_nframes()), self.channel.get_sampwidth(), 1) newchannel.set_frames( a.mul(factor) ) self.channel = newchannel