Debian Codegraph @

pyo/examples/x17-osc/02-receive-streams.py

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