2 * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
3 * Copyright (C) 2010-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "ardour/audioengine.h"
25 #include "ardour/buffer_set.h"
26 #include "ardour/thread_buffers.h"
28 using namespace ARDOUR;
31 ThreadBuffers::ThreadBuffers ()
32 : silent_buffers (new BufferSet)
33 , scratch_buffers (new BufferSet)
34 , noinplace_buffers (new BufferSet)
35 , route_buffers (new BufferSet)
36 , mix_buffers (new BufferSet)
37 , gain_automation_buffer (0)
38 , trim_automation_buffer (0)
39 , send_gain_automation_buffer (0)
40 , scratch_automation_buffer (0)
41 , pan_automation_buffer (0)
47 ThreadBuffers::ensure_buffers (ChanCount howmany, size_t custom)
49 // std::cerr << "ThreadBuffers " << this << " resize buffers with count = " << howmany << std::endl;
51 /* this is all protected by the process lock in the Session
54 /* we always need at least 1 midi buffer */
55 if (howmany.n_midi() < 1) {
59 if (howmany.n_audio() == 0 && howmany.n_midi() == 1) {
63 AudioEngine* _engine = AudioEngine::instance ();
65 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
66 size_t count = std::max (scratch_buffers->available().get(*t), howmany.get(*t));
71 size = (*t == DataType::MIDI)
72 ? _engine->raw_buffer_size (*t)
73 : _engine->raw_buffer_size (*t) / sizeof (Sample);
76 scratch_buffers->ensure_buffers (*t, count, size);
77 noinplace_buffers->ensure_buffers (*t, count, size);
78 mix_buffers->ensure_buffers (*t, count, size);
79 silent_buffers->ensure_buffers (*t, count, size);
80 route_buffers->ensure_buffers (*t, count, size);
83 size_t audio_buffer_size = custom > 0 ? custom : _engine->raw_buffer_size (DataType::AUDIO) / sizeof (Sample);
85 delete [] gain_automation_buffer;
86 gain_automation_buffer = new gain_t[audio_buffer_size];
87 delete [] trim_automation_buffer;
88 trim_automation_buffer = new gain_t[audio_buffer_size];
89 delete [] send_gain_automation_buffer;
90 send_gain_automation_buffer = new gain_t[audio_buffer_size];
91 delete [] scratch_automation_buffer;
92 scratch_automation_buffer = new gain_t[audio_buffer_size];
94 allocate_pan_automation_buffers (audio_buffer_size, howmany.n_audio(), false);
98 ThreadBuffers::allocate_pan_automation_buffers (samplecnt_t nframes, uint32_t howmany, bool force)
100 /* we always need at least 2 pan buffers */
102 howmany = max (2U, howmany);
104 if (!force && howmany <= npan_buffers) {
108 if (pan_automation_buffer) {
110 for (uint32_t i = 0; i < npan_buffers; ++i) {
111 delete [] pan_automation_buffer[i];
114 delete [] pan_automation_buffer;
117 pan_automation_buffer = new pan_t*[howmany];
119 for (uint32_t i = 0; i < howmany; ++i) {
120 pan_automation_buffer[i] = new pan_t[nframes];
123 npan_buffers = howmany;