sample.py 文件源码

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

项目:synthesizer 作者: irmen 项目源码 文件源码
def fadeout(self, seconds, target_volume=0.0):
        """Fade the end of the sample out to the target volume (usually zero) in the given time."""
        assert not self.__locked
        seconds = min(seconds, self.duration)
        i = self.frame_idx(self.duration-seconds)
        begin = self.__frames[:i]
        end = self.__frames[i:]  # we fade this chunk
        numsamples = len(end)/self.__samplewidth
        decrease = 1.0-target_volume
        _sw = self.__samplewidth     # optimization
        _getsample = audioop.getsample   # optimization
        faded = Sample.get_array(_sw, [int(_getsample(end, _sw, i)*(1.0-i*decrease/numsamples)) for i in range(int(numsamples))])
        end = faded.tobytes()
        if sys.byteorder == "big":
            end = audioop.byteswap(end, self.__samplewidth)
        self.__frames = begin + end
        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号