Debian Codegraph @

pyo/examples/x07-effects/06-hand-made-harmonizer.py

raw symbols SCIP
1 """
2 07-hand-made-harmonizer.py - Hand-written harmonizer effect.
3
4 A harmonizer is a type of pitch shifter that combines the "shifted" pitch
5 with the original pitch to create a two or more note harmony.
6
7 The implementation consists of two overlapping delay lines for which the
8 reading head speed is tuned to transpose the signal by an amount specified
9 in semitones.
10
11 The Harmonizer object (from pyo) implements an pitch shifter and should
12 use less CPU than the hand-written version. this example's purpose is only
13 to show how it works or to be used as a starting point to build an extended
14 version.
15
16 """
17 from pyo import *
18
19 s = Server(duplex=0).boot()
20
21 # Play a melodic sound and send its signal to the left speaker.
22 sf = SfPlayer("../snds/flute.aif", speed=1, loop=True, mul=0.5).out()
23
24 # Half-sine window used as the amplitude envelope of the overlaps.
25 env = WinTable(8)
26
27 # Length of the window in seconds.
28 wsize = 0.1
29
30 # Amount of transposition in semitones.
31 trans = -7
32
33 # Compute the transposition ratio.
34 ratio = pow(2.0, trans / 12.0)
35
36 # Compute the reading head speed.
37 rate = -(ratio - 1) / wsize
38
39 # Two reading heads out-of-phase.
40 ind = Phasor(freq=rate, phase=[0, 0.5])
41
42 # Each head reads the amplitude envelope...
43 win = Pointer(table=env, index=ind, mul=0.7)
44
45 # ... and modulates the delay time (scaled by the window size) of a delay line.
46 # mix(1) is used to mix the two overlaps on a single audio stream.
47 snd = Delay(sf, delay=ind * wsize, mul=win).mix(1)
48
49 # The transposed signal is sent to the right speaker.
50 snd.out(1)
51
52 s.gui(locals())