File: 01-envelopes.rst.txt

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 (71 lines) | stat: -rw-r--r-- 2,998 bytes parent folder | download | duplicates (2)
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
62
63
64
65
66
67
68
69
70
71
01-envelopes.py - Using break-point function to control an FM synthesis.
============================================================================================================================================


This example shows how break-point tables can be used to control synthesis/effect
parameters at audio rate. Pyo offers many objects to generate break-point function:

- LinTable: Construct a table from segments of straight lines.
- CosTable: Construct a table from cosine interpolated segments.
- ExpTable: Construct a table from exponential interpolated segments.
- CurveTable: Construct a table from curve, with tension and bias, interpolated segments.
- LogTable: Construct a table from logarithmic segments.
- CosLogTable: Construct a table from logarithmic-cosine segments.

These objects implement a `graph()` method (as well as Linseg and Expseg) which show
a graph window with which the user can set the shape of the trajectory.

With the focus on the graph window, the copy menu item (Ctrl+C) saves to the
clipboard the list of points in a format well suited to be paste in the code.
Useful to experiment graphically and then copy/paste the result in the script.

To play more notes, in the Interpreter field of the Server GUI, call the `note(freq, dur)`
function with the desired frequency and duration.

Note: The wxPython Phoenix graphical library must be installed to use the graph. Infos at:

http://www.wxpython.org/

.. code-block:: python

    from pyo import *
    
    s = Server().boot()
    
    # Defines tables for the amplitude, the ratio and the modulation index.
    amp_table = CosTable([(0, 0), (100, 1), (1024, 0.5), (7000, 0.5), (8192, 0)])
    rat_table = ExpTable(
        [(0, 0.5), (1500, 0.5), (2000, 0.25), (3500, 0.25), (4000, 1), (5500, 1), (6000, 0.5), (8192, 0.5),]
    )
    ind_table = LinTable([(0, 20), (512, 10), (8192, 0)])
    
    # call their graph() method. Use the "yrange" argument to set the minimum
    # and maximum bundaries of the graph (defaults to 0 and 1).
    amp_table.graph(title="Amplitude envelope")
    rat_table.graph(title="Ratio envelope")
    ind_table.graph(yrange=(0, 20), title="Modulation index envelope")
    
    # Initialize the table readers (TableRead.play() must be called explicitly).
    amp = TableRead(table=amp_table, freq=1, loop=False, mul=0.3)
    rat = TableRead(table=rat_table, freq=1, loop=False)
    ind = TableRead(table=ind_table, freq=1, loop=False)
    
    # Use the signals from the table readers to control an FM synthesis.
    fm = FM(carrier=[100, 100], ratio=rat, index=ind, mul=amp).out()
    
    # Call the "note" function to generate an event.
    def note(freq=100, dur=1):
        fm.carrier = [freq, freq * 1.005]
        amp.freq = 1.0 / dur
        rat.freq = 1.0 / dur
        ind.freq = 1.0 / dur
        amp.play()
        rat.play()
        ind.play()
    
    
    # Play one note, carrier = 100 Hz, duration = 2 seconds.
    note(200, 2)
    
    s.gui(locals())