From f02e8d34e39d7acd2bdb0aa3240adf86303b9db0 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 22 May 2022 18:21:16 +0200 Subject: [PATCH] Make resampler reset idempotent --- libs/ardour/audio_port.cc | 1 - libs/zita-resampler/vmresampler.cc | 6 ++++++ libs/zita-resampler/zita-resampler/vmresampler.h | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc index 615173fe95..c096cd37fb 100644 --- a/libs/ardour/audio_port.cc +++ b/libs/ardour/audio_port.cc @@ -69,7 +69,6 @@ AudioPort::cycle_start (pframes_t nframes) _buffer->prepare (); } else if (!externally_connected ()) { /* ardour internal port, just silence input, don't resample */ - // TODO reset resampler only once _src.reset (); memset (_data, 0, _cycle_nframes * sizeof (float)); } else { diff --git a/libs/zita-resampler/vmresampler.cc b/libs/zita-resampler/vmresampler.cc index 4e10ac7854..9193d09cd6 100644 --- a/libs/zita-resampler/vmresampler.cc +++ b/libs/zita-resampler/vmresampler.cc @@ -33,6 +33,7 @@ VMResampler::VMResampler (void) , _buff (0) , _c1 (0) , _c2 (0) + , _reset (false) { reset (); } @@ -91,6 +92,7 @@ VMResampler::clear (void) _pstep = 0; _qstep = 0; _wstep = 1; + _reset = false; reset (); } @@ -144,6 +146,7 @@ int VMResampler::reset (void) { if (!_table) return 1; + if (_reset) return 0; inp_count = 0; out_count = 0; @@ -155,6 +158,7 @@ VMResampler::reset (void) memset (_buff, 0, sizeof(float) * (_nread + 249)); _nread -= _table->_hl - 1; + _reset = true; return 0; } @@ -175,6 +179,8 @@ VMResampler::process (void) dp = _pstep; n = 2 * hl - nr; + _reset = false; + #if 1 /* optimized full-cycle no-resampling */ if (dp == np && _qstep == np && nr == 1 && inp_count == out_count) { diff --git a/libs/zita-resampler/zita-resampler/vmresampler.h b/libs/zita-resampler/zita-resampler/vmresampler.h index 52789ebff1..b8efd35625 100644 --- a/libs/zita-resampler/zita-resampler/vmresampler.h +++ b/libs/zita-resampler/zita-resampler/vmresampler.h @@ -66,6 +66,7 @@ private: float *_buff; float *_c1; float *_c2; + bool _reset; }; };