Add a fixed (not de-clicked) multi-buffer audio/midi delayline.
[ardour.git] / libs / ardour / ardour / fixed_delay.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef __ardour_fixed_delay_h__
20 #define __ardour_fixed_delay_h__
21
22 #include <vector>
23 #include "ardour/buffer.h"
24
25 namespace ARDOUR {
26
27 class ChanCount;
28
29 class LIBARDOUR_API FixedDelay
30 {
31 public:
32         FixedDelay ();
33         ~FixedDelay ();
34
35         void configure (const ChanCount& count, framecnt_t);
36         void set (const ChanCount& count, framecnt_t);
37
38         void delay (ARDOUR::DataType, uint32_t, Buffer&, const Buffer&, pframes_t, framecnt_t dst_offset = 0, framecnt_t src_offset = 0);
39         void flush() { _pending_flush = true; }
40
41 private:
42         framecnt_t _max_delay;
43         framecnt_t _delay;
44         bool       _pending_flush;
45         ChanCount  _count;
46
47         struct DelayBuffer {
48                 public:
49                 DelayBuffer () : buf (0), pos (0) {}
50                 DelayBuffer (DataType dt, size_t capacity)
51                         : buf (Buffer::create (dt, capacity)), pos (0) {}
52                 ~DelayBuffer () { delete buf; }
53                 Buffer * buf;
54                 framepos_t pos;
55         };
56
57         typedef std::vector<DelayBuffer*> BufferVec;
58         // Vector of vectors, indexed by DataType
59         std::vector<BufferVec> _buffers;
60
61         void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity);
62         void clear ();
63 };
64
65 } // namespace ARDOUR
66
67 #endif // __ardour_fixed_delay_h__