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.
21 #include "ardour/buffer_manager.h"
22 #include "ardour/thread_buffers.h"
24 using namespace ARDOUR;
27 RingBufferNPT<ThreadBuffers*>* BufferManager::thread_buffers = 0;
30 BufferManager::init (uint32_t size)
32 thread_buffers = new ThreadBufferFIFO (size+1); // must be one larger than requested
34 /* and populate with actual ThreadBuffers
37 std::cerr << "BM: initial read space: " << thread_buffers->read_space() << std::endl;
39 for (uint32_t n = 0; n < size; ++n) {
40 ThreadBuffers* ts = new ThreadBuffers;
41 thread_buffers->write (&ts, 1);
42 std::cerr << "BM: added one, read = " << thread_buffers->read_space()
43 << " write = " << thread_buffers->write_space()
47 std::cerr << "BM: final, read = " << thread_buffers->read_space()
48 << " write = " << thread_buffers->write_space()
51 std::cerr << "BUFFER MANAGER INITIALIZED WITH " << size << " BUFFERs\n";
55 BufferManager::get_thread_buffers ()
59 if (thread_buffers->read (&tbp, 1) == 1) {
67 BufferManager::put_thread_buffers (ThreadBuffers* tbp)
69 thread_buffers->write (&tbp, 1);
73 BufferManager::ensure_buffers (ChanCount howmany)
75 /* this is protected by the audioengine's process lock: we do not */
77 std::cerr << "BufMgr: ensure " << thread_buffers->bufsize() - 1 << " buffers match " << howmany << std::endl;
79 for (uint32_t n = 0; n < thread_buffers->bufsize() - 1; ++n) {
80 thread_buffers->buffer()[n]->ensure_buffers (howmany);