A sine wave modulates the amplitude of a triangle wave (amplitude modulation).
We modulate at a frequency of 2 Hz. The triangle is then sent to out. Notice out is defined as global in setup(), otherwise it will have local scope. Also draw() does not have to know have that it is global, since here it is read-only and global will be searched since there is no local variable by that name.
# Ex2.pyde
# PathingAnInput.pde in Examples
'''
This sketch demonstrates how to create a simple
synthesis chain that involves controlling the
value of a UGenInput with the output of a UGen.
In this case, we patch an Oscil generating a
sine wave into the amplitude input of an Oscil
generating a triangle wave. The result is known
as amplitude modulation. For more information
about Minim and additional features, visit
http://code.compartmental.net/minim/
'''
add_library('minim')
out = None
def setup():
size(512, 200)
global out
minim = Minim(this)
# use the getLineOut method of the Minim object to
# get an AudioOutput object
out = minim.getLineOut()
# create a triangle wave Oscil, set to 440 Hz,
# at 1.0 amplitude. In this case, the amplitude
# that we construct the Oscil with doesn't matter
# because we will be patching something to its
# amplitude input.
wave = Oscil(440, 1, Waves.TRIANGLE)
# create a sine wave Oscil for modulating the
# amplitude of wave
mod = Oscil(2, 0.4, Waves.SINE)
# mod patched to wave amplitude input
mod.patch(wave.amplitude)
# patch wave to the output
wave.patch(out)
# green stroke of 2 width for the draw
stroke(0,255,0)
strokeWeight(2)
def draw():
background(255,128,128)
# draw the waveform of the output
for i in xrange(out.bufferSize()-1):
line(i, 50 - out.left.get(i)*50,
i+1, 50 - out.left.get(i+1)*50)
line(i, 150 - out.right.get(i)*50,
i+1, 150 - out.right.get(i+1)*50)
This is the output:
No comments:
Post a Comment