2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #ifndef __ardour_fixed_delay_h__
20 #define __ardour_fixed_delay_h__
23 #include "ardour/buffer.h"
29 /** Multichannel Audio/Midi Delay Line
31 * This is an efficient delay line operating directly on Ardour buffers.
32 * The drawback is that there is no thread safety:
33 * All calls need to be executed in the same thread.
35 * After configuration, the delay can be changed safely up to the maximum
36 * configured delay but doing so flushes the buffer. There is no de-clicking
37 * (see ARDOUR::Delayline for those cases).
39 * Increasing the delay above the max configured or requesting more
40 * buffers will allocate the required space (not realtime safe).
42 * All buffers part of the set are treated separately.
44 class LIBARDOUR_API FixedDelay
50 /** initial configuration, usually done after instantiation
52 * @param count Channel Count (audio+midi)
53 * @param max_delay the maximum number of samples to delay
54 * @param shrink when false already allocated buffers are kept if both channel-count and max-delay requirements are satisified
56 void configure (const ChanCount& count, framecnt_t max_delay, bool shrink = true);
58 /** set delay time and update active process buffers
60 * This calls configure with shrink = false and sets the current delay time
61 * if the delay time mismatches, the buffers are silenced (zeroed).
63 * @param count channels to be processed
64 * @param delay number of audio samples to delay
66 void set (const ChanCount& count, framecnt_t delay);
70 * Read N samples from the input buffer, delay them by the configured delay-time and write
71 * the delayed samples to the output buffer at the given offset.
74 * @param id buffer number (starting at 0)
75 * @param out output buffer to write data to
76 * @param in input buffer to read data from
77 * @param n_samples number of samples to process (must be <= 8192)
78 * @param dst_offset offset in output buffer to start writing to
79 * @param src_offset offset in input buffer to start reading from
81 void delay (ARDOUR::DataType dt, uint32_t id, Buffer& out, const Buffer& in, pframes_t n_samples, framecnt_t dst_offset = 0, framecnt_t src_offset = 0);
83 /** zero all buffers */
87 framecnt_t _max_delay;
94 DelayBuffer () : buf (0), pos (0) {}
95 DelayBuffer (DataType dt, size_t capacity)
96 : buf (Buffer::create (dt, capacity)), pos (0) {}
97 ~DelayBuffer () { delete buf; }
102 typedef std::vector<DelayBuffer*> BufferVec;
103 // Vector of vectors, indexed by DataType
104 std::vector<BufferVec> _buffers;
106 void ensure_buffers(DataType type, size_t num_buffers, size_t buffer_capacity);
110 } // namespace ARDOUR
112 #endif // __ardour_fixed_delay_h__