2.5: Sound branch merge!
[blender-staging.git] / intern / audaspace / SDL / AUD_SDLMixerFactory.cpp
1 /*
2  * $Id$
3  *
4  * ***** BEGIN LGPL LICENSE BLOCK *****
5  *
6  * Copyright 2009 Jörg Hermann Müller
7  *
8  * This file is part of AudaSpace.
9  *
10  * AudaSpace is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Lesser General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * AudaSpace is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * along with AudaSpace.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * ***** END LGPL LICENSE BLOCK *****
24  */
25
26 #include "AUD_SDLMixerFactory.h"
27 #include "AUD_SDLMixerReader.h"
28
29 AUD_SDLMixerFactory::AUD_SDLMixerFactory(AUD_IReader* reader, AUD_Specs specs) :
30                 AUD_MixerFactory(reader, specs) {}
31
32 AUD_SDLMixerFactory::AUD_SDLMixerFactory(AUD_IFactory* factory, AUD_Specs specs) :
33                 AUD_MixerFactory(factory, specs) {}
34
35 AUD_SDLMixerFactory::AUD_SDLMixerFactory(AUD_Specs specs) :
36                 AUD_MixerFactory(specs) {}
37
38 AUD_IReader* AUD_SDLMixerFactory::createReader()
39 {
40         AUD_IReader* reader = getReader();
41
42         if(reader != 0)
43         {
44                 AUD_Specs specs = reader->getSpecs();
45                 if(memcmp(&m_specs, &specs, sizeof(AUD_Specs)) != 0)
46                 {
47                         try
48                         {
49                                 reader = new AUD_SDLMixerReader(reader, m_specs);
50                                 AUD_NEW("reader")
51                         }
52                         catch(AUD_Exception e)
53                         {
54                                 // return 0 in case SDL cannot mix the source
55                                 if(e.error != AUD_ERROR_SDL)
56                                         throw;
57                                 else
58                                         reader = NULL;
59                         }
60                 }
61         }
62         return reader;
63 }