resize audio port _data buffer based on current buffer size
authorPaul Davis <paul@linuxaudiosystems.com>
Thu, 11 Jul 2019 05:39:02 +0000 (23:39 -0600)
committerPaul Davis <paul@linuxaudiosystems.com>
Tue, 17 Sep 2019 23:14:39 +0000 (17:14 -0600)
libs/ardour/ardour/audio_port.h
libs/ardour/ardour/port.h
libs/ardour/ardour/port_manager.h
libs/ardour/audio_port.cc
libs/ardour/audioengine.cc
libs/ardour/port.cc
libs/ardour/port_manager.cc

index bf4b8efe1e015583f85236f508fb7b404de0ee43..c9eaab025919764673a1150796968eaca4997e40 100644 (file)
@@ -47,6 +47,7 @@ public:
        }
 
        AudioBuffer& get_audio_buffer (pframes_t nframes);
+       void set_buffer_size (pframes_t nframes);
 
 protected:
        friend class PortManager;
index 427a510d2200a38f26bf011ad6f9adfe2a502160..d2fb0ed03fb48097d19709ee3e05c2b31f802e8e 100644 (file)
@@ -123,6 +123,7 @@ public:
        virtual void flush_buffers (pframes_t /*nframes*/) {}
        virtual void transport_stopped () {}
        virtual void realtime_locate () {}
+       virtual void set_buffer_size (pframes_t) {}
 
        bool physically_connected () const;
        uint32_t externally_connected () const { return _externally_connected; }
index 9a156c147e901525dca09766593f5f1bd3d4e312..46e6dc77ad8159354735a8a0f4a6fa5139a271d6 100644 (file)
@@ -223,6 +223,8 @@ class LIBARDOUR_API PortManager
        void fill_midi_port_info_locked ();
 
        void filter_midi_ports (std::vector<std::string>&, MidiPortFlags, MidiPortFlags);
+
+       void set_port_buffer_sizes (pframes_t);
 };
 
 
index 878f6c2625ed89a081dc80c7cc0d95ddf8239011..6d0a90a1879d85a0ca8e7f1f035be1a3331c438e 100644 (file)
@@ -29,6 +29,7 @@
 #include "ardour/audio_port.h"
 #include "ardour/data_type.h"
 #include "ardour/port_engine.h"
+#include "ardour/rc_configuration.h"
 
 using namespace ARDOUR;
 using namespace std;
@@ -39,19 +40,26 @@ using namespace std;
 AudioPort::AudioPort (const std::string& name, PortFlags flags)
        : Port (name, DataType::AUDIO, flags)
        , _buffer (new AudioBuffer (0))
+       , _data (0)
 {
        assert (name.find_first_of (':') == string::npos);
-       cache_aligned_malloc ((void**) &_data, sizeof (Sample) * 8192);
        _src.setup (_resampler_quality);
        _src.set_rrfilt (10);
 }
 
 AudioPort::~AudioPort ()
 {
-       cache_aligned_free (_data);
+       if (_data) cache_aligned_free (_data);
        delete _buffer;
 }
 
+void
+AudioPort::set_buffer_size (pframes_t nframes)
+{
+       if (_data) cache_aligned_free (_data);
+       cache_aligned_malloc ((void**) &_data, sizeof (Sample) * lrint (floor (nframes * Config->get_max_transport_speed())));
+}
+
 void
 AudioPort::cycle_start (pframes_t nframes)
 {
index e6961af875fd7030fff9d876e5bb9cd403cd3acc..73e48f1e937c6e400464dc72291149f10abf0add 100644 (file)
@@ -181,6 +181,8 @@ AudioEngine::sample_rate_change (pframes_t nframes)
 int
 AudioEngine::buffer_size_change (pframes_t bufsiz)
 {
+       set_port_buffer_sizes (bufsiz);
+
        if (_session) {
                _session->set_block_size (bufsiz);
                last_monitor_check = 0;
index 4caace07c08fcd6cf093fc850b7f698a6a8a1c70..03210baf80dab178e93ea5cb7261c22fbdff2b43 100644 (file)
 #include "pbd/compose.h"
 #include "pbd/error.h"
 #include "pbd/failed_constructor.h"
+#include "pbd/i18n.h"
 
 #include "ardour/audioengine.h"
 #include "ardour/debug.h"
 #include "ardour/port.h"
 #include "ardour/port_engine.h"
-
-#include "pbd/i18n.h"
+#include "ardour/rc_configuration.h"
 
 using namespace std;
 using namespace ARDOUR;
@@ -645,10 +645,11 @@ Port::set_state (const XMLNode& node, int)
 /*static*/ void
 Port::set_speed_ratio (double s) {
        /* see VMResampler::set_rratio() for min/max range */
-       _speed_ratio = std::min (16.0, std::max (0.5, s));
+       _speed_ratio = std::min ((double) Config->get_max_transport_speed(), std::max (0.5, s));
 }
 
 /*static*/ void
-Port::set_cycle_samplecnt (pframes_t n) {
+Port::set_cycle_samplecnt (pframes_t n)
+{
        _cycle_nframes = floor (n * _speed_ratio);
 }
index 8d9f47cf84770efb8273428b0480d65526dc2943..75d93af320b5b50bf57b0c3aba865fa602a6c2be 100644 (file)
@@ -420,12 +420,13 @@ PortManager::register_port (DataType dtype, const string& portname, bool input,
                        throw PortRegistrationFailure (string_compose ("unable to create port '%1': %2", portname, _("(unknown type)")));
                }
 
+               newport->set_buffer_size (AudioEngine::instance()->samples_per_cycle());
+
                RCUWriter<Ports> writer (ports);
                boost::shared_ptr<Ports> ps = writer.get_copy ();
                ps->insert (make_pair (make_port_name_relative (portname), newport));
 
                /* writer goes out of scope, forces update */
-
        }
 
        catch (PortRegistrationFailure& err) {
@@ -1353,3 +1354,14 @@ PortManager::fill_midi_port_info_locked ()
 
        midi_info_dirty = false;
 }
+
+void
+PortManager::set_port_buffer_sizes (pframes_t n)
+{
+
+       boost::shared_ptr<Ports> all = ports.reader();
+
+       for (Ports::iterator p = all->begin(); p != all->end(); ++p) {
+               p->second->set_buffer_size (n);
+       }
+}