2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
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.
20 #include "audio_delay.h"
21 #include "audio_buffers.h"
22 #include "dcpomatic_assert.h"
26 using boost::shared_ptr;
28 AudioDelay::AudioDelay (int samples)
34 shared_ptr<AudioBuffers>
35 AudioDelay::run (shared_ptr<const AudioBuffers> in)
37 /* You can't call this with varying channel counts */
38 DCPOMATIC_ASSERT (!_tail || in->channels() == _tail->channels());
40 shared_ptr<AudioBuffers> out (new AudioBuffers (in->channels(), in->frames()));
42 if (in->frames() > _samples) {
45 /* No tail; use silence */
46 out->make_silent (0, _samples);
49 out->copy_from (_tail.get(), _samples, 0, 0);
53 out->copy_from (in.get(), in->frames() - _samples, 0, _samples);
57 _tail.reset (new AudioBuffers (in->channels(), _samples));
59 _tail->copy_from (in.get(), _samples, in->frames() - _samples, 0);
63 /* First part of the tail into the output */
65 out->copy_from (_tail.get(), out->frames(), 0, 0);
68 _tail.reset (new AudioBuffers (out->channels(), _samples));
69 _tail->make_silent ();
72 /* Shuffle the tail down */
73 _tail->move (out->frames(), 0, _tail->frames() - out->frames());
75 /* Copy input into the tail */
76 _tail->copy_from (in.get(), in->frames(), 0, _tail->frames() - in->frames());