File: 02-get-method.py

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (58 lines) | stat: -rw-r--r-- 1,724 bytes parent folder | download | duplicates (3)
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
"""
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
----------------
"""

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())