Debian Codegraph @

pyo/examples/x08-dynamics/01-dynamic-range.py

raw symbols SCIP
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 # The original source.
31 src = SfPlayer("../snds/drumloop.wav", loop=True)
32
33 # The three dynamic processing.
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 # These are labels that are shown as the scope window title.
39 labels = ["Original", "Compressed", "Expanded", "Gated"]
40
41 # List of signals to choose from.
42 signals = [src, cmp, exp, gat]
43
44 # Selector is used here to choose which signal to listen to.
45 output = Selector(signals)
46
47 # Converts the signal from mono to stereo.
48 stout = output.mix(2).out()
49
50 # Live oscilloscope of the alternated signals.
51 sc = Scope(output, wintitle="=== Original ===")
52
53 # The endOfLoop function cycles through the different signals
54 # and change the selection of the Selector object.
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 # endOfLoop is called every time the SfPlayer reaches the end of the sound.
68 tf = TrigFunc(src["trig"], endOfLoop)
69
70 s.gui(locals())