1111RingBuffer = _init_ringbuffer (_ffi , _lib )
1212
1313
14+ # Get constants from C library
15+ for _k , _v in vars (_lib ).items ():
16+ if _k .isupper ():
17+ globals ()[_k ] = _v
18+
19+
1420class _Base (_sd ._StreamBase ):
1521 """Base class for Mixer et al."""
1622
@@ -53,7 +59,7 @@ def cancel(self, action, time=0, allow_belated=True):
5359
5460 """
5561 cancel_action = _ffi .new ('struct action*' , dict (
56- type = _lib . CANCEL ,
62+ type = CANCEL ,
5763 allow_belated = allow_belated ,
5864 requested_time = time ,
5965 action = action ,
@@ -132,7 +138,7 @@ def play_buffer(self, buffer, channels, start=0, allow_belated=True):
132138 buffer = _ffi .from_buffer (buffer )
133139 _ , samplesize = _sd ._split (self .samplesize )
134140 action = _ffi .new ('struct action*' , dict (
135- type = _lib . PLAY_BUFFER ,
141+ type = PLAY_BUFFER ,
136142 allow_belated = allow_belated ,
137143 requested_time = start ,
138144 buffer = _ffi .cast ('float*' , buffer ),
@@ -158,11 +164,11 @@ def play_ringbuffer(self, ringbuffer, channels=None, start=0,
158164 if ringbuffer .elementsize != samplesize * channels :
159165 raise ValueError ('Incompatible elementsize' )
160166 action = _ffi .new ('struct action*' , dict (
161- type = _lib . PLAY_RINGBUFFER ,
167+ type = PLAY_RINGBUFFER ,
162168 allow_belated = allow_belated ,
163169 requested_time = start ,
164170 ringbuffer = ringbuffer ._ptr ,
165- total_frames = _lib . ULONG_MAX ,
171+ total_frames = ULONG_MAX ,
166172 channels = channels ,
167173 mapping = mapping ,
168174 ))
@@ -197,7 +203,7 @@ def record_buffer(self, buffer, channels, start=0, allow_belated=True):
197203 buffer = _ffi .from_buffer (buffer )
198204 samplesize , _ = _sd ._split (self .samplesize )
199205 action = _ffi .new ('struct action*' , dict (
200- type = _lib . RECORD_BUFFER ,
206+ type = RECORD_BUFFER ,
201207 allow_belated = allow_belated ,
202208 requested_time = start ,
203209 buffer = _ffi .cast ('float*' , buffer ),
@@ -223,11 +229,11 @@ def record_ringbuffer(self, ringbuffer, channels=None, start=0,
223229 if ringbuffer .elementsize != samplesize * channels :
224230 raise ValueError ('Incompatible elementsize' )
225231 action = _ffi .new ('struct action*' , dict (
226- type = _lib . RECORD_RINGBUFFER ,
232+ type = RECORD_RINGBUFFER ,
227233 allow_belated = allow_belated ,
228234 requested_time = start ,
229235 ringbuffer = ringbuffer ._ptr ,
230- total_frames = _lib . ULONG_MAX ,
236+ total_frames = ULONG_MAX ,
231237 channels = channels ,
232238 mapping = mapping ,
233239 ))
0 commit comments