| 1 |
/*************************************************************************** |
| 2 |
* Copyright (C) 2005-2019 by the FIFE team * |
| 3 |
* http://www.fifengine.net * |
| 4 |
* This file is part of FIFE. * |
| 5 |
* * |
| 6 |
* FIFE is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Lesser General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2.1 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * |
| 14 |
* Lesser General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Lesser General Public * |
| 17 |
* License along with this library; if not, write to the * |
| 18 |
* Free Software Foundation, Inc., * |
| 19 |
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
| 20 |
***************************************************************************/ |
| 21 |
|
| 22 |
#ifndef FIFE_SOUNDDECODER_H |
| 23 |
#define FIFE_SOUNDDECODER_H |
| 24 |
|
| 25 |
// Standard C++ library includes |
| 26 |
|
| 27 |
// Platform specific includes |
| 28 |
|
| 29 |
// 3rd party library includes |
| 30 |
|
| 31 |
// FIFE includes |
| 32 |
// These includes are split up in two parts, separated by one empty line |
| 33 |
// First block: files included from the FIFE root src directory |
| 34 |
// Second block: files included from the same folder |
| 35 |
|
| 36 |
#include "soundconfig.h" |
| 37 |
#include "fife_openal.h" |
| 38 |
|
| 39 |
namespace FIFE { |
| 40 |
|
| 41 |
class SoundDecoder { |
| 42 |
public: |
| 43 |
|
| 44 |
virtual ~SoundDecoder() {} |
| 45 |
|
| 46 |
/** Returns the decoded length of the file in bytes |
| 47 |
*/ |
| 48 |
virtual uint64_t getDecodedLength() const = 0; |
| 49 |
|
| 50 |
/** A stream or not? |
| 51 |
* |
| 52 |
* The decision if we decode the whole audio file in one buffer or use a |
| 53 |
* kind of streaming depends on the value of MAX_KEEP_IN_MEM from |
| 54 |
* soundconfig.h |
| 55 |
* |
| 56 |
* @return Return true for a streaming decoder, false if the sound is |
| 57 |
* decoded in one buffer |
| 58 |
*/ |
| 59 |
bool needsStreaming() const { return getDecodedLength() > MAX_KEEP_IN_MEM; } |
| 60 |
|
| 61 |
/** Sets the current position in the file (in bytes) |
| 62 |
* |
| 63 |
* @return True, if the positioning was successful |
| 64 |
*/ |
| 65 |
virtual bool setCursor(uint64_t pos) = 0; |
| 66 |
|
| 67 |
/** Request the decoding of the next part of the stream. |
| 68 |
* |
| 69 |
* @param length The length of the decoded part |
| 70 |
* @return 0 (False), if decoding was successful |
| 71 |
*/ |
| 72 |
virtual bool decode(uint64_t length) = 0; |
| 73 |
|
| 74 |
/** Returns the next decoded buffer. |
| 75 |
* |
| 76 |
* The length of the buffer is returned by getBufferSize(). |
| 77 |
*/ |
| 78 |
virtual void* getBuffer() const = 0; |
| 79 |
|
| 80 |
/** Returns the byte-size of the buffer returned by getBuffer(). |
| 81 |
*/ |
| 82 |
virtual uint64_t getBufferSize() = 0; |
| 83 |
|
| 84 |
/** Releases the buffer returned by getBuffer() |
| 85 |
*/ |
| 86 |
virtual void releaseBuffer() = 0; |
| 87 |
|
| 88 |
/** Tests if the audio data is stereo data or mono. |
| 89 |
* |
| 90 |
* @return Returns true if the audio data is stereo, false if mono. |
| 91 |
*/ |
| 92 |
bool isStereo() const { |
| 93 |
return m_isstereo; |
| 94 |
} |
| 95 |
|
| 96 |
/** Returns the openAL-Format of the audio file |
| 97 |
*/ |
| 98 |
ALenum getALFormat() const { |
| 99 |
if (m_isstereo) { |
| 100 |
return m_is8bit ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16; |
| 101 |
} else { |
| 102 |
return m_is8bit ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16; |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
/** Returns the bit resolution |
| 107 |
*/ |
| 108 |
int16_t getBitResolution() const { |
| 109 |
return m_is8bit ? 8 : 16; |
| 110 |
} |
| 111 |
|
| 112 |
/** Returns the sample rate |
| 113 |
*/ |
| 114 |
uint64_t getSampleRate() const{ |
| 115 |
return m_samplerate; |
| 116 |
} |
| 117 |
|
| 118 |
protected: |
| 119 |
bool m_isstereo; |
| 120 |
bool m_is8bit; |
| 121 |
uint64_t m_samplerate; |
| 122 |
}; |
| 123 |
} |
| 124 |
|
| 125 |
#endif |