MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
audiomanager.cpp
1 // © Copyright 2010 - 2014 BlackTopp Studios Inc.
2 /* This file is part of The Mezzanine Engine.
3 
4  The Mezzanine Engine is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  The Mezzanine Engine is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with The Mezzanine Engine. If not, see <http://www.gnu.org/licenses/>.
16 */
17 /* The original authors have included a copy of the license specified above in the
18  'Docs' folder. See 'gpl.txt'
19 */
20 /* We welcome the use of the Mezzanine engine to anyone, including companies who wish to
21  Build professional software and charge for their product.
22 
23  However there are some practical restrictions, so if your project involves
24  any of the following you should contact us and we will try to work something
25  out:
26  - DRM or Copy Protection of any kind(except Copyrights)
27  - Software Patents You Do Not Wish to Freely License
28  - Any Kind of Linking to Non-GPL licensed Works
29  - Are Currently In Violation of Another Copyright Holder's GPL License
30  - If You want to change our code and not add a few hundred MB of stuff to
31  your distribution
32 
33  These and other limitations could cause serious legal problems if you ignore
34  them, so it is best to simply contact us or the Free Software Foundation, if
35  you have any questions.
36 
37  Joseph Toppi - toppij@gmail.com
38  John Blackwood - makoenergy02@gmail.com
39 */
40 // Copyright (c) 2008-2010 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones
41 // This file is part of the "cAudio Engine"
42 // For conditions of distribution and use, see copyright notice in cAudio-ZLIBLicense.txt
43 #ifndef _audioaudiomanager_cpp
44 #define _audioaudiomanager_cpp
45 
46 #include "Audio/audiomanager.h"
47 #include "Audio/recorder.h"
48 #include "Audio/sound.h"
49 #include "Audio/effectshandler.h"
50 #include "Audio/soundscapemanager.h"
51 #include "Audio/decoder.h"
52 #include "Audio/decoderfactory.h"
53 #include "exception.h"
54 
55 #include "Audio/rawdecoderfactory.h"
56 #include "Audio/vorbisdecoderfactory.h"
57 #include "Audio/wavdecoderfactory.h"
58 
59 namespace Mezzanine
60 {
61  template<> Audio::AudioManager* Singleton<Audio::AudioManager>::SingletonPtr = 0;
62 
63  namespace Audio
64  {
65  //template<> AudioManager* Singleton<AudioManager>::SingletonPtr = 0;
66 
68  {
69 #ifdef ENABLE_RAW_ENCODE
70  this->AddDecoderFactory(new RawDecoderFactory());
71 #endif
72 #ifdef ENABLE_VORBIS_ENCODE
73  this->AddDecoderFactory(new VorbisDecoderFactory());
74 #endif
75 #ifdef ENABLE_WAV_ENCODE
76  this->AddDecoderFactory(new WavDecoderFactory());
77 #endif
78  }
79 
81  {
82  }
83 
85  { this->DestroyAllDecoderFactories(); }
86 
87  ///////////////////////////////////////////////////////////////////////////////
88  // Utility
89 
90  ///////////////////////////////////////////////////////////////////////////////
91  // Sound Management
92 
93  ///////////////////////////////////////////////////////////////////////////////
94  // Convenience Creation Methods
95 
97  { return this->CreateSound(Audio::ST_Ambient); }
99  { return this->CreateSound(Audio::ST_Dialog); }
101  { return this->CreateSound(Audio::ST_Effect); }
103  { return this->CreateSound(Audio::ST_Music); }
104 
106  { return this->CreateSound(Audio::ST_Ambient,Stream,Encode); }
108  { return this->CreateSound(Audio::ST_Dialog,Stream,Encode); }
110  { return this->CreateSound(Audio::ST_Effect,Stream,Encode); }
112  { return this->CreateSound(Audio::ST_Music,Stream,Encode); }
113 
115  { return this->CreateSound(Audio::ST_Ambient,Stream,Frequency,Config); }
117  { return this->CreateSound(Audio::ST_Dialog,Stream,Frequency,Config); }
119  { return this->CreateSound(Audio::ST_Effect,Stream,Frequency,Config); }
121  { return this->CreateSound(Audio::ST_Music,Stream,Frequency,Config); }
122 
123  iSound* AudioManager::CreateAmbientSound(const String& FileName, const String& Group)
124  { return this->CreateSound(Audio::ST_Ambient,FileName,Group); }
125  iSound* AudioManager::CreateDialogSound(const String& FileName, const String& Group)
126  { return this->CreateSound(Audio::ST_Dialog,FileName,Group); }
127  iSound* AudioManager::CreateEffectSound(const String& FileName, const String& Group)
128  { return this->CreateSound(Audio::ST_Effect,FileName,Group); }
129  iSound* AudioManager::CreateMusicSound(const String& FileName, const String& Group)
130  { return this->CreateSound(Audio::ST_Music,FileName,Group); }
131 
132  iSound* AudioManager::CreateAmbientSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
133  { return this->CreateSound(Audio::ST_Ambient,StreamName,Buffer,Length,Encode); }
134  iSound* AudioManager::CreateDialogSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
135  { return this->CreateSound(Audio::ST_Dialog,StreamName,Buffer,Length,Encode); }
136  iSound* AudioManager::CreateEffectSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
137  { return this->CreateSound(Audio::ST_Effect,StreamName,Buffer,Length,Encode); }
138  iSound* AudioManager::CreateMusicSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
139  { return this->CreateSound(Audio::ST_Music,StreamName,Buffer,Length,Encode); }
140 
141  iSound* AudioManager::CreateAmbientSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
142  { return this->CreateSound(Audio::ST_Ambient,StreamName,Buffer,Length,Frequency,Config); }
143  iSound* AudioManager::CreateDialogSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
144  { return this->CreateSound(Audio::ST_Dialog,StreamName,Buffer,Length,Frequency,Config); }
145  iSound* AudioManager::CreateEffectSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
146  { return this->CreateSound(Audio::ST_Effect,StreamName,Buffer,Length,Frequency,Config); }
147  iSound* AudioManager::CreateMusicSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
148  { return this->CreateSound(Audio::ST_Music,StreamName,Buffer,Length,Frequency,Config); }
149 
150  ///////////////////////////////////////////////////////////////////////////////
151  // Volume Management
152 
153  ///////////////////////////////////////////////////////////////////////////////
154  // Convenience Type Volume Methods
155 
157  { this->SetTypeVolume(Audio::ST_Ambient,Ambient); }
159  { return this->GetTypeVolume(Audio::ST_Ambient); }
160  void AudioManager::MuteAmbient(bool Enable)
161  { this->MuteType(Audio::ST_Ambient,Enable); }
163  { return this->IsTypeMuted(Audio::ST_Ambient); }
164 
166  { this->SetTypeVolume(Audio::ST_Dialog,Dialog); }
168  { return this->GetTypeVolume(Audio::ST_Dialog); }
169  void AudioManager::MuteDialog(bool Enable)
170  { this->MuteType(Audio::ST_Dialog,Enable); }
172  { return this->IsTypeMuted(Audio::ST_Dialog); }
173 
175  { this->SetTypeVolume(Audio::ST_Effect,Effect); }
177  { return this->GetTypeVolume(Audio::ST_Effect); }
178  void AudioManager::MuteEffect(bool Enable)
179  { this->MuteType(Audio::ST_Effect,Enable); }
181  { return this->IsTypeMuted(Audio::ST_Effect); }
182 
184  { this->SetTypeVolume(Audio::ST_Music,Music); }
186  { return this->GetTypeVolume(Audio::ST_Music); }
187  void AudioManager::MuteMusic(bool Enable)
188  { this->MuteType(Audio::ST_Music,Enable); }
190  { return this->IsTypeMuted(Audio::ST_Music); }
191 
192  ///////////////////////////////////////////////////////////////////////////////
193  // Playback Device Management
194 
195  ///////////////////////////////////////////////////////////////////////////////
196  // Recording Device Management
197 
198  ///////////////////////////////////////////////////////////////////////////////
199  // Decoder Management
200 
202  {
203  this->DecoderFactories.insert(std::pair<Audio::Encoding,iDecoderFactory*>(ToBeAdded->GetSupportedEncoding(),ToBeAdded));
204  //std::pair<DecoderFactoryIterator,bool> Result = this->DecoderFactories.insert(std::pair<Audio::Encoding,iDecoderFactory*>(ToBeAdded->GetSupportedEncoding(),ToBeAdded));
205  //return Result.first;
206  }
207 
209  {
210  return this->DecoderFactories.count(Encode);
211  }
212 
214  {
215  DecoderFactoryIterator FactIt = this->DecoderFactories.find(Encode);
216  if( FactIt != this->DecoderFactories.end() ) return (*FactIt).second;
217  else return NULL;
218  }
219 
221  {
222  this->RemoveDecoderFactory(ToBeRemoved->GetSupportedEncoding());
223  }
224 
226  {
227  this->DecoderFactories.erase(Encode);
228  }
229 
231  {
232  this->DecoderFactories.clear();
233  }
234 
236  {
237  this->DestroyDecoderFactory(ToBeDestroyed->GetSupportedEncoding());
238  }
239 
241  {
242  DecoderFactoryIterator FactIt = this->DecoderFactories.find(Encode);
243  if( FactIt != this->DecoderFactories.end() )
244  {
245  delete (*FactIt).second;
246  this->DecoderFactories.erase(FactIt);
247  }
248  }
249 
251  {
252  for( DecoderFactoryIterator FactIt = this->DecoderFactories.begin() ; FactIt != this->DecoderFactories.end() ; ++FactIt )
253  {
254  delete (*FactIt).second;
255  }
256  this->DecoderFactories.clear();
257  }
258 
259  ///////////////////////////////////////////////////////////////////////////////
260  // Inherited from Managerbase
261 
263  { return ManagerBase::MT_AudioManager; }
264 
265  ///////////////////////////////////////////////////////////////////////////////
266  // Internal Methods
267  }//Audio
268 }//Mezzanine
269 
270 #endif