2 * Copyright (C) 2007-2010 David Robillard <d@drobilla.net>
3 * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4 * Copyright (C) 2013-2014 Robin Gareus <robin@gareus.org>
6 * This program 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 * This program 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 along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "ardour/audio_buffer.h"
24 #include "pbd/error.h"
25 #include "pbd/malign.h"
30 using namespace ARDOUR;
32 AudioBuffer::AudioBuffer(size_t capacity)
33 : Buffer (DataType::AUDIO)
38 _owns_data = true; // prevent resize() from gagging
40 _silent = false; // force silence on the intial buffer state
45 AudioBuffer::~AudioBuffer()
48 cache_aligned_free(_data);
52 AudioBuffer::resize (size_t size)
55 /* XXX how the hell is this enforced? */
60 if (_data && size < _capacity) {
61 /* buffer is already large enough */
65 cache_aligned_free (_data);
67 cache_aligned_malloc ((void**) &_data, sizeof (Sample) * size);
74 AudioBuffer::check_silence (pframes_t nframes, pframes_t& n) const
76 for (n = 0; n < nframes; ++n) {
77 if (_data[n] != Sample (0)) {
85 AudioBuffer::silence (samplecnt_t len, samplecnt_t offset) {
88 assert(_capacity > 0);
89 assert(offset + len <= _capacity);
90 memset(_data + offset, 0, sizeof (Sample) * len);
91 if (len == _capacity) {