def fadein(self, seconds, start_volume=0.0):
"""Fade the start of the sample in from the starting volume (usually zero) in the given time."""
assert not self.__locked
seconds = min(seconds, self.duration)
i = self.frame_idx(seconds)
begin = self.__frames[:i] # we fade this chunk
end = self.__frames[i:]
numsamples = len(begin)/self.__samplewidth
increase = 1.0-start_volume
_sw = self.__samplewidth # optimization
_getsample = audioop.getsample # optimization
_incr = increase/numsamples # optimization
faded = Sample.get_array(_sw, [int(_getsample(begin, _sw, i)*(i*_incr+start_volume)) for i in range(int(numsamples))])
begin = faded.tobytes()
if sys.byteorder == "big":
begin = audioop.byteswap(begin, self.__samplewidth)
self.__frames = begin + end
return self
评论列表
文章目录