summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2013-11-29 22:26:33 -0500
committerPaul Davis <paul@linuxaudiosystems.com>2013-11-29 22:26:33 -0500
commitd1cc7e5a50e2144d7aea01bc5eceed6657513c1b (patch)
treeae923ee081a7b19a1f3cc29da50dd12de5bd5596
parent0c4457fa8361d7678b09ec5911917750e7ade67e (diff)
fix up a bunch of confusion regarding the size/capacity/allocation of audio & midi buffers
-rw-r--r--libs/ardour/audio_buffer.cc26
-rw-r--r--libs/ardour/audio_port.cc9
-rw-r--r--libs/ardour/buffer_set.cc4
-rw-r--r--libs/ardour/midi_buffer.cc21
-rw-r--r--libs/ardour/thread_buffers.cc10
5 files changed, 41 insertions, 29 deletions
diff --git a/libs/ardour/audio_buffer.cc b/libs/ardour/audio_buffer.cc
index 1fd0337dd1..a36ad81c2a 100644
--- a/libs/ardour/audio_buffer.cc
+++ b/libs/ardour/audio_buffer.cc
@@ -28,15 +28,15 @@ using namespace PBD;
using namespace ARDOUR;
AudioBuffer::AudioBuffer(size_t capacity)
- : Buffer(DataType::AUDIO, capacity)
+ : Buffer (DataType::AUDIO)
, _owns_data (false)
, _data (0)
{
- if (_capacity > 0) {
+ if (capacity) {
_owns_data = true; // prevent resize() from gagging
- resize (_capacity);
+ resize (capacity);
_silent = false; // force silence on the intial buffer state
- silence (_capacity);
+ clear ();
}
}
@@ -50,21 +50,29 @@ void
AudioBuffer::resize (size_t size)
{
if (!_owns_data) {
+ /* XXX how the hell is this enforced? */
+ _capacity = size;
return;
}
- if (size < _capacity) {
- _size = size;
+ if (_data && size < _capacity) {
+ /* buffer is already large enough */
+
+ if (size < _size) {
+ /* truncate */
+ _size = size;
+ }
+
return;
}
free (_data);
+ cache_aligned_malloc ((void**) &_data, sizeof (Sample) * size);
+
_capacity = size;
- _size = size;
+ _size = 0;
_silent = false;
-
- cache_aligned_malloc ((void**) &_data, sizeof (Sample) * _capacity);
}
bool
diff --git a/libs/ardour/audio_port.cc b/libs/ardour/audio_port.cc
index 6a86360b69..2fecbf9392 100644
--- a/libs/ardour/audio_port.cc
+++ b/libs/ardour/audio_port.cc
@@ -56,14 +56,11 @@ AudioPort::cycle_start (pframes_t nframes)
}
void
-AudioPort::cycle_end (pframes_t)
+AudioPort::cycle_end (pframes_t nframes)
{
if (sends_output() && !_buffer->written()) {
- /* we can't use nframes here because the current buffer capacity may
- be shorter than the full buffer size if we split the cycle.
- */
- if (_buffer->capacity () > 0) {
- _buffer->silence (_buffer->capacity());
+ if (_buffer->capacity() >= nframes) {
+ _buffer->silence (nframes);
}
}
}
diff --git a/libs/ardour/buffer_set.cc b/libs/ardour/buffer_set.cc
index e67aee6be7..227d7a1e95 100644
--- a/libs/ardour/buffer_set.cc
+++ b/libs/ardour/buffer_set.cc
@@ -167,7 +167,7 @@ BufferSet::ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capac
// If there's not enough or they're too small, just nuke the whole thing and
// rebuild it (so I'm lazy..)
if (bufs.size() < num_buffers
- || (bufs.size() > 0 && bufs[0]->capacity() < buffer_capacity)) {
+ || (bufs.size() > 0 && bufs[0]->capacity() < buffer_capacity)) {
// Nuke it
for (BufferVec::iterator i = bufs.begin(); i != bufs.end(); ++i) {
@@ -179,7 +179,7 @@ BufferSet::ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capac
for (size_t i = 0; i < num_buffers; ++i) {
bufs.push_back(Buffer::create(type, buffer_capacity));
}
-
+
_available.set(type, num_buffers);
_count.set (type, num_buffers);
}
diff --git a/libs/ardour/midi_buffer.cc b/libs/ardour/midi_buffer.cc
index d75b861ea1..1a6cb7fa26 100644
--- a/libs/ardour/midi_buffer.cc
+++ b/libs/ardour/midi_buffer.cc
@@ -33,12 +33,12 @@ using namespace PBD;
// FIXME: mirroring for MIDI buffers?
MidiBuffer::MidiBuffer(size_t capacity)
- : Buffer(DataType::MIDI, capacity)
- , _data(0)
+ : Buffer (DataType::MIDI)
+ , _data (0)
{
if (capacity) {
- resize(_capacity);
- silence(_capacity);
+ resize (capacity);
+ silence (capacity);
}
}
@@ -50,17 +50,22 @@ MidiBuffer::~MidiBuffer()
void
MidiBuffer::resize(size_t size)
{
- assert(size > 0);
+ if (_data && size < _capacity) {
+
+ if (_size < size) {
+ /* truncate */
+ _size = size;
+ }
- if (size < _capacity) {
return;
}
- free(_data);
+ free (_data);
+
+ cache_aligned_malloc ((void**) &_data, size);
_size = 0;
_capacity = size;
- cache_aligned_malloc ((void**) &_data, _capacity);
assert(_data);
}
diff --git a/libs/ardour/thread_buffers.cc b/libs/ardour/thread_buffers.cc
index fd3160bb15..e469187ce9 100644
--- a/libs/ardour/thread_buffers.cc
+++ b/libs/ardour/thread_buffers.cc
@@ -60,7 +60,7 @@ ThreadBuffers::ensure_buffers (ChanCount howmany)
for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
size_t count = std::max (scratch_buffers->available().get(*t), howmany.get(*t));
- size_t size = _engine->raw_buffer_size (*t);
+ size_t size = _engine->raw_buffer_size (*t) / sizeof (Sample);
scratch_buffers->ensure_buffers (*t, count, size);
mix_buffers->ensure_buffers (*t, count, size);
@@ -68,12 +68,14 @@ ThreadBuffers::ensure_buffers (ChanCount howmany)
route_buffers->ensure_buffers (*t, count, size);
}
+ size_t audio_buffer_size = _engine->raw_buffer_size (DataType::AUDIO) / sizeof (Sample);
+
delete [] gain_automation_buffer;
- gain_automation_buffer = new gain_t[_engine->raw_buffer_size (DataType::AUDIO)];
+ gain_automation_buffer = new gain_t[audio_buffer_size];
delete [] send_gain_automation_buffer;
- send_gain_automation_buffer = new gain_t[_engine->raw_buffer_size (DataType::AUDIO)];
+ send_gain_automation_buffer = new gain_t[audio_buffer_size];
- allocate_pan_automation_buffers (_engine->raw_buffer_size (DataType::AUDIO), howmany.n_audio(), false);
+ allocate_pan_automation_buffers (audio_buffer_size, howmany.n_audio(), false);
}
void