X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fthread_buffers.cc;h=5aa90a0598cedecd3f53c6ee97fd6c6a2abb0bcb;hb=9775c5c9f1b81340f3177ede038f02faed71c887;hp=2436b6d36549a969c4d52d0a29616764fe982808;hpb=73192bc1a7ea55fa1864dc3826845b15c00dd2ec;p=ardour.git diff --git a/libs/ardour/thread_buffers.cc b/libs/ardour/thread_buffers.cc index 2436b6d365..5aa90a0598 100644 --- a/libs/ardour/thread_buffers.cc +++ b/libs/ardour/thread_buffers.cc @@ -18,6 +18,7 @@ */ #include +#include #include "ardour/audioengine.h" #include "ardour/buffer_set.h" @@ -27,47 +28,78 @@ using namespace ARDOUR; using namespace std; ThreadBuffers::ThreadBuffers () - : silent_buffers (new BufferSet) - , scratch_buffers (new BufferSet) - , mix_buffers (new BufferSet) - , gain_automation_buffer (0) - , pan_automation_buffer (0) - , npan_buffers (0) + : silent_buffers (new BufferSet) + , scratch_buffers (new BufferSet) + , noinplace_buffers (new BufferSet) + , route_buffers (new BufferSet) + , mix_buffers (new BufferSet) + , gain_automation_buffer (0) + , trim_automation_buffer (0) + , send_gain_automation_buffer (0) + , scratch_automation_buffer (0) + , pan_automation_buffer (0) + , npan_buffers (0) { } void -ThreadBuffers::ensure_buffers (ChanCount howmany) +ThreadBuffers::ensure_buffers (ChanCount howmany, size_t custom) { - // std::cerr << "ThreadBuffers " << this << " resize buffers with count = " << howmany << std::endl; + // std::cerr << "ThreadBuffers " << this << " resize buffers with count = " << howmany << std::endl; - /* this is all protected by the process lock in the Session - */ + /* this is all protected by the process lock in the Session + */ - if (howmany.n_total() == 0) { - return; - } + /* we always need at least 1 midi buffer */ + if (howmany.n_midi() < 1) { + howmany.set_midi(1); + } + + if (howmany.n_audio() == 0 && howmany.n_midi() == 1) { + return; + } - AudioEngine* _engine = AudioEngine::instance (); + AudioEngine* _engine = AudioEngine::instance (); 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; + if (custom > 0) { + size = custom; + } else { + size = (*t == DataType::MIDI) + ? _engine->raw_buffer_size (*t) + : _engine->raw_buffer_size (*t) / sizeof (Sample); + } scratch_buffers->ensure_buffers (*t, count, size); + noinplace_buffers->ensure_buffers (*t, count, size); mix_buffers->ensure_buffers (*t, count, size); - silent_buffers->ensure_buffers (*t, count, size); + silent_buffers->ensure_buffers (*t, count, size); + route_buffers->ensure_buffers (*t, count, size); } - delete [] gain_automation_buffer; - gain_automation_buffer = new gain_t[_engine->raw_buffer_size (DataType::AUDIO)]; + size_t audio_buffer_size = custom > 0 ? custom : _engine->raw_buffer_size (DataType::AUDIO) / sizeof (Sample); + + delete [] gain_automation_buffer; + gain_automation_buffer = new gain_t[audio_buffer_size]; + delete [] trim_automation_buffer; + trim_automation_buffer = new gain_t[audio_buffer_size]; + delete [] send_gain_automation_buffer; + send_gain_automation_buffer = new gain_t[audio_buffer_size]; + delete [] scratch_automation_buffer; + scratch_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 -ThreadBuffers::allocate_pan_automation_buffers (framecnt_t nframes, uint32_t howmany, bool force) +ThreadBuffers::allocate_pan_automation_buffers (samplecnt_t nframes, uint32_t howmany, bool force) { + /* we always need at least 2 pan buffers */ + + howmany = max (2U, howmany); + if (!force && howmany <= npan_buffers) { return; }