Skip to content

Commit

Permalink
bleeperoo example: more reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Aug 30, 2019
1 parent a1cc70b commit 5d861c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
33 changes: 30 additions & 3 deletions examples/bleeperoo.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,42 @@
assert bleep.flags.c_contiguous
bleeplist.append(bleep)

actionlist = []
with rtmixer.Mixer(device=device, channels=channels, blocksize=blocksize,
samplerate=samplerate, latency=latency, qsize=qsize) as m:
start_time = m.time
for bleep in bleeplist:
actionlist = [
m.play_buffer(bleep,
channels=[r.randint(channels) + 1],
start=start_time + r.uniform(start_min, start_max))
start=start_time + r.uniform(start_min, start_max),
allow_belated=False)
for bleep in bleeplist
]
while m.actions:
sd.sleep(100)
# TODO: get list of actions and check if all were started on time?
print('{0} buffer underflows in {1} processed audio blocks'.format(
m.stats.output_underflows, m.stats.blocks))

belated = 0
min_delay = np.inf
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
assert action.done_frames == 0
continue
assert action.done_frames == action.total_frames
delay = action.actual_time - action.requested_time
if delay > max_delay:
max_delay = delay
if delay < min_delay:
min_delay = delay

print('total number of bleeps:', len(actionlist))
print('belated bleeps (not played):', belated)
print('maxiumum delay (in usec):', max_delay * 1000 * 1000)
print('maxiumum negative delay: ', -min_delay * 1000 * 1000)
print('half sampling period: ', 0.5 * 1000 * 1000 / samplerate)
2 changes: 1 addition & 1 deletion src/rtmixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct stats
struct action
{
const enum actiontype type;
bool allow_belated;
bool allow_belated; // NB: Might be invalidated in the callback function!
const PaTime requested_time;
PaTime actual_time;
struct action* next; // Used to create singly linked list of actions
Expand Down

0 comments on commit 5d861c6

Please sign in to comment.