Spinning Topp Logo BlackTopp Studios
inc
audiomanager.cpp
1 // © Copyright 2010 - 2016 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  /// @brief A statically accessible pointer to the one and only AudioManager.
62  template<> Audio::AudioManager* Singleton<Audio::AudioManager>::SingletonPtr = 0;
63 
64  namespace Audio
65  {
66  //template<> AudioManager* Singleton<AudioManager>::SingletonPtr = 0;
67 
69  {
70 #ifdef ENABLE_RAW_ENCODE
71  this->AddDecoderFactory(new RawDecoderFactory());
72 #endif
73 #ifdef ENABLE_VORBIS_ENCODE
74  this->AddDecoderFactory(new VorbisDecoderFactory());
75 #endif
76 #ifdef ENABLE_WAV_ENCODE
77  this->AddDecoderFactory(new WavDecoderFactory());
78 #endif
79  }
80 
82  {
83 #ifdef ENABLE_RAW_ENCODE
84  this->AddDecoderFactory(new RawDecoderFactory());
85 #endif
86 #ifdef ENABLE_VORBIS_ENCODE
87  this->AddDecoderFactory(new VorbisDecoderFactory());
88 #endif
89 #ifdef ENABLE_WAV_ENCODE
90  this->AddDecoderFactory(new WavDecoderFactory());
91 #endif
92  }
93 
95  { this->DestroyAllDecoderFactories(); }
96 
97  ///////////////////////////////////////////////////////////////////////////////
98  // Utility
99 
100  ///////////////////////////////////////////////////////////////////////////////
101  // Sound Management
102 
103  ///////////////////////////////////////////////////////////////////////////////
104  // Convenience Creation Methods
105 
107  { return this->CreateSound(Audio::ST_Ambient); }
109  { return this->CreateSound(Audio::ST_Dialog); }
111  { return this->CreateSound(Audio::ST_Effect); }
113  { return this->CreateSound(Audio::ST_Music); }
114 
116  { return this->CreateSound(Audio::ST_Ambient,Stream,Encode); }
118  { return this->CreateSound(Audio::ST_Dialog,Stream,Encode); }
120  { return this->CreateSound(Audio::ST_Effect,Stream,Encode); }
122  { return this->CreateSound(Audio::ST_Music,Stream,Encode); }
123 
125  { return this->CreateSound(Audio::ST_Ambient,Stream,Frequency,Config); }
127  { return this->CreateSound(Audio::ST_Dialog,Stream,Frequency,Config); }
129  { return this->CreateSound(Audio::ST_Effect,Stream,Frequency,Config); }
131  { return this->CreateSound(Audio::ST_Music,Stream,Frequency,Config); }
132 
133  iSound* AudioManager::CreateAmbientSound(const String& FileName, const String& Group)
134  { return this->CreateSound(Audio::ST_Ambient,FileName,Group); }
135  iSound* AudioManager::CreateDialogSound(const String& FileName, const String& Group)
136  { return this->CreateSound(Audio::ST_Dialog,FileName,Group); }
137  iSound* AudioManager::CreateEffectSound(const String& FileName, const String& Group)
138  { return this->CreateSound(Audio::ST_Effect,FileName,Group); }
139  iSound* AudioManager::CreateMusicSound(const String& FileName, const String& Group)
140  { return this->CreateSound(Audio::ST_Music,FileName,Group); }
141 
142  iSound* AudioManager::CreateAmbientSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
143  { return this->CreateSound(Audio::ST_Ambient,StreamName,Buffer,Length,Encode); }
144  iSound* AudioManager::CreateDialogSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
145  { return this->CreateSound(Audio::ST_Dialog,StreamName,Buffer,Length,Encode); }
146  iSound* AudioManager::CreateEffectSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
147  { return this->CreateSound(Audio::ST_Effect,StreamName,Buffer,Length,Encode); }
148  iSound* AudioManager::CreateMusicSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode)
149  { return this->CreateSound(Audio::ST_Music,StreamName,Buffer,Length,Encode); }
150 
151  iSound* AudioManager::CreateAmbientSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
152  { return this->CreateSound(Audio::ST_Ambient,StreamName,Buffer,Length,Frequency,Config); }
153  iSound* AudioManager::CreateDialogSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
154  { return this->CreateSound(Audio::ST_Dialog,StreamName,Buffer,Length,Frequency,Config); }
155  iSound* AudioManager::CreateEffectSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
156  { return this->CreateSound(Audio::ST_Effect,StreamName,Buffer,Length,Frequency,Config); }
157  iSound* AudioManager::CreateMusicSound(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config)
158  { return this->CreateSound(Audio::ST_Music,StreamName,Buffer,Length,Frequency,Config); }
159 
160  ///////////////////////////////////////////////////////////////////////////////
161  // Volume Management
162 
163  ///////////////////////////////////////////////////////////////////////////////
164  // Convenience Type Volume Methods
165 
167  { this->SetTypeVolume(Audio::ST_Ambient,Ambient); }
169  { return this->GetTypeVolume(Audio::ST_Ambient); }
171  { this->MuteType(Audio::ST_Ambient,Enable); }
173  { return this->IsTypeMuted(Audio::ST_Ambient); }
174 
176  { this->SetTypeVolume(Audio::ST_Dialog,Dialog); }
178  { return this->GetTypeVolume(Audio::ST_Dialog); }
180  { this->MuteType(Audio::ST_Dialog,Enable); }
182  { return this->IsTypeMuted(Audio::ST_Dialog); }
183 
185  { this->SetTypeVolume(Audio::ST_Effect,Effect); }
187  { return this->GetTypeVolume(Audio::ST_Effect); }
189  { this->MuteType(Audio::ST_Effect,Enable); }
191  { return this->IsTypeMuted(Audio::ST_Effect); }
192 
194  { this->SetTypeVolume(Audio::ST_Music,Music); }
196  { return this->GetTypeVolume(Audio::ST_Music); }
198  { this->MuteType(Audio::ST_Music,Enable); }
200  { return this->IsTypeMuted(Audio::ST_Music); }
201 
202  ///////////////////////////////////////////////////////////////////////////////
203  // Playback Device Management
204 
205  ///////////////////////////////////////////////////////////////////////////////
206  // Recording Device Management
207 
208  ///////////////////////////////////////////////////////////////////////////////
209  // Decoder Management
210 
212  {
213  this->DecoderFactories.insert(std::pair<Audio::Encoding,iDecoderFactory*>(ToBeAdded->GetSupportedEncoding(),ToBeAdded));
214  //std::pair<DecoderFactoryIterator,Boole> Result = this->DecoderFactories.insert(std::pair<Audio::Encoding,iDecoderFactory*>(ToBeAdded->GetSupportedEncoding(),ToBeAdded));
215  //return Result.first;
216  }
217 
219  {
220  return this->DecoderFactories.count(Encode);
221  }
222 
224  {
225  DecoderFactoryIterator FactIt = this->DecoderFactories.find(Encode);
226  if( FactIt != this->DecoderFactories.end() ) return (*FactIt).second;
227  else return NULL;
228  }
229 
231  {
232  this->RemoveDecoderFactory(ToBeRemoved->GetSupportedEncoding());
233  }
234 
236  {
237  this->DecoderFactories.erase(Encode);
238  }
239 
241  {
242  this->DecoderFactories.clear();
243  }
244 
246  {
247  this->DestroyDecoderFactory(ToBeDestroyed->GetSupportedEncoding());
248  }
249 
251  {
252  DecoderFactoryIterator FactIt = this->DecoderFactories.find(Encode);
253  if( FactIt != this->DecoderFactories.end() )
254  {
255  delete (*FactIt).second;
256  this->DecoderFactories.erase(FactIt);
257  }
258  }
259 
261  {
262  for( DecoderFactoryIterator FactIt = this->DecoderFactories.begin() ; FactIt != this->DecoderFactories.end() ; ++FactIt )
263  {
264  delete (*FactIt).second;
265  }
266  this->DecoderFactories.clear();
267  }
268 
269  ///////////////////////////////////////////////////////////////////////////////
270  // Inherited from Managerbase
271 
273  { return ManagerBase::MT_AudioManager; }
274 
275  ///////////////////////////////////////////////////////////////////////////////
276  // Internal Methods
277  }//Audio
278 }//Mezzanine
279 
280 #endif
virtual void SetTypeVolume(const UInt16 Type, const Real Vol)=0
Sets the volume for all stored Sound instances of the specified type.
virtual Audio::Encoding GetSupportedEncoding() const =0
Gets the encoding supported by decoders made by this factory.
void RemoveAllDecoderFactories()
Removes (but does not destroy) all registered iDecoderFactory instances.
void RemoveDecoderFactory(iDecoderFactory *ToBeRemoved)
Removes (but does not destroy) an iDecoderFactory.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
ManagerType
A listing of Manager Types.
Definition: managerbase.h:65
virtual Boole IsMusicMuted() const
Gets whether or not Music Sound instances are muted.
virtual void MuteDialog(Boole Enable)
Sets whether or not to mute all Dialog Sound instances.
Various effects such as objects colliding, explosions, guns firing, etc.
Environmental sounds. Bird's chirping, water washing against rocks, etc.
A simple reference counting pointer.
Definition: countedptr.h:70
virtual void SetEffectVolume(const Real &Effect)
Sets the volume for all stored Effect Sound instances.
void DestroyAllDecoderFactories()
Destroys all registered iDecoderFactory instances.
Self explanitory. The game SoundTrack.
virtual void MuteType(const UInt16 Type, Boole Enable)=0
Sets whether or not to mute all Sound instances of a specified type.
This implements the exception hiearchy for Mezzanine.
virtual Real GetEffectVolume() const
Gets the currently set Effect volume.
This is an interface class for a non-spacialized sound.
Definition: sound.h:60
This is an interface class for factories that create decoders.
virtual Boole IsDialogMuted() const
Gets whether or not Dialog Sound instances are muted.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
char Char8
A datatype to represent one character.
Definition: datatypes.h:169
virtual void SetDialogVolume(const Real &Dialog)
Sets the volume for all stored Dialog Sound instances.
virtual void SetMusicVolume(const Real &Music)
Sets the volume for all stored Music Sound instances.
void DestroyDecoderFactory(iDecoderFactory *ToBeDestroyed)
Destroy a registered iDecoderFactory.
virtual void MuteMusic(Boole Enable)
Sets whether or not to mute all Music Sound instances.
void AddDecoderFactory(iDecoderFactory *ToBeAdded)
Adds a iDecoderFactory to this manager allowing the playback of new types of sound formats...
virtual Boole IsTypeMuted(const UInt16 Type) const =0
Gets whether or not Sound instances of the specified type are currently muted.
virtual iSound * CreateEffectSound()
Creates a blank Effect iSound without a stream attached to it.
A light-weight handle for manipulating nodes in DOM tree.
Definition: node.h:89
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
virtual Boole IsAmbientMuted() const
Gets whether or not Ambient Sound instances are muted.
virtual Real GetTypeVolume(const UInt16 Type) const =0
Gets the volume for all stored Sound instances of the specified type.
virtual Real GetAmbientVolume() const
Gets the currently set Ambient volume.
virtual ~AudioManager()
Class Destructor.
DecoderFactoryContainer::iterator DecoderFactoryIterator
Iterator type for iDecoderFactory instances stored by this class.
Definition: audiomanager.h:120
virtual Real GetMusicVolume() const
Gets the currently set Music volume.
virtual iSound * CreateSound(const UInt16 Type)=0
Creates a blank iSound without a stream attached to it.
Encoding
The encoding to use when reading or writing an audio buffer.
virtual Real GetDialogVolume() const
Gets the currently set Dialog volume.
virtual ManagerType GetInterfaceType() const
This returns the type of this manager.
Character sounds and speech.
Boole DecoderFactoryExists(const Audio::Encoding Format)
Checks if a iDecoderFactory is already registered with this manager.
virtual void SetAmbientVolume(const Real &Ambient)
Sets the volume for all stored Ambient Sound instances.
AudioManager()
Class Constructor.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual void MuteAmbient(Boole Enable)
Sets whether or not to mute all Ambient Sound instances.
virtual void MuteEffect(Boole Enable)
Sets whether or not to mute all Effect Sound instances.
virtual iSound * CreateAmbientSound()
Creates a blank Ambient iSound without a stream attached to it.
virtual Boole IsEffectMuted() const
Gets whether or not Effect Sound instances are muted.
std::string String
A datatype used to a series of characters.
Definition: datatypes.h:159
virtual iSound * CreateDialogSound()
Creates a blank Dialog iSound without a stream attached to it.
iDecoderFactory * GetDecoderFactory(const Audio::Encoding Format)
Gets an iDecoderFactory by it's supported Audio::Encoding.
DecoderFactoryContainer DecoderFactories
Container storing all registered iDecoderFactory instances.
Definition: audiomanager.h:126
virtual iSound * CreateMusicSound()
Creates a blank Music iSound without a stream attached to it.
BitConfig
Used to describe the different bit configurations supported by this audio system. ...