Debian Codegraph @

pyo/examples/x10-tables/08-table-lookup.py

raw symbols SCIP
1 """
2 08-table-lookup.py - Table as transfer function.
3
4 In computer science, a lookup table is an array that replaces runtime computation
5 with a simpler array indexing operation. The savings in terms of processing time
6 can be significant, since retrieving a value from memory is often faster than
7 undergoing an "expensive" computation.
8
9 This technic is also used a lot in audio synthesis, where the waveform can be
10 pre-computed and stored in a table, then simply readed with a ramp at the desired
11 frequency.
12
13 """
14 from pyo import *
15
16 s = Server().boot()
17
18 src = SfPlayer("../snds/flute.aif", loop=True)
19
20 # Arctangent transfer function table.
21 table = AtanTable(slope=0.5, size=512)
22 table.view()
23
24 # A signal to dynamically control the drive of the transfer function.
25 drive = Sig(0.5)
26
27 # We give it True to the dataonly argument when opening the sliders window,
28 # otherwise the table would be rewrite way too often.
29 drive.ctrl([SLMap(0, 1, "lin", "value", 0.5, dataOnly=True)], title="Transfer fonction slope")
30
31 # Lookup reads a table given an audio index lying between -1 and 1.
32 # It is especially designed to scan a transfer function with an audio signal.
33 look = Lookup(table, index=src, mul=0.5).out()
34
35 # Function called to redraw the transfer function.
36 def redraw():
37 table.slope = drive.get()
38
39
40 # We call the "redraw" function every time the "drive" value changes.
41 trig = TrigFunc(Change(drive), function=redraw)
42
43 sc = Scope(look)
44
45 s.gui(locals())