Debian Codegraph @

pyo/examples/x07-effects/04-ping-pong-delay.py

raw symbols SCIP
1 """
2 04-ping-pong-delay.py - Stereo ping-pong delay.
3
4 A stereo ping-pong delay is when you use two delays, one hard left and the
5 other hard right, and the delays alternate.
6
7 This exemple illustrates how we can pass the signal of a first object to
8 the input of a second even if the first object does not exist yet when the
9 second is created.
10
11 """
12 from pyo import *
13 import random
14
15 s = Server(duplex=0).boot()
16
17 # Compute the duration, in seconds, of one buffer size.
18 buftime = s.getBufferSize() / s.getSamplingRate()
19
20 # Delay parameters
21 delay_time_l = Sig(0.125) # Delay time for the left channel delay.
22 delay_time_l.ctrl()
23 delay_feed = Sig(0.75) # Feedback value for both delays.
24 delay_feed.ctrl()
25
26 # Because the right delay gets its input sound from the left delay, while
27 # it is computed before (to send its output sound to the left delay), it
28 # will be one buffer size late. To compensate this additional delay on the
29 # right, we substract one buffer size from the real delay time.
30 delay_time_r = Sig(delay_time_l, add=-buftime)
31
32 # Setup up a soundfile player.
33 sf = SfPlayer("../snds/alum1.wav").stop()
34
35 # Send the original sound to both speakers.
36 sfout = sf.mix(2).out()
37
38 # Initialize the right delay with zeros as input because the left delay
39 # does not exist yet.
40 right = Delay(Sig(0), delay=delay_time_r).out(1)
41
42 # Initialize the left delay with the original mono source and the right
43 # delay signal (multiplied by the feedback value) as input.
44 left = Delay(sf + right * delay_feed, delay=delay_time_l).out()
45
46 # One issue with recursive cross-delay is if we set the feedback to
47 # 0, the right delay never gets any signal. To resolve this, we add a
48 # non-recursive delay, with a gain that is the inverse of the feedback,
49 # to the right delay input.
50 original_delayed = Delay(sf, delay_time_l, mul=1 - delay_feed)
51
52 # Change the right delay input (now that the left delay exists).
53 right.setInput(original_delayed + left * delay_feed)
54
55
56 def playit():
57 "Assign a sound to the player and start playback."
58 which = random.randint(1, 4)
59 path = "../snds/alum%d.wav" % which
60 sf.path = path
61 sf.play()
62
63
64 # Call the function "playit" every second.
65 pat = Pattern(playit, 1).play()
66
67 s.gui(locals())