From d1cc7e5a50e2144d7aea01bc5eceed6657513c1b Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Fri, 29 Nov 2013 22:26:33 -0500 Subject: fix up a bunch of confusion regarding the size/capacity/allocation of audio & midi buffers --- libs/ardour/audio_buffer.cc | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'libs/ardour/audio_buffer.cc') 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 -- cgit v1.2.3