Skip to content

Commit 199d19b

Browse files
committed
add some paning example
1 parent b684434 commit 199d19b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

examples/paning.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# -*- coding: utf-8 -*-
2+
import time
3+
from math import sin, cos
4+
5+
from pyrilla import core
6+
7+
from base import main
8+
9+
10+
def pan_voices(lvoice, rvoice, t):
11+
# use two sounds like two independent channels
12+
# its not as good as HRTF but can fake that
13+
# sound source moves if you really want to believe :)
14+
lvoice.gain = ((sin(t) + 1.) / 2.)
15+
rvoice.gain = ((cos(t) + 1.) / 2.)
16+
17+
18+
def file_handle(filename, ext):
19+
sound = core.Sound(filename, ext)
20+
lvoice = core.Voice(sound, loop=True)
21+
rvoice = core.Voice(sound, loop=True)
22+
23+
lvoice.play()
24+
rvoice.play()
25+
26+
lvoice.pan = -1.
27+
rvoice.pan = 1.
28+
29+
try:
30+
while True:
31+
pan_voices(lvoice, rvoice, time.time())
32+
core.update()
33+
time.sleep(0.001)
34+
35+
36+
except KeyboardInterrupt:
37+
print("interrupted")
38+
39+
if __name__ == "__main__":
40+
main(file_handle)

0 commit comments

Comments
 (0)