Skip to content

Commit

Permalink
Use actual_time to encode allow_belated argument
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier authored and larsoner committed May 27, 2021
1 parent 22e863a commit 2b26c52
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
1 change: 0 additions & 1 deletion examples/bleeperoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
max_delay = -np.inf
for action in actionlist:
assert action.type == rtmixer.PLAY_BUFFER
# NB: action.allow_belated might have been invalidated
assert action.requested_time != 0
if not action.actual_time:
belated += 1
Expand Down
10 changes: 6 additions & 4 deletions src/rtmixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int callback(const void* input, void* output, frame_t frameCount

// Due to inaccuracies in timeInfo, "diff" might have a small negative
// value in a future block. We don't count this as "belated" though:
action->allow_belated = true;
action->actual_time = -1.0;
actionaddr = &(action->next);
continue;
}
Expand All @@ -170,9 +170,9 @@ int callback(const void* input, void* output, frame_t frameCount
else
{
// We are too late!
if (!action->allow_belated)
if (action->actual_time == 0.0)
{
action->actual_time = 0.0; // a.k.a. "false"
// allow_belated == False
remove_action(actionaddr, state);
continue;
}
Expand Down Expand Up @@ -213,8 +213,10 @@ int callback(const void* input, void* output, frame_t frameCount
}
else
{
if (!delinquent->allow_belated)
if (delinquent->actual_time == 0.0)
{
// allow_belated == False

// TODO: save some status information?
break; // The action will not be started, no need to cancel it
}
Expand Down
3 changes: 1 addition & 2 deletions src/rtmixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ struct stats
struct action
{
const enum actiontype type;
bool allow_belated; // NB: Might be invalidated in the callback function!
const PaTime requested_time;
PaTime actual_time;
PaTime actual_time; // Set != 0.0 to allow belated actions
struct action* next; // Used to create singly linked list of actions
union {
float* const buffer;
Expand Down
12 changes: 6 additions & 6 deletions src/rtmixer.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def cancel(self, action, time=0, allow_belated=True):
"""
cancel_action = _ffi.new('struct action*', dict(
type=CANCEL,
allow_belated=allow_belated,
actual_time=-1.0 if allow_belated else 0.0,
requested_time=time,
action=action,
))
Expand All @@ -88,7 +88,7 @@ def fetch_and_reset_stats(self, time=0, allow_belated=True):
"""
action = _ffi.new('struct action*', dict(
type=FETCH_AND_RESET_STATS,
allow_belated=allow_belated,
actual_time=-1.0 if allow_belated else 0.0,
requested_time=time,
))
self._enqueue(action)
Expand Down Expand Up @@ -173,7 +173,7 @@ def play_buffer(self, buffer, channels, start=0, allow_belated=True):
_, samplesize = _sd._split(self.samplesize)
action = _ffi.new('struct action*', dict(
type=PLAY_BUFFER,
allow_belated=allow_belated,
actual_time=-1.0 if allow_belated else 0.0,
requested_time=start,
buffer=_ffi.cast('float*', buffer),
total_frames=len(buffer) // channels // samplesize,
Expand All @@ -199,7 +199,7 @@ def play_ringbuffer(self, ringbuffer, channels=None, start=0,
raise ValueError('Incompatible elementsize')
action = _ffi.new('struct action*', dict(
type=PLAY_RINGBUFFER,
allow_belated=allow_belated,
actual_time=-1.0 if allow_belated else 0.0,
requested_time=start,
ringbuffer=ringbuffer._ptr,
total_frames=ULONG_MAX,
Expand Down Expand Up @@ -238,7 +238,7 @@ def record_buffer(self, buffer, channels, start=0, allow_belated=True):
samplesize, _ = _sd._split(self.samplesize)
action = _ffi.new('struct action*', dict(
type=RECORD_BUFFER,
allow_belated=allow_belated,
actual_time=-1.0 if allow_belated else 0.0,
requested_time=start,
buffer=_ffi.cast('float*', buffer),
total_frames=len(buffer) // channels // samplesize,
Expand All @@ -264,7 +264,7 @@ def record_ringbuffer(self, ringbuffer, channels=None, start=0,
raise ValueError('Incompatible elementsize')
action = _ffi.new('struct action*', dict(
type=RECORD_RINGBUFFER,
allow_belated=allow_belated,
actual_time=-1.0 if allow_belated else 0.0,
requested_time=start,
ringbuffer=ringbuffer._ptr,
total_frames=ULONG_MAX,
Expand Down

0 comments on commit 2b26c52

Please sign in to comment.