MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
soundscapemanager.h
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 #ifndef _audiosoundscapemanager_h
41 #define _audiosoundscapemanager_h
42 
43 #include "worldmanager.h"
44 #include "managerfactory.h"
45 #include "Audio/audioenumerations.h"
46 #include "Threading/workunit.h"
47 
48 namespace Mezzanine
49 {
50  namespace Audio
51  {
52  class iListener;
53  class SoundProxy;
54 
55  ///////////////////////////////////////////////////////////////////////////////
56  /// @brief This is the work unit for updating audio buffers as necessary for audio playback.
57  /// @details
58  ///////////////////////////////////////
60  {
61  public:
62  /// @brief Class destructor.
64 
65  ///////////////////////////////////////////////////////////////////////////////
66  // Utility
67 
68  /// @brief This does any required updating of audio buffers belonging to sound proxies in this manager.
69  /// @param CurrentThreadStorage The storage class for all resources owned by this work unit during it's execution.
70  virtual void DoWork(Threading::DefaultThreadSpecificStorage::Type& CurrentThreadStorage) = 0;
71  };//iBufferUpdate3DWorkUnit
72 
73  ///////////////////////////////////////////////////////////////////////////////
74  /// @brief This is the base manager class for audio being played in a 3D environment.
75  /// @details
76  ///////////////////////////////////////
78  {
79  public:
80  protected:
81  public:
82  /// @brief Class constructor.
84  /// @brief XML constructor.
85  /// @param XMLNode The node of the xml document to construct from.
86  SoundScapeManager(XML::Node& XMLNode);
87  /// @brief Class destructor.
88  virtual ~SoundScapeManager();
89 
90  ///////////////////////////////////////////////////////////////////////////////
91  // Listener Management
92 
93  /// @brief Creates a new @ref iListener.
94  /// @return Returns a pointer to the @ref iListener instance that was created.
95  virtual iListener* CreateListener() = 0;
96  /// @brief Gets an @ref iListener instance by index.
97  /// @param Index The index of the @ref iListener to be retrieved.
98  /// @return Returns a pointer to the @ref iListener at the specified index.
99  virtual iListener* GetListener(const UInt32 Index) const = 0;
100  /// @brief Gets the number of @ref iListener instances in this manager.
101  /// @return Returns a UInt32 representing the number of @ref iListener instances contained in this manager.
102  virtual UInt32 GetNumListeners() const = 0;
103  /// @brief Deletes a @ref iListener.
104  /// @param ToBeDestroyed A pointer to the @ref iListener you want deleted.
105  virtual void DestroyListener(iListener* ToBeDestroyed) = 0;
106  /// @brief Deletes all stored @ref iListener instances.
107  virtual void DestroyAllListeners() = 0;
108 
109  ///////////////////////////////////////////////////////////////////////////////
110  // Proxy Management
111 
112  /// @brief Creates a blank @ref SoundProxy without a stream attached to it.
113  /// @param Type A UInt16 that is the ID for the type of sound the created @ref SoundProxy is to be categorized as.
114  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
115  virtual SoundProxy* CreateSoundProxy(const UInt16 Type) = 0;
116  /// @brief Creates a new @ref SoundProxy from a custom stream that is encoded.
117  /// @param Type A UInt16 that is the ID for the type of sound the created @ref SoundProxy is to be categorized as.
118  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
119  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
120  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
121  virtual SoundProxy* CreateSoundProxy(const UInt16 Type, Resource::DataStreamPtr Stream, const Audio::Encoding Encode) = 0;
122  /// @brief Creates a new @ref SoundProxy from a custom stream that is unencoded.
123  /// @param Type A UInt16 that is the ID for the type of sound the created @ref SoundProxy is to be categorized as.
124  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
125  /// @param Frequency The frequency (or sample rate) of the audio data.
126  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
127  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
128  virtual SoundProxy* CreateSoundProxy(const UInt16 Type, Resource::DataStreamPtr Stream, const UInt32 Frequency, const Audio::BitConfig Config) = 0;
129  /// @brief Creates a new @ref SoundProxy from a file.
130  /// @param Type A UInt16 that is the ID for the type of sound the created @ref SoundProxy is to be categorized as.
131  /// @param FileName The name of the file to read audio data from.
132  /// @param Group The resource group in which the file resides.
133  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
134  virtual SoundProxy* CreateSoundProxy(const UInt16 Type, const String& FileName, const String& Group) = 0;
135  /// @brief Creates a new @ref SoundProxy from a memory buffer that is encoded.
136  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
137  /// @param Type A UInt16 that is the ID for the type of sound the created @ref SoundProxy is to be categorized as.
138  /// @param StreamName The name to be given to the stream being created.
139  /// @param Buffer A pointer to the buffer where the audio data is located.
140  /// @param Length The length of the buffer provided to this method(in bytes).
141  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
142  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
143  virtual SoundProxy* CreateSoundProxy(const UInt16 Type, const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode) = 0;
144  /// @brief Creates a new @ref SoundProxy from a memory buffer that is unencoded.
145  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
146  /// @param Type A UInt16 that is the ID for the type of sound the created @ref SoundProxy is to be categorized as.
147  /// @param StreamName The name to be given to the stream being created.
148  /// @param Buffer A pointer to the buffer where the audio data is located.
149  /// @param Length The length of the buffer provided to this method(in bytes).
150  /// @param Frequency The frequency (or sample rate) of the audio data.
151  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
152  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
153  virtual SoundProxy* CreateSoundProxy(const UInt16 Type, const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config) = 0;
154  /// @brief Gets an @ref SoundProxy instance by index.
155  /// @param Index The index of the @ref SoundProxy to be retrieved.
156  /// @return Returns a pointer to the @ref SoundProxy at the specified index.
157  virtual SoundProxy* GetSoundProxy(const UInt32 Index) const = 0;
158  /// @brief Gets the number of @ref SoundProxy instances in this manager.
159  /// @return Returns a UInt32 representing the number of @ref SoundProxy instances contained in this manager.
160  virtual UInt32 GetNumSoundProxies() const = 0;
161  /// @brief Deletes a @ref SoundProxy.
162  /// @param ToBeDestroyed A pointer to the @ref SoundProxy you want deleted.
163  virtual void DestroySoundProxy(SoundProxy* ToBeDestroyed) = 0;
164  /// @brief Deletes all stored @ref SoundProxy instances.
165  virtual void DestroyAllSoundProxies() = 0;
166 
167  ///////////////////////////////////////////////////////////////////////////////
168  // Convenience Creation Methods
169 
170  /// @brief Creates a blank Ambient @ref SoundProxy without a stream attached to it.
171  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
172  virtual SoundProxy* CreateAmbientSoundProxy();
173  /// @brief Creates a blank Dialog @ref SoundProxy without a stream attached to it.
174  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
175  virtual SoundProxy* CreateDialogSoundProxy();
176  /// @brief Creates a blank Effect @ref SoundProxy without a stream attached to it.
177  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
178  virtual SoundProxy* CreateEffectSoundProxy();
179  /// @brief Creates a blank Music @ref SoundProxy without a stream attached to it.
180  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
181  virtual SoundProxy* CreateMusicSoundProxy();
182 
183  /// @brief Creates a new Ambient @ref SoundProxy from a custom stream that is encoded.
184  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
185  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
186  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
187  virtual SoundProxy* CreateAmbientSoundProxy(Resource::DataStreamPtr Stream, const Audio::Encoding Encode);
188  /// @brief Creates a new Dialog @ref SoundProxy from a custom stream that is encoded.
189  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
190  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
191  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
192  virtual SoundProxy* CreateDialogSoundProxy(Resource::DataStreamPtr Stream, const Audio::Encoding Encode);
193  /// @brief Creates a new Effect @ref SoundProxy from a custom stream that is encoded.
194  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
195  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
196  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
197  virtual SoundProxy* CreateEffectSoundProxy(Resource::DataStreamPtr Stream, const Audio::Encoding Encode);
198  /// @brief Creates a new Music @ref SoundProxy from a custom stream that is encoded.
199  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
200  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
201  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
202  virtual SoundProxy* CreateMusicSoundProxy(Resource::DataStreamPtr Stream, const Audio::Encoding Encode);
203 
204  /// @brief Creates a new Ambient @ref SoundProxy from a custom stream that is unencoded.
205  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
206  /// @param Frequency The frequency (or sample rate) of the audio data.
207  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
208  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
209  virtual SoundProxy* CreateAmbientSoundProxy(Resource::DataStreamPtr Stream, const UInt32 Frequency, const Audio::BitConfig Config);
210  /// @brief Creates a new Dialog @ref SoundProxy from a custom stream that is unencoded.
211  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
212  /// @param Frequency The frequency (or sample rate) of the audio data.
213  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
214  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
215  virtual SoundProxy* CreateDialogSoundProxy(Resource::DataStreamPtr Stream, const UInt32 Frequency, const Audio::BitConfig Config);
216  /// @brief Creates a new Effect @ref SoundProxy from a custom stream that is unencoded.
217  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
218  /// @param Frequency The frequency (or sample rate) of the audio data.
219  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
220  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
221  virtual SoundProxy* CreateEffectSoundProxy(Resource::DataStreamPtr Stream, const UInt32 Frequency, const Audio::BitConfig Config);
222  /// @brief Creates a new Music @ref SoundProxy from a custom stream that is unencoded.
223  /// @param Stream A Datastream containing the data to be streamed for this @ref SoundProxy.
224  /// @param Frequency The frequency (or sample rate) of the audio data.
225  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
226  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
227  virtual SoundProxy* CreateMusicSoundProxy(Resource::DataStreamPtr Stream, const UInt32 Frequency, const Audio::BitConfig Config);
228 
229  /// @brief Creates a new Ambient @ref SoundProxy from a file.
230  /// @param FileName The name of the file to read audio data from.
231  /// @param Group The resource group in which the file resides.
232  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
233  virtual SoundProxy* CreateAmbientSoundProxy(const String& FileName, const String& Group);
234  /// @brief Creates a new Dialog @ref SoundProxy from a file.
235  /// @param FileName The name of the file to read audio data from.
236  /// @param Group The resource group in which the file resides.
237  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
238  virtual SoundProxy* CreateDialogSoundProxy(const String& FileName, const String& Group);
239  /// @brief Creates a new Effect @ref SoundProxy from a file.
240  /// @param FileName The name of the file to read audio data from.
241  /// @param Group The resource group in which the file resides.
242  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
243  virtual SoundProxy* CreateEffectSoundProxy(const String& FileName, const String& Group);
244  /// @brief Creates a new Music @ref SoundProxy from a file.
245  /// @param FileName The name of the file to read audio data from.
246  /// @param Group The resource group in which the file resides.
247  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
248  virtual SoundProxy* CreateMusicSoundProxy(const String& FileName, const String& Group);
249 
250  /// @brief Creates a new Ambient @ref SoundProxy from a memory buffer that is encoded.
251  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
252  /// @param StreamName The name to be given to the stream being created.
253  /// @param Buffer A pointer to the buffer where the audio data is located.
254  /// @param Length The length of the buffer provided to this method(in bytes).
255  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
256  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
257  virtual SoundProxy* CreateAmbientSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode);
258  /// @brief Creates a new Dialog @ref SoundProxy from a memory buffer that is encoded.
259  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
260  /// @param SoundName The name of the @ref SoundProxy instance.
261  /// @param Buffer A pointer to the buffer where the audio data is located.
262  /// @param Length The length of the buffer provided to this method(in bytes).
263  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
264  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
265  virtual SoundProxy* CreateDialogSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode);
266  /// @brief Creates a new Effect @ref SoundProxy from a memory buffer that is encoded.
267  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
268  /// @param StreamName The name to be given to the stream being created.
269  /// @param Buffer A pointer to the buffer where the audio data is located.
270  /// @param Length The length of the buffer provided to this method(in bytes).
271  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
272  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
273  virtual SoundProxy* CreateEffectSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode);
274  /// @brief Creates a new Music @ref SoundProxy from a memory buffer that is encoded.
275  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
276  /// @param StreamName The name to be given to the stream being created.
277  /// @param Buffer A pointer to the buffer where the audio data is located.
278  /// @param Length The length of the buffer provided to this method(in bytes).
279  /// @param Encode The encoding to be expected when decoding audio for this @ref SoundProxy.
280  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
281  virtual SoundProxy* CreateMusicSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const Audio::Encoding Encode);
282 
283  /// @brief Creates a new Ambient @ref SoundProxy from a memory buffer that is unencoded.
284  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
285  /// @param StreamName The name to be given to the stream being created.
286  /// @param Buffer A pointer to the buffer where the audio data is located.
287  /// @param Length The length of the buffer provided to this method(in bytes).
288  /// @param Frequency The frequency (or sample rate) of the audio data.
289  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
290  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
291  virtual SoundProxy* CreateAmbientSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config);
292  /// @brief Creates a new Dialog @ref SoundProxy from a memory buffer that is unencoded.
293  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
294  /// @param StreamName The name to be given to the stream being created.
295  /// @param Buffer A pointer to the buffer where the audio data is located.
296  /// @param Length The length of the buffer provided to this method(in bytes).
297  /// @param Frequency The frequency (or sample rate) of the audio data.
298  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
299  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
300  virtual SoundProxy* CreateDialogSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config);
301  /// @brief Creates a new Effect @ref SoundProxy from a memory buffer that is unencoded.
302  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
303  /// @param StreamName The name to be given to the stream being created.
304  /// @param Buffer A pointer to the buffer where the audio data is located.
305  /// @param Length The length of the buffer provided to this method(in bytes).
306  /// @param Frequency The frequency (or sample rate) of the audio data.
307  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
308  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
309  virtual SoundProxy* CreateEffectSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config);
310  /// @brief Creates a new Music @ref SoundProxy from a memory buffer that is unencoded.
311  /// @note The buffer is copied and put into a memory stream. Thus safe for disposal afterward.
312  /// @param StreamName The name to be given to the stream being created.
313  /// @param Buffer A pointer to the buffer where the audio data is located.
314  /// @param Length The length of the buffer provided to this method(in bytes).
315  /// @param Frequency The frequency (or sample rate) of the audio data.
316  /// @param Config The bit configuration of the audio data. Helps to determine sample size.
317  /// @return Returns a pointer to the @ref SoundProxy instance that was created.
318  virtual SoundProxy* CreateMusicSoundProxy(const String& StreamName, Char8* Buffer, const UInt32 Length, const UInt32 Frequency, const Audio::BitConfig Config);
319 
320  ///////////////////////////////////////////////////////////////////////////////
321  // Utility
322 
323  /// @copydoc WorldManager::Pause(const UInt32)
324  virtual void Pause(const UInt32 PL) = 0;
325 
326  /// @copydoc WorldManager::Initialize()
327  virtual void Initialize() = 0;
328  /// @copydoc ManagerBase::Deinitialize()
329  virtual void Deinitialize() = 0;
330 
331  /// @brief Gets the work unit responsible for updating the buffers of soundproxies.
332  /// @return Returns a pointer to the iBufferUpdate3DWorkUnit used by this manager.
333  virtual iBufferUpdate3DWorkUnit* GetBufferUpdate3DWork() = 0;
334 
335  ///////////////////////////////////////////////////////////////////////////////
336  // Type Identifier Methods
337 
338  /// @copydoc ManagerBase::GetInterfaceType()
339  virtual ManagerType GetInterfaceType() const;
340  };//SoundScapeManager
341  }//Audio
342 }//Mezzanine
343 
344 #endif