summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/fixed_delay.h
blob: c98b40c315dcf962045253985d4f639ab6c94265 (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
/*
 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#ifndef __ardour_fixed_delay_h__
#define __ardour_fixed_delay_h__

#include <vector>
#include "ardour/buffer.h"

namespace ARDOUR {

class ChanCount;

class LIBARDOUR_API FixedDelay
{
public:
	FixedDelay ();
	~FixedDelay ();

	void configure (const ChanCount& count, framecnt_t);
	void set (const ChanCount& count, framecnt_t);

	void delay (ARDOUR::DataType, uint32_t, Buffer&, const Buffer&, pframes_t, framecnt_t dst_offset = 0, framecnt_t src_offset = 0);
	void flush() { _pending_flush = true; }

private:
	framecnt_t _max_delay;
	framecnt_t _delay;
	bool       _pending_flush;
	ChanCount  _count;

	struct DelayBuffer {
		public:
		DelayBuffer () : buf (0), pos (0) {}
		DelayBuffer (DataType dt, size_t capacity)
			: buf (Buffer::create (dt, capacity)), pos (0) {}
		~DelayBuffer () { delete buf; }
		Buffer * buf;
		framepos_t pos;
	};

	typedef std::vector<DelayBuffer*> BufferVec;
	// Vector of vectors, indexed by DataType
	std::vector<BufferVec> _buffers;

	void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity);
	void clear ();
};

} // namespace ARDOUR

#endif // __ardour_fixed_delay_h__