From 1809b6ae9aadaa3af0c1577b9bf3c88551060827 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 10 May 2022 05:38:38 +0200 Subject: [PATCH] Reset port resampler after freewheeling This clears out any data potently left there by export processing. Previously this could cause an audible click. --- libs/ardour/ardour/audio_port.h | 4 ++++ libs/ardour/ardour/port.h | 1 + libs/ardour/ardour/port_manager.h | 2 ++ libs/ardour/audio_port.cc | 6 ++++++ libs/ardour/audioengine.cc | 3 +++ libs/ardour/port_manager.cc | 7 +++++++ 6 files changed, 23 insertions(+) diff --git a/libs/ardour/ardour/audio_port.h b/libs/ardour/ardour/audio_port.h index c9eaab0259..419d067d54 100644 --- a/libs/ardour/ardour/audio_port.h +++ b/libs/ardour/ardour/audio_port.h @@ -42,6 +42,9 @@ public: void cycle_end (pframes_t); void cycle_split (); + /* reset SRC, clear out any state */ + void reinit (); + Buffer& get_buffer (pframes_t nframes) { return get_audio_buffer (nframes); } @@ -53,6 +56,7 @@ protected: friend class PortManager; AudioPort (std::string const &, PortFlags); + /* special access for PortManager only (hah, C++) */ Sample* engine_get_whole_audio_buffer (); diff --git a/libs/ardour/ardour/port.h b/libs/ardour/ardour/port.h index 9e6bcc2bf0..eaaed6c16d 100644 --- a/libs/ardour/ardour/port.h +++ b/libs/ardour/ardour/port.h @@ -121,6 +121,7 @@ public: virtual void cycle_start (pframes_t); virtual void cycle_end (pframes_t) = 0; virtual void cycle_split () = 0; + virtual void reinit () {} virtual Buffer& get_buffer (pframes_t nframes) = 0; virtual void flush_buffers (pframes_t /*nframes*/) {} virtual void transport_stopped () {} diff --git a/libs/ardour/ardour/port_manager.h b/libs/ardour/ardour/port_manager.h index ecef697de9..922e6be174 100644 --- a/libs/ardour/ardour/port_manager.h +++ b/libs/ardour/ardour/port_manager.h @@ -293,6 +293,8 @@ protected: */ void cycle_end (pframes_t nframes, Session* s = 0); + void reinit (); + void cycle_end_fade_out (gain_t, gain_t, pframes_t, Session* s = 0); static std::string port_info_file (); diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc index 313eeadf29..615173fe95 100644 --- a/libs/ardour/audio_port.cc +++ b/libs/ardour/audio_port.cc @@ -127,6 +127,12 @@ AudioPort::cycle_split () { } +void +AudioPort::reinit () +{ + _src.reset (); +} + AudioBuffer& AudioPort::get_audio_buffer (pframes_t nframes) { diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index 59b3650955..7ced5d813e 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -1483,6 +1483,9 @@ AudioEngine::freewheel_callback (bool onoff) { DEBUG_TRACE (DEBUG::BackendCallbacks, string_compose (X_("freewheel callback onoff %1\n"), onoff)); _freewheeling = onoff; + if (!_freewheeling) { + PortManager::reinit (); + } } void diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index 260ac21080..1186150153 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -1183,6 +1183,13 @@ PortManager::silence (pframes_t nframes, Session* s) } } } +void +PortManager::reinit () +{ + for (auto const& p : *_ports.reader ()) { + p.second->reinit (); + } +} void PortManager::silence_outputs (pframes_t nframes)