ardour
thread_buffers.cc
Go to the documentation of this file.
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 #include <algorithm>
22 
23 #include "ardour/audioengine.h"
24 #include "ardour/buffer_set.h"
25 #include "ardour/thread_buffers.h"
26 
27 using namespace ARDOUR;
28 using namespace std;
29 
31  : silent_buffers (new BufferSet)
32  , scratch_buffers (new BufferSet)
33  , route_buffers (new BufferSet)
34  , mix_buffers (new BufferSet)
35  , gain_automation_buffer (0)
36  , trim_automation_buffer (0)
37  , send_gain_automation_buffer (0)
38  , pan_automation_buffer (0)
39  , npan_buffers (0)
40 {
41 }
42 
43 void
44 ThreadBuffers::ensure_buffers (ChanCount howmany, size_t custom)
45 {
46  // std::cerr << "ThreadBuffers " << this << " resize buffers with count = " << howmany << std::endl;
47 
48  /* this is all protected by the process lock in the Session
49  */
50 
51  /* we always need at least 1 midi buffer */
52  if (howmany.n_midi() < 1) {
53  howmany.set_midi(1);
54  }
55 
56  if (howmany.n_audio() == 0 && howmany.n_midi() == 1) {
57  return;
58  }
59 
60  AudioEngine* _engine = AudioEngine::instance ();
61 
62  for (DataType::iterator t = DataType::begin(); t != DataType::end(); ++t) {
63  size_t count = std::max (scratch_buffers->available().get(*t), howmany.get(*t));
64  size_t size;
65  if (custom > 0) {
66  size = custom;
67  } else {
68  size = (*t == DataType::MIDI)
69  ? _engine->raw_buffer_size (*t)
70  : _engine->raw_buffer_size (*t) / sizeof (Sample);
71  }
72 
73  scratch_buffers->ensure_buffers (*t, count, size);
74  mix_buffers->ensure_buffers (*t, count, size);
75  silent_buffers->ensure_buffers (*t, count, size);
76  route_buffers->ensure_buffers (*t, count, size);
77  }
78 
79  size_t audio_buffer_size = custom > 0 ? custom : _engine->raw_buffer_size (DataType::AUDIO) / sizeof (Sample);
80 
81  delete [] gain_automation_buffer;
82  gain_automation_buffer = new gain_t[audio_buffer_size];
83  delete [] trim_automation_buffer;
84  trim_automation_buffer = new gain_t[audio_buffer_size];
86  send_gain_automation_buffer = new gain_t[audio_buffer_size];
87 
88  allocate_pan_automation_buffers (audio_buffer_size, howmany.n_audio(), false);
89 }
90 
91 void
92 ThreadBuffers::allocate_pan_automation_buffers (framecnt_t nframes, uint32_t howmany, bool force)
93 {
94  /* we always need at least 2 pan buffers */
95 
96  howmany = max (2U, howmany);
97 
98  if (!force && howmany <= npan_buffers) {
99  return;
100  }
101 
102  if (pan_automation_buffer) {
103 
104  for (uint32_t i = 0; i < npan_buffers; ++i) {
105  delete [] pan_automation_buffer[i];
106  }
107 
108  delete [] pan_automation_buffer;
109  }
110 
111  pan_automation_buffer = new pan_t*[howmany];
112 
113  for (uint32_t i = 0; i < howmany; ++i) {
114  pan_automation_buffer[i] = new pan_t[nframes];
115  }
116 
117  npan_buffers = howmany;
118 }
void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity)
Definition: buffer_set.cc:149
void allocate_pan_automation_buffers(framecnt_t nframes, uint32_t howmany, bool force)
float pan_t
Definition: types.h:57
BufferSet * route_buffers
uint32_t n_audio() const
Definition: chan_count.h:63
Definition: Beats.hpp:239
gain_t * gain_automation_buffer
float gain_t
Definition: types.h:58
void ensure_buffers(ChanCount howmany=ChanCount::ZERO, size_t custom=0)
static AudioEngine * instance()
Definition: audioengine.h:196
uint32_t n_midi() const
Definition: chan_count.h:66
static iterator end()
Definition: data_type.h:109
int64_t framecnt_t
Definition: types.h:76
float Sample
Definition: types.h:54
gain_t * send_gain_automation_buffer
pan_t ** pan_automation_buffer
Definition: amp.h:29
BufferSet * scratch_buffers
size_t raw_buffer_size(DataType t)
gain_t * trim_automation_buffer
uint32_t get(DataType t) const
Definition: chan_count.h:59
void set_midi(uint32_t m)
Definition: chan_count.h:67
const ChanCount & available() const
Definition: buffer_set.h:84
static iterator begin()
Definition: data_type.h:108
BufferSet * silent_buffers