From a232e67dd873405079b1b444f4f4b00e11bdf16e Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 5 Sep 2019 13:10:00 +0200 Subject: [PATCH] resample: completely fill resampler start with a completely filled resampler so that the first input byte immediately gives an output sample. When then have n_taps/2 leading (almost) 0 samples. Also make the passthrough resampler act like the real resampler by introducing an n_taps/2 delay. --- spa/plugins/audioconvert/resample-native-impl.h | 5 +++-- spa/plugins/audioconvert/resample-native.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/spa/plugins/audioconvert/resample-native-impl.h b/spa/plugins/audioconvert/resample-native-impl.h index 27e012efd..4654d1ea6 100644 --- a/spa/plugins/audioconvert/resample-native-impl.h +++ b/spa/plugins/audioconvert/resample-native-impl.h @@ -59,7 +59,7 @@ void do_resample_##type##_##arch(struct resample *r, \ DEFINE_RESAMPLER(copy,arch) \ { \ struct native_data *data = r->data; \ - uint32_t index, n_taps = data->n_taps; \ + uint32_t index, n_taps = data->n_taps, n_taps2 = n_taps/2; \ uint32_t c, olen = *out_len, ilen = *in_len; \ \ if (r->channels == 0) \ @@ -72,7 +72,8 @@ DEFINE_RESAMPLER(copy,arch) \ for (c = 0; c < r->channels; c++) { \ const float *s = src[c]; \ float *d = dst[c]; \ - memcpy(&d[offs], &s[index], to_copy * sizeof(float)); \ + memcpy(&d[offs], &s[index + n_taps2], \ + to_copy * sizeof(float)); \ } \ index += to_copy; \ offs += to_copy; \ diff --git a/spa/plugins/audioconvert/resample-native.h b/spa/plugins/audioconvert/resample-native.h index 5d4f7654c..731a4c125 100644 --- a/spa/plugins/audioconvert/resample-native.h +++ b/spa/plugins/audioconvert/resample-native.h @@ -243,7 +243,7 @@ static void impl_native_reset (struct resample *r) { struct native_data *d = r->data; memset(d->hist_mem, 0, r->channels * sizeof(float) * d->n_taps * 2); - d->hist = d->n_taps / 2; + d->hist = d->n_taps - 1; d->phase = 0; }