Optimise BufferSet::attach_buffers code to avoid memory allocation in the RT thread and speed things up a bit.
git-svn-id: svn://localhost/ardour2/branches/3.0@8490 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
f7cef2016f
commit
dd7caa0165
|
@ -66,7 +66,8 @@ public:
|
|||
|
||||
void clear();
|
||||
|
||||
void attach_buffers(PortSet& ports, framecnt_t nframes, framecnt_t offset = 0);
|
||||
void attach_buffers (PortSet& ports);
|
||||
void get_jack_port_addresses (PortSet &, framecnt_t, framecnt_t);
|
||||
|
||||
/* the capacity here is a size_t and has a different interpretation depending
|
||||
on the DataType of the buffers. for audio, its a frame count. for MIDI
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "ardour/session_object.h"
|
||||
#include "ardour/types.h"
|
||||
#include "ardour/utils.h"
|
||||
#include "ardour/buffer_set.h"
|
||||
|
||||
class XMLNode;
|
||||
|
||||
|
@ -50,7 +51,6 @@ namespace ARDOUR {
|
|||
class Amp;
|
||||
class AudioEngine;
|
||||
class AudioPort;
|
||||
class BufferSet;
|
||||
class Bundle;
|
||||
class MidiPort;
|
||||
class PeakMeter;
|
||||
|
@ -249,6 +249,8 @@ class IO : public SessionObject, public Latent
|
|||
|
||||
void setup_bundle ();
|
||||
std::string bundle_channel_name (uint32_t, uint32_t, DataType) const;
|
||||
|
||||
BufferSet _buffers;
|
||||
};
|
||||
|
||||
} // namespace ARDOUR
|
||||
|
|
|
@ -82,10 +82,12 @@ BufferSet::clear()
|
|||
#endif
|
||||
}
|
||||
|
||||
/** Make this BufferSet a direct mirror of a PortSet's buffers.
|
||||
/** Set up this BufferSet so that its data structures mirror a PortSet's buffers.
|
||||
* This is quite expensive and not RT-safe, so it should not be called in a process context;
|
||||
* get_jack_port_addresses() will fill in a structure set up by this method.
|
||||
*/
|
||||
void
|
||||
BufferSet::attach_buffers (PortSet& ports, framecnt_t nframes, framecnt_t offset)
|
||||
BufferSet::attach_buffers (PortSet& ports)
|
||||
{
|
||||
clear();
|
||||
|
||||
|
@ -95,7 +97,7 @@ BufferSet::attach_buffers (PortSet& ports, framecnt_t nframes, framecnt_t offset
|
|||
|
||||
for (PortSet::iterator p = ports.begin(*t); p != ports.end(*t); ++p) {
|
||||
assert(p->type() == *t);
|
||||
v.push_back(&(p->get_buffer(nframes, offset)));
|
||||
v.push_back (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,6 +107,32 @@ BufferSet::attach_buffers (PortSet& ports, framecnt_t nframes, framecnt_t offset
|
|||
_is_mirror = true;
|
||||
}
|
||||
|
||||
/** Write the JACK port addresses from a PortSet into our data structures. This
|
||||
* call assumes that attach_buffers() has already been called for the same PortSet.
|
||||
* Does not allocate, so RT-safe.
|
||||
*/
|
||||
void
|
||||
BufferSet::get_jack_port_addresses (PortSet& ports, framecnt_t nframes, framecnt_t offset)
|
||||
{
|
||||
assert (_count == ports.count ());
|
||||
assert (_available == ports.count ());
|
||||
assert (_is_mirror);
|
||||
|
||||
assert (_buffers.size() == DataType::num_types);
|
||||
|
||||
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
|
||||
BufferVec& v = _buffers[*t];
|
||||
|
||||
assert (v.size() == ports.num_ports (*t));
|
||||
|
||||
int i = 0;
|
||||
for (PortSet::iterator p = ports.begin(*t); p != ports.end(*t); ++p) {
|
||||
v[i] = &p->get_buffer (nframes, offset);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Ensure that there are @a num_buffers buffers of type @a type available,
|
||||
* each of size at least @a buffer_size
|
||||
*/
|
||||
|
|
|
@ -246,7 +246,7 @@ Delivery::run (BufferSet& bufs, framepos_t start_frame, framepos_t end_frame, pf
|
|||
processing pathway that wants to use this->output_buffers() for some reason.
|
||||
*/
|
||||
|
||||
output_buffers().attach_buffers (ports, nframes, _output_offset);
|
||||
output_buffers().get_jack_port_addresses (ports, nframes, _output_offset);
|
||||
|
||||
// this Delivery processor is not a derived type, and thus we assume
|
||||
// we really can modify the buffers passed in (it is almost certainly
|
||||
|
@ -544,6 +544,6 @@ Delivery::output_changed (IOChange change, void* /*src*/)
|
|||
{
|
||||
if (change.type & IOChange::ConfigurationChanged) {
|
||||
reset_panner ();
|
||||
_output_buffers->attach_buffers (_output->ports ());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -447,6 +447,7 @@ IO::ensure_ports (ChanCount count, bool clear, void* src)
|
|||
change.after = _ports.count ();
|
||||
change.type = IOChange::ConfigurationChanged;
|
||||
this->changed (change, src); /* EMIT SIGNAL */
|
||||
_buffers.attach_buffers (_ports);
|
||||
setup_bundle ();
|
||||
_session.set_dirty ();
|
||||
}
|
||||
|
@ -1522,12 +1523,10 @@ IO::connected_to (boost::shared_ptr<const IO> other) const
|
|||
void
|
||||
IO::process_input (boost::shared_ptr<Processor> proc, framepos_t start_frame, framepos_t end_frame, pframes_t nframes)
|
||||
{
|
||||
BufferSet bufs;
|
||||
|
||||
/* don't read the data into new buffers - just use the port buffers directly */
|
||||
|
||||
bufs.attach_buffers (_ports, nframes, 0);
|
||||
proc->run (bufs, start_frame, end_frame, nframes, true);
|
||||
_buffers.get_jack_port_addresses (_ports, nframes, 0);
|
||||
proc->run (_buffers, start_frame, end_frame, nframes, true);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in New Issue
Block a user