@@ -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+
3646int 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 ;
0 commit comments