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 , pan_automation_buffer (0)
45 ThreadBuffers::ensure_buffers (ChanCount howmany, size_t custom)
47 // std::cerr << "ThreadBuffers " << this << " resize buffers with count = " << howmany << std::endl;
49 /* this is all protected by the process lock in the Session
52 /* we always need at least 1 midi buffer */
53 if (howmany.n_midi() < 1) {
57 if (howmany.n_audio() == 0 && howmany.n_midi() == 1) {
61 AudioEngine* _engine = AudioEngine::instance ();
63 for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
64 size_t count = std::max (scratch_buffers->available().get(*t), howmany.get(*t));
69 size = (*t == DataType::MIDI)
70 ? _engine->raw_buffer_size (*t)
71 : _engine->raw_buffer_size (*t) / sizeof (Sample);
74 scratch_buffers->ensure_buffers (*t, count, size);
75 noinplace_buffers->ensure_buffers (*t, count, size);
76 mix_buffers->ensure_buffers (*t, count, size);
77 silent_buffers->ensure_buffers (*t, count, size);
78 route_buffers->ensure_buffers (*t, count, size);
81 size_t audio_buffer_size = custom > 0 ? custom : _engine->raw_buffer_size (DataType::AUDIO) / sizeof (Sample);
83 delete [] gain_automation_buffer;
84 gain_automation_buffer = new gain_t[audio_buffer_size];
85 delete [] trim_automation_buffer;
86 trim_automation_buffer = new gain_t[audio_buffer_size];
87 delete [] send_gain_automation_buffer;
88 send_gain_automation_buffer = new gain_t[audio_buffer_size];
90 allocate_pan_automation_buffers (audio_buffer_size, howmany.n_audio(), false);
94 ThreadBuffers::allocate_pan_automation_buffers (framecnt_t nframes, uint32_t howmany, bool force)
96 /* we always need at least 2 pan buffers */
98 howmany = max (2U, howmany);
100 if (!force && howmany <= npan_buffers) {
104 if (pan_automation_buffer) {
106 for (uint32_t i = 0; i < npan_buffers; ++i) {
107 delete [] pan_automation_buffer[i];
110 delete [] pan_automation_buffer;
113 pan_automation_buffer = new pan_t*[howmany];
115 for (uint32_t i = 0; i < howmany; ++i) {
116 pan_automation_buffer[i] = new pan_t[nframes];
119 npan_buffers = howmany;