diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2013-11-29 22:26:33 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2013-11-29 22:26:33 -0500 |
commit | d1cc7e5a50e2144d7aea01bc5eceed6657513c1b (patch) | |
tree | ae923ee081a7b19a1f3cc29da50dd12de5bd5596 /libs/ardour/audio_buffer.cc | |
parent | 0c4457fa8361d7678b09ec5911917750e7ade67e (diff) |
fix up a bunch of confusion regarding the size/capacity/allocation of audio & midi buffers
Diffstat (limited to 'libs/ardour/audio_buffer.cc')
-rw-r--r-- | libs/ardour/audio_buffer.cc | 26 |
1 files changed, 17 insertions, 9 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 |