2.5 audio cleanup:
[blender.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 #include <cstring>
30
31 AUD_SDLMixerFactory::AUD_SDLMixerFactory(AUD_IReader* reader, AUD_Specs specs) :
32                 AUD_MixerFactory(reader, specs) {}
33
34 AUD_SDLMixerFactory::AUD_SDLMixerFactory(AUD_IFactory* factory, AUD_Specs specs) :
35                 AUD_MixerFactory(factory, specs) {}
36
37 AUD_SDLMixerFactory::AUD_SDLMixerFactory(AUD_Specs specs) :
38                 AUD_MixerFactory(specs) {}
39
40 AUD_IReader* AUD_SDLMixerFactory::createReader()
41 {
42         AUD_IReader* reader = getReader();
43
44         if(reader != 0)
45         {
46                 AUD_Specs specs = reader->getSpecs();
47                 if(memcmp(&m_specs, &specs, sizeof(AUD_Specs)) != 0)
48                 {
49                         try
50                         {
51                                 reader = new AUD_SDLMixerReader(reader, m_specs);
52                                 AUD_NEW("reader")
53                         }
54                         catch(AUD_Exception e)
55                         {
56                                 // return 0 in case SDL cannot mix the source
57                                 if(e.error != AUD_ERROR_SDL)
58                                         throw;
59                                 else
60                                         reader = NULL;
61                         }
62                 }
63         }
64         return reader;
65 }