1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
Retrieving current value of a PyoObject as a python float
============================================================================================================================================
**02-get-method.py**
The get() method of the PyoObject allow the user to retrieve the current
value of an audio signal as a python float. This can useful if one wants
to use an audio signal to drive an algorithm written in pure python.
If the `all` argument of the get() method is True, it will return a list
with the current value of all streams managed by the object. If False (the
default), te value of the first audio stream will be returned as a float::
lfos = Sine(freq=[.1,.2,.4,.3], mul=100, add=500)
synth = SineLoop(freq=lfos, feedback=.07, mul=.05).out()
def print_val():
# Print all four frequencies assigned to SineLoop's freq argument
print(lfos.get(all=True))
pat = Pattern(print_val, .25).play()
Complete example
----------------
.. code-block:: python
from pyo import *
s = Server(duplex=0).boot()
t = CurveTable([(0, 0), (2048, 0.5), (4096, 0.2), (6144, 0.5), (8192, 0)], tension=0, bias=20).normalize()
t.view(title="LFO Waveform")
# LFO applied on amplitude value of the synths.
a = Osc(table=t, freq=2, mul=0.1)
# Make some modulated noise...
synth1 = BrownNoise(a).mix(2).out()
synth2 = FM(carrier=[100, 50], ratio=[0.495, 1.01], index=10, mul=a).out()
# Oscillator from which to get values to modify the shape of the LFO waveform.
c = Sine(0.1, 0, 10, 10)
def change():
# Get the current value of the oscillator.
val = c.get()
# Print the value to the console.
print("Current oscillator value:", val)
# Change the bias of the curve and normalize the table.
t.setBias(val)
t.normalize()
# Call change() function 10 times per second.
p = Pattern(change, 0.1).play()
s.gui(locals())
|