| 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 |
|
| 21 |
table = AtanTable(slope=0.5, size=512) |
| 22 |
table.view() |
| 23 |
|
| 24 |
|
| 25 |
drive = Sig(0.5) |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
drive.ctrl([SLMap(0, 1, "lin", "value", 0.5, dataOnly=True)], title="Transfer fonction slope") |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
look = Lookup(table, index=src, mul=0.5).out() |
| 34 |
|
| 35 |
|
| 36 |
def redraw(): |
| 37 |
table.slope = drive.get() |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
trig = TrigFunc(Change(drive), function=redraw) |
| 42 |
|
| 43 |
sc = Scope(look) |
| 44 |
|
| 45 |
s.gui(locals()) |