Debian Codegraph @

pyo/examples/x02-controls/03-output-range.py

raw symbols SCIP
1 """
2 03-output-range.py - The `mul` and `add` attributes.
3
4 Almost all audio objects have a `mul` and `add` attributes.
5 These are defined inside the PyoObject, which is the base
6 class for all objects generating audio signal. The manual
7 page of the PyoObject explains all behaviours common to
8 audio objects.
9
10 An audio signal outputs samples as floating-point numbers in
11 the range -1 to 1. The `mul` and `add` attributes can be used
12 to change the output range. Common uses are for modulating the
13 amplitude of a sound or for building control signals like low
14 frequency oscillators.
15
16 A shortcut to automatically manipulate both `mul` and `add`
17 attributes is to call the range(min, max) method of the
18 PyoObject. This method sets `mul` and `add` attributes
19 according to the desired `min` and `max` output values. It
20 assumes that the generated signal is in the range -1 to 1.
21
22 """
23 from pyo import *
24
25 s = Server().boot().start()
26
27 # The `mul` attribute multiplies each sample by its value.
28 a = Sine(freq=100, mul=0.1)
29
30 # The `add` attribute adds an offset to each sample.
31 # The multiplication is applied before the addition.
32 b = Sine(freq=100, mul=0.5, add=0.5)
33
34 # Using the range(min, max) method allows to automatically
35 # compute both `mul` and `add` attributes.
36 c = Sine(freq=100).range(-0.25, 0.5)
37
38 # Displays the waveforms
39 sc = Scope([a, b, c])
40
41 s.gui(locals())