File: 02-audio-in.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 (74 lines) | stat: -rw-r--r-- 1,823 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
72
73
74
Manipulating audio signal in input
============================================================================================================================================


**02-audio-in.py**

The expression illustrated in this example use a phasor signal
in input as the running phase of a self-modulated sine wave.

Here is the complete expression:

.. code-block:: scheme

    (sin (+ (* twopi $x[0]) (* $y[-1] 0.8)))

From inner to outer expression, we have:

.. code-block:: scheme

    (* $y[-1] 0.8)

Where `$y[-1]` is the last output sample multiplied by a feedback
factor (0.8). Then we have the running phase, `$x[0]` is the current
input sample, rescaled to the range 0 -> 2pi for the `sin` function:

.. code-block:: scheme

    (* twopi $x[0])

We add the output delay to the running phase:

.. code-block:: scheme

    (+ (* twopi $x[0]) (* $y[-1] 0.8))

This gives the modulated running phase driving the `sin` function:

.. code-block:: scheme

    (sin (+ (* twopi $x[0]) (* $y[-1] 0.8)))

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

.. code-block:: python

    from pyo import *
    
    s = Server().boot()
    
    expression = """
    // Self-modulated sine wave with running phase given in input.
    // Try different feedback factors between 0 and 1. 
    (sin (+ (* twopi $x[0]) (* $y[-1] 0.8)))
    """
    
    # External signal used as the running phase.
    input = Phasor(86)
    input.ctrl()
    
    # 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(input, 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())