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
评论列表
文章目录