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