def mix(self, other, other_seconds=None, pad_shortest=True):
"""
Mix another sample into the current sample.
You can limit the length taken from the other sample.
When pad_shortest is False, no sample length adjustment is done.
"""
assert not self.__locked
assert self.samplewidth == other.samplewidth
assert self.samplerate == other.samplerate
assert self.nchannels == other.nchannels
frames1 = self.__frames
if other_seconds:
frames2 = other.__frames[:other.frame_idx(other_seconds)]
else:
frames2 = other.__frames
if pad_shortest:
if len(frames1) < len(frames2):
frames1 += b"\0"*(len(frames2)-len(frames1))
elif len(frames2) < len(frames1):
frames2 += b"\0"*(len(frames1)-len(frames2))
self.__frames = audioop.add(frames1, frames2, self.samplewidth)
return self
评论列表
文章目录