Skip to content

Commit b867993

Browse files
committed
rename internal to core and add looping voice support
1 parent c6203d6 commit b867993

File tree

4 files changed

+60
-26
lines changed

4 files changed

+60
-26
lines changed

examples/loop.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

examples/play_voice.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: utf-8 -*-

extensions/internal.pyx renamed to extensions/core.pyx

Lines changed: 57 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,53 +38,85 @@ cdef class CallbackContext(object):
3838
self.sound = sound
3939

4040

41-
cdef class Sound(object):
42-
cdef ga.Sound* sound
43-
cdef ga.Handle* handle
41+
cdef class Mixer(object):
42+
pass
4443

45-
def __cinit__(self):
46-
self.sound = NULL
47-
self.handle = NULL
4844

49-
def __init__(
50-
self,
51-
filename,
52-
ext,
53-
stream=False,
54-
):
55-
if not stream:
56-
self.sound = gau.load_sound_file(filename, ext)
57-
else:
58-
raise NotImplementedError("streams ntt implemented yet")
45+
cdef class Voice(object):
46+
cdef Sound sound
47+
cdef int loop
48+
cdef Mixer mixer
5949

60-
def play(self, on_finish=None):
61-
cdef ga.Handle* handle
50+
cdef gau.SampleSourceLoop* loop_src
51+
cdef ga.Handle* handle
52+
53+
def __cinit__(
54+
self,
55+
Sound sound,
56+
object on_finish,
57+
int loop=False,
58+
Mixer mixer=None,
59+
):
6260
cdef CallbackContext context
6361

62+
self.sound = sound
63+
self.mixer = mixer
64+
self.loop = loop
65+
self.handle = NULL
66+
6467
if on_finish:
65-
context = CallbackContext(on_finish, self)
68+
context = CallbackContext(on_finish, self.sound)
6669

6770
# note: we are going to cast on void* so we need to manually
6871
# control reference counters
6972
Py_INCREF(context)
7073

71-
handle = gau.create_handle_sound(
74+
self.handle = gau.create_handle_sound(
7275
global_mixer,
73-
self.sound,
76+
self.sound.sound,
7477
<ga.FinishCallback>&on_finish_callback,
7578
<void*>context,
76-
NULL
79+
&self.loop_src if self.loop else NULL
7780
)
81+
7882
else:
7983
handle = gau.create_handle_sound(
8084
global_mixer,
81-
self.sound,
85+
self.sound.sound,
8286
<ga.FinishCallback>&gau.on_finish_destroy,
8387
NULL,
84-
NULL
88+
&self.loop_src if self.loop else NULL
8589
)
8690

87-
ga.handle_play(handle)
91+
def play(self):
92+
ga.handle_play(self.handle)
93+
94+
def stop(self):
95+
ga.handle_stop(self.handle)
96+
97+
def __del__(self):
98+
ga.handle_destroy(self.handle)
99+
100+
101+
cdef class Sound(object):
102+
cdef ga.Sound* sound
103+
104+
def __cinit__(self):
105+
self.sound = NULL
106+
107+
def __init__(self, filename, ext, stream=False):
108+
if not stream:
109+
self.sound = gau.load_sound_file(filename, ext)
110+
else:
111+
raise NotImplementedError("streams ntt implemented yet")
112+
113+
def play(self, on_finish=None):
114+
cdef Voice voice
115+
116+
voice = Voice(self, on_finish, 0, None)
117+
voice.play()
118+
119+
return voice
88120

89121
def __del__(self):
90122
"""Release sound (gorilla uses refcounting for that)"""

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def read_md(f):
6565
cmdclass={'build_ext': build_ext},
6666
ext_modules=[
6767
Extension(
68-
"pyrilla.internal", ["extensions/internal.pyx"],
68+
"pyrilla.core", ["extensions/core.pyx"],
6969
include_dirs=EXTENSIONS_INCLUDE_DIRS,
7070
extra_objects=EXTENSIONS_EXTRA_OBJECTS,
7171
libraries=LIBRARIES,

0 commit comments

Comments
 (0)