diff options
author | Carl Hetherington <carl@carlh.net> | 2011-01-10 16:23:54 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2011-01-10 16:23:54 +0000 |
commit | dd7caa01654dc58d3259eeed0e0f2b8ddb293b66 (patch) | |
tree | 58c4f85e4a8c4882f8213a686f4c5182f27af79f /libs/ardour/buffer_set.cc | |
parent | f7cef2016f737a7c80b5307d3d45d8065b9e8789 (diff) |
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
Diffstat (limited to 'libs/ardour/buffer_set.cc')
-rw-r--r-- | libs/ardour/buffer_set.cc | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/libs/ardour/buffer_set.cc b/libs/ardour/buffer_set.cc index c60c0ac2b9..159a24c217 100644 --- a/libs/ardour/buffer_set.cc +++ b/libs/ardour/buffer_set.cc @@ -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 */ |