sample.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:synthesizer 作者: irmen 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号