Spinning Topp Logo BlackTopp Studios
inc
decoder.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 _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  protected:
62  /// @brief Clears EoF and Fail bits from the stream if they are present.
63  /// @remarks This should only check for the EoF bit, and if found clear EoF and Fail bits. Both of these
64  /// can be encountered when the stream reaches EoF and isn't an error condition when streaming audio.
65  virtual void ClearStreamErrors() = 0;
66  public:
67  /// @brief Class constructor.
68  iDecoder() { }
69  /// @brief Class destructor.
70  virtual ~iDecoder() { }
71 
72  ///////////////////////////////////////////////////////////////////////////////
73  // Utility
74 
75  /// @brief Gets whether or not the decoder is ready to be used.
76  /// @note On failure the issue likely lies with the stream being an improper format/encoding.
77  /// @return Returns true if this decoder is ready for playback, false otherwise.
78  virtual Boole IsValid() = 0;
79  /// @brief Gets the encoding supported by this decoder.
80  /// @return Returns an @ref Audio::Encoding value representing the encoding supported by this decoder.
81  virtual Audio::Encoding GetEncoding() const = 0;
82  /// @brief Gets whether or not seeking is supported.
83  /// @return Returns true if you can skip to a specific point in the stream, false if you are stuck waiting.
84  virtual Boole IsSeekingSupported() = 0;
85  /// @brief Gets the Bit Configuration used to decode the audio stream.
86  /// @return Returns the Bit Configuration currently being used to decode this stream.
87  virtual Audio::BitConfig GetBitConfiguration() const = 0;
88  /// @brief Gets the frequency used to decode the audio stream.
89  /// @return Returns the frequency (or sample rate) currently being used to decode this stream.
90  virtual UInt32 GetFrequency() const = 0;
91  /// @brief Gets the stream being decoded.
92  /// @return Returns a shared pointer to the DataStream being decoded.
93  virtual Resource::DataStreamPtr GetStream() const = 0;
94  /// @brief Checks to see if the decode has reached the end of the stream.
95  /// @remarks Multiple decoders may use the same stream, and when this happens the actual underlying stream position
96  /// may be altered multiple times to varying positions in the stream. Because of this, checking the underlying
97  /// stream directly may not give you an accurate idea of if this decoders point in the stream has reached it's end.
98  /// That is what this function is meant to address.
99  /// @return Returns true if all of the data in the stream has been decoded, false otherwise.
100  virtual Boole IsEndOfStream() const = 0;
101 
102  /// @brief Gets the sample size based on the decoders current configuration.
103  /// @return Returns a UInt32 representing the size of a single sample from the underlying stream.
104  virtual UInt32 GetSampleSize() const
105  {
106  switch(this->GetBitConfiguration())
107  {
108  case Mezzanine::Audio::BC_8Bit_Mono: return 1; break;
109  case Mezzanine::Audio::BC_8Bit_Stereo: return 2; break;
110  case Mezzanine::Audio::BC_16Bit_Mono: return 2; break;
111  case Mezzanine::Audio::BC_16Bit_Stereo: return 4; break;
112  case Mezzanine::Audio::BC_24Bit_Mono: return 3; break;
113  case Mezzanine::Audio::BC_24Bit_Stereo: return 6; break;
114  default: return -1;
115  }
116  }
117 
118  /// @brief Sets the position (in bytes) of the stream.
119  /// @param Position The number of bytes to move(if relative) or the actual position in the stream to set.
120  /// @param Relative Whether or not to move from the current position. If false this will set from the beginning.
121  /// @return Returns true if the position was successfully set, false otherwise.
122  virtual Boole SetPosition(Int32 Position, const Boole Relative) = 0;
123  /// @brief Moves the current time position in the stream.
124  /// @param Seconds The position in seconds to move to in the stream.
125  /// @param Relative Whether or not to move from the current position. If false this will seek from the beginning.
126  /// @return Returns true if the position was successfully moved, false otherwise.
127  virtual Boole Seek(const Real Seconds, const Boole Relative) = 0;
128 
129  /// @brief Reads from the audio stream and writes what is read to a buffer.
130  /// @param Output The buffer to write to when reading the audio stream.
131  /// @param Amount The number of bytes desired to be read from the audio stream.
132  /// @return Returns the number of bytes successfully read from the audio stream.
133  virtual UInt32 ReadAudioData(void* Output, UInt32 Amount) = 0;
134 
135  ///////////////////////////////////////////////////////////////////////////////
136  // Stream Stats
137 
138  /// @brief Gets the length of the stream in seconds.
139  /// @return Returns the total amount of time needed to playback the sound in seconds.
140  virtual Real GetTotalTime() const = 0;
141  /// @brief Gets the current time position in the stream.
142  /// @return Returns the current position in the stream in seconds.
143  virtual Real GetCurrentTime() const = 0;
144  /// @brief Gets the size of the decoded audio source in use.
145  /// @return Returns the size of the decoded audio source.
146  virtual UInt32 GetTotalSize() const = 0;
147  /// @brief Gets the size of the encoded audio source in use.
148  /// @return Returns the size of the encoded audio source.
149  virtual UInt32 GetCompressedSize() const = 0;
150  /// @brief Gets the sounds current position in the decoded audio source.
151  /// @return Returns the current position in the decoded audio source in bytes.
152  virtual UInt32 GetCurrentPosition() const = 0;
153  /// @brief Gets the sounds current position in the encoded audio source.
154  /// @return Returns the current position in the encoded audio source in bytes.
155  virtual UInt32 GetCurrentCompressedPosition() const = 0;
156  };//iDecoder
157  }//Audio
158 }//Mezzanine
159 
160 #endif
int32_t Int32
An 32-bit integer.
Definition: datatypes.h:124
This is an interface class for the decoding of audio from a stream.
Definition: decoder.h:59
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 UInt32 GetTotalSize() const =0
Gets the size of the decoded audio source in use.
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 void ClearStreamErrors()=0
Clears EoF and Fail bits from the stream if they are present.
virtual Boole IsSeekingSupported()=0
Gets whether or not seeking is supported.
virtual Boole SetPosition(Int32 Position, const Boole Relative)=0
Sets the position (in bytes) of the stream.
float Real
A Datatype used to represent a real floating point number.
Definition: datatypes.h:141
virtual ~iDecoder()
Class destructor.
Definition: decoder.h:70
virtual Audio::BitConfig GetBitConfiguration() const =0
Gets the Bit Configuration used to decode the audio stream.
virtual Real GetCurrentTime() const =0
Gets the current time position in the stream.
iDecoder()
Class constructor.
Definition: decoder.h:68
virtual UInt32 ReadAudioData(void *Output, UInt32 Amount)=0
Reads from the audio stream and writes what is read to a buffer.
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 UInt32 GetFrequency() const =0
Gets the frequency used to decode the audio stream.
virtual Resource::DataStreamPtr GetStream() const =0
Gets the stream being decoded.
virtual Audio::Encoding GetEncoding() const =0
Gets the encoding supported by this decoder.
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 Boole Seek(const Real Seconds, const Boole Relative)=0
Moves the current time position in the stream.
virtual Boole IsEndOfStream() const =0
Checks to see if the decode has reached the end of the stream.
virtual UInt32 GetSampleSize() const
Gets the sample size based on the decoders current configuration.
Definition: decoder.h:104
Declaration of DataStream.
virtual Boole IsValid()=0
Gets whether or not the decoder is ready to be used.
BitConfig
Used to describe the different bit configurations supported by this audio system. ...