| 1 |
""" |
| 2 |
06-table-stutter.py - Variable length table reading. |
| 3 |
|
| 4 |
This little program use a function and a time-variable function caller |
| 5 |
to stutter a sound loaded in a table. The starting point of the table |
| 6 |
playback is set initially to near the end of the table, and move toward |
| 7 |
the beginning each time a new playback is called. |
| 8 |
|
| 9 |
For the playback, we use a Pointer object, which is a table reader with |
| 10 |
control on the pointer position (normalized between 0 and 1). |
| 11 |
|
| 12 |
""" |
| 13 |
from pyo import * |
| 14 |
import random |
| 15 |
|
| 16 |
s = Server().boot() |
| 17 |
|
| 18 |
STUTTER = 0.025 |
| 19 |
FADETIME = 0.01 |
| 20 |
|
| 21 |
|
| 22 |
table = SndTable(SNDS_PATH + "/transparent.aif") |
| 23 |
tabdur = table.getDur() |
| 24 |
|
| 25 |
|
| 26 |
line = Linseg([(0, 0), (1, 1)]) |
| 27 |
|
| 28 |
|
| 29 |
amp = Fader(FADETIME, FADETIME, dur=STUTTER, mul=0.5) |
| 30 |
amp.setExp(2) |
| 31 |
|
| 32 |
|
| 33 |
read = Pointer(table=table, index=line, mul=amp).mix(2).out() |
| 34 |
|
| 35 |
|
| 36 |
start = tabdur - STUTTER |
| 37 |
dur = STUTTER |
| 38 |
|
| 39 |
|
| 40 |
def go(): |
| 41 |
"Read a segment of a sound table and set the duration before the next iteration." |
| 42 |
global start, dur |
| 43 |
|
| 44 |
|
| 45 |
line.list = [(0, start / tabdur), (dur, 1)] |
| 46 |
|
| 47 |
|
| 48 |
amp.dur = pat.time = dur |
| 49 |
|
| 50 |
|
| 51 |
start -= STUTTER |
| 52 |
dur += STUTTER |
| 53 |
|
| 54 |
|
| 55 |
if start < 0: |
| 56 |
start = tabdur - STUTTER |
| 57 |
dur = STUTTER |
| 58 |
|
| 59 |
|
| 60 |
line.play() |
| 61 |
amp.play() |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
pat = Pattern(function=go, time=STUTTER).play() |
| 66 |
|
| 67 |
s.gui(locals()) |