Fixing assert due to failure of src_process
authorBill Lash <william.lash@gmail.com>
Fri, 28 Jun 2019 03:35:46 +0000 (22:35 -0500)
committerDavid Griffith <dave@661.org>
Sat, 29 Jun 2019 00:37:07 +0000 (17:37 -0700)
Based on discussion with @borg323 src_process was leaving the
input data pointer at an old value if it ran out of input data and
completed the output buffer in the same call.  Fixed it by setting
the input data pointer back to the beginning, but since the number
of input frames was set to 0, it wouldn't read any data from it.

src/curses/ux_audio.c

index 3db196e52de57442645064fa7b59b630bb026a58..b700d5df9a1390cc2cd22e65c8b5ac31d4aa91a9 100644 (file)
@@ -291,20 +291,18 @@ resampler_step(resampler_t *rsmp, float *block)
         rsmp->src_data.data_in      = rsmp->input;
         rsmp->src_data.input_frames = smps;
     }
-
-    if (src_process(rsmp->src_state, &rsmp->src_data))
-    {
-       /*
-        * src_process returned an error, don't update
-        * the rsmp structure, and tell the caller to
-        * re-run the resampler
-        */
-       return 1;
-    }
+    int err = src_process(rsmp->src_state, &rsmp->src_data);
+    assert(err == 0);
 
     int u_in = rsmp->src_data.input_frames_used;
     rsmp->src_data.data_in      += 2*u_in;
     rsmp->src_data.input_frames -= u_in;
+    /*
+     * If input buffer is empty, reset data_in pointer just in case
+     * the output buffer is also full.
+     */
+    if(rsmp->src_data.input_frames == 0)
+       rsmp->src_data.data_in      = rsmp->input;
     int g_out = rsmp->src_data.output_frames_gen;
     rsmp->src_data.data_out      += 2*g_out;
     rsmp->src_data.output_frames -= g_out;