| 1 |
Mixing multiple inputs to multiple outputs with fading time |
| 2 |
============================================================================================================================================ |
| 3 |
|
| 4 |
|
| 5 |
**09-audio-mixer.py** |
| 6 |
|
| 7 |
The Mixer object allows to route multiple inputs to multiple outputs |
| 8 |
with individual amplitude. A portamento time, defined with the `time` |
| 9 |
argument, is applied to amplitude changes to make smooth mixing |
| 10 |
variations. |
| 11 |
|
| 12 |
The initialization argument `outs` lets defined the number of available |
| 13 |
outputs and the argument `chnls` specifies how many channels per output. |
| 14 |
If `chnls` is 2 and a single audio stream is given to an input, the signal |
| 15 |
will be dupplicated to fill the two channels of the voice. |
| 16 |
|
| 17 |
.. code-block:: python |
| 18 |
|
| 19 |
from pyo import * |
| 20 |
import random |
| 21 |
|
| 22 |
s = Server(duplex=0).boot() |
| 23 |
|
| 24 |
# Define some input signals for the mixer. |
| 25 |
low = SfPlayer("../snds/flute.aif", speed=0.5, loop=True, mul=0.3) |
| 26 |
mid = SfPlayer("../snds/flute.aif", speed=0.75, loop=True, mul=0.3) |
| 27 |
hig = SfPlayer("../snds/flute.aif", speed=1.0, loop=True, mul=0.3) |
| 28 |
|
| 29 |
# Mixer with 3 outputs, 2 channels per voice and 0.5 second of amplitude fading time. |
| 30 |
mm = Mixer(outs=3, chnls=2, time=0.5) |
| 31 |
|
| 32 |
# Route the mixer's outputs to some effects. |
| 33 |
octaveBelow = Harmonizer(mm[0], transpo=-12, feedback=0.25, add=mm[0]).out() |
| 34 |
fifthBelow = Harmonizer(mm[1], transpo=-7, feedback=0.25, add=mm[1]).out() |
| 35 |
secondAbove = Harmonizer(mm[2], transpo=2, feedback=0.25, add=mm[2]).out() |
| 36 |
|
| 37 |
# Add signals as inputs to the mixer. |
| 38 |
mm.addInput(voice=0, input=low) |
| 39 |
mm.addInput(voice=1, input=mid) |
| 40 |
mm.addInput(voice=2, input=hig) |
| 41 |
|
| 42 |
# Initial assignment of inputs to outputs with amplitude balance. |
| 43 |
mm.setAmp(vin=0, vout=0, amp=0.25) |
| 44 |
mm.setAmp(vin=1, vout=2, amp=0.25) |
| 45 |
|
| 46 |
# Dictionaries used to print assigment messages. |
| 47 |
inputs = {0: "low", 1: "mid", 2: "hig"} |
| 48 |
outputs = {0: "Octave below", 1: "Fifth below", 2: "Second above"} |
| 49 |
|
| 50 |
# Dynamic assignation of inputs to outputs with random amplitude. |
| 51 |
def assign(): |
| 52 |
vin = random.randint(0, 2) |
| 53 |
vout = random.randint(0, 2) |
| 54 |
amp = random.choice([0, 0, 0.25, 0.33, 0.5]) |
| 55 |
print("%s -> %s, amp = %f" % (inputs[vin], outputs[vout], amp)) |
| 56 |
mm.setAmp(vin=vin, vout=vout, amp=amp) |
| 57 |
|
| 58 |
|
| 59 |
# Call a new assignment every 3 seconds. |
| 60 |
pat = Pattern(function=assign, time=3).play() |
| 61 |
|
| 62 |
s.gui(locals()) |
| 63 |
|