2 Copyright (C) 2015 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
6 DCP-o-matic is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 DCP-o-matic is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
21 #include "audio_delay.h"
22 #include "audio_buffers.h"
23 #include "dcpomatic_assert.h"
24 #include <boost/make_shared.hpp>
28 using boost::shared_ptr;
29 using boost::make_shared;
31 AudioDelay::AudioDelay (int samples)
37 shared_ptr<AudioBuffers>
38 AudioDelay::run (shared_ptr<const AudioBuffers> in)
40 /* You can't call this with varying channel counts */
41 DCPOMATIC_ASSERT (!_tail || in->channels() == _tail->channels());
43 shared_ptr<AudioBuffers> out = make_shared<AudioBuffers> (in->channels(), in->frames());
45 if (in->frames() > _samples) {
48 /* No tail; use silence */
49 out->make_silent (0, _samples);
52 out->copy_from (_tail.get(), _samples, 0, 0);
56 out->copy_from (in.get(), in->frames() - _samples, 0, _samples);
60 _tail.reset (new AudioBuffers (in->channels(), _samples));
62 _tail->copy_from (in.get(), _samples, in->frames() - _samples, 0);
66 /* First part of the tail into the output */
68 out->copy_from (_tail.get(), out->frames(), 0, 0);
71 _tail.reset (new AudioBuffers (out->channels(), _samples));
72 _tail->make_silent ();
75 /* Shuffle the tail down */
76 _tail->move (out->frames(), 0, _tail->frames() - out->frames());
78 /* Copy input into the tail */
79 _tail->copy_from (in.get(), in->frames(), 0, _tail->frames() - in->frames());