ref: 9ce4a4abbea00c1ef12be901441b83dff458f8b8
parent: c04163d3edba15e39a2e25423a4bbb046be3423e
author: Mans Rullgard <mans@mansr.com>
date: Tue Aug 11 07:46:02 EDT 2020
rate: fix crash when input and output rates are very close [bug #334] If the rate factor is too close to 1, resampling isn't possible. Detect this and bypass the rate effect. This only happens if the output rate is within about 50 ppb of the input, so it is unlikely to occur in normal use.
--- a/src/rate.c
+++ b/src/rate.c
@@ -337,6 +337,10 @@
}
p->num_stages = shift + have_pre_stage + have_arb_stage + have_post_stage;
+
+ if (!p->num_stages)
+ return;
+
p->stages = calloc(p->num_stages + 1, sizeof(*p->stages));
for (i = 0; i < p->num_stages; ++i)
p->stages[i].shared = shared;
@@ -496,9 +500,14 @@
static void rate_close(rate_t * p)
{
- rate_shared_t * shared = p->stages[0].shared;
+ rate_shared_t *shared;
int i;
+ if (!p->num_stages)
+ return;
+
+ shared = p->stages[0].shared;
+
for (i = 0; i <= p->num_stages; ++i)
fifo_delete(&p->stages[i].fifo);
free(shared->dft_filter[0].coefs);
@@ -632,6 +641,12 @@
rate_init(&p->rate, p->shared_ptr, effp->in_signal.rate/out_rate,p->bit_depth,
p->phase, p->bw_0dB_pc, p->anti_aliasing_pc, p->rolloff, !p->given_0dB_pt,
p->use_hi_prec_clock, p->coef_interp, p->max_coefs_size, p->noIOpt);
+
+ if (!p->rate.num_stages) {
+ lsx_warn("input and output rates too close, skipping resampling");
+ return SOX_EFF_NULL;
+ }
+
return SOX_SUCCESS;
}