Blender V2.61 - r43446

AUD_DoubleReader.cpp

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * Copyright 2009-2011 Jörg Hermann Müller
00005  *
00006  * This file is part of AudaSpace.
00007  *
00008  * Audaspace is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * AudaSpace is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Audaspace; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #include "AUD_DoubleReader.h"
00031 
00032 #include <cstring>
00033 
00034 AUD_DoubleReader::AUD_DoubleReader(AUD_Reference<AUD_IReader> reader1,
00035                                    AUD_Reference<AUD_IReader> reader2) :
00036         m_reader1(reader1), m_reader2(reader2), m_finished1(false)
00037 {
00038     AUD_Specs s1, s2;
00039     s1 = reader1->getSpecs();
00040     s2 = reader2->getSpecs();
00041 }
00042 
00043 AUD_DoubleReader::~AUD_DoubleReader()
00044 {
00045 }
00046 
00047 bool AUD_DoubleReader::isSeekable() const
00048 {
00049     return m_reader1->isSeekable() && m_reader2->isSeekable();
00050 }
00051 
00052 void AUD_DoubleReader::seek(int position)
00053 {
00054     m_reader1->seek(position);
00055 
00056     int pos1 = m_reader1->getPosition();
00057 
00058     if((m_finished1 = (pos1 < position)))
00059         m_reader2->seek(position - pos1);
00060     else
00061         m_reader2->seek(0);
00062 }
00063 
00064 int AUD_DoubleReader::getLength() const
00065 {
00066     int len1 = m_reader1->getLength();
00067     int len2 = m_reader2->getLength();
00068     if(len1 < 0 || len2 < 0)
00069         return -1;
00070     return len1 + len2;
00071 }
00072 
00073 int AUD_DoubleReader::getPosition() const
00074 {
00075     return m_reader1->getPosition() + m_reader2->getPosition();
00076 }
00077 
00078 AUD_Specs AUD_DoubleReader::getSpecs() const
00079 {
00080     return m_finished1 ? m_reader1->getSpecs() : m_reader2->getSpecs();
00081 }
00082 
00083 void AUD_DoubleReader::read(int& length, bool& eos, sample_t* buffer)
00084 {
00085     eos = false;
00086 
00087     if(!m_finished1)
00088     {
00089         int len = length;
00090 
00091         m_reader1->read(len, m_finished1, buffer);
00092 
00093         if(len < length)
00094         {
00095             AUD_Specs specs1, specs2;
00096             specs1 = m_reader1->getSpecs();
00097             specs2 = m_reader2->getSpecs();
00098             if(AUD_COMPARE_SPECS(specs1, specs2))
00099             {
00100                 int len2 = length - len;
00101                 m_reader2->read(len2, eos, buffer + specs1.channels * len);
00102                 length = len + len2;
00103             }
00104             else
00105                 length = len;
00106         }
00107     }
00108     else
00109     {
00110         m_reader2->read(length, eos, buffer);
00111     }
00112 }