diff options
author | Rob Sykes <robs@users.sourceforge.net> | 2015-08-20 16:13:22 +0300 |
---|---|---|
committer | Rob Sykes <robs@users.sourceforge.net> | 2015-08-20 16:13:22 +0300 |
commit | fa5a48198754be33ddfe40624dafad929b61648d (patch) | |
tree | 7d6fe48e2ee0bbe97211ac5a43b3f3707dcc98b8 | |
parent | 755012f51557449ed278f2900e2670b2986d6f3e (diff) |
fix soxr_delay returning a negative number after end-of-input has been indicated
-rw-r--r-- | src/rate.h | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -621,17 +621,19 @@ static void rate_flush(rate_t * p) uint64_t samples_out = (uint64_t)((double)p->samples_in / p->factor + .5); #endif size_t remaining = (size_t)(samples_out - p->samples_out); - sample_t * buff = calloc(1024, sizeof(*buff)); - if (samples_out > p->samples_out) { + if ((size_t)fifo_occupancy(fifo) < remaining) { + uint64_t samples_in = p->samples_in; + sample_t * buff = calloc(1024, sizeof(*buff)); + while ((size_t)fifo_occupancy(fifo) < remaining) { rate_input(p, buff, 1024); rate_process(p); } fifo_trim_to(fifo, (int)remaining); - p->samples_in = 0; + p->samples_in = samples_in; + free(buff); } - free(buff); } static void rate_close(rate_t * p) @@ -663,10 +665,10 @@ static double rate_delay(rate_t * p) { #if defined _MSC_VER && _MSC_VER == 1200 double samples_out = (double)(int64_t)p->samples_in / p->factor; - return samples_out - (double)(int64_t)p->samples_out; + return max(0, samples_out - (double)(int64_t)p->samples_out); #else double samples_out = (double)p->samples_in / p->factor; - return samples_out - (double)p->samples_out; + return max(0, samples_out - (double)p->samples_out); #endif } |