Debian Codegraph @

pyo/examples/x10-tables/05-micro-montage.py

raw symbols SCIP
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 # Path and duration of the choosen soundfile.
26 path = "../snds/baseballmajeur_m.aif"
27 snddur = sndinfo(path)[1]
28
29 # Initialize an empty sound table.
30 table = SndTable()
31
32 # Before generating a new table mix, we activate the fadeout of the
33 # envelope to ensure that the table is modified in the silence. As
34 # soon as the table is generated, we call the envelope fadein.
35 fade = Fader(fadein=0.005, fadeout=0.005, dur=0, mul=0.7)
36
37 # Reads the table with forward looping.
38 loop = Looper(table, dur=table.getDur(), xfade=5, mul=fade)
39
40 # Adds some reverb and send the signal to the output.
41 rvrb = STRev(loop, inpos=0.50, revtime=1.5, bal=0.15).out()
42
43
44 def addsnd():
45 # Randomly choose a new starting point and a new duration.
46 start = random.uniform(0, snddur * 0.7)
47 duration = random.uniform(0.1, 0.3)
48
49 # Randomly choose an insert point in the sound table and a croosfade time.
50 pos = random.uniform(0.05, table.getDur() - 0.5)
51 cross = random.uniform(0.04, duration / 2)
52
53 # Insert the new chunk in the current sound table.
54 table.insert(path, pos=pos, crossfade=cross, start=start, stop=start + duration)
55
56
57 def delgen():
58 # Randomly choose a new starting point and a new duration.
59 start = random.uniform(0, snddur * 0.7)
60 duration = random.uniform(0.1, 0.3)
61
62 # Load the chosen segment in the sound table.
63 table.setSound(path, start=start, stop=start + duration)
64
65 # Add 10 more chunks.
66 for i in range(10):
67 addsnd()
68
69 # Set the new table duration to the Looper and reset it.
70 loop.dur = table.getDur()
71 loop.reset()
72
73 # Activate the envelope fadein.
74 fade.play()
75
76
77 # CallAfter calls a function after a given delay time.
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() # Launch the fadeout...
84 caller.play() # ... then call the delayed generation.
85
86
87 # Generate the intial table.
88 gen()
89
90 s.gui(locals())