| 1 |
""" |
| 2 |
05-micro-montage.py - Create table from random chunks of a soundfile. |
| 3 |
|
| 4 |
This example creates a new sound table from random chunks of a soundfile. |
| 5 |
|
| 6 |
The SndTable object has some methods to help mixing different sounds or |
| 7 |
parts of sounds into a single table: |
| 8 |
|
| 9 |
- setSound(path, start=0, stop=None) |
| 10 |
Replace the table content with the new sound. |
| 11 |
- insert(path, pos=0, crossfade=0, start=0, stop=None) |
| 12 |
Insert samples at a given position in the table, with crossfades. |
| 13 |
- append(path, crossfade=0, start=0, stop=None) |
| 14 |
Append samples at the end of the table, with crossfade. |
| 15 |
|
| 16 |
To generate a new mix in the sound table, call the `gen()` function |
| 17 |
in the Interpreter field of the Server GUI. |
| 18 |
|
| 19 |
""" |
| 20 |
from pyo import * |
| 21 |
import random |
| 22 |
|
| 23 |
s = Server().boot() |
| 24 |
|
| 25 |
|
| 26 |
path = "../snds/baseballmajeur_m.aif" |
| 27 |
snddur = sndinfo(path)[1] |
| 28 |
|
| 29 |
|
| 30 |
table = SndTable() |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
fade = Fader(fadein=0.005, fadeout=0.005, dur=0, mul=0.7) |
| 36 |
|
| 37 |
|
| 38 |
loop = Looper(table, dur=table.getDur(), xfade=5, mul=fade) |
| 39 |
|
| 40 |
|
| 41 |
rvrb = STRev(loop, inpos=0.50, revtime=1.5, bal=0.15).out() |
| 42 |
|
| 43 |
|
| 44 |
def addsnd(): |
| 45 |
|
| 46 |
start = random.uniform(0, snddur * 0.7) |
| 47 |
duration = random.uniform(0.1, 0.3) |
| 48 |
|
| 49 |
|
| 50 |
pos = random.uniform(0.05, table.getDur() - 0.5) |
| 51 |
cross = random.uniform(0.04, duration / 2) |
| 52 |
|
| 53 |
|
| 54 |
table.insert(path, pos=pos, crossfade=cross, start=start, stop=start + duration) |
| 55 |
|
| 56 |
|
| 57 |
def delgen(): |
| 58 |
|
| 59 |
start = random.uniform(0, snddur * 0.7) |
| 60 |
duration = random.uniform(0.1, 0.3) |
| 61 |
|
| 62 |
|
| 63 |
table.setSound(path, start=start, stop=start + duration) |
| 64 |
|
| 65 |
|
| 66 |
for i in range(10): |
| 67 |
addsnd() |
| 68 |
|
| 69 |
|
| 70 |
loop.dur = table.getDur() |
| 71 |
loop.reset() |
| 72 |
|
| 73 |
|
| 74 |
fade.play() |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
caller = CallAfter(function=delgen, time=0.005).stop() |
| 79 |
|
| 80 |
|
| 81 |
def gen(): |
| 82 |
"Create a new mix in the sound table." |
| 83 |
fade.stop() |
| 84 |
caller.play() |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
gen() |
| 89 |
|
| 90 |
s.gui(locals()) |