@@ -140,21 +140,20 @@ int callback(const void* input, void* output, frame_t frameCount
140140 device_data = (float * )input + offset * state -> input_channels ;
141141 }
142142
143- frame_t frames = 0 ;
143+ frame_t frames = action -> total_frames - action -> done_frames ;
144144
145- if (using_buffer )
145+ if (frameCount < frames )
146146 {
147- frames = action -> total_frames - action -> done_frames ;
148- if (frameCount < frames )
149- {
150- frames = frameCount ;
151- }
152- if (frames + offset > frameCount )
153- {
154- assert (frameCount > offset );
155- frames = frameCount - offset ;
156- }
147+ frames = frameCount ;
148+ }
149+ if (frames + offset > frameCount )
150+ {
151+ assert (frameCount > offset );
152+ frames = frameCount - offset ;
153+ }
157154
155+ if (using_buffer )
156+ {
158157 float * buffer = action -> buffer + action -> done_frames * action -> channels ;
159158 action -> done_frames += frames ;
160159 if (playing )
@@ -179,16 +178,9 @@ int callback(const void* input, void* output, frame_t frameCount
179178 device_data += state -> input_channels ;
180179 }
181180 }
182- if (action -> done_frames == action -> total_frames )
183- {
184- remove_action (actionaddr , state );
185- continue ;
186- }
187181 }
188182 else if (using_ringbuffer )
189183 {
190- // TODO: continue to ignore action->total_frames?
191-
192184 float * block1 = NULL ;
193185 float * block2 = NULL ;
194186 ring_buffer_size_t size1 = 0 ;
@@ -198,7 +190,7 @@ int callback(const void* input, void* output, frame_t frameCount
198190 if (playing )
199191 {
200192 totalsize = PaUtil_GetRingBufferReadRegions (action -> ringbuffer
201- , (ring_buffer_size_t )( frameCount - offset )
193+ , (ring_buffer_size_t )frames
202194 , (void * * )& block1 , & size1 , (void * * )& block2 , & size2 );
203195
204196 while (size1 -- )
@@ -223,7 +215,7 @@ int callback(const void* input, void* output, frame_t frameCount
223215 else if (recording )
224216 {
225217 totalsize = PaUtil_GetRingBufferWriteRegions (action -> ringbuffer
226- , (ring_buffer_size_t )( frameCount - offset )
218+ , (ring_buffer_size_t )frames
227219 , (void * * )& block1 , & size1 , (void * * )& block2 , & size2 );
228220
229221 while (size1 -- )
@@ -246,7 +238,7 @@ int callback(const void* input, void* output, frame_t frameCount
246238 PaUtil_AdvanceRingBufferWriteIndex (action -> ringbuffer , totalsize );
247239 }
248240
249- if (totalsize < frameCount - offset )
241+ if (totalsize < frames )
250242 {
251243 // Ring buffer is empty or full
252244
@@ -256,6 +248,12 @@ int callback(const void* input, void* output, frame_t frameCount
256248 continue ;
257249 }
258250 }
251+
252+ if (action -> done_frames == action -> total_frames )
253+ {
254+ remove_action (actionaddr , state );
255+ continue ;
256+ }
259257 actionaddr = & (action -> next );
260258 }
261259 return paContinue ;
0 commit comments