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