def mix_at(self, seconds, other, other_seconds=None):
"""
Mix another sample into the current sample at a specific time point.
You can limit the length taken from the other sample.
"""
if seconds == 0.0:
return self.mix(other, other_seconds)
assert not self.__locked
assert self.samplewidth == other.samplewidth
assert self.samplerate == other.samplerate
assert self.nchannels == other.nchannels
start_frame_idx = self.frame_idx(seconds)
if other_seconds:
other_frames = other.__frames[:other.frame_idx(other_seconds)]
else:
other_frames = other.__frames
# Mix the frames. Unfortunately audioop requires splitting and copying the sample data, which is slow.
pre, to_mix, post = self._mix_split_frames(len(other_frames), start_frame_idx)
self.__frames = None # allow for garbage collection
mixed = audioop.add(to_mix, other_frames, self.samplewidth)
del to_mix # more garbage collection
self.__frames = self._mix_join_frames(pre, mixed, post)
return self
评论列表
文章目录