| 1 |
""" |
| 2 |
01-dynamic-range.py - Adjust the dynamic range of the signal. |
| 3 |
|
| 4 |
Comparison of three objects used to adjust the dynamic range of the signal. |
| 5 |
|
| 6 |
- Compress : Reduces the dynamic range of an audio signal. |
| 7 |
- Expand : Increases the dynamic range of an audio signal. |
| 8 |
- Gate : Allows a signal to pass only when its amplitude is above a threshold. |
| 9 |
|
| 10 |
These three objects, by default, process independently each audio stream |
| 11 |
relatively to its own RMS value. This can be a problem if they are passed |
| 12 |
a stereo signal (or any multiphonic signals) where both channels should be |
| 13 |
processed in the same way. |
| 14 |
|
| 15 |
An alternative usage to the one illustrated below is to mix a multi-channel |
| 16 |
signal prior to the dynamic processor and to tell the object to output the |
| 17 |
amplitude value that should be applied to all streams at once. Something |
| 18 |
like this: |
| 19 |
|
| 20 |
>>> sf = SfPlayer("your/stereo.sound.wav") |
| 21 |
>>> cmp = Compress(sf.mix(1), thresh=-18, ratio=3, outputAmp=True) |
| 22 |
>>> # Compress both signal with the common amplitude curve. |
| 23 |
>>> compressed = sf * cmp |
| 24 |
|
| 25 |
""" |
| 26 |
from pyo import * |
| 27 |
|
| 28 |
s = Server().boot() |
| 29 |
|
| 30 |
|
| 31 |
src = SfPlayer("../snds/drumloop.wav", loop=True) |
| 32 |
|
| 33 |
|
| 34 |
cmp = Compress(src, thresh=-18, ratio=3, risetime=0.005, falltime=0.05, knee=0.5) |
| 35 |
exp = Expand(src, downthresh=-32, upthresh=-12, ratio=3, risetime=0.005, falltime=0.05) |
| 36 |
gat = Gate(src, thresh=-40, risetime=0.005, falltime=0.05) |
| 37 |
|
| 38 |
|
| 39 |
labels = ["Original", "Compressed", "Expanded", "Gated"] |
| 40 |
|
| 41 |
|
| 42 |
signals = [src, cmp, exp, gat] |
| 43 |
|
| 44 |
|
| 45 |
output = Selector(signals) |
| 46 |
|
| 47 |
|
| 48 |
stout = output.mix(2).out() |
| 49 |
|
| 50 |
|
| 51 |
sc = Scope(output, wintitle="=== Original ===") |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
num_of_sigs = len(signals) |
| 56 |
c = 1 |
| 57 |
|
| 58 |
|
| 59 |
def endOfLoop(): |
| 60 |
global c |
| 61 |
output.voice = c |
| 62 |
if sc.viewFrame is not None: |
| 63 |
sc.viewFrame.SetTitle("=== %s ===" % labels[c]) |
| 64 |
c = (c + 1) % num_of_sigs |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
tf = TrigFunc(src["trig"], endOfLoop) |
| 69 |
|
| 70 |
s.gui(locals()) |