Skip to content

Commit 2b26c52

Browse files
mgeierlarsoner
authored andcommitted
Use actual_time to encode allow_belated argument
1 parent 22e863a commit 2b26c52

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

examples/bleeperoo.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
max_delay = -np.inf
9191
for action in actionlist:
9292
assert action.type == rtmixer.PLAY_BUFFER
93-
# NB: action.allow_belated might have been invalidated
9493
assert action.requested_time != 0
9594
if not action.actual_time:
9695
belated += 1

src/rtmixer.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int callback(const void* input, void* output, frame_t frameCount
160160

161161
// Due to inaccuracies in timeInfo, "diff" might have a small negative
162162
// value in a future block. We don't count this as "belated" though:
163-
action->allow_belated = true;
163+
action->actual_time = -1.0;
164164
actionaddr = &(action->next);
165165
continue;
166166
}
@@ -170,9 +170,9 @@ int callback(const void* input, void* output, frame_t frameCount
170170
else
171171
{
172172
// We are too late!
173-
if (!action->allow_belated)
173+
if (action->actual_time == 0.0)
174174
{
175-
action->actual_time = 0.0; // a.k.a. "false"
175+
// allow_belated == False
176176
remove_action(actionaddr, state);
177177
continue;
178178
}
@@ -213,8 +213,10 @@ int callback(const void* input, void* output, frame_t frameCount
213213
}
214214
else
215215
{
216-
if (!delinquent->allow_belated)
216+
if (delinquent->actual_time == 0.0)
217217
{
218+
// allow_belated == False
219+
218220
// TODO: save some status information?
219221
break; // The action will not be started, no need to cancel it
220222
}

src/rtmixer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ struct stats
3434
struct action
3535
{
3636
const enum actiontype type;
37-
bool allow_belated; // NB: Might be invalidated in the callback function!
3837
const PaTime requested_time;
39-
PaTime actual_time;
38+
PaTime actual_time; // Set != 0.0 to allow belated actions
4039
struct action* next; // Used to create singly linked list of actions
4140
union {
4241
float* const buffer;

src/rtmixer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def cancel(self, action, time=0, allow_belated=True):
7272
"""
7373
cancel_action = _ffi.new('struct action*', dict(
7474
type=CANCEL,
75-
allow_belated=allow_belated,
75+
actual_time=-1.0 if allow_belated else 0.0,
7676
requested_time=time,
7777
action=action,
7878
))
@@ -88,7 +88,7 @@ def fetch_and_reset_stats(self, time=0, allow_belated=True):
8888
"""
8989
action = _ffi.new('struct action*', dict(
9090
type=FETCH_AND_RESET_STATS,
91-
allow_belated=allow_belated,
91+
actual_time=-1.0 if allow_belated else 0.0,
9292
requested_time=time,
9393
))
9494
self._enqueue(action)
@@ -173,7 +173,7 @@ def play_buffer(self, buffer, channels, start=0, allow_belated=True):
173173
_, samplesize = _sd._split(self.samplesize)
174174
action = _ffi.new('struct action*', dict(
175175
type=PLAY_BUFFER,
176-
allow_belated=allow_belated,
176+
actual_time=-1.0 if allow_belated else 0.0,
177177
requested_time=start,
178178
buffer=_ffi.cast('float*', buffer),
179179
total_frames=len(buffer) // channels // samplesize,
@@ -199,7 +199,7 @@ def play_ringbuffer(self, ringbuffer, channels=None, start=0,
199199
raise ValueError('Incompatible elementsize')
200200
action = _ffi.new('struct action*', dict(
201201
type=PLAY_RINGBUFFER,
202-
allow_belated=allow_belated,
202+
actual_time=-1.0 if allow_belated else 0.0,
203203
requested_time=start,
204204
ringbuffer=ringbuffer._ptr,
205205
total_frames=ULONG_MAX,
@@ -238,7 +238,7 @@ def record_buffer(self, buffer, channels, start=0, allow_belated=True):
238238
samplesize, _ = _sd._split(self.samplesize)
239239
action = _ffi.new('struct action*', dict(
240240
type=RECORD_BUFFER,
241-
allow_belated=allow_belated,
241+
actual_time=-1.0 if allow_belated else 0.0,
242242
requested_time=start,
243243
buffer=_ffi.cast('float*', buffer),
244244
total_frames=len(buffer) // channels // samplesize,
@@ -264,7 +264,7 @@ def record_ringbuffer(self, ringbuffer, channels=None, start=0,
264264
raise ValueError('Incompatible elementsize')
265265
action = _ffi.new('struct action*', dict(
266266
type=RECORD_RINGBUFFER,
267-
allow_belated=allow_belated,
267+
actual_time=-1.0 if allow_belated else 0.0,
268268
requested_time=start,
269269
ringbuffer=ringbuffer._ptr,
270270
total_frames=ULONG_MAX,

0 commit comments

Comments
 (0)