src_simple does not produce any output for small ratios with SRC_SINC_*
Closed this issue · 0 comments
Flamefire commented
Documenting bug found in #87:
When a ratio smaller or equal to 1/214
is used with src_simple
and one of the SINC converters no output is produced no matter how big the input is.
Code reproducing this:
static void
src_simple_produces_output_test (int converter, int channels, double src_ratio)
{
// Choose a suitable number of frames.
// Here set to something VERY high to prove the point, do not use for unit tests!
const long NUM_FRAMES = 100000000;
int error;
float *input = calloc (NUM_FRAMES * channels, sizeof (float));
float *output = calloc (NUM_FRAMES * channels, sizeof (float));
SRC_DATA src_data;
memset (&src_data, 0, sizeof (src_data)) ;
src_data.data_in = input;
src_data.data_out = output;
src_data.input_frames = NUM_FRAMES;
src_data.output_frames = NUM_FRAMES;
src_data.src_ratio = src_ratio;
if ((error = src_simple (&src_data, converter, channels)))
{ printf ("\n\nLine %d : %s\n\n", __LINE__, src_strerror (error)) ;
exit (1) ;
} ;
if (src_data.input_frames_used == 0)
{ printf ("\n\nLine %d : No input frames used. Converter=%d, channels = %d, ratio=%g\n\n", __LINE__, converter, channels, src_ratio) ;
exit (1) ;
} ;
if (src_data.output_frames_gen == 0)
{ printf ("\n\nLine %d : No output frames generated. Converter=%d, channels = %d, ratio=%g\n\n", __LINE__, converter, channels, src_ratio) ;
exit (1) ;
} ;
free(input);
free(output);
}
// Call
src_simple_produces_output_test(SRC_SINC_FASTEST, 1, 1./214);
// Output: No output frames generated. Converter=2, channels = 1, ratio=0.0046729
Using the advanced method (repeatable callingsrc_process
with chunks of the input) the first output sample for a ratio of 1/215
is produced after about 4992 input frames, so the transport delay does not seem to be the cause. Also increasing the input frame count does not change anything.
Possible cause (from most likely to least likely):
- Wrong
b_len
calculated at https://github.com/erikd/libsamplerate/blob/1b3d5b1114b6cac1baed0a1a24ea8bb451cfc1b1/src/src_sinc.c#L215 - Wrong
len
calculated at https://github.com/erikd/libsamplerate/blob/1b3d5b1114b6cac1baed0a1a24ea8bb451cfc1b1/src/src_sinc.c#L1178 - (unlikely) Wrong condition (triggers with src_simple on first encounter) at https://github.com/erikd/libsamplerate/blob/1b3d5b1114b6cac1baed0a1a24ea8bb451cfc1b1/src/src_sinc.c#L387