sample.py 文件源码

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

项目:synthesizer 作者: irmen 项目源码 文件源码
def modulate_amp(self, modulator):
        """
        Perform amplitude modulation by another waveform or oscillator.
        You can use a Sample (or array of sample values) or an oscillator as modulator.
        If you use a Sample (or array), it will be cycled if needed and its maximum amplitude
        is scaled to be 1.0, effectively using it as if it was an oscillator.
        """
        assert not self.__locked
        frames = self.get_frame_array()
        if isinstance(modulator, (Sample, list, array.array)):
            # modulator is a waveform, turn that into an 'oscillator' ran
            if isinstance(modulator, Sample):
                modulator = modulator.get_frame_array()
            biggest = max(max(modulator), abs(min(modulator)))
            modulator = (v/biggest for v in itertools.cycle(modulator))
        else:
            modulator = iter(modulator)
        for i in range(len(frames)):
            frames[i] = int(frames[i] * next(modulator))
        self.__frames = frames.tobytes()
        if sys.byteorder == "big":
            self.__frames = audioop.byteswap(self.__frames, self.__samplewidth)
        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号