Debian Codegraph @

docs/_sources/examples/17-osc/02-receive-streams.rst.txt

raw
1 Receiving Open Sound Control messages as audio streams
2 ============================================================================================================================================
3
4
5 **02-receive-streams.py**
6
7 This script shows a granulation process controlled by OSC messages
8 coming from another program (run the next example, *03-send-streams.py*,
9 to get values coming in).
10
11 .. code-block:: python
12
13 from pyo import *
14
15 s = Server().boot()
16
17 # The sound table to granulate.
18 table = SndTable("../snds/flute.aif")
19
20 # Listen addresses '/density', '/position', '/pitch_rand' and '/duration' on port 9000.
21 rec = OscReceive(port=9000, address=["/density", "/position", "/pitch_rand", "/duration"])
22
23 # Sets initial values for the OSC streams. This allow the program to run with
24 # minimal behaviour even if no message have been sent on these addresses.
25 rec.setValue("/density", 0.5)
26 rec.setValue("/position", 0.5)
27 rec.setValue("/pitch_rand", 0.0)
28 rec.setValue("/duration", 0.5)
29
30 # Density of grains, between 1 and 250 grains per second.
31 dens = SigTo(rec["/density"], time=0.05, mul=249, add=1)
32
33 # Reading position, in samples, in the table + little jitter noise.
34 pos = SigTo(rec["/position"], time=0.05, mul=table.getSize(), add=Noise(100))
35
36 # Amplitude of a jitter noise around 1.0 to control the pitch of individual grains.
37 rpit = SigTo(rec["/pitch_rand"], time=0.05, mul=0.2, add=0.001)
38 pit = Noise(mul=rpit, add=1)
39
40 # Grain duration, between 0.025 and 0.5 second.
41 dur = SigTo(rec["/duration"], time=0.05, mul=0.475, add=0.025)
42
43 grain = Particle(
44 table=table, # table to read samples from.
45 env=HannTable(), # grain envelope.
46 dens=dens, # density of grains per second.
47 pitch=pit, # pitch of grains.
48 pos=pos, # position in the table where to start the grain.
49 dur=dur, # grain duration.
50 dev=0.01, # Maximum deviation of the starting time of the grain.
51 pan=Noise(0.5, 0.5), # Panning factor of the grain.
52 chnls=2, # Number of channels to output.
53 mul=0.15,
54 ).out()
55
56 s.gui(locals())
57