Debian Codegraph @

pyo/examples/x07-effects/03-fuzz-disto.py

raw symbols SCIP
1 """
2 03-fuzz-disto.py - Hand-written asymmetrical tranfert function.
3
4 This example implements a fuzz distortion. Bandpass filtered signal is
5 eavily boosted, then feeded to an asymmetrical transfert function, and
6 finally lowpass filtered to smooth out the sound. Balance between the
7 dry and the distorted sound is applied before sending the signal to the
8 outputs.
9
10 Builtin objects to distort an audio signal:
11
12 Disto, Clip, Mirror, Wrap
13
14 Degrade object applies some kind of distortion to a signal by changing
15 its sampling rate and bit depth.
16
17 """
18 from pyo import *
19
20 s = Server(duplex=0).boot()
21
22 # The audio source (try with your own sounds).
23 SOURCE = "../snds/flute.aif"
24
25 # Distortion parameters
26 BP_CENTER_FREQ = 400 # Bandpass filter center frequency.
27 BP_Q = 3 # Bandpass Q (center_freq / Q = bandwidth).
28 BOOST = 25 # Pre-boost (linear gain).
29 LP_CUTOFF_FREQ = 3000 # Lowpass filter cutoff frequency.
30 BALANCE = 0.7 # Balance dry - wet.
31
32 src = SfPlayer(SOURCE, loop=True).mix(2)
33
34 # The transfert function is build in two phases.
35
36 # 1. Transfert function for signal lower than 0.
37 table = ExpTable([(0, -0.25), (4096, 0), (8192, 0)], exp=30)
38
39 # 2. Transfert function for signal higher than 0.
40 # First, create an exponential function from 1 (at the beginning of the table)
41 # to 0 (in the middle of the table).
42 high_table = ExpTable([(0, 1), (2000, 1), (4096, 0), (4598, 0), (8192, 0)], exp=5, inverse=False)
43 # Then, reverse the table’s data in time, to put the shape in the second
44 # part of the table.
45 high_table.reverse()
46
47 # Finally, add the second table to the first, point by point.
48 table.add(high_table)
49
50 # Show the transfert function.
51 table.view(title="Transfert function")
52
53 # Bandpass filter and boost gain applied on input signal.
54 bp = ButBP(src, freq=BP_CENTER_FREQ, q=BP_Q)
55 boost = Sig(bp, mul=BOOST)
56
57 # Apply the transfert function.
58 sig = Lookup(table, boost)
59
60 # Lowpass filter on the distorted signal.
61 lp = ButLP(sig, freq=LP_CUTOFF_FREQ, mul=0.7)
62
63 # Balance between dry and wet signals.
64 mixed = Interp(src, lp, interp=BALANCE)
65
66 # Send the signal to the outputs.
67 out = (mixed * 0.3).out()
68
69 # Show the resulting waveform.
70 sc = Scope(mixed)
71
72 s.gui(locals())