File: 02-receive-streams.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 (57 lines) | stat: -rw-r--r-- 2,212 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
Receiving Open Sound Control messages as audio streams
============================================================================================================================================


**02-receive-streams.py**

This script shows a granulation process controlled by OSC messages
coming from another program (run the next example, *03-send-streams.py*,
to get values coming in).

.. code-block:: python

    from pyo import *
    
    s = Server().boot()
    
    # The sound table to granulate.
    table = SndTable("../snds/flute.aif")
    
    # Listen addresses '/density', '/position', '/pitch_rand' and '/duration' on port 9000.
    rec = OscReceive(port=9000, address=["/density", "/position", "/pitch_rand", "/duration"])
    
    # Sets initial values for the OSC streams. This allow the program to run with
    # minimal behaviour even if no message have been sent on these addresses.
    rec.setValue("/density", 0.5)
    rec.setValue("/position", 0.5)
    rec.setValue("/pitch_rand", 0.0)
    rec.setValue("/duration", 0.5)
    
    # Density of grains, between 1 and 250 grains per second.
    dens = SigTo(rec["/density"], time=0.05, mul=249, add=1)
    
    # Reading position, in samples, in the table + little jitter noise.
    pos = SigTo(rec["/position"], time=0.05, mul=table.getSize(), add=Noise(100))
    
    # Amplitude of a jitter noise around 1.0 to control the pitch of individual grains.
    rpit = SigTo(rec["/pitch_rand"], time=0.05, mul=0.2, add=0.001)
    pit = Noise(mul=rpit, add=1)
    
    # Grain duration, between 0.025 and 0.5 second.
    dur = SigTo(rec["/duration"], time=0.05, mul=0.475, add=0.025)
    
    grain = Particle(
        table=table,  # table to read samples from.
        env=HannTable(),  # grain envelope.
        dens=dens,  # density of grains per second.
        pitch=pit,  # pitch of grains.
        pos=pos,  # position in the table where to start the grain.
        dur=dur,  # grain duration.
        dev=0.01,  # Maximum deviation of the starting time of the grain.
        pan=Noise(0.5, 0.5),  # Panning factor of the grain.
        chnls=2,  # Number of channels to output.
        mul=0.15,
    ).out()
    
    s.gui(locals())