summaryrefslogtreecommitdiff
path: root/libs/ardour/buffer_manager.cc
blob: 3436dac72d203b93a3876ebd159f4fb9178e9ff1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
    Copyright (C) 2010 Paul Davis

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <iostream>
#include "ardour/buffer_manager.h"
#include "ardour/thread_buffers.h"

using namespace ARDOUR;
using namespace PBD;

RingBufferNPT<ThreadBuffers*>* BufferManager::thread_buffers = 0;

void
BufferManager::init (uint32_t size)
{
        thread_buffers = new ThreadBufferFIFO (size+1); // must be one larger than requested

        /* and populate with actual ThreadBuffers 
         */

        std::cerr << "BM: initial read space: " << thread_buffers->read_space() << std::endl;
        
        for (uint32_t n = 0; n < size; ++n) {        
                ThreadBuffers* ts = new ThreadBuffers;
                thread_buffers->write (&ts, 1);
                std::cerr << "BM: added one, read =  " << thread_buffers->read_space() 
                          << " write = " << thread_buffers->write_space() 
                          << std::endl;
        }

        std::cerr << "BM: final, read =  " << thread_buffers->read_space() 
                  << " write = " << thread_buffers->write_space() 
                  << std::endl;

        std::cerr << "BUFFER MANAGER INITIALIZED WITH " << size << " BUFFERs\n";
}

ThreadBuffers*
BufferManager::get_thread_buffers ()
{
        ThreadBuffers* tbp;

        if (thread_buffers->read (&tbp, 1) == 1) {
                return tbp;
        }

        return 0;
}

void
BufferManager::put_thread_buffers (ThreadBuffers* tbp)
{
        thread_buffers->write (&tbp, 1);
}

void
BufferManager::ensure_buffers (ChanCount howmany)
{
        /* this is protected by the audioengine's process lock: we do not  */

        std::cerr << "BufMgr: ensure " << thread_buffers->bufsize() - 1 << " buffers match " << howmany << std::endl;

        for (uint32_t n = 0; n < thread_buffers->bufsize() - 1; ++n) {
                thread_buffers->buffer()[n]->ensure_buffers (howmany);
        }
}