2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2006-2007 Paul Davis
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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.
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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.
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
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.,
|
|
|
|
675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2009-04-23 13:48:37 -04:00
|
|
|
#include <errno.h>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/audio_buffer.h"
|
|
|
|
#include "pbd/error.h"
|
2009-04-23 13:48:37 -04:00
|
|
|
#include "pbd/malign.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace PBD;
|
2009-01-30 02:40:13 -05:00
|
|
|
using namespace ARDOUR;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
AudioBuffer::AudioBuffer(size_t capacity)
|
|
|
|
: Buffer(DataType::AUDIO, capacity)
|
|
|
|
, _owns_data (false)
|
|
|
|
, _data (0)
|
|
|
|
{
|
|
|
|
if (_capacity > 0) {
|
|
|
|
_owns_data = true; // prevent resize() from gagging
|
|
|
|
resize (_capacity);
|
2009-01-30 02:40:13 -05:00
|
|
|
_silent = false; // force silence on the intial buffer state
|
2008-06-02 17:41:35 -04:00
|
|
|
silence (_capacity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioBuffer::~AudioBuffer()
|
|
|
|
{
|
|
|
|
if (_owns_data)
|
|
|
|
free(_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
AudioBuffer::resize (size_t size)
|
|
|
|
{
|
2009-01-30 02:40:13 -05:00
|
|
|
if (!_owns_data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (size < _capacity) {
|
|
|
|
_size = size;
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-02-23 15:25:53 -05:00
|
|
|
free (_data);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
_capacity = size;
|
|
|
|
_size = size;
|
|
|
|
_silent = false;
|
|
|
|
|
2009-04-23 13:48:37 -04:00
|
|
|
cache_aligned_malloc ((void**) &_data, sizeof (Sample) * _capacity);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|