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