File: 03-multiple-inputs.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 (54 lines) | stat: -rw-r--r-- 1,649 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
Using more than one input signal in a single expression
============================================================================================================================================


**03-multiple-inputs.py**

It is possible to give a list of audio signals to the `input`
argument if you need more than one signal in your expression.

You can either pass a list of audio objects (as in the complete
example below) or a single multi-streams object, as in::

    sig = Sine(freq=[10.7647, 10.0000, 87.9023, 296.4831])
    ex = Expr(sig, "(* (* (* $x[0] $x1[0]) $x2[0]) $x3[0])").out()

If multiple signals are used, the position in the list must be
given between the `$x` and the sample position `[0]`. So, for the
second audio signal, one would retrieve it with `$x1[0]`. The 0
for the first signal can be ommited, `$x[0]` is the same as `$x0[0]`.

Complete example
----------------

.. code-block:: python

    from pyo import *
    
    s = Server().boot()
    
    expression = """
    // Four signals ring-modulation.
    (* (* (* $x[0] $x1[0]) $x2[0]) $x3[0])
    """
    
    # Multiple input signals.
    s1 = Sine(freq=10.7647)
    s2 = Sine(freq=10.0)
    s3 = Sine(freq=87.9023)
    s4 = Sine(freq=296.4831)
    
    # Create the Expr object and show its expression editor. To
    # re-evaluate the expression hit Ctrl+Enter when the editor
    # has the focus.
    expr = Expr([s1, s2, s3, s4], expression, mul=0.5)
    expr.editor()
    
    # Shows the generated signal.
    sc = Scope(expr)
    
    # Converts the mono signal to stereo and sends it to the soundcard.
    pan = Pan(expr).out()
    
    s.gui(locals())