Spinning Topp Logo BlackTopp Studios
inc
sound.h
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 _audiosound_h
44 #define _audiosound_h
45 
46 #include "datatypes.h"
47 #include "Audio/audioenumerations.h"
48 #include "Audio/decoder.h"
49 
50 namespace Mezzanine
51 {
52  namespace Audio
53  {
54  class iFilter;
55  class iEffect;
56  ///////////////////////////////////////////////////////////////////////////////
57  /// @brief This is an interface class for a non-spacialized sound.
58  /// @details The iSound class is intended for non-3D purposes only.
59  ///////////////////////////////////////
60  class iSound
61  {
62  public:
63  /// @brief Class constructor.
64  iSound() { }
65  /// @brief Class destructor.
66  virtual ~iSound() { }
67 
68  ///////////////////////////////////////////////////////////////////////////////
69  // Utility
70 
71  /// @brief Checks to see if this sound is valid and is ready for playback.
72  /// @return Returns true if this sound is ready for playback, false if it is misconfigured.
73  virtual Boole IsValid() const = 0;
74  /// @brief Gets the sound type of this sound.
75  /// @return Returns a SoundType enum value that is the type of this sound.
76  virtual UInt16 GetType() const = 0;
77  /// @brief Gets the decoder that belongs to this sound.
78  /// @return Returns a pointer to the decoder being used by this sound for playback.
79  virtual iDecoder* GetDecoder() const = 0;
80 
81  /// @brief Sets the pitch of the sound source.
82  /// @note Higher values will speed up the playback of the sound. Default: 1.0
83  /// @param Pitch The new pitch of the sound.
84  virtual void SetPitch(const Real Pitch) = 0;
85  /// @brief Gets the pitch of the sound source.
86  /// @return Returns the pitch of the source.
87  virtual Real GetPitch() const = 0;
88  /// @brief Sets a new stream for playback by this @ref iSound.
89  /// @param Stream The stream to be decoded and played by this sound.
90  /// @param Encode The encoding to expect when decoding the stream provided.
91  virtual void SetStream(Resource::DataStreamPtr Stream, const Audio::Encoding Encode) = 0;
92  /// @brief Sets a new stream for playback by this @ref iSound.
93  /// @param Type The new type to set this @ref iSound instance as.
94  /// @param Stream The stream to be decoded and played by this sound.
95  /// @param Encode The encoding to expect when decoding the stream provided.
96  virtual void SetStream(const UInt16 Type, Resource::DataStreamPtr Stream, const Audio::Encoding Encode) = 0;
97  /// @brief Sets a new stream for playback by this @ref iSound via a new decoder.
98  /// @warning @ref iSound instances take ownership of decoders. Decoders should not be shared between @ref iSound instances.
99  /// @param Decode A pointer to the decoder containing the stream that will be used by this @ref iSound.
100  virtual void SetStream(iDecoder* Decode) = 0;
101  /// @brief Sets a new stream for playback by this @ref iSound via a new decoder.
102  /// @warning @ref iSound instances take ownership of decoders. Decoders should not be shared between @ref iSound instances.
103  /// @param Type The new type to set this @ref iSound instance as.
104  /// @param Decode A pointer to the decoder containing the stream that will be used by this @ref iSound.
105  virtual void SetStream(const UInt16 Type, iDecoder* Decode) = 0;
106 
107  ///////////////////////////////////////////////////////////////////////////////
108  // Playback
109 
110  /// @brief Plays the sound with it's current configuration.
111  /// @note This will restart playback in the event it is already playing.
112  /// @return Returns true if the sound succussfully started playing, false if there was an error.
113  virtual Boole Play() = 0;
114  /// @brief Gets whether or not the sound is currently playing.
115  /// @return Returns true if the sound is playing, false otherwise.
116  virtual Boole IsPlaying() const = 0;
117  /// @brief Pauses playback of the sound at it's current position in the stream.
118  virtual void Pause() = 0;
119  /// @brief Gets whether or not the sound is currently paused.
120  /// @return Returns true if the sound is paused, false otherwise.
121  virtual Boole IsPaused() const = 0;
122  /// @brief Stops playback of the sound and resets it's position back to the start.
123  virtual void Stop() = 0;
124  /// @brief Gets whether or not the sound is currently stopped.
125  /// @return Returns true if the sound is stopped, false otherwise.
126  virtual Boole IsStopped() const = 0;
127  /// @brief Sets whether the playback of the sound should loop or not.
128  /// @param ToLoop Whether to restart the sound when the end of playback is reached.
129  virtual void Loop(Boole ToLoop) = 0;
130  /// @brief Checks to see if the sound is currently set to loop.
131  /// @return Returns true if this sound will restart from the beginning when it finishes playing back.
132  virtual Boole IsLooping() const = 0;
133 
134  /// @brief Sets the current position of the stream from which to playback audio.
135  /// @note May not be supported by all codecs.
136  /// @param Seconds Number of seconds to seek.
137  /// @param Relative Whether to seek from the current position or the start of the stream.
138  /// @return Returns true on success, False if the codec does not support seeking.
139  virtual Boole Seek(const Real Seconds, Boole Relative = false) = 0;
140 
141  ///////////////////////////////////////////////////////////////////////////////
142  // Sound Stream Stats
143 
144  /// @brief Gets the length of the stream in seconds.
145  /// @return Returns the total amount of time needed to playback the sound in seconds.
146  virtual Real GetTotalTime() const
147  { return this->GetDecoder()->GetTotalTime(); }
148  /// @brief Gets the current time position in the stream.
149  /// @return Returns the current position in the stream in seconds.
150  virtual Real GetCurrentTime() const
151  { return this->GetDecoder()->GetCurrentTime(); }
152  /// @brief Gets the size of the decoded audio source in use.
153  /// @return Returns the size of the decoded audio source.
154  virtual UInt32 GetTotalSize() const
155  { return this->GetDecoder()->GetTotalSize(); }
156  /// @brief Gets the size of the encoded audio source in use.
157  /// @return Returns the size of the encoded audio source.
158  virtual UInt32 GetCompressedSize() const
159  { return this->GetDecoder()->GetCompressedSize(); }
160  /// @brief Gets the sounds current position in the decoded audio source.
161  /// @return Returns the current position in the decoded audio source in bytes.
162  virtual UInt32 GetCurrentPosition() const
163  { return this->GetDecoder()->GetCurrentPosition(); }
164  /// @brief Gets the sounds current position in the encoded audio source.
165  /// @return Returns the current position in the encoded audio source in bytes.
167  { return this->GetDecoder()->GetCurrentCompressedPosition(); }
168 
169  ///////////////////////////////////////////////////////////////////////////////
170  // Volume Control
171 
172  /// @brief Gets the current volume of the sound source after all volume settings are applied.
173  /// @note The internal constructs for sound will be updated of any changes to the volume of this object when the _Update() method is called.
174  /// @return Returns a Real representing the volume of this sound after all volume settings are applied.
175  virtual Real GetVolume() const = 0;
176  /// @brief Sets the current volume of the sound source before effects and other volume settings.
177  /// @details This function will set the current volume of the sound source before effects
178  /// (like attenuation) are applied.
179  /// @param Base The volume of the sound source to be applied.
180  virtual void SetBaseVolume(const Real Base) = 0;
181  /// @brief Gets the current volume of the sound source.
182  /// @details This function will get the current volume of the sound source before effects and other volume settings are applied.
183  /// @return Returns the source volume before attenuation and other effects.
184  virtual Real GetBaseVolume() const = 0;
185  /// @brief Sets the minimum volume the sound source can achieve.
186  /// @details This function will set the minimum volume the sound source can achieve after
187  /// effects(like attenuation) have been applied.
188  /// @param MinVol The minimum volume allowed for the sound source.
189  virtual void SetMinVolume(const Real MinVol) = 0;
190  /// @brief Gets the minimum volume of the sound source.
191  /// @return Returns the minimum volume that the source can be attenuated to.
192  virtual Real GetMinVolume() const = 0;
193  /// @brief Sets the maximum volume the sound source can achieve.
194  /// @details This function will set the maximum volume the sound source can achieve after
195  /// effects(like attenuation) have been applied.
196  /// @param MaxVol The maximum volume allowed for the sound source.
197  virtual void SetMaxVolume(const Real MaxVol) = 0;
198  /// @brief Gets the Maximum volume of the sound source.
199  /// @return Returns the maximum volume that the source can achieve.
200  virtual Real GetMaxVolume() const = 0;
201 
202  ///////////////////////////////////////////////////////////////////////////////
203  // Effects Methods
204 
205  /// @brief Attaches an @ref iEffect to this sound.
206  /// @remarks Valid Slot Range: 0 to @ref iSound::GetNumEffectSlotsAvailable()
207  /// @param Slot The slot into which the @ref iEffect will be attached.
208  /// @param Eff The @ref iEffect to be attached.
209  /// @return Returns true if the @ref iEffect was successfully attached, false otherwise.
210  virtual Boole AttachEffect(const UInt32 Slot, iEffect* Eff) = 0;
211  /// @brief Gets the @ref iEffect attached at the specified slot.
212  /// @param Slot The slot to retrieve the @ref iEffect from.
213  /// @return Returns a pointer to the @ref iEffect attached at the specified slot, or NULL if none are attached.
214  virtual iEffect* GetEffect(const UInt32 Slot) const = 0;
215  /// @brief Gets the max number of @ref iEffect instances that can be attached to this sound.
216  /// @return Returns the maximum number of @ref iEffect instances this sound can support.
217  virtual UInt32 GetMaxEffectSlots() const = 0;
218  /// @brief Gets the number of @ref iEffect slots remaining that can be attached to.
219  /// @return Returns the remaining number of @ref iEffect instances this sound can support before it reaches it's max.
220  virtual UInt32 GetNumEffectSlotsAvailable() const = 0;
221  /// @brief Removes the @ref iEffect in the specified slot.
222  /// @remarks Valid Slot Range: 0 to @ref iSound::GetNumEffectSlotsAvailable()
223  /// @param Slot The slot to remove the occupying @ref iEffect.
224  virtual void RemoveEffect(const UInt32 Slot) = 0;
225 
226  ///////////////////////////////////////////////////////////////////////////////
227  // Filter Methods
228 
229  /// @brief Attaches a filter to this sound that will operate on the direct feed, separate from any effects.
230  /// @note This will remove any previously attached filter. Only one filter can be attached at a given time.
231  /// @param Fil The filter to be attached.
232  /// @return Returns true if the filter was successfully attached, false otherwise.
233  virtual Boole AttachFilter(iFilter* Fil) = 0;
234  /// @brief Gets the filter currently being used by this object.
235  /// @return Returns a pointer to the currently attached filter, or NULL if there isn't one.
236  virtual iFilter* GetFilter() const = 0;
237  /// @brief Removes any currently attached filters.
238  virtual void RemoveFilter() = 0;
239  };//iSound
240  }//Audio
241 }//Mezzanine
242 
243 #endif
virtual UInt32 GetTotalSize() const
Gets the size of the decoded audio source in use.
Definition: sound.h:154
virtual void Pause()=0
Pauses playback of the sound at it's current position in the stream.
This is an interface class for the decoding of audio from a stream.
Definition: decoder.h:59
iSound()
Class constructor.
Definition: sound.h:64
virtual Boole IsPlaying() const =0
Gets whether or not the sound is currently playing.
virtual UInt32 GetCurrentPosition() const =0
Gets the sounds current position in the decoded audio source.
bool Boole
Generally acts a single bit, true or false.
Definition: datatypes.h:173
virtual Real GetVolume() const =0
Gets the current volume of the sound source after all volume settings are applied.
virtual void Stop()=0
Stops playback of the sound and resets it's position back to the start.
virtual Real GetCurrentTime() const
Gets the current time position in the stream.
Definition: sound.h:150
virtual Boole IsLooping() const =0
Checks to see if the sound is currently set to loop.
virtual UInt32 GetTotalSize() const =0
Gets the size of the decoded audio source in use.
virtual void SetPitch(const Real Pitch)=0
Sets the pitch of the sound source.
virtual void SetMaxVolume(const Real MaxVol)=0
Sets the maximum volume the sound source can achieve.
virtual UInt32 GetNumEffectSlotsAvailable() const =0
Gets the number of iEffect slots remaining that can be attached to.
virtual Real GetMaxVolume() const =0
Gets the Maximum volume of the sound source.
virtual Boole IsValid() const =0
Checks to see if this sound is valid and is ready for playback.
virtual void SetMinVolume(const Real MinVol)=0
Sets the minimum volume the sound source can achieve.
All the definitions for datatypes as well as some basic conversion functions are defined here...
A simple reference counting pointer.
Definition: countedptr.h:70
virtual Boole Play()=0
Plays the sound with it's current configuration.
virtual void RemoveFilter()=0
Removes any currently attached filters.
virtual void RemoveEffect(const UInt32 Slot)=0
Removes the iEffect in the specified slot.
This is an interface class for a non-spacialized sound.
Definition: sound.h:60
This is an interface class for an effect that can be applied to a sound.
Definition: effect.h:58
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
virtual ~iSound()
Class destructor.
Definition: sound.h:66
virtual UInt32 GetCurrentPosition() const
Gets the sounds current position in the decoded audio source.
Definition: sound.h:162
virtual void Loop(Boole ToLoop)=0
Sets whether the playback of the sound should loop or not.
uint16_t UInt16
An 16-bit unsigned integer.
Definition: datatypes.h:122
virtual Real GetCurrentTime() const =0
Gets the current time position in the stream.
virtual Real GetBaseVolume() const =0
Gets the current volume of the sound source.
uint32_t UInt32
An 32-bit unsigned integer.
Definition: datatypes.h:126
virtual UInt32 GetCurrentCompressedPosition() const =0
Gets the sounds current position in the encoded audio source.
virtual iFilter * GetFilter() const =0
Gets the filter currently being used by this object.
virtual Real GetMinVolume() const =0
Gets the minimum volume of the sound source.
virtual void SetStream(Resource::DataStreamPtr Stream, const Audio::Encoding Encode)=0
Sets a new stream for playback by this iSound.
virtual Real GetTotalTime() const
Gets the length of the stream in seconds.
Definition: sound.h:146
virtual void SetBaseVolume(const Real Base)=0
Sets the current volume of the sound source before effects and other volume settings.
virtual UInt32 GetCompressedSize() const
Gets the size of the encoded audio source in use.
Definition: sound.h:158
virtual Boole Seek(const Real Seconds, Boole Relative=false)=0
Sets the current position of the stream from which to playback audio.
virtual Boole AttachEffect(const UInt32 Slot, iEffect *Eff)=0
Attaches an iEffect to this sound.
virtual UInt32 GetCurrentCompressedPosition() const
Gets the sounds current position in the encoded audio source.
Definition: sound.h:166
virtual iEffect * GetEffect(const UInt32 Slot) const =0
Gets the iEffect attached at the specified slot.
Encoding
The encoding to use when reading or writing an audio buffer.
virtual UInt32 GetCompressedSize() const =0
Gets the size of the encoded audio source in use.
virtual Real GetTotalTime() const =0
Gets the length of the stream in seconds.
The bulk of the engine components go in this namspace.
Definition: actor.cpp:56
virtual Real GetPitch() const =0
Gets the pitch of the sound source.
virtual iDecoder * GetDecoder() const =0
Gets the decoder that belongs to this sound.
This is an interface class for the application of filters to audio playback.
Definition: filter.h:57
virtual Boole IsPaused() const =0
Gets whether or not the sound is currently paused.
virtual Boole IsStopped() const =0
Gets whether or not the sound is currently stopped.
virtual UInt32 GetMaxEffectSlots() const =0
Gets the max number of iEffect instances that can be attached to this sound.
virtual UInt16 GetType() const =0
Gets the sound type of this sound.
virtual Boole AttachFilter(iFilter *Fil)=0
Attaches a filter to this sound that will operate on the direct feed, separate from any effects...