13
0

resize audio port _data buffer based on current buffer size

This commit is contained in:
Paul Davis 2019-07-10 23:39:02 -06:00
parent 455039255b
commit ea30642ae3
7 changed files with 34 additions and 7 deletions

View File

@ -47,6 +47,7 @@ public:
}
AudioBuffer& get_audio_buffer (pframes_t nframes);
void set_buffer_size (pframes_t nframes);
protected:
friend class PortManager;

View 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; }

View 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);
};

View 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)
{

View 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;

View File

@ -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);
}

View 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);
}
}