@@ -38,53 +38,85 @@ cdef class CallbackContext(object):
38
38
self .sound = sound
39
39
40
40
41
- cdef class Sound(object ):
42
- cdef ga.Sound* sound
43
- cdef ga.Handle* handle
41
+ cdef class Mixer(object ):
42
+ pass
44
43
45
- def __cinit__ (self ):
46
- self .sound = NULL
47
- self .handle = NULL
48
44
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
59
49
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
+ ):
62
60
cdef CallbackContext context
63
61
62
+ self .sound = sound
63
+ self .mixer = mixer
64
+ self .loop = loop
65
+ self .handle = NULL
66
+
64
67
if on_finish:
65
- context = CallbackContext(on_finish, self )
68
+ context = CallbackContext(on_finish, self .sound )
66
69
67
70
# note: we are going to cast on void* so we need to manually
68
71
# control reference counters
69
72
Py_INCREF(context)
70
73
71
- handle = gau.create_handle_sound(
74
+ self . handle = gau.create_handle_sound(
72
75
global_mixer,
73
- self .sound,
76
+ self .sound.sound ,
74
77
< ga.FinishCallback> & on_finish_callback,
75
78
< void * > context,
76
- NULL
79
+ & self .loop_src if self .loop else NULL
77
80
)
81
+
78
82
else :
79
83
handle = gau.create_handle_sound(
80
84
global_mixer,
81
- self .sound,
85
+ self .sound.sound ,
82
86
< ga.FinishCallback> & gau.on_finish_destroy,
83
87
NULL ,
84
- NULL
88
+ & self .loop_src if self .loop else NULL
85
89
)
86
90
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
88
120
89
121
def __del__ (self ):
90
122
""" Release sound (gorilla uses refcounting for that)"""
0 commit comments