Skip to content

Commit b684434

Browse files
committed
core.Voice: add param support
1 parent 31e7dfd commit b684434

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

examples/voice_params.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
# -*- coding: utf-8 -*-
3+
from pyrilla import core
4+
5+
from base import main, update_till_interrupt
6+
7+
again = 0
8+
9+
def file_handle(filename, ext):
10+
sound = core.Sound(filename, ext)
11+
voice = core.Voice(sound, loop=True)
12+
13+
voice.play()
14+
voice.pitch = 1.5
15+
voice.pan = -.5
16+
voice.gain = .5
17+
18+
print("pitch: %5.1f" % voice.pitch)
19+
print("pan: %5.1f" % voice.pan)
20+
print("gain: %5.1f" % voice.gain)
21+
22+
update_till_interrupt()
23+
24+
25+
if __name__ == "__main__":
26+
main(file_handle)

extensions/core.pyx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,36 @@ cdef class Voice(object):
110110
else:
111111
self.play()
112112

113+
property pitch:
114+
def __get__(self):
115+
cdef ga.float32 value
116+
117+
ga.handle_getParamf(self.handle, ga.HANDLE_PARAM_PITCH, &value)
118+
return value
119+
120+
def __set__(self, ga.float32 value):
121+
ga.handle_setParamf(self.handle, ga.HANDLE_PARAM_PITCH, value)
122+
123+
property gain:
124+
def __get__(self):
125+
cdef ga.float32 value
126+
127+
ga.handle_getParamf(self.handle, ga.HANDLE_PARAM_GAIN, &value)
128+
return value
129+
130+
def __set__(self, ga.float32 value):
131+
ga.handle_setParamf(self.handle, ga.HANDLE_PARAM_GAIN, value)
132+
133+
property pan:
134+
def __get__(self):
135+
cdef ga.float32 value
136+
137+
ga.handle_getParamf(self.handle, ga.HANDLE_PARAM_PAN, &value)
138+
return value
139+
140+
def __set__(self, ga.float32 value):
141+
ga.handle_setParamf(self.handle, ga.HANDLE_PARAM_PAN, value)
142+
113143
cdef class Sound(object):
114144
cdef ga.Sound* sound
115145

0 commit comments

Comments
 (0)