Blender  V2.59
AUD_ChannelMapperFactory.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: AUD_ChannelMapperFactory.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_ChannelMapperFactory.h"
00033 #include "AUD_ChannelMapperReader.h"
00034 
00035 #include <cstring>
00036 
00037 AUD_ChannelMapperFactory::AUD_ChannelMapperFactory(AUD_IFactory* factory,
00038                                                                                                    AUD_DeviceSpecs specs) :
00039                 AUD_MixerFactory(factory, specs)
00040 {
00041         memset(m_mapping, 0, sizeof(m_mapping));
00042 }
00043 
00044 AUD_ChannelMapperFactory::~AUD_ChannelMapperFactory()
00045 {
00046         for(int i = 1; i < 10; i++)
00047                 deleteMapping(i);
00048 }
00049 
00050 float** AUD_ChannelMapperFactory::getMapping(int ic)
00051 {
00052         ic--;
00053         if(ic > 8 || ic < 0)
00054                 return 0;
00055 
00056         if(m_mapping[ic])
00057         {
00058                 int channels = -1;
00059                 while(m_mapping[ic][++channels] != 0);
00060                 if(channels != m_specs.channels)
00061                         deleteMapping(ic+1);
00062         }
00063 
00064         if(!m_mapping[ic])
00065         {
00066                 int channels = m_specs.channels;
00067 
00068                 m_mapping[ic] = new float*[channels+1];
00069                 m_mapping[ic][channels] = 0;
00070 
00071                 for(int i = 0; i < channels; i++)
00072                 {
00073                         m_mapping[ic][i] = new float[ic+1];
00074                         for(int j = 0; j <= ic; j++)
00075                                 m_mapping[ic][i][j] = ((i == j) || (channels == 1) ||
00076                                                                            (ic == 0)) ? 1.0f : 0.0f;
00077                 }
00078         }
00079 
00080         return m_mapping[ic];
00081 }
00082 
00083 void AUD_ChannelMapperFactory::deleteMapping(int ic)
00084 {
00085         ic--;
00086         if(ic > 8 || ic < 0)
00087                 return;
00088 
00089         if(m_mapping[ic])
00090         {
00091                 for(int i = 0; 1; i++)
00092                 {
00093                         if(m_mapping[ic][i] != 0)
00094                         {
00095                                 delete[] m_mapping[ic][i];
00096                         }
00097                         else
00098                                 break;
00099                 }
00100                 delete[] m_mapping[ic];
00101                 m_mapping[ic] = 0;
00102         }
00103 }
00104 
00105 AUD_IReader* AUD_ChannelMapperFactory::createReader() const
00106 {
00107         AUD_IReader* reader = getReader();
00108         int ic = reader->getSpecs().channels;
00109 
00110         return new AUD_ChannelMapperReader(reader,
00111                                    const_cast<AUD_ChannelMapperFactory*>(this)->getMapping(ic));
00112 }