fix up a bunch of confusion regarding the size/capacity/allocation of audio & midi buffers

This commit is contained in:
Paul Davis 2013-11-29 22:26:33 -05:00
parent 0c4457fa83
commit d1cc7e5a50
5 changed files with 44 additions and 32 deletions

View File

@ -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);
_capacity = size;
_size = size;
_silent = false;
cache_aligned_malloc ((void**) &_data, sizeof (Sample) * size);
cache_aligned_malloc ((void**) &_data, sizeof (Sample) * _capacity);
_capacity = size;
_size = 0;
_silent = false;
}
bool

View File

@ -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);
}
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}
delete [] gain_automation_buffer;
gain_automation_buffer = new gain_t[_engine->raw_buffer_size (DataType::AUDIO)];
delete [] send_gain_automation_buffer;
send_gain_automation_buffer = new gain_t[_engine->raw_buffer_size (DataType::AUDIO)];
size_t audio_buffer_size = _engine->raw_buffer_size (DataType::AUDIO) / sizeof (Sample);
allocate_pan_automation_buffers (_engine->raw_buffer_size (DataType::AUDIO), howmany.n_audio(), false);
delete [] gain_automation_buffer;
gain_automation_buffer = new gain_t[audio_buffer_size];
delete [] send_gain_automation_buffer;
send_gain_automation_buffer = new gain_t[audio_buffer_size];
allocate_pan_automation_buffers (audio_buffer_size, howmany.n_audio(), false);
}
void