Blender V2.61 - r43446
|
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_SuperposeReader.h" 00031 00032 #include <cstring> 00033 00034 static const char* specs_error = "AUD_SuperposeReader: Both readers have to " 00035 "have the same specs."; 00036 00037 AUD_SuperposeReader::AUD_SuperposeReader(AUD_Reference<AUD_IReader> reader1, AUD_Reference<AUD_IReader> reader2) : 00038 m_reader1(reader1), m_reader2(reader2) 00039 { 00040 } 00041 00042 AUD_SuperposeReader::~AUD_SuperposeReader() 00043 { 00044 } 00045 00046 bool AUD_SuperposeReader::isSeekable() const 00047 { 00048 return m_reader1->isSeekable() && m_reader2->isSeekable(); 00049 } 00050 00051 void AUD_SuperposeReader::seek(int position) 00052 { 00053 m_reader1->seek(position); 00054 m_reader2->seek(position); 00055 } 00056 00057 int AUD_SuperposeReader::getLength() const 00058 { 00059 int len1 = m_reader1->getLength(); 00060 int len2 = m_reader2->getLength(); 00061 if((len1 < 0) || (len2 < 0)) 00062 return -1; 00063 return AUD_MIN(len1, len2); 00064 } 00065 00066 int AUD_SuperposeReader::getPosition() const 00067 { 00068 int pos1 = m_reader1->getPosition(); 00069 int pos2 = m_reader2->getPosition(); 00070 return AUD_MAX(pos1, pos2); 00071 } 00072 00073 AUD_Specs AUD_SuperposeReader::getSpecs() const 00074 { 00075 return m_reader1->getSpecs(); 00076 } 00077 00078 void AUD_SuperposeReader::read(int& length, bool& eos, sample_t* buffer) 00079 { 00080 AUD_Specs specs = m_reader1->getSpecs(); 00081 AUD_Specs s2 = m_reader2->getSpecs(); 00082 if(!AUD_COMPARE_SPECS(specs, s2)) 00083 AUD_THROW(AUD_ERROR_SPECS, specs_error); 00084 00085 int samplesize = AUD_SAMPLE_SIZE(specs); 00086 00087 m_buffer.assureSize(length * samplesize); 00088 00089 int len1 = length; 00090 m_reader1->read(len1, eos, buffer); 00091 00092 if(len1 < length) 00093 memset(buffer + len1 * specs.channels, 0, (length - len1) * samplesize); 00094 00095 int len2 = length; 00096 bool eos2; 00097 sample_t* buf = m_buffer.getBuffer(); 00098 m_reader2->read(len2, eos2, buf); 00099 00100 for(int i = 0; i < len2 * specs.channels; i++) 00101 buffer[i] += buf[i]; 00102 00103 length = AUD_MAX(len1, len2); 00104 eos &= eos2; 00105 }