History

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.

Mans Rullgard committed 6 years ago

Commit 9ce4a4a1 parent c04163d1 file · +16 −1Browse files

Unified · Split

src/rate.c+16−1
@@ -337,6 +337,10 @@ static void rate_init( · 336 unmodified lines
337 }337 }
338 338
339 p->num_stages = shift + have_pre_stage + have_arb_stage + have_post_stage;339 p->num_stages = shift + have_pre_stage + have_arb_stage + have_post_stage;
340
341 if (!p->num_stages)
342 return;
343
340 p->stages = calloc(p->num_stages + 1, sizeof(*p->stages));344 p->stages = calloc(p->num_stages + 1, sizeof(*p->stages));
341 for (i = 0; i < p->num_stages; ++i)345 for (i = 0; i < p->num_stages; ++i)
342 p->stages[i].shared = shared;346 p->stages[i].shared = shared;
@@ -496,9 +500,14 @@ static void rate_flush(rate_t * p) · 153 unmodified lines
496 500
497static void rate_close(rate_t * p)501static void rate_close(rate_t * p)
498{502{
499 rate_shared_t * shared = p->stages[0].shared;503 rate_shared_t *shared;
500 int i;504 int i;
501 505
506 if (!p->num_stages)
507 return;
508
509 shared = p->stages[0].shared;
510
502 for (i = 0; i <= p->num_stages; ++i)511 for (i = 0; i <= p->num_stages; ++i)
503 fifo_delete(&p->stages[i].fifo);512 fifo_delete(&p->stages[i].fifo);
504 free(shared->dft_filter[0].coefs);513 free(shared->dft_filter[0].coefs);
@@ -632,6 +641,12 @@ static int start(sox_effect_t * effp) · 127 unmodified lines
632 rate_init(&p->rate, p->shared_ptr, effp->in_signal.rate/out_rate,p->bit_depth,641 rate_init(&p->rate, p->shared_ptr, effp->in_signal.rate/out_rate,p->bit_depth,
633 p->phase, p->bw_0dB_pc, p->anti_aliasing_pc, p->rolloff, !p->given_0dB_pt,642 p->phase, p->bw_0dB_pc, p->anti_aliasing_pc, p->rolloff, !p->given_0dB_pt,
634 p->use_hi_prec_clock, p->coef_interp, p->max_coefs_size, p->noIOpt);643 p->use_hi_prec_clock, p->coef_interp, p->max_coefs_size, p->noIOpt);
644
645 if (!p->rate.num_stages) {
646 lsx_warn("input and output rates too close, skipping resampling");
647 return SOX_EFF_NULL;
648 }
649
635 return SOX_SUCCESS;650 return SOX_SUCCESS;
636}651}
637 652

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t