2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "ardour/audioengine.h"
24 #include "ardour/buffer_set.h"
25 #include "ardour/thread_buffers.h"
27 using namespace ARDOUR;
30 ThreadBuffers::ThreadBuffers ()
31 : silent_buffers (new BufferSet)
32 , scratch_buffers (new BufferSet)
33 , noinplace_buffers (new BufferSet)
34 , route_buffers (new BufferSet)
35 , mix_buffers (new BufferSet)
36 , gain_automation_buffer (0)
37 , trim_automation_buffer (0)
38 , send_gain_automation_buffer (0)
39 , scratch_automation_buffer (0)
40 , pan_automation_buffer (0)
46 ThreadBuffers::ensure_buffers (ChanCount howmany, size_t custom)
48 // std::cerr << "ThreadBuffers " << this << " resize buffers with count = " << howmany << std::endl;
50 /* this is all protected by the process lock in the Session
53 /* we always need at least 1 midi buffer */
54 if (howmany.n_midi() < 1) {
58 if (howmany.n_audio() == 0 && howmany.n_midi() == 1) {
62 AudioEngine* _engine = AudioEngine::instance ();
64 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
65 size_t count = std::max (scratch_buffers->available().get(*t), howmany.get(*t));
70 size = (*t == DataType::MIDI)
71 ? _engine->raw_buffer_size (*t)
72 : _engine->raw_buffer_size (*t) / sizeof (Sample);
75 scratch_buffers->ensure_buffers (*t, count, size);
76 noinplace_buffers->ensure_buffers (*t, count, size);
77 mix_buffers->ensure_buffers (*t, count, size);
78 silent_buffers->ensure_buffers (*t, count, size);
79 route_buffers->ensure_buffers (*t, count, size);
82 size_t audio_buffer_size = custom > 0 ? custom : _engine->raw_buffer_size (DataType::AUDIO) / sizeof (Sample);
84 delete [] gain_automation_buffer;
85 gain_automation_buffer = new gain_t[audio_buffer_size];
86 delete [] trim_automation_buffer;
87 trim_automation_buffer = new gain_t[audio_buffer_size];
88 delete [] send_gain_automation_buffer;
89 send_gain_automation_buffer = new gain_t[audio_buffer_size];
90 delete [] scratch_automation_buffer;
91 scratch_automation_buffer = new gain_t[audio_buffer_size];
93 allocate_pan_automation_buffers (audio_buffer_size, howmany.n_audio(), false);
97 ThreadBuffers::allocate_pan_automation_buffers (samplecnt_t nframes, uint32_t howmany, bool force)
99 /* we always need at least 2 pan buffers */
101 howmany = max (2U, howmany);
103 if (!force && howmany <= npan_buffers) {
107 if (pan_automation_buffer) {
109 for (uint32_t i = 0; i < npan_buffers; ++i) {
110 delete [] pan_automation_buffer[i];
113 delete [] pan_automation_buffer;
116 pan_automation_buffer = new pan_t*[howmany];
118 for (uint32_t i = 0; i < howmany; ++i) {
119 pan_automation_buffer[i] = new pan_t[nframes];
122 npan_buffers = howmany;