@@ -79,14 +79,15 @@ def on_key_release(self, event):
7979 # TODO: fade out (both recording and playback)?
8080 assert sample .action is not None
8181 if sample .action .type == rtmixer .RECORD_RINGBUFFER :
82- # TODO: check for errors/xruns? check for rinbuffer overflow?
8382 # Stop recording
83+ sample .keep_alive = sample .action
8484 sample .action = self .stream .cancel (sample .action )
8585 # A CANCEL action is returned which is checked by poll_ringbuffer()
8686 elif sample .action .type == rtmixer .PLAY_BUFFER :
8787 # TODO: check for errors/xruns?
8888 # Stop playback (if still running)
8989 if sample .action in self .stream .actions :
90+ sample .keep_alive = sample .action
9091 sample .action = self .stream .cancel (sample .action )
9192 # TODO: do something with sample.action?
9293 elif sample .action .type == rtmixer .CANCEL :
@@ -99,17 +100,22 @@ def poll_ringbuffer(self, sample):
99100 assert sample .action is not None
100101 assert sample .action .type in (rtmixer .RECORD_RINGBUFFER ,
101102 rtmixer .CANCEL )
102- # TODO: check for errors? is everything still working OK?
103- # TODO: check for xruns?
104- chunk = sample .ringbuffer .read ()
105- if chunk :
106- sample .buffer .extend (chunk )
107-
108103 if sample .action not in self .stream .actions :
109104 # Recording is finished
110- # TODO: check for errors in CANCEL action?
111105 self .rec_counter -= 1
106+ if sample .action .type == rtmixer .CANCEL :
107+ # TODO: check for errors in CANCEL action?
108+ action = sample .action .action
109+ else :
110+ action = sample .action
111+ assert action .type == rtmixer .RECORD_RINGBUFFER
112+ if action .done_frames != action .total_frames :
113+ print ('error while recording (ringbuffer too short?)' )
114+ # TODO: check for xruns?
115+ # NB: We make sure that the ringbuffer is emptied after recording:
116+ sample .buffer .extend (sample .ringbuffer .read ())
112117 else :
118+ sample .buffer .extend (sample .ringbuffer .read ())
113119 # Set polling rate based on input latency (which may change!):
114120 self .after (int (self .stream .latency [0 ] * 1000 ),
115121 self .poll_ringbuffer , sample )
0 commit comments