Debian Codegraph @

docs/_sources/examples/02-controls/06-multichannel-expansion.rst.txt

raw
1 06-multichannel-expansion.py - What is a `Stream`? Polyphonic objects.
2 ============================================================================================================================================
3
4
5 List expansion is a powerful technique for generating many audio
6 streams at once.
7
8 What is a "stream"? A "stream" is a monophonic channel of samples.
9 It is the basic structure over which all the library is built. Any
10 PyoObject can handle as many streams as necessary to represent the
11 defined process. When a polyphonic (ie more than one stream) object
12 is asked to send its signals to the output, the server will use the
13 arguments (`chnl` and `inc`) of the out() method to distribute the
14 streams over the available output channels.
15
16 Almost all attributes of all objects of the library accept list of
17 values instead of a single value. The object will create internally
18 the same number of streams than the length of the largest list
19 given to an attribute at the initialization time. Each value of the
20 list is used to generate one stream. Shorter lists will wrap around
21 when reaching the end of the list.
22
23 A PyoObject is considered by other object as a list. The function
24 `len(obj)` returns the number of streams managed by the object. This
25 feature is useful to create a polyphonic dsp chain.
26
27 .. code-block:: python
28
29 from pyo import *
30
31 s = Server().boot()
32
33 ### Using multichannel-expansion to create a square wave ###
34
35 # Sets fundamental frequency.
36 freq = 100
37 # Sets the highest harmonic.
38 high = 20
39
40 # Generates the list of harmonic frequencies (odd only).
41 harms = [freq * i for i in range(1, high) if i % 2 == 1]
42 # Generates the list of harmonic amplitudes (1 / n).
43 amps = [0.33 / i for i in range(1, high) if i % 2 == 1]
44
45 # Creates all sine waves at once.
46 a = Sine(freq=harms, mul=amps)
47 # Prints the number of streams managed by "a".
48 print(len(a))
49
50 # The mix(voices) method (defined in PyoObject) mixes
51 # the object streams into `voices` streams.
52 b = a.mix(voices=1).out()
53
54 # Displays the waveform.
55 sc = Scope(b)
56
57 s.gui(locals())
58