shithub: libsamplerate

Download patch

ref: 0fcc45fde036246ed3215f767cc038ba75838168
parent: d5b8a861ce138f553752734022ca23640acae5a3
author: Flamefire <git@grundis.de>
date: Sun Aug 25 15:59:00 EDT 2019

Increase buffer size for SINC converters

To fulfil the condition `samples_in_hand <= half_filter_chan_len` after
the first call to prepare_data the buffer size `b_len` must be bigger
than 3*half_filter_chan_len.
Tracing that back results in the implemented calculation.
Fixes #92

--- a/src/src_sinc.c
+++ b/src/src_sinc.c
@@ -212,9 +212,10 @@
 	** a better way. Need to look at prepare_data () at the same time.
 	*/
 
-	temp_filter.b_len = (int) lrint (2.5 * temp_filter.coeff_half_len / (temp_filter.index_inc * 1.0) * SRC_MAX_RATIO) ;
+	temp_filter.b_len = 3 * (int) lrint ((temp_filter.coeff_half_len + 2.0) / temp_filter.index_inc * SRC_MAX_RATIO + 1) ;
 	temp_filter.b_len = MAX (temp_filter.b_len, 4096) ;
 	temp_filter.b_len *= temp_filter.channels ;
+	temp_filter.b_len += 1 ; // There is a <= check against samples_in_hand requiring a buffer bigger than the calculation above
 
 	if ((filter = ZERO_ALLOC (SINC_FILTER, sizeof (SINC_FILTER) + sizeof (filter->buffer [0]) * (temp_filter.b_len + temp_filter.channels))) == NULL)
 		return SRC_ERR_MALLOC_FAILED ;