Debian Codegraph @

pyo/examples/x03-generators/06-random-generators.py

raw symbols SCIP
1 """
2 06-random-generators.py - Overview of some random generators of pyo.
3
4 The pyo's random category contains many objects that can be used
5 for different purposes. This category really deserves to be studied.
6
7 In this tutorial, we use three random objects (Choice, Randi, RandInt)
8 to control the pitches, the amplitude and the tone of a simple synth.
9
10 We will come back to random generators when we will talk about musical
11 algorithms.
12
13 """
14 from pyo import *
15
16 s = Server().boot()
17
18 # Two streams of midi pitches chosen randomly in a predefined list.
19 # The argument `choice` of Choice object can be a list of lists to
20 # list-expansion.
21 mid = Choice(choice=[60, 62, 63, 65, 67, 69, 71, 72], freq=[2, 3])
22
23 # Two small jitters applied on frequency streams.
24 # Randi interpolates between old and new values.
25 jit = Randi(min=0.993, max=1.007, freq=[4.3, 3.5])
26
27 # Converts midi pitches to frequencies and applies the jitters.
28 fr = MToF(mid, mul=jit)
29
30 # Chooses a new feedback value, between 0 and 0.15, every 4 seconds.
31 fd = Randi(min=0, max=0.15, freq=0.25)
32
33 # RandInt generates a pseudo-random integer number between 0 and `max`
34 # values at a frequency specified by `freq` parameter. It holds the
35 # value until the next generation.
36 # Generates an new LFO frequency once per second.
37 sp = RandInt(max=6, freq=1, add=8)
38 # Creates an LFO oscillating between 0 and 0.4.
39 amp = Sine(sp, mul=0.2, add=0.2)
40
41 # A simple synth...
42 a = SineLoop(freq=fr, feedback=fd, mul=amp).out()
43
44 s.gui(locals())