From dc01b294a24c9684b29b4486907eff5e2ebae5fa Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 2 Apr 2019 23:06:46 +0200 Subject: [PATCH] resample: return the number of consumed samples We need to return the number of consumed samples, even when we don't start from the first sample in the buffer. Add some more logging. --- spa/plugins/audioconvert/resample-native-impl.h | 4 ++-- spa/plugins/audioconvert/resample-native.h | 17 +++++++++++------ spa/plugins/audioconvert/resample.c | 5 +++-- spa/plugins/audioconvert/resample.h | 2 ++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/spa/plugins/audioconvert/resample-native-impl.h b/spa/plugins/audioconvert/resample-native-impl.h index ba002c565..ca1e2729e 100644 --- a/spa/plugins/audioconvert/resample-native-impl.h +++ b/spa/plugins/audioconvert/resample-native-impl.h @@ -116,7 +116,7 @@ DEFINE_RESAMPLER(full,arch) \ inner_product_##arch(&d[o], ip, taps, n_taps); \ } \ } \ - *in_len = index - data->index; \ + *in_len = index; \ *out_len = o; \ data->index = index; \ data->phase = phase; \ @@ -163,7 +163,7 @@ DEFINE_RESAMPLER(inter,arch) \ inner_product_ip_##arch(&d[o], ip, t0, t1, x, n_taps); \ } \ } \ - *in_len = index - data->index; \ + *in_len = index; \ *out_len = o; \ data->index = index; \ data->phase = phase; \ diff --git a/spa/plugins/audioconvert/resample-native.h b/spa/plugins/audioconvert/resample-native.h index 82d0a0571..1a8e91fa4 100644 --- a/spa/plugins/audioconvert/resample-native.h +++ b/spa/plugins/audioconvert/resample-native.h @@ -142,8 +142,8 @@ static void impl_native_process(struct resample *r, const float **s = (const float **)src; uint32_t c, refill, hist, in, out, remain; - out = refill = in = 0; hist = data->hist; + refill = 0; if (hist) { /* first work on the history if any. */ @@ -169,37 +169,42 @@ static void impl_native_process(struct resample *r, in = hist + refill; out = *out_len; data->func(r, (const void**)history, &in, dst, 0, &out); + spa_log_trace_fp(r->log, "native %p: in:%d/%d out %d/%d idx:%d hist:%d", + r, hist + refill, in, *out_len, out, data->index, hist); + } else { + out = in = 0; } - if (data->index >= hist) { + if (in >= hist) { /* we are past the history and can now work on the new * input data */ data->index -= hist; in = *in_len; data->func(r, src, &in, dst, out, out_len); + spa_log_trace_fp(r->log, "native %p: in:%d/%d out %d/%d", + r, *in_len, in, *out_len, out); remain = *in_len - in; - if (remain < n_taps) { + if (remain > 0 && remain < n_taps) { /* not enough input data remaining for more output, * copy to history */ for (c = 0; c < r->channels; c++) memcpy(history[c], &s[c][in], remain * sizeof(float)); } else { /* we have enough input data remaining to produce - * more output ask to resubmit. else we copy the - * remainder to the history */ + * more output ask to resubmit. */ remain = 0; *in_len = in; } } else { /* we are still working on the history */ + *out_len = out; remain = hist - in; if (*in_len < n_taps) { /* not enough input data, add it to the history because * resubmitting it is not going to make progress. * We copied this into the history above. */ remain += refill; - *in_len = refill; } else { /* input has enough data to possibly produce more output * from the history so ask to resubmit */ diff --git a/spa/plugins/audioconvert/resample.c b/spa/plugins/audioconvert/resample.c index 08f78ae76..33764b64b 100644 --- a/spa/plugins/audioconvert/resample.c +++ b/spa/plugins/audioconvert/resample.c @@ -153,6 +153,7 @@ static int setup_convert(struct impl *this, this->resample.channels = src_info->info.raw.channels; this->resample.i_rate = src_info->info.raw.rate; this->resample.o_rate = dst_info->info.raw.rate; + this->resample.log = this->log; if (this->monitor) err = impl_peaks_init(&this->resample); @@ -749,8 +750,8 @@ static int impl_node_process(struct spa_node *node) spa_return_val_if_fail(outio != NULL, -EIO); spa_return_val_if_fail(inio != NULL, -EIO); - spa_log_trace_fp(this->log, NAME " %p: status %d %d %p", - this, inio->status, outio->status, outport->io_control); + spa_log_trace_fp(this->log, NAME " %p: status %d %d %d", + this, inio->status, outio->status, inio->buffer_id); if (outport->io_control) process_control(this, outport, &outport->io_control->sequence); diff --git a/spa/plugins/audioconvert/resample.h b/spa/plugins/audioconvert/resample.h index 5344fe81e..9b52d19aa 100644 --- a/spa/plugins/audioconvert/resample.h +++ b/spa/plugins/audioconvert/resample.h @@ -26,12 +26,14 @@ #define RESAMPLE_H #include +#include struct resample { uint32_t cpu_flags; uint32_t channels; uint32_t i_rate; uint32_t o_rate; + struct spa_log *log; void (*free) (struct resample *r); void (*update_rate) (struct resample *r, double rate);