2010-07-09 08:56:25 +00:00
|
|
|
/*
|
2011-02-18 23:47:37 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2010-07-09 08:56:25 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* Copyright 2009-2011 Jörg Hermann Müller
|
2010-07-09 08:56:25 +00:00
|
|
|
*
|
|
|
|
* This file is part of AudaSpace.
|
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* Audaspace 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
|
2010-07-09 08:56:25 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* AudaSpace 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
|
2011-02-18 23:47:37 +00:00
|
|
|
* GNU General Public License for more details.
|
2010-07-09 08:56:25 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Audaspace; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-07-09 08:56:25 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2010-07-09 08:56:25 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 10:21:56 +00:00
|
|
|
/** \file audaspace/FX/AUD_SuperposeReader.cpp
|
|
|
|
* \ingroup audfx
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2010-07-09 08:56:25 +00:00
|
|
|
#include "AUD_SuperposeReader.h"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2010-08-03 08:07:21 +00:00
|
|
|
static const char* specs_error = "AUD_SuperposeReader: Both readers have to "
|
|
|
|
"have the same specs.";
|
|
|
|
|
2012-11-05 14:24:35 +00:00
|
|
|
AUD_SuperposeReader::AUD_SuperposeReader(boost::shared_ptr<AUD_IReader> reader1, boost::shared_ptr<AUD_IReader> reader2) :
|
2010-07-09 08:56:25 +00:00
|
|
|
m_reader1(reader1), m_reader2(reader2)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AUD_SuperposeReader::~AUD_SuperposeReader()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
bool AUD_SuperposeReader::isSeekable() const
|
2010-07-09 08:56:25 +00:00
|
|
|
{
|
|
|
|
return m_reader1->isSeekable() && m_reader2->isSeekable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_SuperposeReader::seek(int position)
|
|
|
|
{
|
|
|
|
m_reader1->seek(position);
|
|
|
|
m_reader2->seek(position);
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
int AUD_SuperposeReader::getLength() const
|
2010-07-09 08:56:25 +00:00
|
|
|
{
|
|
|
|
int len1 = m_reader1->getLength();
|
|
|
|
int len2 = m_reader2->getLength();
|
|
|
|
if((len1 < 0) || (len2 < 0))
|
|
|
|
return -1;
|
2010-07-28 09:36:03 +00:00
|
|
|
return AUD_MIN(len1, len2);
|
2010-07-09 08:56:25 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
int AUD_SuperposeReader::getPosition() const
|
2010-07-09 08:56:25 +00:00
|
|
|
{
|
|
|
|
int pos1 = m_reader1->getPosition();
|
|
|
|
int pos2 = m_reader2->getPosition();
|
|
|
|
return AUD_MAX(pos1, pos2);
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
AUD_Specs AUD_SuperposeReader::getSpecs() const
|
2010-07-09 08:56:25 +00:00
|
|
|
{
|
|
|
|
return m_reader1->getSpecs();
|
|
|
|
}
|
|
|
|
|
2011-06-21 20:14:53 +00:00
|
|
|
void AUD_SuperposeReader::read(int& length, bool& eos, sample_t* buffer)
|
2010-07-09 08:56:25 +00:00
|
|
|
{
|
|
|
|
AUD_Specs specs = m_reader1->getSpecs();
|
2011-06-21 20:35:09 +00:00
|
|
|
AUD_Specs s2 = m_reader2->getSpecs();
|
2011-08-11 11:41:24 +00:00
|
|
|
if(!AUD_COMPARE_SPECS(specs, s2))
|
2011-06-21 20:35:09 +00:00
|
|
|
AUD_THROW(AUD_ERROR_SPECS, specs_error);
|
|
|
|
|
2010-07-09 08:56:25 +00:00
|
|
|
int samplesize = AUD_SAMPLE_SIZE(specs);
|
|
|
|
|
2011-06-21 20:13:27 +00:00
|
|
|
m_buffer.assureSize(length * samplesize);
|
2010-07-09 08:56:25 +00:00
|
|
|
|
|
|
|
int len1 = length;
|
2011-06-21 20:14:53 +00:00
|
|
|
m_reader1->read(len1, eos, buffer);
|
2010-07-09 08:56:25 +00:00
|
|
|
|
|
|
|
if(len1 < length)
|
|
|
|
memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize);
|
|
|
|
|
|
|
|
int len2 = length;
|
2011-06-21 20:14:53 +00:00
|
|
|
bool eos2;
|
2011-06-14 12:13:19 +00:00
|
|
|
sample_t* buf = m_buffer.getBuffer();
|
2011-06-21 20:14:53 +00:00
|
|
|
m_reader2->read(len2, eos2, buf);
|
2010-07-09 08:56:25 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < len2 * specs.channels; i++)
|
|
|
|
buffer[i] += buf[i];
|
|
|
|
|
|
|
|
length = AUD_MAX(len1, len2);
|
2011-06-21 20:14:53 +00:00
|
|
|
eos &= eos2;
|
2010-07-09 08:56:25 +00:00
|
|
|
}
|