From 1bc07f860fa7f01763586f45b7fb2e53cd1c2557 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 13 Jun 2016 16:26:19 +0200 Subject: Initialise the zita resampler correctly to avoid latency. --- src/chresampler.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/chresampler.cc b/src/chresampler.cc index c3c19bf..94737c6 100644 --- a/src/chresampler.cc +++ b/src/chresampler.cc @@ -76,9 +76,20 @@ void CHResampler::setup(double input_fs, double output_fs) DEBUG(resampler, "Using zita-resampler (%d -> %d)", (int)input_fs, (int)output_fs); - int hlen = 72; // 16 ≤ hlen ≤ 96 // delay is 2 * hlen, 72 corresponds to delay introduced by SRC. + int hlen = 72; // 16 ≤ hlen ≤ 96 + + prv->zita.reset(); prv->zita.setup(input_fs, output_fs, nchan, hlen); + + std::size_t null_size = prv->zita.inpsize() / 2 - 1; + prv->zita.inp_data = nullptr; + prv->zita.inp_count = null_size; + + prv->zita.out_data = nullptr; + prv->zita.out_count = 1024 * 1024; + + prv->zita.process(); #elif defined(USE_SRC) DEBUG(resampler, "Using libsamplerate (%d -> %d)", (int)input_fs, (int)output_fs); @@ -141,8 +152,13 @@ void CHResampler::process() std::size_t CHResampler::getLatency() const { + if (input_fs == output_fs) + { + return 0; + } + #if defined(USE_ZITA) - return prv->zita.inpdist(); + return 0; #elif defined(USE_SRC) return 0; // TODO? #endif -- cgit v1.2.3