Debian Codegraph @

docs/_sources/examples/06-filters/05-convolution-filters.rst.txt

raw
1 05-convolution-filters.py - Circular convolution.
2 ============================================================================================================================================
3
4
5 A circular convolution is defined as the integral of the
6 product of two functions after one is reversed and shifted.
7
8 Circular convolution allows to implement very complex FIR
9 filters, at a CPU cost that is related to the filter impulse
10 response (kernel) length.
11
12 Within pyo, there is a family of IR* filter objects using
13 circular convolution with predefined kernel:
14
15 - IRAverage : moving average filter
16 - IRFM : FM-like filter
17 - IRPulse : comb-like filter
18 - RWinSinc : break wall filters (lp, hp, hp, br)
19
20 For general circular convolution, use the Convolve object
21 with a PyoTableObject as the kernel, as in this example:
22
23 A white noise is filtered by four impulses taken from the input mic.
24
25 Call r1.play(), r2.play(), r3.play() or r4.play() in the Interpreter
26 field while making some noise in the mic to fill the impulse response
27 tables. The slider handles the morphing between the four kernels.
28
29 Call t1.view(), t2.view(), t3.view() or t4.view() to view impulse
30 response tables.
31
32 Because circular convolution is very expensive, TLEN (in samples)
33 should be keep small.
34
35 .. code-block:: python
36
37 from pyo import *
38
39 # duplex=1 to tell the Server we need both input and output sounds.
40 s = Server(duplex=1).boot()
41
42 # Length of the impulse response in samples.
43 TLEN = 512
44
45 # Conversion to seconds for NewTable objects.
46 DUR = sampsToSec(TLEN)
47
48 # Excitation signal for the filters.
49 sf = Noise(0.5)
50
51 # Signal from the mic to record the kernels.
52 inmic = Input()
53
54 # Four tables and recorders.
55 t1 = NewTable(length=DUR, chnls=1)
56 r1 = TableRec(inmic, table=t1, fadetime=0.001)
57
58 t2 = NewTable(length=DUR, chnls=1)
59 r2 = TableRec(inmic, table=t2, fadetime=0.001)
60
61 t3 = NewTable(length=DUR, chnls=1)
62 r3 = TableRec(inmic, table=t3, fadetime=0.001)
63
64 t4 = NewTable(length=DUR, chnls=1)
65 r4 = TableRec(inmic, table=t4, fadetime=0.001)
66
67 # Interpolation control between the tables.
68 pha = Sig(0)
69 pha.ctrl(title="Impulse responses morphing")
70
71 # Morphing between the four impulse responses.
72 res = NewTable(length=DUR, chnls=1)
73 morp = TableMorph(pha, res, [t1, t2, t3, t4])
74
75 # Circular convolution between the excitation and the morphed kernel.
76 a = Convolve(sf, table=res, size=res.getSize(), mul=0.1).mix(2).out()
77
78 s.gui(locals())
79