Debian Codegraph @

pyo/examples/x16-midi/03-midi-envelope.py

raw symbols SCIP
1 """
2 03-midi-envelope.py - Shaping the sound of a MIDI synth.
3
4 This program illustrates a classic way of shaping the dynamic of the
5 sound of a MIDI synthesizer with two MIDI-triggered envelope objects:
6
7 - MidiAdsr: a classic Attack - Decay - Sustain - Release envelope.
8 - MidiDelAdsr: a classic ADSR envelope with a delay added prior the attack.
9
10 We will use these envelopes to control the gain of two parts of the sound.
11 The first part is an oscillator at the root frequency with a sharp attack.
12 The second part is a pair of oscillators slightly detuned raising smoothly
13 after a half-second delay. This gradually introduces beating into the sound.
14
15 """
16 from pyo import *
17
18 s = Server()
19 s.setMidiInputDevice(99) # Open all input devices.
20 s.boot()
21
22 # Automatically converts MIDI pitches to frequencies in Hz.
23 notes = Notein(scale=1)
24 notes.keyboard()
25
26 # MIDI-triggered ADSR envelope.
27 env1 = MidiAdsr(notes["velocity"], attack=0.005, decay=0.1, sustain=0.7, release=0.5, mul=0.1)
28
29 # MIDI-triggered DADSR envelope (a classic ADSR with an adjustable pre-delay).
30 env2 = MidiDelAdsr(notes["velocity"], delay=0.5, attack=1, decay=0.5, sustain=0.5, release=0.5, mul=0.1)
31
32 # Root frequency appears instantly.
33 sig1 = RCOsc(freq=notes["pitch"], sharp=0.5, mul=env1).mix().mix(2).out()
34
35 # Small frequency deviations appear smoothly after a half-second delay.
36 sig2 = RCOsc(freq=notes["pitch"] * 0.992, sharp=0.8, mul=env2).mix()
37 sig3 = RCOsc(freq=notes["pitch"] * 1.008, sharp=0.8, mul=env2).mix()
38
39 # Create a stereo signal from the frequency deviations.
40 stereo = Mix([sig2, sig3], voices=2)
41
42 # Sum the signals and apply a global reverberation.
43 rev = WGVerb(sig1 + stereo, feedback=0.8, cutoff=5000, bal=0.3).out()
44
45 s.gui(locals())