Skip to content

Commit 5d861c6

Browse files
committed
bleeperoo example: more reporting
1 parent a1cc70b commit 5d861c6

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

examples/bleeperoo.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,42 @@
6969
assert bleep.flags.c_contiguous
7070
bleeplist.append(bleep)
7171

72+
actionlist = []
7273
with rtmixer.Mixer(device=device, channels=channels, blocksize=blocksize,
7374
samplerate=samplerate, latency=latency, qsize=qsize) as m:
7475
start_time = m.time
75-
for bleep in bleeplist:
76+
actionlist = [
7677
m.play_buffer(bleep,
7778
channels=[r.randint(channels) + 1],
78-
start=start_time + r.uniform(start_min, start_max))
79+
start=start_time + r.uniform(start_min, start_max),
80+
allow_belated=False)
81+
for bleep in bleeplist
82+
]
7983
while m.actions:
8084
sd.sleep(100)
81-
# TODO: get list of actions and check if all were started on time?
8285
print('{0} buffer underflows in {1} processed audio blocks'.format(
8386
m.stats.output_underflows, m.stats.blocks))
87+
88+
belated = 0
89+
min_delay = np.inf
90+
max_delay = -np.inf
91+
for action in actionlist:
92+
assert action.type == rtmixer.PLAY_BUFFER
93+
# NB: action.allow_belated might have been invalidated
94+
assert action.requested_time != 0
95+
if not action.actual_time:
96+
belated += 1
97+
assert action.done_frames == 0
98+
continue
99+
assert action.done_frames == action.total_frames
100+
delay = action.actual_time - action.requested_time
101+
if delay > max_delay:
102+
max_delay = delay
103+
if delay < min_delay:
104+
min_delay = delay
105+
106+
print('total number of bleeps:', len(actionlist))
107+
print('belated bleeps (not played):', belated)
108+
print('maxiumum delay (in usec):', max_delay * 1000 * 1000)
109+
print('maxiumum negative delay: ', -min_delay * 1000 * 1000)
110+
print('half sampling period: ', 0.5 * 1000 * 1000 / samplerate)

src/rtmixer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct stats
3434
struct action
3535
{
3636
const enum actiontype type;
37-
bool allow_belated;
37+
bool allow_belated; // NB: Might be invalidated in the callback function!
3838
const PaTime requested_time;
3939
PaTime actual_time;
4040
struct action* next; // Used to create singly linked list of actions

0 commit comments

Comments
 (0)