2009-08-09 21:16:39 +00:00
|
|
|
/*
|
2011-02-18 23:47:37 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2009-08-09 21:16:39 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* Copyright 2009-2011 Jörg Hermann Müller
|
2009-08-09 21:16:39 +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
|
2009-08-09 21:16:39 +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.
|
2009-08-09 21:16:39 +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.
|
2009-08-09 21:16:39 +00:00
|
|
|
*
|
2011-02-18 23:47:37 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2009-08-09 21:16:39 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 10:21:56 +00:00
|
|
|
/** \file audaspace/FX/AUD_DoubleReader.cpp
|
|
|
|
* \ingroup audfx
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
#include "AUD_DoubleReader.h"
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2011-06-03 23:28:57 +00:00
|
|
|
AUD_DoubleReader::AUD_DoubleReader(AUD_Reference<AUD_IReader> reader1,
|
|
|
|
AUD_Reference<AUD_IReader> reader2) :
|
2010-07-28 09:36:03 +00:00
|
|
|
m_reader1(reader1), m_reader2(reader2), m_finished1(false)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-28 09:36:03 +00:00
|
|
|
AUD_Specs s1, s2;
|
|
|
|
s1 = reader1->getSpecs();
|
|
|
|
s2 = reader2->getSpecs();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AUD_DoubleReader::~AUD_DoubleReader()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
bool AUD_DoubleReader::isSeekable() const
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2010-07-28 09:36:03 +00:00
|
|
|
return m_reader1->isSeekable() && m_reader2->isSeekable();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AUD_DoubleReader::seek(int position)
|
|
|
|
{
|
2010-07-28 09:36:03 +00:00
|
|
|
m_reader1->seek(position);
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
int pos1 = m_reader1->getPosition();
|
2009-08-09 21:16:39 +00:00
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
if((m_finished1 = (pos1 < position)))
|
|
|
|
m_reader2->seek(position - pos1);
|
2009-08-09 21:16:39 +00:00
|
|
|
else
|
2010-07-28 09:36:03 +00:00
|
|
|
m_reader2->seek(0);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
int AUD_DoubleReader::getLength() const
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
int len1 = m_reader1->getLength();
|
|
|
|
int len2 = m_reader2->getLength();
|
|
|
|
if(len1 < 0 || len2 < 0)
|
|
|
|
return -1;
|
|
|
|
return len1 + len2;
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
int AUD_DoubleReader::getPosition() const
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
|
|
|
return m_reader1->getPosition() + m_reader2->getPosition();
|
|
|
|
}
|
|
|
|
|
2010-07-28 09:36:03 +00:00
|
|
|
AUD_Specs AUD_DoubleReader::getSpecs() const
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:35:09 +00:00
|
|
|
return m_finished1 ? m_reader1->getSpecs() : m_reader2->getSpecs();
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
|
2011-06-21 20:14:53 +00:00
|
|
|
void AUD_DoubleReader::read(int& length, bool& eos, sample_t* buffer)
|
2009-08-09 21:16:39 +00:00
|
|
|
{
|
2011-06-21 20:21:43 +00:00
|
|
|
eos = false;
|
|
|
|
|
2009-08-09 21:16:39 +00:00
|
|
|
if(!m_finished1)
|
|
|
|
{
|
2011-07-30 16:24:11 +00:00
|
|
|
int len = length;
|
|
|
|
|
|
|
|
m_reader1->read(len, m_finished1, buffer);
|
|
|
|
|
|
|
|
if(len < length)
|
|
|
|
{
|
|
|
|
AUD_Specs specs1, specs2;
|
|
|
|
specs1 = m_reader1->getSpecs();
|
|
|
|
specs2 = m_reader2->getSpecs();
|
2011-08-09 08:38:14 +00:00
|
|
|
if(AUD_COMPARE_SPECS(specs1, specs2))
|
2011-07-30 16:24:11 +00:00
|
|
|
{
|
|
|
|
int len2 = length - len;
|
|
|
|
m_reader2->read(len2, eos, buffer + specs1.channels * len);
|
|
|
|
length = len + len2;
|
|
|
|
}
|
2011-08-11 11:41:24 +00:00
|
|
|
else
|
|
|
|
length = len;
|
2011-07-30 16:24:11 +00:00
|
|
|
}
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-21 20:14:53 +00:00
|
|
|
m_reader2->read(length, eos, buffer);
|
2009-08-09 21:16:39 +00:00
|
|
|
}
|
|
|
|
}
|