Blender  V2.59
AUD_ConverterReader.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: AUD_ConverterReader.cpp 35141 2011-02-25 10:21:56Z jesterking $
00003  *
00004  * ***** BEGIN GPL LICENSE BLOCK *****
00005  *
00006  * Copyright 2009-2011 Jörg Hermann Müller
00007  *
00008  * This file is part of AudaSpace.
00009  *
00010  * Audaspace is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * AudaSpace is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License
00021  * along with Audaspace; if not, write to the Free Software Foundation,
00022  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00023  *
00024  * ***** END GPL LICENSE BLOCK *****
00025  */
00026 
00032 #include "AUD_ConverterReader.h"
00033 
00034 AUD_ConverterReader::AUD_ConverterReader(AUD_IReader* reader,
00035                                                                                  AUD_DeviceSpecs specs) :
00036                 AUD_EffectReader(reader)
00037 {
00038         m_specs.specs = reader->getSpecs();
00039 
00040         int bigendian = 1;
00041         bigendian = (((char*)&bigendian)[0]) ? 0: 1; // 1 if Big Endian
00042 
00043         switch(specs.format)
00044         {
00045         case AUD_FORMAT_U8:
00046                 m_convert = AUD_convert_float_u8;
00047                 break;
00048         case AUD_FORMAT_S16:
00049                 m_convert = AUD_convert_float_s16;
00050                 break;
00051         case AUD_FORMAT_S24:
00052                 if(bigendian)
00053                         m_convert = AUD_convert_float_s24_be;
00054                 else
00055                         m_convert = AUD_convert_float_s24_le;
00056                 break;
00057         case AUD_FORMAT_S32:
00058                 m_convert = AUD_convert_float_s32;
00059                 break;
00060         case AUD_FORMAT_FLOAT32:
00061                 m_convert = AUD_convert_copy<float>;
00062                 break;
00063         case AUD_FORMAT_FLOAT64:
00064                 m_convert = AUD_convert_float_double;
00065                 break;
00066         default:
00067                 break;
00068         }
00069 
00070         m_specs.format = specs.format;
00071 }
00072 
00073 AUD_Specs AUD_ConverterReader::getSpecs() const
00074 {
00075         return m_specs.specs;
00076 }
00077 
00078 void AUD_ConverterReader::read(int & length, sample_t* & buffer)
00079 {
00080         m_reader->read(length, buffer);
00081 
00082         int samplesize = AUD_SAMPLE_SIZE(m_specs);
00083 
00084         if(m_buffer.getSize() < length * samplesize)
00085                 m_buffer.resize(length * samplesize);
00086 
00087         m_convert((data_t*)m_buffer.getBuffer(), (data_t*)buffer,
00088                           length * m_specs.channels);
00089 
00090         buffer = m_buffer.getBuffer();
00091 }