MezzanineEngine 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
decoder.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 // 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 _audiodecoder_h
44 #define _audiodecoder_h
45 
46 #include "datatypes.h"
47 #include "Audio/audioenumerations.h"
48 
49 #include "Resource/datastream.h"
50 
51 namespace Mezzanine
52 {
53  namespace Audio
54  {
55  ///////////////////////////////////////////////////////////////////////////////
56  /// @brief This is an interface class for the decoding of audio from a stream.
57  /// @details
58  ///////////////////////////////////////
59  class iDecoder
60  {
61  public:
62  /// @brief Class constructor.
63  iDecoder() { }
64  /// @brief Class destructor.
65  virtual ~iDecoder() { }
66 
67  ///////////////////////////////////////////////////////////////////////////////
68  // Utility
69 
70  /// @brief Gets whether or not the decoder is ready to be used.
71  /// @note On failure the issue likely lies with the stream being an improper format/encoding.
72  /// @return Returns true if this decoder is ready for playback, false otherwise.
73  virtual bool IsValid() = 0;
74  /// @brief Gets the encoding supported by this decoder.
75  /// @return Returns an @ref Audio::Encoding value representing the encoding supported by this decoder.
76  virtual Audio::Encoding GetEncoding() const = 0;
77  /// @brief Gets whether or not seeking is supported.
78  /// @return Returns true if you can skip to a specific point in the stream, false if you are stuck waiting.
79  virtual bool IsSeekingSupported() = 0;
80  /// @brief Gets the Bit Configuration used to decode the audio stream.
81  /// @return Returns the Bit Configuration currently being used to decode this stream.
82  virtual Audio::BitConfig GetBitConfiguration() const = 0;
83  /// @brief Gets the frequency used to decode the audio stream.
84  /// @return Returns the frequency (or sample rate) currently being used to decode this stream.
85  virtual UInt32 GetFrequency() const = 0;
86  /// @brief Gets the stream being decoded.
87  /// @return Returns a shared pointer to the DataStream being decoded.
88  virtual Resource::DataStreamPtr GetStream() const = 0;
89 
90  /// @brief Gets the sample size based on the decoders current configuration.
91  /// @return Returns a UInt32 representing the size of a single sample from the underlying stream.
92  virtual UInt32 GetSampleSize() const
93  {
94  switch(this->GetBitConfiguration())
95  {
96  case Mezzanine::Audio::BC_8Bit_Mono: return 1; break;
97  case Mezzanine::Audio::BC_8Bit_Stereo: return 2; break;
98  case Mezzanine::Audio::BC_16Bit_Mono: return 2; break;
99  case Mezzanine::Audio::BC_16Bit_Stereo: return 4; break;
100  case Mezzanine::Audio::BC_24Bit_Mono: return 3; break;
101  case Mezzanine::Audio::BC_24Bit_Stereo: return 6; break;
102  default: return -1;
103  }
104  }
105 
106  /// @brief Sets the position (in bytes) of the stream.
107  /// @param Position The number of bytes to move(if relative) or the actual position in the stream to set.
108  /// @param Relative Whether or not to move from the current position. If false this will set from the beginning.
109  /// @return Returns true if the position was successfully set, false otherwise.
110  virtual bool SetPosition(Int32 Position, bool Relative) = 0;
111  /// @brief Moves the current time position in the stream.
112  /// @param Seconds The position in seconds to move to in the stream.
113  /// @param Relative Whether or not to move from the current position. If false this will seek from the beginning.
114  /// @return Returns true if the position was successfully moved, false otherwise.
115  virtual bool Seek(const Real Seconds, bool Relative) = 0;
116 
117  /// @brief Reads from the audio stream and writes what is read to a buffer.
118  /// @param Output The buffer to write to when reading the audio stream.
119  /// @param Amount The number of bytes desired to be read from the audio stream.
120  /// @return Returns the number of bytes successfully read from the audio stream.
121  virtual UInt32 ReadAudioData(void* Output, UInt32 Amount) = 0;
122 
123  ///////////////////////////////////////////////////////////////////////////////
124  // Stream Stats
125 
126  /// @brief Gets the length of the stream in seconds.
127  /// @return Returns the total amount of time needed to playback the sound in seconds.
128  virtual Real GetTotalTime() const = 0;
129  /// @brief Gets the current time position in the stream.
130  /// @return Returns the current position in the stream in seconds.
131  virtual Real GetCurrentTime() const = 0;
132  /// @brief Gets the size of the decoded audio source in use.
133  /// @return Returns the size of the decoded audio source.
134  virtual UInt32 GetTotalSize() const = 0;
135  /// @brief Gets the size of the encoded audio source in use.
136  /// @return Returns the size of the encoded audio source.
137  virtual UInt32 GetCompressedSize() const = 0;
138  /// @brief Gets the sounds current position in the decoded audio source.
139  /// @return Returns the current position in the decoded audio source in bytes.
140  virtual UInt32 GetCurrentPosition() const = 0;
141  /// @brief Gets the sounds current position in the encoded audio source.
142  /// @return Returns the current position in the encoded audio source in bytes.
143  virtual UInt32 GetCurrentCompressedPosition() const = 0;
144  };//iDecoder
145  }//Audio
146 }//Mezzanine
147 
148 #endif