Debian Codegraph @

docs/_sources/examples/05-envelopes/04-simple-envelopes.rst.txt

raw
1 04-simple-envelopes.py - ASR and ADSR envelopes.
2 ============================================================================================================================================
3
4
5 The Fader object is a simple way to setup an Attack/Sustain/Release envelope.
6 This envelope allows to apply fadein and fadeout on audio streams.
7
8 If the `dur` argument of the Fader object is set to 0 (the default), the
9 object waits for a stop() command before activating the release part of
10 the envelope. Otherwise, the sum of `fadein` and `fadeout` must be less
11 than or egal to `dur` and the envelope runs to the end on a play() command.
12
13 The Adsr object (Attack/Decay/Sustain/Release) acts exactly like the Fader
14 object, with a more flexible (and so common) kind of envelope.
15
16 .. code-block:: python
17
18 from pyo import *
19 import random
20
21 s = Server().boot()
22
23 # Infinite sustain for the global envelope.
24 globalamp = Fader(fadein=2, fadeout=2, dur=0).play()
25
26 # Envelope for discrete events, sharp attack, long release.
27 env = Adsr(attack=0.01, decay=0.1, sustain=0.5, release=1.5, dur=2, mul=0.5)
28 # setExp method can be used to create exponential or logarithmic envelope.
29 env.setExp(0.75)
30
31 # Initialize a simple wave player and apply both envelopes.
32 sig = SuperSaw(freq=[100, 101], detune=0.6, bal=0.8, mul=globalamp * env).out()
33
34
35 def play_note():
36 "Play a new note with random frequency and jitterized envelope."
37 freq = random.choice(midiToHz([36, 38, 41, 43, 45]))
38 sig.freq = [freq, freq * 1.005]
39 env.attack = random.uniform(0.002, 0.01)
40 env.decay = random.uniform(0.1, 0.5)
41 env.sustain = random.uniform(0.3, 0.6)
42 env.release = random.uniform(0.8, 1.4)
43 # Start the envelope for the event.
44 env.play()
45
46
47 # Periodically call a function.
48 pat = Pattern(play_note, time=2).play()
49
50 s.gui(locals())
51