diff --git a/libs/ardour/ardour/audio_port.h b/libs/ardour/ardour/audio_port.h index bf4b8efe1e..c9eaab0259 100644 --- a/libs/ardour/ardour/audio_port.h +++ b/libs/ardour/ardour/audio_port.h @@ -47,6 +47,7 @@ public: } AudioBuffer& get_audio_buffer (pframes_t nframes); + void set_buffer_size (pframes_t nframes); protected: friend class PortManager; diff --git a/libs/ardour/ardour/port.h b/libs/ardour/ardour/port.h index 427a510d22..d2fb0ed03f 100644 --- a/libs/ardour/ardour/port.h +++ b/libs/ardour/ardour/port.h @@ -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; } diff --git a/libs/ardour/ardour/port_manager.h b/libs/ardour/ardour/port_manager.h index 9a156c147e..46e6dc77ad 100644 --- a/libs/ardour/ardour/port_manager.h +++ b/libs/ardour/ardour/port_manager.h @@ -223,6 +223,8 @@ class LIBARDOUR_API PortManager void fill_midi_port_info_locked (); void filter_midi_ports (std::vector&, MidiPortFlags, MidiPortFlags); + + void set_port_buffer_sizes (pframes_t); }; diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc index 878f6c2625..6d0a90a187 100644 --- a/libs/ardour/audio_port.cc +++ b/libs/ardour/audio_port.cc @@ -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) { diff --git a/libs/ardour/audioengine.cc b/libs/ardour/audioengine.cc index e6961af875..73e48f1e93 100644 --- a/libs/ardour/audioengine.cc +++ b/libs/ardour/audioengine.cc @@ -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; diff --git a/libs/ardour/port.cc b/libs/ardour/port.cc index 4caace07c0..03210baf80 100644 --- a/libs/ardour/port.cc +++ b/libs/ardour/port.cc @@ -26,13 +26,13 @@ #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); } diff --git a/libs/ardour/port_manager.cc b/libs/ardour/port_manager.cc index 8d9f47cf84..75d93af320 100644 --- a/libs/ardour/port_manager.cc +++ b/libs/ardour/port_manager.cc @@ -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 writer (ports); boost::shared_ptr 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 all = ports.reader(); + + for (Ports::iterator p = all->begin(); p != all->end(); ++p) { + p->second->set_buffer_size (n); + } +}