File: 02-bandpass-filters.py

package info (click to toggle)
python-pyo 1.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 52,332 kB
  • sloc: python: 135,133; ansic: 127,822; javascript: 16,116; sh: 395; makefile: 388; cpp: 242
file content (37 lines) | stat: -rw-r--r-- 1,006 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
02-bandpass-filters.py - Narrowing a bandpass filter bandwidth.

This example illustrates the difference between a simple IIR second-order
bandpass filter and a cascade of second-order bandpass filters. A cascade
of four bandpass filters with a high Q can be used as a efficient resonator
on the signal.

"""
from pyo import *

s = Server().boot()

# White noise generator
n = Noise(0.5)

# Common cutoff frequency control
freq = Sig(1000)
freq.ctrl([SLMap(50, 5000, "lin", "value", 1000)], title="Cutoff Frequency")

# Common filter's Q control
q = Sig(5)
q.ctrl([SLMap(0.7, 20, "log", "value", 5)], title="Filter's Q")

# Second-order bandpass filter
bp1 = Reson(n, freq, q=q)
# Cascade of second-order bandpass filters
bp2 = Resonx(n, freq, q=q, stages=4)

# Interpolates between input objects to produce a single output
sel = Selector([bp1, bp2]).out()
sel.ctrl(title="Filter selector (0=Reson, 1=Resonx)")

# Displays the spectrum contents of the chosen source
sp = Spectrum(sel)

s.gui(locals())