Skip to content

Commit 01f89c8

Browse files
committed
Store over/underflows
1 parent fd5083c commit 01f89c8

5 files changed

Lines changed: 34 additions & 11 deletions

File tree

examples/delay.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@
2323
stream.record_ringbuffer(q, start=start, allow_belated=False)
2424
stream.play_ringbuffer(q, start=start + delay, allow_belated=False)
2525
# TODO: check if start was successful
26+
print('#' * 80)
27+
print('press Return to quit')
28+
print('#' * 80)
2629
input()
30+
# TODO: check xruns

examples/plot_input.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,5 +74,6 @@ def update_plot(frame):
7474
with stream:
7575
elementsize = channels * stream.samplesize
7676
q = rtmixer.RingBuffer(elementsize, stepsize * qsize)
77-
stream.record_ringbuffer(q)
77+
action = stream.record_ringbuffer(q)
7878
plt.show()
79+
print('Input overflows:', action.stats.input_overflows)

examples/plot_recording.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
m.wait(action)
4646
buffer = buffer[:action.done_frames]
4747
t = t[:action.done_frames]
48-
# TODO: check for xruns
48+
49+
print('Input overflows during recording:', action.stats.input_overflows)
4950

5051
plt.plot(t, buffer)
5152
plt.xlabel('Time / seconds')

src/rtmixer.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ void remove_action(struct action** addr, struct state* state)
3333
}
3434
}
3535

36+
void get_stats(PaStreamCallbackFlags flags, struct stats* stats)
37+
{
38+
++stats->blocks;
39+
40+
if (flags & paInputUnderflow) { ++stats->input_underflows; }
41+
if (flags & paInputOverflow) { ++stats->input_overflows; }
42+
if (flags & paOutputUnderflow) { ++stats->output_underflows; }
43+
if (flags & paOutputOverflow) { ++stats->output_overflows; }
44+
}
45+
3646
int callback(const void* input, void* output, frame_t frameCount
3747
, const PaStreamCallbackTimeInfo* timeInfo, PaStreamCallbackFlags statusFlags
3848
, void* userData)
@@ -42,14 +52,7 @@ int callback(const void* input, void* output, frame_t frameCount
4252

4353
memset(output, 0, sizeof(float) * state->output_channels * frameCount);
4454

45-
if (statusFlags & paInputUnderflow) { printf("Input underflow!\n"); }
46-
if (statusFlags & paInputOverflow) { printf("Input overflow!\n"); }
47-
if (statusFlags & paOutputUnderflow) { printf("Output underflow!\n"); }
48-
if (statusFlags & paOutputOverflow) { printf("Output overflow!\n"); }
49-
50-
// TODO: store information about overflows/underflows
51-
52-
// TODO: check if main thread is still running?
55+
get_stats(statusFlags, &(state->stats));
5356

5457
for (struct action* action = NULL
5558
; PaUtil_ReadRingBuffer(state->action_q, &action, 1)
@@ -145,6 +148,10 @@ int callback(const void* input, void* output, frame_t frameCount
145148
continue;
146149
}
147150

151+
// Store buffer over-/underflow information
152+
153+
get_stats(statusFlags, &(action->stats));
154+
148155
// Get number of remaining frames in the current block
149156

150157
frame_t frames = action->total_frames - action->done_frames;

src/rtmixer.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ enum actiontype
1010
// TODO: action to query xrun stats etc.?
1111
};
1212

13+
struct stats
14+
{
15+
frame_t blocks;
16+
frame_t input_underflows;
17+
frame_t input_overflows;
18+
frame_t output_underflows;
19+
frame_t output_overflows;
20+
};
21+
1322
struct action
1423
{
1524
const enum actiontype type;
@@ -25,7 +34,7 @@ struct action
2534
frame_t total_frames;
2635
frame_t done_frames;
2736
// TODO: something to store the result of the action?
28-
// TODO: number of xruns during the runtime of the current action?
37+
struct stats stats;
2938
// TODO: queue usage: store smallest available write/read size?
3039
const frame_t channels; // Size of the following array
3140
const frame_t mapping[]; // "flexible array member"
@@ -39,6 +48,7 @@ struct state
3948
PaUtilRingBuffer* const action_q; // Queue for incoming commands
4049
PaUtilRingBuffer* const result_q; // Queue for results and command disposal
4150
struct action* actions; // Singly linked list of actions
51+
struct stats stats;
4252
};
4353

4454
int callback(const void* input, void* output, frame_t frameCount

0 commit comments

Comments
 (0)