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