Remove all use of nframes_t.
[ardour.git] / libs / ardour / thread_buffers.cc
1 /*
2     Copyright (C) 2010 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #include <iostream>
21
22 #include "ardour/audioengine.h"
23 #include "ardour/buffer_set.h"
24 #include "ardour/thread_buffers.h"
25
26 using namespace ARDOUR;
27 using namespace std;
28
29 ThreadBuffers::ThreadBuffers ()
30         : silent_buffers (new BufferSet)
31         , scratch_buffers (new BufferSet)
32         , mix_buffers (new BufferSet)
33         , gain_automation_buffer (0)
34         , pan_automation_buffer (0)
35         , npan_buffers (0)
36 {
37 }
38
39 void
40 ThreadBuffers::ensure_buffers (ChanCount howmany)
41 {
42         // std::cerr << "ThreadBuffers " << this << " resize buffers with count = " << howmany << std::endl;
43
44         /* this is all protected by the process lock in the Session
45          */
46
47         if (howmany.n_total() == 0) {
48                 return;
49         }
50
51         AudioEngine* _engine = AudioEngine::instance ();
52
53         for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
54                 size_t count = std::max (scratch_buffers->available().get(*t), howmany.get(*t));
55                 size_t size = _engine->raw_buffer_size (*t);
56
57                 scratch_buffers->ensure_buffers (*t, count, size);
58                 mix_buffers->ensure_buffers (*t, count, size);
59                 silent_buffers->ensure_buffers (*t, count, size);
60         }
61
62         delete [] gain_automation_buffer;
63         gain_automation_buffer = new gain_t[_engine->raw_buffer_size (DataType::AUDIO)];
64
65         allocate_pan_automation_buffers (_engine->raw_buffer_size (DataType::AUDIO), howmany.n_audio(), false);
66 }
67
68 void
69 ThreadBuffers::allocate_pan_automation_buffers (framecnt_t nframes, uint32_t howmany, bool force)
70 {
71         if (!force && howmany <= npan_buffers) {
72                 return;
73         }
74
75         if (pan_automation_buffer) {
76
77                 for (uint32_t i = 0; i < npan_buffers; ++i) {
78                         delete [] pan_automation_buffer[i];
79                 }
80
81                 delete [] pan_automation_buffer;
82         }
83
84         pan_automation_buffer = new pan_t*[howmany];
85
86         for (uint32_t i = 0; i < howmany; ++i) {
87                 pan_automation_buffer[i] = new pan_t[nframes];
88         }
89
90         npan_buffers = howmany;
91 }